diff --git a/flow3r_openhab/__init__.py b/flow3r_openhab/__init__.py index 0b19b11..d0f2ec2 100644 --- a/flow3r_openhab/__init__.py +++ b/flow3r_openhab/__init__.py @@ -29,6 +29,7 @@ class Flow3rOpenhabMqtt(Application): self.touch_last = [None]*10 self.touch_base = [False]*10 self.touch_tip = [False]*10 + self.touch_log = [[]]*10 def draw(self, ctx: Context) -> None: if self.state == 0: @@ -38,6 +39,14 @@ class Flow3rOpenhabMqtt(Application): ctx.rgb(0, 0, 0).rectangle(-120, -120, 240, 240).fill() ctx.rgb(0.3, 0.3, 0.3).arc(0, 0, 90, 0, 2.39, 0).arc(0, 0, 90, 2.79, 6.29, 0).stroke() ctx.rgb(0.9, 0.3, 0.1).move_to(-96, 53).line_to(-1, -43).line_to(71, 29).stroke() + if CONFIG.get('debug_touch', False): + ctx.line_width =1 + for i in range(10): + if len(self.touch_log[i]) > 0: + ctx.rgb(1, 0, 0).move_to(int(self.touch_log[i][0][1]*0.0024), -int(self.touch_log[i][0][0]*0.0024)) + for j in range(1, len(self.touch_log[i])): + ctx.line_to(int(self.touch_log[i][j][1]*0.0024), -int(self.touch_log[i][j][0]*0.0024)) + ctx.stroke() def do_connect(self): self.nic.active(True) @@ -58,22 +67,27 @@ class Flow3rOpenhabMqtt(Application): if self.state == 1: for i in range(10): if ins.captouch.petals[i].pressed: - if self.touch_begin[i] is None: - self.touch_begin[i] = ins.captouch.petals[i].position + # Ignore the first few ms of touch events, as position data appears to be unrealiable at first + if self.touch_time[i] is None: self.touch_time[i] = time.ticks_ms() - self.touch_last[i] = ins.captouch.petals[i].position - self.touch_base[i] = ins.captouch.petals[i].pads.base - if hasattr(ins.captouch.petals[i].pads, 'tip'): - self.touch_tip[i] = ins.captouch.petals[i].pads.tip - else: - self.touch_tip[i] = ins.captouch.petals[i].pads.cw or ins.captouch.petals[i].pads.ccw + elif time.ticks_ms() - self.touch_time[i] > 25: + if self.touch_begin[i] is None: + self.touch_begin[i] = ins.captouch.petals[i].position + self.touch_last[i] = ins.captouch.petals[i].position + if CONFIG.get('debug_touch', False): + self.touch_log[i].append(ins.captouch.petals[i].position) + self.touch_base[i] = ins.captouch.petals[i].pads.base + if hasattr(ins.captouch.petals[i].pads, 'tip'): + self.touch_tip[i] = ins.captouch.petals[i].pads.tip + else: + self.touch_tip[i] = ins.captouch.petals[i].pads.cw or ins.captouch.petals[i].pads.ccw else: if self.touch_begin[i] is not None: duration = time.ticks_ms() - self.touch_time[i] d_x = self.touch_last[i][0] - self.touch_begin[i][0] d_y = self.touch_last[i][1] - self.touch_begin[i][1] event = None - if abs(d_x) < 25000 and abs(d_y) < 25000: + if abs(d_x) < 15000 and abs(d_y) < 15000: if self.touch_base[i]: event = 'touch_base' elif self.touch_tip[i]: @@ -96,6 +110,8 @@ class Flow3rOpenhabMqtt(Application): self.touch_last[i] = None self.touch_base[i] = False self.touch_tip[i] = False + self.touch_log[i].clear() + gc.collect() if __name__ == "__main__":