Beispiel #1
0
    def execute(self):
        self.green_led = gpio.gpio(48)
        self.green_led.setDirectionValue('out')
        self.green_led.setGpioValue(0)

        self.red_led = gpio.gpio(49)
        self.red_led.setDirectionValue('out')
        self.red_led.setGpioValue(0)

        self.yellow_led = gpio.gpio(60)
        self.yellow_led.setDirectionValue('out')
        self.yellow_led.setGpioValue(0)

        service_uuid = "00001101-0000-1000-8000-00805F9B34FB"

        server_sock = BluetoothSocket(RFCOMM)
        server_sock.bind(("", PORT_ANY))
        server_sock.listen(1)

        port = server_sock.getsockname()[1]

        advertise_service(server_sock,
                          "PerkyBlue",
                          service_id=service_uuid,
                          service_classes=[service_uuid, SERIAL_PORT_CLASS],
                          profiles=[SERIAL_PORT_PROFILE])

        print("awaiting RFCOMM connection on channel:%d" % port)

        client_sock, client_info = server_sock.accept()
        print("accepted connection from:", client_info)

        try:
            while True:
                data = client_sock.recv(1024).strip()
                if len(data) == 0: break
                print("received [%s]" % data)
                client_sock.sendall('OK')

                self.toggleLed(data)
        except IOError:
            pass

        print("disconnected")

        client_sock.close()
        server_sock.close()
        print("all done")
Beispiel #2
0
    def __init__(self, ui, dbgio):
        self.ui = ui
        self.dbgio = dbgio
        self.device = vendor.get_device(self.ui, soc_name)
        self.dbgio.connect(self.device.cpu_info.name, "swd")
        self.cpu = cortexm.cortexm(self, ui, self.dbgio, self.device)
        self.device.bind_cpu(self.cpu)
        self.mem = mem.mem(self.cpu)
        self.flash = flash.flash(flash_driver.stm32f0xx(self.device), self.device, self.mem)
        gpio_drv = gpio_driver.drv(self.device, gpio_cfg)
        self.gpio = gpio.gpio(gpio_drv)
        self.i2c = i2c.i2c(i2c_driver.gpio(gpio_drv, "PB6", "PB7"))

        self.menu_root = (
            ("cpu", self.cpu.menu, "cpu functions"),
            ("da", self.cpu.cmd_disassemble, cortexm.help_disassemble),
            ("debugger", self.dbgio.menu, "debugger functions"),
            ("exit", self.cmd_exit),
            ("flash", self.flash.menu, "flash functions"),
            ("go", self.cpu.cmd_go),
            ("gpio", self.gpio.menu, "gpio functions"),
            ("halt", self.cpu.cmd_halt),
            ("help", self.ui.cmd_help),
            ("history", self.ui.cmd_history, cli.history_help),
            ("i2c", self.i2c.menu, "i2c functions"),
            ("map", self.device.cmd_map),
            ("mem", self.mem.menu, "memory functions"),
            ("program", self.flash.cmd_program, flash.help_program),
            ("regs", self.cmd_regs, soc.help_regs),
            ("vtable", self.cpu.cmd_vtable),
        )

        self.ui.cli.set_root(self.menu_root)
        self.set_prompt()
        self.dbgio.cmd_info(self.ui, None)
Beispiel #3
0
    def __init__(self):
        interrupt = 157
        tx_port = 138
        rx_port = 139

        spi.setup("/dev/spidev4.0")

        # setup the TR switch
        self.tx_ant = gpio(tx_port, "out")
        self.tx_ant.write(0)

        self.rx_ant = gpio(rx_port, "out")
        self.rx_ant.write(0)

        # setup irq line
        self.irq = gpio(interrupt, "in")
    def __init__(self):
        interrupt = 157
        tx_port = 138
        rx_port = 139

        spi.setup("/dev/spidev4.0")

        # setup the TR switch
        self.tx_ant = gpio(tx_port, "out")
        self.tx_ant.write(0)

        self.rx_ant = gpio(rx_port, "out")
        self.rx_ant.write(0)

        # setup irq line
        self.irq = gpio(interrupt, "in")
