def configureKeyboard(self, currentDevice):
        menus.clearPreviousMenu()

        print('Configuring {0}'.format(currentDevice['name']))
        device = []  # Append new controls to this list
        deviceName = currentDevice[
            'name']  # Current controller being configured

        # Second, Configure Buttons
        for button in currentDevice['buttons']:
            cmdName = button[0]
            command = button[1]
            unit = pcolor('cyan', cmdName)
            print('Press and hold GPIO pin(s) to map {0}'.format(unit),
                  end=' ')
            sys.stdout.flush()
            pressed = self.wait_for_pin()
            pressed = ', '.join(map(str, pressed))
            print('- Pins(s):', pressed)
            self.waitForButtonRelease()
            device.append((deviceName, cmdName, 'KEY', command, pressed))

        # Save to Database
        print('Saving Configuration!')
        # Delete Old Entries
        SQL.deleteDevice(deviceName)

        # Create New Entries
        SQL.createDevice(device)
        time.sleep(1)
        self.getControllerType()
    def __init__(self, args):
        self.args = args

        # Stop any running GPIOnext1 components
        subprocess.call(('systemctl', 'stop', 'gpionext1'))
        time.sleep(1)  #give time to stop processes
        try:
            active = subprocess.check_output(
                ['systemctl', 'is-active', 'gpionext1'])
        except:
            active = 'active'
        if 'active' in active:
            self.DEBUG('ERROR: systemctl stop gpionext1 has failed!')
            self.DEBUG('Please stop gpionext1 before running config!')
        else:
            self.DEBUG('gpionext1 service has been successfully stopped')

        self.DEBUG('Initializing SIGNAL HANDLERS')
        for sig in [signal.SIGTERM, signal.SIGQUIT, signal.SIGINT]:
            signal.signal(sig, self.signal_handler)

        gpio.pinPressMethods.append(self.setTimer)
        gpio.pinReleaseMethods.append(self.clearTimer)

        self.set_args()
        SQL.init()
        gpio.setupGPIO(self.args)
        self.getControllerType()
    def editCommand(self, cmd):
        # User input Prompts
        promptButton = (pcolor("fuschia", "Hold a button ") +
                        "to configure this command")
        promptCommand = (pcolor("fuschia", "Enter a command ") +
                         "to map to this button: ")
        promptAdditonal = ("Map an additional command " +
                           pcolor("cyan", "to this button? "))
        promptName = (pcolor("fuschia", "Enter a name ") +
                      "for this command: ")

        # name command
        cmd['name'] = self.getInput(promptName, cmd['name'])

        # Press Button to map
        print(promptButton, end=' ')
        sys.stdout.flush()
        pressed = self.wait_for_pin()
        cmd['pins'] = ', '.join(map(str, pressed))
        print('- Pin(s):', cmd['pins'])
        self.waitForButtonRelease()

        # get commands
        print()
        answer = 'Y'
        commandList = []
        while 'Y' in answer.upper():
            # Enter new command
            commandList.append(self.getInput(promptCommand, cmd['command']))
            cmd['command'] = ''
            # add another command?
            answer = input(promptAdditonal)
        cmd['command'] = '; '.join(commandList)
        cmd['device'] = 'Commands'
        SQL.updateEntry(cmd)
    def configureCommands(self):
        while True:
            cmd = menus.editCommandButton()
            if cmd == menus.GOTO_MAIN:
                return self.getControllerType()

            if cmd[0] == 'EDIT':
                self.editCommand(cmd[1])
            elif cmd[0] == 'DELETE':
                SQL.deleteEntry(cmd[1])
Exemplo n.º 5
0
 def reload(self, signal, frame):
     self.DEBUG(addSeparator=True)
     self.DEBUG("Received Reload Signal. Reloading GPIOnext1!")
     self.DEBUG(addSeparator=True)
     gpio.cleanup()
     importlib.reload(gpio)
     importlib.reload(SQL)
     gpio.setupGPIO(self.args)
     SQL.init()
     self.devices = SQL.getDevices(DEVICE_LIST, self.args)
     gpio.registerDevices(self.devices)
