class MultiTouchInput: current_state = 0 current_state_counter = [0] * 12 touch_timer = None def __init__(self, ipcon, key_queue): if not config.UID_MULTI_TOUCH_BRICKLET: print("Not Configured: Multi Touch") return self.key_queue = key_queue self.ipcon = ipcon self.mt = MultiTouch(config.UID_MULTI_TOUCH_BRICKLET, self.ipcon) try: self.mt.get_electrode_sensitivity() print("Found: Multi Touch ({0})").format( config.UID_MULTI_TOUCH_BRICKLET) except: print("Not Found: Multi Touch ({0})").format( config.UID_MULTI_TOUCH_BRICKLET) return self.mt.set_electrode_sensitivity(100) self.mt.register_callback(self.mt.CALLBACK_TOUCH_STATE, self.cb_touch_state) self.touch_timer = RepeatedTimer(0.1, self.touch_tick) def stop(self): if self.touch_timer is not None: self.touch_timer.stop() def state_to_queue(self, state): for item in config.KEYMAP_MULTI_TOUCH.items(): if state & (1 << item[0]): self.key_queue.put(item[1]) def touch_tick(self): state = 0 for i in range(12): if self.current_state & (1 << i): self.current_state_counter[i] += 1 else: self.current_state_counter[i] = 0 if self.current_state_counter[i] > 5: state |= (1 << i) if state != 0: self.state_to_queue(state) def cb_touch_state(self, state): changed_state = self.current_state ^ state self.current_state = state self.state_to_queue(changed_state & self.current_state)
class MultiTouchInput: current_state = 0 current_state_counter = [0]*12 touch_timer = None def __init__(self, ipcon, key_queue): if not config.UID_MULTI_TOUCH_BRICKLET: print("Not Configured: Multi Touch") return self.key_queue = key_queue self.ipcon = ipcon self.mt = MultiTouch(config.UID_MULTI_TOUCH_BRICKLET, self.ipcon) try: self.mt.get_electrode_sensitivity() print("Found: Multi Touch ({0})").format(config.UID_MULTI_TOUCH_BRICKLET) except: print("Not Found: Multi Touch ({0})").format(config.UID_MULTI_TOUCH_BRICKLET) return self.mt.set_electrode_sensitivity(100) self.mt.register_callback(self.mt.CALLBACK_TOUCH_STATE, self.cb_touch_state) self.touch_timer = RepeatedTimer(0.1, self.touch_tick) def stop(self): if self.touch_timer is not None: self.touch_timer.stop() def state_to_queue(self, state): for item in config.KEYMAP_MULTI_TOUCH.items(): if state & (1 << item[0]): self.key_queue.put(item[1]) def touch_tick(self): state = 0 for i in range(12): if self.current_state & (1 << i): self.current_state_counter[i] += 1 else: self.current_state_counter[i] = 0 if self.current_state_counter[i] > 5: state |= (1 << i) if state != 0: self.state_to_queue(state) def cb_touch_state(self, state): changed_state = self.current_state ^ state self.current_state = state self.state_to_queue(changed_state & self.current_state)