Beispiel #5
0
    def __init__(self, ui, dbgio):
        self.ui = ui
        self.dbgio = dbgio
        self.device = vendor.get_device(self.ui, soc_name)
        self.dbgio.connect(self.device.cpu_info.name, 'swd')
        self.cpu = cortexm.cortexm(self, ui, self.dbgio, self.device)
        self.device.bind_cpu(self.cpu)
        self.mem = mem.mem(self.cpu)
        self.flash = flash.flash(flash_driver.stm32l4x2(self.device),
                                 self.device, self.mem)
        gpio_drv = (gpio_driver.drv(self.device, gpio_cfg))
        self.gpio = gpio.gpio(gpio_drv)

        self.menu_root = (
            ('cpu', self.cpu.menu, 'cpu functions'),
            ('da', self.cpu.cmd_disassemble, cortexm.help_disassemble),
            ('debugger', self.dbgio.menu, 'debugger functions'),
            ('exit', self.cmd_exit),
            ('flash', self.flash.menu, 'flash functions'),
            ('go', self.cpu.cmd_go),
            ('gpio', self.gpio.menu, 'gpio functions'),
            ('halt', self.cpu.cmd_halt),
            ('help', self.ui.cmd_help),
            ('history', self.ui.cmd_history, cli.history_help),
            ('map', self.device.cmd_map),
            ('mem', self.mem.menu, 'memory functions'),
            ('program', self.flash.cmd_program, flash.help_program),
            ('regs', self.cmd_regs, soc.help_regs),
            ('vtable', self.cpu.cmd_vtable),
        )

        self.ui.cli.set_root(self.menu_root)
        self.set_prompt()
        self.dbgio.cmd_info(self.ui, None)
Beispiel #6
0
  def __init__(self, ui, dbgio):
    self.ui = ui
    self.dbgio = dbgio
    self.device = vendor.get_device(self.ui, soc_name)
    self.dbgio.connect(self.device.cpu_info.name, 'swd')
    self.cpu = cortexm.cortexm(self, ui, self.dbgio, self.device)
    self.device.bind_cpu(self.cpu)
    self.mem = mem.mem(self.cpu)
    self.flash = flash.flash(flash_driver.stm32f0xx(self.device), self.device, self.mem)
    gpio_drv = (gpio_driver.drv(self.device, gpio_cfg))
    self.gpio = gpio.gpio(gpio_drv)

    self.menu_root = (
      ('cpu', self.cpu.menu, 'cpu functions'),
      ('da', self.cpu.cmd_disassemble, cortexm.help_disassemble),
      ('debugger', self.dbgio.menu, 'debugger functions'),
      ('exit', self.cmd_exit),
      ('flash', self.flash.menu, 'flash functions'),
      ('go', self.cpu.cmd_go),
      ('gpio', self.gpio.menu, 'gpio functions'),
      ('halt', self.cpu.cmd_halt),
      ('help', self.ui.cmd_help),
      ('history', self.ui.cmd_history, cli.history_help),
      ('map', self.device.cmd_map),
      ('mem', self.mem.menu, 'memory functions'),
      ('program', self.flash.cmd_program, flash.help_program),
      ('regs', self.cmd_regs, soc.help_regs),
      ('vtable', self.cpu.cmd_vtable),
    )

    self.ui.cli.set_root(self.menu_root)
    self.set_prompt()
    self.dbgio.cmd_info(self.ui, None)
Beispiel #7
0
def main():
    g = gpio.gpio()
    w = watchdog.watchdog(gpio=g)

    while True:
        w.pet()
        common.msleep(10 * 1000)
Beispiel #8
0
def clockstart(board = 'blinkt'):	
	"""Main:clock7"""
	print "main:- Clock7.4 - alarm clock code."
	print 'Board selected:', board
	if board == 'slice':
		myGpio=gpio.gpio(board)
	elif board == 'ledborg':
		myGpio=gpio.Ledborg()
	elif board == 'blinkt':
		myGpio = blinktcontrol.Blinktcontrol()
	addr = '0'
