Welcome! Log In Create A New Profile

Advanced

Control DockStar with USB keypad

Posted by twinpeaks 
Control DockStar with USB keypad
November 19, 2010 03:51PM
Hi,

Here is a small guide how to set up a small cheap USB keypad to control the DockStar with simple key presses without logging in using SSH etc.

These keypads can be found on eBay for under USD 5,- from China, but of course any USB keyboard should work for that purpose.

I use the packages LIRC together with inputlirc to do the trick. It might seem strange to use LIRC since we don't use an IR receiver, but it works... :-)


Part One, Basic Setup:

Install inputlirc and lirc:
apt-get install inputlirc
apt-get install lirc

Edit the options line of /etc/default/inputlirc to:
OPTIONS="-m 55 -r 300"
This sets the minimal key code that inputlirc evaluates. "-m 55" enables all keys of a keypad. To use all keys of a regular keyboard you would have to lower the -m value until all needed keys work, "-m 0" should enable all keys.
The "-r 300" option sets the time period in ms that will be used to detect and flag repeated keys.

After restarting inputlircd with
/etc/init.d/inputlirc restart
you can check if it sends the right key codes with
irw
This should print one line for each key press and if you keep a key pressed it should increase the repeat counter like that:
52 0 KEY_KP0 event0
52 1 KEY_KP0 event0
52 2 KEY_KP0 event0
...

We don't really need LIRC (because we don't have an IR receiver and use inputlirc instead) but we need irexec that comes with LIRC running in the background to execute our commands or scripts.

One way to let is start automatically on system boot is to edit /etc/lirc/lircd.conf and delete the first line (#UNCONFIGURED). This way irexec is started but lircd is not which is exactly what we want.

Then create a file /etc/lirc/lircrc to configure what key triggers which action. A very simple test template is e.g.:

/etc/lirc/lircrc:
#
# LIRCRC for controlling the Seagate Dockstar using an USB Keypad
#

begin
	button = KEY_KP0
	repeat = 0
	prog = irexec
	config = echo "none" > /sys/class/leds/dockstar\:orange\:misc/trigger
end

begin
	button = KEY_KP1
	repeat = 0
	prog = irexec
	config = echo "default-on" > /sys/class/leds/dockstar\:orange\:misc/trigger
end

Start LIRC:
/etc/init.d/lirc start

Now you should be able to turn the orange LED on and off with the '1' and '0' key.
You have to restart irexec after every change of /etc/lirc/lircrc:
/etc/init.d/lirc restart

If all this basic stuff works, you can now tweak your settings to your needs.


Part Two, Advanced Setup:

LIRC lets you also define more complex key patterns to trigger actions. For example I use key sequences instead of single keys:

begin
	button = KEY_KP0
	button = KEY_KP0
	button = KEY_KPENTER
	repeat = 0
	prog = irexec
	config = shutdown -h now
end

begin
	button = KEY_KP0
	button = KEY_KP1
	button = KEY_KPENTER
	repeat = 0
	prog = irexec
	config = shutdown -r now
end

Pressing 0 0 ENTER will halt the system and 0 1 ENTER will restart it, etc... and nothing is executed until I press ENTER, so I have time to think twice and if I change my mind I simply press an different key and start again. The possibilities are endless.


One problem I found with this cheap rubber keypad is that it has very poor tactile feedback, i.e. you are never sure that it really accepted your key press. To overcome this, I use the setleds program (from console-tools package) to flash the Num Lock LED on each key press.
apt-get install console-tools

and insert into /etc/lirc/lircrc:
# Flash Num Lock LED on every key press
begin
	button = *
	repeat = 0
	prog = irexec
	config = `setleds +num < /dev/tty0` && `sleep 0.01` && `setleds -num < /dev/tty0`
end


This will flash the Num Lock LED for ~ 10 ms for every key press and this way you have at least optical feedback which helps a lot! :-)


Have fun!

Best regards,
twinpeaks



Edit: Use "setleds" to flash LED as seen on the similar project: http://anwendungsentwickler.ws/dockstar_keylistener/entry/318/



