Sending commands to UHK from Linux shell

The user-guide explains that a shell script can be used to send commands to the UHK, and lists the following script:

#!/bin/bash
hidraw=`grep 'UHK 60' /sys/class/hidraw/hidraw*/device/uevent | LC_ALL=C sort -h | head -n 1 | grep -o 'hidraw[0-9][0-9]*'`
echo -e "\x14$*" > "/dev/$hidraw"

When I tried to use this, however, I found that I have to reverse the sorting order (sort -r), because commands were only accepted by the last of the hidraw devices, not the first one. Is this due to latest changes in USB device ordering?

This is what I use now:

#!/bin/bash
hidraw=`grep 'UHK 60' /sys/class/hidraw/hidraw*/device/uevent | LC_ALL=C sort -rh | head -n 1 | grep -o 'hidraw[0-9][0-9]*'`
echo -e "\x14$*" > "/dev/$hidraw"

If that’s all correct, the docs should be modified accordingly.

You are spot on, just updated the docs.

Thanks!

1 Like

Now that I can send commands, I am experimenting with this.

I am getting weird errors. Is there a bug, or am I doing something wrong?

I use this script (which also echoes the commands to the tty via tee):

(base) max@max-framework:~/src/uhk-learn-layout$ cat uhk-cmd.sh
#!/bin/bash
hidraw=`grep 'UHK 60' /sys/class/hidraw/hidraw*/device/uevent | LC_ALL=C sort -rh | head -n 1 | grep -o 'hidraw[0-9][0-9]*'`
echo -e "\x14$*" | tee "/dev/$hidraw"

Now I try to send some longer sequences:

(base) max@max-framework:~/src/uhk-learn-layout$ ./uhk-cmd.sh "set keystrokeDelay 5" ; sleep 1; ./uhk-cmd.sh "tapKeySeq u d space minusAndUnderscore u enter"
set keystrokeDelay 5
tapKeySeq u d space minusAndUnderscore u enter
(base) max@max-framework:~/src/uhk-learn-layout$ ls -l
total 24
-rw-rw-r-- 1 max max  1075 Jun 23  2023 LICENSE
-rw-rw-r-- 1 max max  3483 Dez 23 04:05 README.md
-rwxrwxr-x 1 max max   175 Jun 11 10:01 uhk-cmd.sh
-rwxrwxr-x 1 max max 11021 Jul  6  2023 uhk-learn-layout.py

Which seems to work – the shell executes the intended ls -l command. Interestingly, I had to set keystrokeDelay; I never need that when I run tapKeySeq directly from macros. But I get the UHK to type the commands. (Because of Colemak mapping on the host OS, I have to send u d for the ls command… I know it’s weird…)

However, once this is complete, ERR flashes on the display. So I start up Agent to find the following error message:

Error at  1/2/1: Unrecognized command: inus
> 2 | inus enter

???

Are there some length restrictions in the commands?

Also, how can I send a sequence of commands, i.e. a whole macro such as:

set something...
tapKey something...
delayUntil...
tapKey something else...
etc.

However, once this is complete, ERR flashes on the display. So I start up Agent to find the following error message:

Please post the actual command that produces it. uhkcmd "tapKeySeq u d space minusAndUnderscore u" works fine for me.

Are there some length restrictions in the commands?

Something like 63 chars.

Also, how can I send a sequence of commands, i.e. a whole macro such as:

Please dont.

Instead, create a macro on UHK, and execute it from the host via fork myMacroName

But these are actually the commands I have used. I have copy/pasted directly from my terminal / shell output.

Aw… that won’t work for what I am trying to do. I would need to create that macro on the host system and somehow upload it to the UHK first. (But I also don’t want to keep frequently overwriting flash memory.)

I basically want to create some command sequences dynamically, and have the UHK execute them. Since they are not static, I can’t store them already in some fixed macros.

I can happily only send one command at a time, but I would need to know when the previous execution is finished. If I run a command such as setLedTxt 500 'ABC' then the uhk-cmd.sh returns immediately after sending the command, although the execution will take just over 500ms.

Any ideas?

But these are actually the commands I have used. I have copy/pasted directly from my terminal / shell output.

That’s strange. It works fine for me.

I basically want to create some command sequences dynamically, and have the UHK execute them. Since they are not static, I can’t store them already in some fixed macros.

If you really need multiple commands, it should not be hard to send a string that contains newlines.

I am not sure if the parser will accept it, but I think it should.

If I run a command such as setLedTxt 500 'ABC' then the uhk-cmd.sh returns immediately after sending the command

If you run the command when previous usb-executed macro is still running, your command should report an error. This is since there is only one buffer for usb commands, so you can’t start another while the old one is still running.

Any ideas?

Yes, create your own firmware fork, or dig into AHK :innocent:.

LINUX!! :exploding_head:

Ah, I see. Firmware fork it is then :slight_smile: .

nonononononoooooo… :roll_eyes:

:rofl:

@kareltucek I love that you retroactively crossed it out, btw. :smirk:

1 Like