#	addr = myGpio.get_ip_address()
	if addr is not '0':
		last_byte = addr.split('.')[3]
		print 'IP: ',addr,last_byte
		logging.info('IP address: '+addr)
		myGpio.writeleds(last_byte)
	else:
		logging.info('Zero IP address')
		myGpio.flash_error()
	myGpio.sequenceleds()
	myAlarmTime=alarmtime.AlarmTime()
	myAlarmTime.read()
	steptime = 30
	holdtime = 2000					# seconds
	holdtime = myAlarmTime.return_holdtime()
	print 'Entering main loop'
	while True:
		if(myAlarmTime.check()):
#			Parameters below are: delay, holdtime
			myGpio.sequenceleds(steptime,holdtime)	# this is the alarm
		time.sleep(30)				# check every 30 seconds
Beispiel #9
0
def main():
    g = gpio.gpio()
    g.setPinMode(PTT_PIN, gpio.GPIO.OUT)

    pttMode = 0
    if len(sys.argv) > 1:
        pttMode = sys.argv[1]

    if pttMode == "1":
        g.setHigh(PTT_PIN)
    else:
        g.setLow(PTT_PIN)
Beispiel #10
0
    def __init__(self, ui, dbgio):
        self.ui = ui
        self.dbgio = dbgio
        self.device = vendor.get_device(self.ui, soc_name)
        # add the 8MiB SDRAM
        self.device.insert(
            soc.make_peripheral('sdram', 0xc0000000, 8 << 20, None,
                                'external sdram'))
        self.dbgio.connect(self.device.cpu_info.name, 'swd')
        self.cpu = cortexm.cortexm(self, ui, self.dbgio, self.device)
        self.device.bind_cpu(self.cpu)
        self.mem = mem.mem(self.cpu)
        self.flash = flash.flash(flash_driver.sdrv(self.device), self.device,
                                 self.mem)
        gpio_drv = (gpio_driver.drv(self.device, gpio_cfg))
        self.gpio = gpio.gpio(gpio_drv)
        self.i2c1 = i2c.i2c(i2c_driver.bitbang(gpio_drv, 'PB8', 'PB9'))
        self.i2c3 = i2c.i2c(i2c_driver.bitbang(gpio_drv, 'PH7', 'PH8'))
        # setup the rtt client
        ram = self.device.sram
        self.rtt = rtt.rtt(self.cpu, mem.region('ram', ram.address, ram.size))

        self.menu_root = (
            ('cpu', self.cpu.menu, 'cpu functions'),
            ('da', self.cpu.cmd_disassemble, cortexm.help_disassemble),
            ('debugger', self.dbgio.menu, 'debugger functions'),
            ('exit', self.cmd_exit),
            ('flash', self.flash.menu, 'flash functions'),
            ('go', self.cpu.cmd_go),
            ('gpio', self.gpio.menu, 'gpio functions'),
            ('halt', self.cpu.cmd_halt),
            ('help', self.ui.cmd_help),
            ('history', self.ui.cmd_history, cli.history_help),
            ('i2c1', self.i2c1.menu, 'i2c1 functions'),
            ('i2c3', self.i2c3.menu, 'i2c3 functions'),
            ('map', self.device.cmd_map),
            ('mem', self.mem.menu, 'memory functions'),
            ('program', self.flash.cmd_program, flash.help_program),
            ('regs', self.cmd_regs, soc.help_regs),
            ('rtt', self.rtt.menu, 'rtt client functions'),
            ('vtable', self.cpu.cmd_vtable),
        )

        self.ui.cli.set_root(self.menu_root)
        self.set_prompt()
        self.dbgio.cmd_info(self.ui, None)