Exemplo n.º 6
0
    def __init__(self, args):
        # Watch for system signals
        for sig in [signal.SIGTERM, signal.SIGQUIT, signal.SIGINT]:
            signal.signal(sig, self.signal_handler)
        signal.signal(signal.SIGHUP, self.reload)

        self.args = args
        self.set_args()
        gpio.setupGPIO(self.args)
        SQL.init()
        self.devices = SQL.getDevices(DEVICE_LIST, self.args)
        gpio.registerDevices(self.devices)
        self.main()
Exemplo n.º 7
0
def editCommandButton():
	global currentDevice
	cmdList = SQL.getDeviceRaw( 'Commands' )
	entries = [ '• Edit Command: {0}'.format( x['name'] ) for x in cmdList ]
	entries.insert( 0, '• Add New Command' )
	entries.append( '← Return to Main Menu' )
	
	edit = 2
	while edit == 2:
		clearPreviousMenu()
		choice = SelectionMenu.get_selection( 
								strings = entries, 
								title = 'Configuring {0}'.format( currentDevice['name'] ), 
								subtitle = 'Select a command to edit',
								exit_option = False
								)
		
		if choice == 0:
			return ( 'EDIT', {'command':'', 'pins': None, 'id': None, 'device': None, 'name': '', 'type':'COMMAND' } )
		elif  choice == len( entries ) - 1:
			return GOTO_MAIN
		clearPreviousMenu()
		edit = SelectionMenu.get_selection( 
								strings = ['Edit', 'Delete', '← Go Back' ], 
								title = 'Configuring {0}'.format( cmdList[ choice - 1 ]['name'] ), 
								subtitle = 'Edit or Delete this command?',
								exit_option = False
								)
	edit = 'EDIT' if edit == 0 else 'DELETE'	
	return ( edit, cmdList[ choice - 1 ] )
Exemplo n.º 8
0
def clearDevice():
    clearPreviousMenu()

    options = DEVICE_LIST + ['← Return to Main Menu']
    choice = SelectionMenu.get_selection(
        strings=options,
        title='CLEAR DEVICE',
        subtitle='Remove configs for which device?',
        exit_option=False)

    currentDevice['name'] = options[choice]

    if currentDevice['name'] == '← Return to Main Menu':
        return GOTO_MAIN
    else:
        clearPreviousMenu()
        print('Deleting config files for {0}...'.format(currentDevice['name']))
        SQL.deleteDevice(currentDevice['name'])
        time.sleep(1)
        return clearDevice()
    def configureJoypad(self, currentDevice):
        menus.clearPreviousMenu()

        print('Configuring {0}'.format(currentDevice['name']))
        device = []  # Append new controls to this list
        deviceName = currentDevice[
            'name']  # Current controller being configured

        # First, Configure Joysticks
        for dpad in range(currentDevice['axisCount']):
            # Define Axes
            device.append(self.defineAxis("UP", dpad, deviceName, offset=1))
            device.append(self.defineAxis("DOWN", dpad, deviceName, offset=1))
            device.append(self.defineAxis("LEFT", dpad, deviceName))
            device.append(self.defineAxis("RIGHT", dpad, deviceName))

        # Second, Configure Buttons
        for button in currentDevice['buttons']:
            cmdName = button[0]
            command = button[1]
            unit = pcolor('cyan', cmdName)
            print('Hold {0}'.format(unit), end=' ')
            sys.stdout.flush()
            pressed = self.wait_for_pin()
            pressed = ', '.join(map(str, pressed))
            print('- Pins(s):', pressed)
            self.waitForButtonRelease()
            device.append((deviceName, cmdName, 'BUTTON', command, pressed))

        # Save to Database
        print('Saving Configuration!')
        # Delete Old Entries
        SQL.deleteDevice(deviceName)

        # Create New Entries
        SQL.createDevice(device)
        time.sleep(1)

        self.getControllerType()