Welcome, Guest
Username: Password: Remember me

TOPIC: Linux Question

Linux Question 1 year 2 weeks ago #1367

  • DanielKirk2
  • DanielKirk2's Avatar
  • New Member
  • Posts: 4
  • Thank you received: 6
  • Karma: 2
Hi all,

I'm trying to create a setup with a Pedal-Pi attached to a 3-button usb footpad so I can send signals to the pi during songs. I also have a program called FX that I want to boot at startup and be able to accept input from the footpad.
The footpad seems to work like a keyboard with its 3 buttons mapping to the letters a, b, and c.

As an aside I'm using the CSound API which is running synchronously inside my code. CSound has opcodes for reading keyboard input and I'm hoping to use these to detect button presses.

The problem I'm having is getting CSound to recognise the input, I think this is a Linux problem rather than a CSound problem as in some configurations it seems to work, but the ones I need it doesn't.

I've tried the usual ways of starting my program at bootup (rc.local, init.d, and crontab) as well as using ssh, I'll sumarise the results:

- In rc.local I add the line "sudo path-to-FX &" which does load it at boot up but there is no button detection. I think this is because programs loaded in rc.local are not attached to any terminal so don't receive input.

- I got the same results when I put "@reboot sudo path-to-FX &" in crontab.

- I tried creating an init.d script but couldn't get it to load.

- In an ssh session I can load FX from the CLI and it does detect keypresses from my (remote) keyboard, and in fact responds to button presses from my footpad (when it's plugged in to my remote computer).

- When I attach my HDMI cable and a keyboard directly to the PI I can load the program from the CLI, switch the keyboard and footpad around and it successfully detects button presses, though not when I autoload FX using rc.local.

Ideally I want FX to load at startup without any HDMI or ssh connection, but to do so in a way that keyboard input is fed into its stdin channel.

I'm not a wizard with Linux and I hope I've been able to describe the problem clearly. If anyone can diagnose the problem or suggest a solution I'd be so very happy. Let me know if you need more information.

Thanks in advance!

The administrator has disabled public write access.

Linux Question 1 year 2 weeks ago #1378

  • Ray
  • Ray's Avatar
  • Moderator
  • Posts: 615
  • Thank you received: 138
  • Karma: 38
Hi Daniel, I am quite overwhelmed with your post :oops:
I understand what are you trying to do, which is veery cool by the way but dont know a solution for that off the top of my head... maybe some good computer engineer around has more experience on it.
The administrator has disabled public write access.

Linux Question 8 months 3 weeks ago #1507

  • yojimbo
  • yojimbo's Avatar
  • New Member
  • Posts: 4
  • Thank you received: 1
  • Karma: 1
I've seen people do similar things setting up Pis to do headless barcode scanning and such, where the barcode scanner shows up as a USB keyboard. If you type 'lsusb' from your terminal with the pedal switch plugged in you should see what is shows up as on the piI think the answer is to continuously read the input file at /dev/input/by-id/??? where ??? is something akin to what was displayed with the lsusb command. It probably ends in -kbd

You *should* be able to test it using 'tail /dev/input/by-id/<name-of-your-device-kbd>' and pressing the switches to verify that you got the right one.

Now for the code: HERE is an example of how to do it in python (copypasta from the scanner example). you will have to adapt a bit, but its close.
import evdev
from evdev import InputDevice, categorize, ecodes  
dev = InputDevice('/dev/input/event1')
# Modify as needed
scancodes = {
    # Scancode: ASCIICode
    0: None, 1: u'ESC', 2: u'1', 3: u'2', 4: u'3', 5: u'4', 6: u'5', 7: u'6', 8: u'7', 9: u'8',
    10: u'9', 11: u'0', 12: u'-', 13: u'=', 14: u'BKSP', 15: u'TAB', 16: u'q', 17: u'w', 18: u'e', 19: u'r',
    20: u't', 21: u'y', 22: u'u', 23: u'i', 24: u'o', 25: u'p', 26: u'[', 27: u']', 28: u'CRLF', 29: u'LCTRL',
    30: u'a', 31: u's', 32: u'd', 33: u'f', 34: u'g', 35: u'h', 36: u'j', 37: u'k', 38: u'l', 39: u';',
    40: u'"', 41: u'`', 42: u'LSHFT', 43: u'\\', 44: u'z', 45: u'x', 46: u'c', 47: u'v', 48: u'b', 49: u'n',
    50: u'm', 51: u',', 52: u'.', 53: u'/', 54: u'RSHFT', 56: u'LALT', 57: u' ', 100: u'RALT'
capscodes = {
    0: None, 1: u'ESC', 2: u'!', 3: u'@', 4: u'#', 5: u'$', 6: u'%', 7: u'^', 8: u'&', 9: u'*',
    10: u'(', 11: u')', 12: u'_', 13: u'+', 14: u'BKSP', 15: u'TAB', 16: u'Q', 17: u'W', 18: u'E', 19: u'R',
    20: u'T', 21: u'Y', 22: u'U', 23: u'I', 24: u'O', 25: u'P', 26: u'{', 27: u'}', 28: u'CRLF', 29: u'LCTRL',
    30: u'A', 31: u'S', 32: u'D', 33: u'F', 34: u'G', 35: u'H', 36: u'J', 37: u'K', 38: u'L', 39: u':',
    40: u'\'', 41: u'~', 42: u'LSHFT', 43: u'|', 44: u'Z', 45: u'X', 46: u'C', 47: u'V', 48: u'B', 49: u'N',
    50: u'M', 51: u'<', 52: u'>', 53: u'?', 54: u'RSHFT', 56: u'LALT',  57: u' ', 100: u'RALT'
#setup vars
x = ''
caps = False
#grab provides exclusive access to the device
for event in dev.read_loop():
    if event.type == ecodes.EV_KEY:
        data = categorize(event)  # Save the event temporarily to introspect it
        if data.scancode == 42:
            if data.keystate == 1:
                caps = True
            if data.keystate == 0:
                caps = False
        if data.keystate == 1:  # Down events only
            if caps:
                key_lookup = u'{}'.format(capscodes.get(data.scancode)) or u'UNKNOWN:[{}]'.format(data.scancode)  # Lookup or return UNKNOWN:XX
                key_lookup = u'{}'.format(scancodes.get(data.scancode)) or u'UNKNOWN:[{}]'.format(data.scancode)  # Lookup or return UNKNOWN:XX
            if (data.scancode != 42) and (data.scancode != 28):
                x += key_lookup  
            if(data.scancode == 28):
                print x          # Print it all out!
                x = ''[enter link description here][1]
The administrator has disabled public write access.
The following user(s) said Thank You: Ray
Time to create page: 0.147 seconds
Powered by Kunena Forum
Joomla SEF URLs by Artio