Beispiel #11
0
    def __init__(self, ui, dbgio):
        self.ui = ui
        self.dbgio = dbgio
        self.device = vendor.get_device(self.ui, soc_name)
        self.dbgio.connect(self.device.cpu_info.name, 'swd')
        self.cpu = cortexm.cortexm(self, ui, self.dbgio, self.device)
        self.device.bind_cpu(self.cpu)
        self.mem = mem.mem(self.cpu)
        self.flash = flash.flash(flash_driver.sdrv(self.device), self.device,
                                 self.mem)
        gpio_drv = (gpio_driver.drv(self.device, gpio_cfg))
        self.gpio = gpio.gpio(gpio_drv)
        self.i2c = i2c.i2c(i2c_driver.gpio(gpio_drv, 'PB6', 'PB9'))
        self.dac = dac.cs43l22(self.i2c, 0x94, self.dac_reset)
        # setup the rtt client
        ram = self.device.sram
        self.rtt = rtt.rtt(self.cpu, mem.region('ram', ram.address, ram.size))
        # setup the gdb server
        self.gdb = gdb.gdb(self.cpu)

        self.menu_root = (
            ('cpu', self.cpu.menu, 'cpu functions'),
            ('da', self.cpu.cmd_disassemble, cortexm.help_disassemble),
            ('dac', self.dac.menu, 'dac functions'),
            ('debugger', self.dbgio.menu, 'debugger functions'),
            ('exit', self.cmd_exit),
            ('flash', self.flash.menu, 'flash functions'),
            ('gdb', self.gdb.run),
            ('go', self.cpu.cmd_go),
            ('gpio', self.gpio.menu, 'gpio functions'),
            ('halt', self.cpu.cmd_halt),
            ('help', self.ui.cmd_help),
            ('history', self.ui.cmd_history, cli.history_help),
            ('i2c', self.i2c.menu, 'i2c functions'),
            ('map', self.device.cmd_map),
            ('mem', self.mem.menu, 'memory functions'),
            ('program', self.flash.cmd_program, flash.help_program),
            ('regs', self.cmd_regs, soc.help_regs),
            ('rtt', self.rtt.menu, 'rtt client functions'),
            ('vtable', self.cpu.cmd_vtable),
        )

        self.ui.cli.set_root(self.menu_root)
        self.set_prompt()
        self.dbgio.cmd_info(self.ui, None)
Beispiel #12
0
  def __init__(self, ui, dbgio):
    self.ui = ui
    self.dbgio = dbgio
    self.device = vendor.get_device(self.ui, soc_name)
    self.dbgio.connect(self.device.cpu_info.name, 'swd')
    self.cpu = cortexm.cortexm(self, ui, self.dbgio, self.device)
    self.device.bind_cpu(self.cpu)
    self.mem = mem.mem(self.cpu)
    self.flash = flash.flash(flash_driver.sdrv(self.device), self.device, self.mem)
    gpio_drv = (gpio_driver.drv(self.device, gpio_cfg))
    self.gpio = gpio.gpio(gpio_drv)
    self.i2c = i2c.i2c(i2c_driver.gpio(gpio_drv, 'PB6', 'PB9'))
    self.dac = dac.cs43l22(self.i2c, 0x94, self.dac_reset)
    # setup the rtt client
    ram = self.device.sram
    self.rtt = rtt.rtt(self.cpu, mem.region('ram', ram.address, ram.size))
    # setup the gdb server
    self.gdb = gdb.gdb(self.cpu)

    self.menu_root = (
      ('cpu', self.cpu.menu, 'cpu functions'),
      ('da', self.cpu.cmd_disassemble, cortexm.help_disassemble),
      ('dac', self.dac.menu, 'dac functions'),
      ('debugger', self.dbgio.menu, 'debugger functions'),
      ('exit', self.cmd_exit),
      ('flash', self.flash.menu, 'flash functions'),
      ('gdb', self.gdb.run),
      ('go', self.cpu.cmd_go),
      ('gpio', self.gpio.menu, 'gpio functions'),
      ('halt', self.cpu.cmd_halt),
      ('help', self.ui.cmd_help),
      ('history', self.ui.cmd_history, cli.history_help),
      ('i2c', self.i2c.menu, 'i2c functions'),
      ('map', self.device.cmd_map),
      ('mem', self.mem.menu, 'memory functions'),
      ('program', self.flash.cmd_program, flash.help_program),
      ('regs', self.cmd_regs, soc.help_regs),
      ('rtt', self.rtt.menu, 'rtt client functions'),
      ('vtable', self.cpu.cmd_vtable),
    )

    self.ui.cli.set_root(self.menu_root)
    self.set_prompt()
    self.dbgio.cmd_info(self.ui, None)