Edited 2 time(s). Last edit at 11/22/2010 04:19PM by twinpeaks.
Attachments:
open | download - dock-kbd.jpg (58.3 KB)
Signal9
Re: Control DockStar with USB keypad
November 23, 2010 11:22AM
I just want to mentioned that this is a very cool hack! Great job!
eppi
Re: Control DockStar with USB keypad
December 27, 2010 02:28AM
Hi all
i have tryed this instllation on Debian Lenny and Squeeze. On squezze working my Wireless Keypad perfectly, on Lenny not. Lenny say on Step irw "NOT CONNECTED". Have Lenny and Squeeze not the same Kernel with drivers, or is a package not installed on Lenny for the Wireless Keypad?
Thx for your help.
Dani
Re: Control DockStar with USB keypad
December 28, 2010 06:08AM
Hi eppi,

well, I only tested it on Squeeze but I don't know why it should not work on Lenny, too.

irw simply connects to the socket /dev/lircd and displays all data that is comming in and inputlirc is delivering this data.
Does /dev/lircd exist in your Lenny installation?
What happens if you run /etc/init.d/inputlirc restart? Any error messages or so?
Is your keyboard recognized by the kernel, please have a look at the output of dmesg. Try running dmesg | grep input, you should see some lines about detecting the keyboard.

twinpeaks
Eppi
Re: Control DockStar with USB keypad
December 29, 2010 02:32AM
Hi Twinpeaks
many thanks for your help!

> Does /dev/lircd exist in your Lenny installation?
no this does't exist on my Lenny.

>What happens if you run /etc/init.d/inputlirc restart? Any error messages or so?
yes, i receive the following error message:

lenny14:~# /etc/init.d/inputlirc restart
Restarting inputlirc configuration
No /usr/sbin/inputlircd found running; none killed.
/usr/sbin/inputlircd: invalid option -- r
Unknown option!


>Try running dmesg | grep input, you should see some lines about detecting the keyboard:

lenny14:~# dmesg | grep input
input: MOSART Semi. 2.4G Keyboard Mouse as /devices/platform/orion-ehci.0/usb1/1-1/1-1.2/1-1.2:1.0/input/input0
generic-usb 0003:062A:3272.0001: input: USB HID v1.10 Keyboard [MOSART Semi. 2.4G Keyboard Mouse] on usb-orion-ehci.0-1.2/input0
input: MOSART Semi. 2.4G Keyboard Mouse as /devices/platform/orion-ehci.0/usb1/1-1/1-1.2/1-1.2:1.1/input/input1
generic-usb 0003:062A:3272.0002: input: USB HID v1.10 Mouse [MOSART Semi. 2.4G Keyboard Mouse] on usb-orion-ehci.0-1.2/input1
input: MOSART Semi. 2.4G Keyboard Mouse as /devices/platform/orion-ehci.0/usb1/1-1/1-1.2/1-1.2:1.0/input/input2
generic-usb 0003:062A:3272.0003: input: USB HID v1.10 Keyboard [MOSART Semi. 2.4G Keyboard Mouse] on usb-orion-ehci.0-1.2/input0
input: MOSART Semi. 2.4G Keyboard Mouse as /devices/platform/orion-ehci.0/usb1/1-1/1-1.2/1-1.2:1.1/input/input3
generic-usb 0003:062A:3272.0004: input: USB HID v1.10 Mouse [MOSART Semi. 2.4G Keyboard Mouse] on usb-orion-ehci.0-1.2/input1


Do you have an idea what to do?

Thank you!
Greets Eppi
Re: Control DockStar with USB keypad
December 31, 2010 08:20AM
Hi Eppi,

it seems that you have an older version of inputlicd as it doesn't recognize the -r option and therefore it fails to start.
So either update inputlircd to a newer version or edit /etc/default/inputlirc and remove the -r and the following number.
Maybe you have to edit /etc/apt/sources.list to get access to the Squeeze version of inputlircd, but I'm no debian expert.


Best regards,
twinpeaks
Re: Control DockStar with USB keypad
January 02, 2011 10:03PM
Thanks for sharing this hack twinpeaks!

Quick question: there appears to be lots of different USB keypads on ebay - while I'm sure most of them will work for this hack, I'd love to know the exact one you're using...
Re: Control DockStar with USB keypad
January 03, 2011 03:15AM
This keypad works fine, although it has bad tactile feedback because of the rubber design, but with the LED flashing hack it's usable:
http://cgi.ebay.de/ws/eBayISAPI.dll?ViewItem&item=320433266061

