Example #1
0
 def cmd_fn(self, fn):
     logging.debug("cmd %s" % fn)
     if CMD_PORT_MAP.has_key(fn):
         port = CMD_PORT_MAP[fn]
         GPIO.output(port, ~GPIO.input(port) & 0x1 ) # toggle
Example #2
0
def status():
    r = dict(map(lambda (cmd, port): (cmd, GPIO.input(port)), CMD_PORT_MAP.iteritems() ))
    #logging.debug(r)
    return r
Example #3
0
 def cmd_direction(self, direction):
     logging.debug("cmd %s" % direction)
     if CMD_PORT_MAP.has_key(direction):
         # run blink in background
         Thread(target=blink, args=(CMD_PORT_MAP[direction],)).start()
Example #4
0
# Logging Configuration
FORMAT = '%(asctime)-15s %(message)s'
logging.basicConfig(format=FORMAT, level=logging.DEBUG)


# use MOCK if not running on rpio
if utils.isRPI():
    import RPi.GPIO as GPIO
else:
    import mock as GPIO

# init GPIO
GPIO.setmode(GPIO.BCM)
# init output ports
for (cmd, port) in CMD_PORT_MAP.iteritems():
    logging.debug("setup port %2d for cmd %s" % (port, cmd))
    GPIO.setup(port,  GPIO.OUT)


#return curren pin status
def status():
    r = dict(map(lambda (cmd, port): (cmd, GPIO.input(port)), CMD_PORT_MAP.iteritems() ))
    #logging.debug(r)
    return r


def blink(port):
    for i in range(3):
        GPIO.output(port, 1)
        time.sleep(0.05)