Beispiel #13
0
        def _run():
            (hi,low) = (self._hi_time, self._low_time)
            def msg_or_timeout(duration=None):
                try:
                    start = time.time()
                    msg = self._messages.get(timeout=duration)
                    if msg is None:
                        raise StopIteration
                    elapsed = time.time() - start
                    return (msg, elapsed)
                except queue.Empty:
                    return ((hi, low), duration)

            with gpio(self.pin_num, "out") as pin:
                try:
                    while True:
                        if hi < 0:     # off until new message arrives
                            pin.set(False)
                            ((hi,low),_) = msg_or_timeout()
                        elif hi == 0:   # on until new message arrives
                            pin.set(True)
                            ((hi,low),_) = msg_or_timeout()
                        else:
                            pin.set(True)

                            ((hi,low),elapsed) = msg_or_timeout(hi)
                            while ( hi > 0 and hi > elapsed):
                                ((hi,low),elapsed2) = msg_or_timeout(hi-elapsed)
                                elapsed += elapsed2
                            if hi <= 0:
                                continue

                            pin.set(False)
                            ((hi,low), elapsed) = msg_or_timeout(low)
                            while ( hi > 0 and low > 0 and low > elapsed):
                                ((hi,low),elapsed2) = msg_or_timeout(low-elapsed)
                                elapsed += elapsed2

                except StopIteration:
                    pass
Beispiel #14
0
import gpio

io = gpio.gpio()

print 'Instantiated Aardvark GPIO interface as io'

Beispiel #15
0
    def __init__(self):
        # read config
        try:
            configfile = '/proc/device-tree/hat/custom_0'
            f = open(configfile)
            self.hatconfig = json.loads(f.read())

            f.close()
        except Exception as e:
            print('failed to load', configfile, ':', e)
            print('assuming original 26 pin tinypilot')
            self.hatconfig = False

        self.config = {
            'remote': False,
            'host': 'pypilot',
            'actions': {},
            'lcd': {}
        }
        self.configfilename = os.getenv('HOME') + '/.pypilot/hat.conf'
        print('loading config file:', self.configfilename)
        try:
            file = open(self.configfilename)
            config = json.loads(file.read())
            file.close()
            for name in config:
                self.config[name] = config[name]
        except Exception as e:
            print('config failed:', e)

        self.lastpollheading = time.time()
        self.servo_timeout = time.time() + 1

        self.longsleep = 30
        self.last_msg = {}

        self.client = False
        self.lcd = lcd.LCD(self)
        self.gpio = gpio.gpio()
        self.arduino = arduino.arduino(self.hatconfig)
        self.lirc = lirc.lirc()
        self.buzzer = buzzer.buzzer(self.hatconfig)

        # keypad for lcd interface
        self.actions = []
        keypadnames = ['auto', 'menu', 'up', 'down', 'select', 'left', 'right']

        for i in range(7):
            self.actions.append(ActionKeypad(self.lcd, i, keypadnames[i]))

        # stateless actions for autopilot control
        self.actions += [
            ActionEngage(self),
            ActionPypilot(self, 'disengage', 'ap.enabled', False),
            ActionHeading(self, 1),
            ActionHeading(self, -1),
            ActionHeading(self, 2),
            ActionHeading(self, -2),
            ActionHeading(self, 10),
            ActionHeading(self, -10),
            ActionPypilot(self, 'compassmode', 'ap.mode', 'compass'),
            ActionPypilot(self, 'gpsmode', 'ap.mode', 'gps'),
            ActionPypilot(self, 'windmode', 'ap.mode', 'wind'),
            ActionTack(self, 'tackport', 'port'),
            ActionTack(self, 'tackstarboard', 'starboard')
        ]

        for action in self.actions:
            if action.name in self.config['actions']:
                action.keys = self.config['actions'][action.name]

        self.web = Web(self)
Beispiel #16
0
    def __init__(self):
        # read config
        self.config = {
            'remote': False,
            'host': '127.0.0.1',
            'actions': {},
            'pi.ir': True,
            'arduino.ir': False,
            'arduino.nmea.in': False,
            'arduino.nmea.out': False,
            'arduino.nmea.baud': 4800,
            'lcd': {}
        }
        self.configfilename = os.getenv('HOME') + '/.pypilot/hat.conf'
        print('loading config file:', self.configfilename)
        try:
            file = open(self.configfilename)
            config = pyjson.loads(file.read())
            file.close()
            for name in config:
                self.config[name] = config[name]
        except Exception as e:
            print('config failed:', e)

        try:
            configfile = '/proc/device-tree/hat/custom_0'
            f = open(configfile)
            hat_config = pyjson.loads(f.read())
            f.close()
            print('loaded device tree hat config')
            if not 'hat' in self.config or hat_config != self.config['hat']:
                self.config['hat'] = hat_config
                print('writing device tree hat to hat.conf')
                self.write_config()
        except Exception as e:
            print('failed to load', configfile, ':', e)

        if not 'hat' in self.config:
            if os.path.exists('/dev/spidev0.0'):
                print(
                    'assuming original 26 pin tinypilot with nokia5110 display'
                )
                self.config['hat'] = {
                    'lcd': {
                        'driver': 'nokia5110',
                        'port': '/dev/spidev0.0'
                    },
                    'lirc': 'gpio4'
                }
            self.write_config()

        self.servo_timeout = time.monotonic() + 1

        self.last_msg = {}
        self.last_msg['ap.enabled'] = False
        self.last_msg['ap.heading_command'] = 0

        if self.config['remote']:
            host = self.config['host']
        else:
            host = 'localhost'
        self.client = pypilotClient(host)
        self.client.registered = False
        self.watchlist = ['ap.enabled', 'ap.heading_command']
        for name in self.watchlist:
            self.client.watch(name)
        self.lcd = lcd.LCD(self)
        self.gpio = gpio.gpio()
        self.arduino = Arduino(self)

        self.poller = select.poll()
        self.poller.register(self.arduino.pipe, select.POLLIN)

        self.lirc = lircd.lirc(self.config)
        self.lirc.registered = False
        self.keytimes = {}
        self.keytimeouts = {}

        # keypad for lcd interface
        self.actions = []
        keypadnames = [
            'auto', 'menu', 'port1', 'starboard1', 'select', 'port10',
            'starboard10', 'tack', 'dodge_port', 'dodge_starboard'
        ]

        for i in range(len(keypadnames)):
            self.actions.append(ActionKeypad(self.lcd, i, keypadnames[i]))

        # stateless actions for autopilot control
        self.actions += [
            ActionEngage(self),
            ActionPypilot(self, 'disengage', 'ap.enabled', False),
            ActionHeading(self, 1),
            ActionHeading(self, -1),
            ActionHeading(self, 2),
            ActionHeading(self, -2),
            ActionHeading(self, 5),
            ActionHeading(self, -5),
            ActionHeading(self, 10),
            ActionHeading(self, -10),
            ActionPypilot(self, 'compassmode', 'ap.mode', 'compass'),
            ActionPypilot(self, 'gpsmode', 'ap.mode', 'gps'),
            ActionPypilot(self, 'windmode', 'ap.mode', 'wind'),
            ActionPypilot(self, 'center', 'servo.position', 0),
            ActionTack(self, 'tackport', 'port'),
            ActionTack(self, 'tackstarboard', 'starboard'),
            ActionNone()
        ]

        for action in self.actions:
            if action.name in self.config['actions']:
                action.keys = self.config['actions'][action.name]

        self.web = Web(self)

        def cleanup(signal_number, frame=None):
            print('got signal', signal_number, 'cleaning up', os.getpid())
            childpids = []
            processes = [self.arduino, self.web]
            for process in processes:
                if process.process:
                    childpids.append(process.process.pid)
            if signal_number == signal.SIGCHLD:
                pid = os.waitpid(-1, os.WNOHANG)
                if not pid[0] in childpids:
                    print('subprocess returned', pid, childpids)
                    # flask or system makes process at startup that dies
                    return
                print('child process', pid, childpids)
            while childpids:
                pid = childpids.pop()
                #print('kill!', pid, childpids, os.getpid())
                try:
                    os.kill(pid, signal.SIGTERM)  # get backtrace
                except ProcessLookupError:
                    pass  # ok, process is already terminated
                sys.stdout.flush()
            for process in processes:
                process.process = False
            if signal_number != 'atexit':
                raise KeyboardInterrupt  # to get backtrace on all processes
            sys.stdout.flush()

        for s in range(1, 16):
            if s != 9 and s != 13:
                signal.signal(s, cleanup)
        signal.signal(signal.SIGCHLD, cleanup)
        import atexit
        atexit.register(lambda: cleanup('atexit'))