I also have this, but cannot recommend it. The keys are good, much better feeling as the above rubber type, but the LED cannot be controled by software, only by the Num-Lock key, and you have to turn Num-Lock off (manually) or the keypad sends a Num-Lock message with every keypress (which I think is not standard behaviour):
http://cgi.ebay.de/ws/eBayISAPI.dll?ViewItem&item=280526229995

twinpeaks
asbo
Re: Control DockStar with USB keypad
April 17, 2011 09:25AM
Hi

I've been building myself a dockstar wifi radio.
I'm using a usb remote which debian recognises as a keyboard.
Currently in /etc/lirc/lircrc I have:

#
# LIRCRC for controlling the Seagate Dockstar using an USB Keypad
#

begin
        button = KEY_PLAYPAUSE
        repeat = 0
        prog = irexec
        config = mplayer -ao alsa -msgcolor -cache 128 -playlist http://bbc.co.uk/radio/listen/live/bbcnorfolk.asx
end

begin
        button = KEY_STOPCD
        repeat = 0
        prog = irexec
        config =  "some command to quit mplayer"
end

When I press play on my remote it plays the radio station. However I can't figure out what to put to quit mplayer or stop it playing.

Can anyone help?
Re: Control DockStar with USB keypad
April 17, 2011 11:22AM
asbo, have you tried

config = killall mplayer

Just guessing.

HTH, Jim
asbo
Re: Control DockStar with USB keypad
April 17, 2011 01:16PM
oops should have put what I've tried.

I've tried:
killall -9 mplayer
killall -KILL mplayer

not sure what the -9 means, some page told me to do it.

variations on
mplayer -stop   
mplayer -quit
etc. etc.

all guesses since google doesn't bring much up.


your suggestion doesn't work either.

Connecting via SHH and running killall mplayer or killall -9 mplayer stops it, but I want to be able to do it via remote so I don't need a PC on.

Thanks for the suggestion.
ST
Re: Control DockStar with USB keypad
January 19, 2012 09:38AM
Hi,

I now have a keypad for my DockStar and I followed your Setup, my keypad is found and pressing keys while using irw results in something like:

45 0 KEY_NUMLOCK event1
47 1 KEY_KP7 event1
45 2 KEY_NUMLOCK event1
45 0 KEY_NUMLOCK event1
47 1 KEY_KP7 event1
45 2 KEY_NUMLOCK event1
66 0 KEY_HOME event1
69 1 KEY_LEFT event1
69 0 KEY_LEFT event1
66 0 KEY_HOME event1
69 1 KEY_LEFT event1
66 0 KEY_HOME event1

But irexec is not working.

In my /etc/lirc/lircrc it looks like that:

begin
    button = KEY_HOME
    repeat = 0
    prog = irexec
    config = mpc play
end

begin
    button = KEY_LEFT
    repeat = 0
    prog = irexec
    config = mpc stop
end

but if I press the keys, nothing is happening.


Can anyone help me with this?
ST
Re: Control DockStar with USB keypad
January 19, 2012 06:59PM
solved it myself: there was some problematic combination between my keypad (sk100 by HAMA) and the repeat-function of inputlirc.
franko_
Re: Control DockStar with USB keypad
March 22, 2012 04:04AM
I tried this with my Twinhan 1025 Remote control, which acts as a usbhid keyboard.
irw works with my MMS Mediacenter, but if i have activated a lircrc file, my remote doesnt work anymore with mms and
irexec. irw give me no ouput of any key pressed.

Is is possible to use irw and lircrc (irexec) ?
At first i want to use mms mediacenter with dockstar with my remote, and if i press a dedicated key, my mediacenter will exit and a iceweasel sessions starts.

BR
Frank
franko_
Re: Control DockStar with USB keypad
March 22, 2012 03:00PM
okay, i got it ...
KLamont
Re: Control DockStar with USB keypad
June 28, 2012 02:44PM
How can one control pianobar with this?
Re: Control DockStar with USB keypad
June 19, 2016 09:36AM
I have lirc controlling pianobar on the dockstar with jessie. I can share details if anyone is interested.

But it doesn't work on the pogoplug pro/oxnas platform with jessie and kernel 4.1.
root@pogobiz1:/etc/lirc# irw
connect: No such file or directory

No socket is created:
root@pogobiz1:/dev# ls -l lircd
lrwxrwxrwx 1 root root 21 Jun 19 08:57 lircd -> ../var/run/lirc/lircd

