Example #1
0
 def __init__(self, invoker, settings, env, callback=None, end_callback=None,
         recorder=None):
     EventProducer.__init__(self, invoker)
     self.callback = callback
     self.end_callback = end_callback
     self.st = settings
     self.env = env
     self.recorder = recorder
Example #2
0
 def _update_buttons(self, rega, regb):
     """
     compares old state of the buttons with the state that is read from registers ``rega`` and
     ``regb``. Typical values for these arguments are GPIO or INTCAP registers
     """
     with self.lock:
         now = time.time()
         values={}
         for addr in self.mcp.keys():
             ra=self.mcp[addr].i2c.readU8(rega)
             rb=self.mcp[addr].i2c.readU8(regb)
             res=(rb<<8)+ra
             #some trivial asserts, can/should be deleted
             assert(rb>=0)
             assert(rb<=255)
             assert(ra>=0)
             assert(ra<=255)
             assert(res>=0)
             assert(res<2**16)
             values[addr]=res
         binary = {}
         for addr, val in values.items():
             # converts val to binary digits
             _str='{0:0=16b}'.format(val)
             assert(len(_str)==16)
             #new state of the keys
             binary[addr] = [int(d) for d in _str]
         for key in self.keyboard.keys:
             addr, pin = key.key_object
             new_value = (binary[addr][15-pin] == 0)
             #if actual state of the key is different from the old one, and if bouncetime
             #condition allows it, fire 'up' or 'down' event on the given key
             if new_value != key.pressed and now - key._last_change >= self.bouncetime:
                 key._last_change = now
                 key.pressed = new_value
                 updown = 'down' if key.pressed else 'up'
                 EventProducer.fire_event(key, key, updown)
Example #3
0
 def __init__(self, invoker, settings, callback=None, end_callback=None):
     EventProducer.__init__(self, invoker)
     self.callback = callback
     self.end_callback = end_callback
     self.st = settings