Beispiel #17
0
"""
from __future__ import print_function

import time

import pwm
import analog
import gpio
import controller

# setup all IOs and global classes
motor = pwm.pwm(3, period=1000)
rotation_count = analog.analog(0)
motor_analog = analog.analog(1)

led = gpio.gpio(13)
led.set_high()

AREF = 5


def pwm_update(pid, target, time_limit):
    # run the system
    start_time = time.time()
    current_time = 0
    run_error = 0

    while current_time < time_limit:
        measurement = rotation_count.get_counts()
        value = -1 * pid.update(measurement)
        if value >= 1:
Beispiel #18
0
        
        rm = self.outputRegex.match( msg.topic )
        
        if rm != None:
            if ( self.on_message_obj != None):
                self.on_message_obj.trigger (rm.group(1), msg.payload)
                

        self.logger.debug("Finished")


    def __del__(self):
        self.mos.disconnect()

#
# MAIN CODE - THIS IS WHAT IS RUN IF YOU TYPE 'python pfmqtt.py' in a shell
#
if __name__ == '__main__':
    # read config file
    cfg = config.config()
    cfg.setLogging()

    conn = mqtt(cfg)
    io = gpio.gpio(cfg, conn)
    conn.on_message_obj = io

    while (True):
        conn.run()

    logging.info("Finished normally")
Beispiel #19
0
 def __init__(self, pinid, onLevel):
         self.onLevel = onLevel
         self.pinid = pinid
         self.gpio = gpio.gpio(pinid, gpio.GPIO_MODE_OUTPUT_PULLDOWN)
         self.gpio.gpioWrite(1 - self.onLevel)
Beispiel #20
0
 def opengpio(self):
     self.gpio = gpio.gpio()
     self.logger.log.info("Opened GPIO interface")
Beispiel #21
0
	def __init__(self):
		#Lets define interfaces
		self.interface_a = interface(int_select = 1)
		self.interface_b = interface(int_select = 2)
	
		#lets initizlize interface A and B into mpsse mode
		self.interface_b.reset()
		self.interface_a.reset_uart()


		#lets define gpio's
		self.led_user = gpio(self.interface_b.port_h, 7, 1, 0)

		if(self.uart_mode == False):
			self.gpio_1 = gpio(self.interface_a.port_l, 4, 1, 0)
			self.gpio_2 = gpio(self.interface_a.port_l, 5, 1, 0)

		self.gpio_mclr = gpio(self.interface_b.port_h, 0, 1, 1)
		self.gpio_boot_en = gpio(self.interface_b.port_h, 1, 1, 1)
		self.gpio_5 = gpio(self.interface_b.port_h, 2, 1, 1)
		self.gpio_6 = gpio(self.interface_b.port_h, 3, 1, 1)
		self.gpio_7 = gpio(self.interface_b.port_h, 4, 1, 1)
		self.gpio_8 = gpio(self.interface_b.port_h, 5, 1, 1)
		self.gpio_9 = gpio(self.interface_b.port_h, 6, 1, 1)

		self.sel_spi_jtag = gpio(self.interface_b.port_l, 4, 1, 0)
		self.sel_spi_uart = gpio(self.interface_b.port_l, 5, 1, 0)