root@pogobiz1:/var/run/lirc# ls
. ..
root@pogobiz1:/var/run/lirc#

Does anyone know of a solution or workaround?
Thanks
Re: Control DockStar with USB keypad
June 19, 2016 05:20PM
@dexter
I cant offer a solution, but a writeup of how you got

"I have lirc controlling pianobar on the dockstar with jessie. I can share details if anyone is interested. "

Would be a worthy addition to the forum knowledge


@Bodhi - a nice howto above for the WIKI
Re: Control DockStar with USB keypad
June 19, 2016 06:08PM
Thanks twinpeaks!

-bodhi
===========================
Forum Wiki
bodhi's corner
Re: Control DockStar with USB keypad
June 20, 2016 07:09AM
Pianobar control from USB keypad notes.

1. get pianobar installed and working. apt-get install pianobar. Use your existing Pandora account or create a new account.
2. for some reason these packages may also be needed: alsa-utils, kbd, psmisc, screen, openssl.
3. To get the usb sound card to work, create /etc/modprobe.d/alsa-base.conf to read: options snd_usb_audio index=0
4. 'aplay -l' will verify if the usb sound card is device 0.
5. There is a 19 digit number shown for each pandora station when playing. Modify /root/.config/pianobar/config to read:
tls_fingerprint = 13CC51AC0C31CD96C55015C76914360F7AC41A00
audio_quality = low
autostart_station = 19digityourfavorite
password = yourpianobarpassword
user = yourpianobarlogin@emailaddress
6. tls_fingerprint may change. to get new tls_fingerprint, run shell script from
https://gist.github.com/r35krag0th/4173333
7. To get pianobar running as a service, add pianobar script to /etc/init.d/ from
https://www.raspberrypi.org/forums/viewtopic.php?t=31399&p=276550
8. run 'update-rc.d pianobar defaults'
9. verify that pianobar can be started and stopped by 'service pianobar start', 'service pianobar stop'
10. Install inputlirc and lirc, and configure as documented earlier in this thread.
11. Use irw to verify keypresses for your USB keypad. I have 2 different keypads and they have different responsed to keypresses. Numlock status also makes a difference. I use 2 digits plus enter for each command, but other setups should work as well. Adding & to the end of the command puts it in the background so other commands (stop or killall) can be entered.
12. I use this command to start pianobar using 99<enter>:
begin
button = KEY_KP9
button = KEY_NUMLOCK
button = KEY_NUMLOCK
button = KEY_KP9
button = KEY_NUMLOCK
button = KEY_KPENTER
repeat = 0
prog = irexec
config = service pianobar restart &
end
13. I use this command to stop pianobar and also vlc using 00<enter>:
begin
button = KEY_KP0
button = KEY_NUMLOCK
button = KEY_NUMLOCK
button = KEY_KP0
button = KEY_NUMLOCK
button = KEY_KPENTER
repeat = 0
prog = irexec
config = killall -9 vlc pianobar &
end
14. To switch between pianobar stations, I make a separate config file for each, and after stopping pianobar, I copy the config file of the desired station over the previous config file, then restart pianobar:
begin
button = KEY_KP1
button = KEY_NUMLOCK
button = KEY_NUMLOCK
button = KEY_KP2
button = KEY_NUMLOCK
button = KEY_KPENTER
repeat = 0
prog = irexec
config = cp /root/.config/pianobar/config.blacksabbath /root/.config/pianobar/config
end
15. I also use the keypad to play mp3 music from local or network folders using vlc, and also play internet radio streams, also using vlc.
begin
button = KEY_KP0
button = KEY_NUMLOCK
button = KEY_NUMLOCK
button = KEY_KP4
button = KEY_NUMLOCK
button = KEY_KPENTER
repeat = 0
prog = irexec
config = cvlc -Z /media/usb0 &
end
begin
button = KEY_KP8
button = KEY_NUMLOCK
button = KEY_NUMLOCK
button = KEY_KP0
button = KEY_NUMLOCK
button = KEY_KPENTER
repeat = 0
prog = irexec
config = cvlc http://news-stream.iowapublicradio.org/News.mp3 &
end
Re: Control DockStar with USB keypad
June 20, 2016 07:44AM
Re: Control DockStar with USB keypad
December 01, 2019 03:22PM
Has anyone had any luck getting irexec to run in the background and process keypad input in later versions of Debian, Stretch and Buster?
Author:

Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: