DevTerm Keyboard firmware mod: hot mode switching / gear switching

Version 2 is released. See 1st post.
@pkr new feature, true powa savage!

3 Likes

Version 3 “emergency grooming” released ((

3 Likes

Version 4 is released, featuring Mouse Overlay.

2 Likes

I love it so much, that you focus on tinkering with the little details and offer help and functionality to the community.

I just struggle to understand, what you did?
Is there an easy way to understand you Upgrades and what the additional functionality brought by the version jumps actually means?

Looks like the flashing went fine on the presumably v4 firmware. Seems like fantastic work! Thank you!

Some questions:

  • Does your version include the changes from the post I've rewritten DevTerm keyboard & trackball firmware
  • Is there any visual indication of the mode/cpu gear? How do you find out? There doesn’t appear to be any, unlike the screenshot.
  • Your download doesn’t seem to have the sources, is the source available somewhere? No way to build manually.
  • Your post mentions services, but those would be in the missing sources directory
  • The git status shows that the bin file had been modified but not checked in. Could you include an sha256 sum of the current binary?
  • Possibly rename the download to include the version number?

FYI I am now on Ubuntu LTS 22.0.4.1 after upgrading, perhaps something has changed/

@jan-peter

I just struggle to understand, what you did?

:smiley: just random bits to improve the keyboard fw, including DPAD mouse, low power mode etc.

The changelog for version bumps are noted at the bottom of the post.

@mowgli

Yes! The trackball improvement was grafted into the official repo, and my work started afterwards.

  • Is there any visual indication of the mode/cpu gear? How do you find out?

This is done by installing the keyboard service, which will send notifications to the X11 desktop. Not ideal – I wish there were LEDs in the front panel for this.

  • Your download doesn’t seem to have the sources, is the source available somewhere? No way to build manually.

It’s in the repo at the top of the post. The keyboard service is also there: DevTerm/Code/devterm_keyboard/service at main · yatli/DevTerm · GitHub

  • The git status shows that the bin file had been modified but not checked in. Could you include an sha256 sum of the current binary?

Got to make sure we’re on the same page: you cloned the repo and built it, and then git status? Which files are changed? I don’t think there’s a build pipeline to obtain keyboard fw yet. The zipped fw files are built with the arduino IDE, then manually assembled.

  • Possibly rename the download to include the version number?

image

Emmm… you mean versions attached to files after unzip?

Yes, sorry for the confusion. I’ve been reading most of these from my phone so I think I might have missed some things.
I downloaded the FW file from the original post, which included .git and the git history. That file wasn’t named that way. Let me check again.

Ok, so good news is I verified I have the correct firmware on the keyboard. I tried changing modes, but for some reason it wasn’t going back to Joystick Mode, but the d-pad keys were working in the terminal as regular keystrokes. Everything seems to be working, until I install the services. Nothing seems to happen so I do a reboot, but now the built in keyboard fails. Nothing works, not typing or rollerball.
Could this be a difference with udev rules in Ubuntu 22.04.1?

Unplugging the keyboard and re-plugging didn’t help.
Dmesg sees the keyboard:

[  285.744015] usb 5-1.1: USB disconnect, device number 3
[  343.055123] usb 5-1.1: new full-speed USB device number 6 using ehci-platform
[  343.164888] usb 5-1.1: New USB device found, idVendor=1eaf, idProduct=0003, bcdDevice= 2.01
[  343.164916] usb 5-1.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[  343.164935] usb 5-1.1: Product: Maple 003
[  343.164951] usb 5-1.1: Manufacturer: LeafLabs
[  343.164967] usb 5-1.1: SerialNumber: LLM 003

EDIT: So apparently connecting via USB works correctly:

[ 2577.678093] usb 5-1.4: new full-speed USB device number 13 using ehci-platform
[ 2577.787888] usb 5-1.4: New USB device found, idVendor=1eaf, idProduct=0003, bcdDevice= 2.01
[ 2577.787919] usb 5-1.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 2577.787937] usb 5-1.4: Product: Maple 003
[ 2577.787954] usb 5-1.4: Manufacturer: LeafLabs
[ 2577.787970] usb 5-1.4: SerialNumber: LLM 003
[ 2578.735633] usb 5-1.4: USB disconnect, device number 13
[ 2578.958128] usb 5-1.4: new full-speed USB device number 14 using ehci-platform
[ 2579.069130] usb 5-1.4: New USB device found, idVendor=1eaf, idProduct=0024, bcdDevice= 2.00
[ 2579.069158] usb 5-1.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 2579.069177] usb 5-1.4: Product: DevTerm
[ 2579.069193] usb 5-1.4: Manufacturer: ClockworkPI
[ 2579.069210] usb 5-1.4: SerialNumber: 20210531
[ 2579.075895] input: ClockworkPI DevTerm Consumer Control as /devices/platform/fe380000.usb/usb5/5-1/5-1.4/5-1.4:1.0/0003:1EAF:0024.000E/input/input24
[ 2579.134963] input: ClockworkPI DevTerm Keyboard as /devices/platform/fe380000.usb/usb5/5-1/5-1.4/5-1.4:1.0/0003:1EAF:0024.000E/input/input25
[ 2579.136954] input: ClockworkPI DevTerm as /devices/platform/fe380000.usb/usb5/5-1/5-1.4/5-1.4:1.0/0003:1EAF:0024.000E/input/input26
[ 2579.137915] input: ClockworkPI DevTerm Mouse as /devices/platform/fe380000.usb/usb5/5-1/5-1.4/5-1.4:1.0/0003:1EAF:0024.000E/input/input27
[ 2579.139075] hid-generic 0003:1EAF:0024.000E: input,hidraw2: USB HID v1.10 Keyboard [ClockworkPI DevTerm] on usb-fe380000.usb-1.4/input0
[ 2579.140090] cdc_acm 5-1.4:1.1: ttyACM0: USB ACM device

But reconnecting it normally doesn’t work.

Try to disable devterm-mouse.service first:

systemctl --user stop devterm-mouse.service
systemctl --user disable devterm-mouse.service

That’s the part that interact with uinput and the udev rule.

You can also check the status of the service: systemctl status devterm-keyboard.service
If it says service “dead” with some logs, please post it here.

You can also stop the keyboard service, using sudo this time:
sudo systemctl stop devterm-keyboard.service
sudo systemctl disable devterm-keyboard.service

After both services are disabled, unplug and plug it back, check if it works.
When the keyboard is powered up, it will have the DPAD in mouse mode.


I downloaded the FW file from the original post, which included .git and the git history. That file wasn’t named that way. Let me check again.

Ok now I remember. Let me explain this a little bit:

  • Official firmware shell scripts: when you run that (e.g. DevTerm_keyboard_firmware_v0.3_utils.sh), it self-extracts the actual firmware, and flashing scripts then execute that (like the NVIDIA Linux driver run.sh :smiley: ). The .git directory comes from that and I didn’t clear it up.
  • I did not figure out how to build that self-extracting shell script, so I just replaced the actual firmware with mine and zipped it.

I rebooted, had the same problem, then completely powered off the DevTerm, took out the batteries and rebooted. I think there must be some hardware caching of usb locations internally. Now everything seems to work again on the keyboard and rollerball. The display notification doesn’t appear to work though, and I have pyserial installed both locally and as root (Your script does the pip install as root). How do you debug or find errors from the service?

Just run the script behind the service, directly:
sudo devterm_keyboard.py and see if it crashes or print out some logs

The installer Makefile says: ln -s which gearbox-clockworkpi-a06 /usr/local/bin/devterm_gearbox.py
This is wrong for Armbian. So the keyboard service probably won’t start…

× devterm-keyboard.service - devterm keyboard service
     Loaded: loaded (/etc/systemd/system/devterm-keyboard.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Thu 2022-08-04 08:29:51 UTC; 25min ago
    Process: 2014 ExecStart=/usr/bin/python3 /usr/local/bin/devterm_keyboard.py (code=exited, status=1/FAILURE)
   Main PID: 2014 (code=exited, status=1/FAILURE)
        CPU: 149ms

Aug 04 08:29:51 clockworkpi-a06 systemd[1]: devterm-keyboard.service: Scheduled restart job, restart counter is at 5.
Aug 04 08:29:51 clockworkpi-a06 systemd[1]: Stopped devterm keyboard service.
Aug 04 08:29:51 clockworkpi-a06 systemd[1]: devterm-keyboard.service: Start request repeated too quickly.
Aug 04 08:29:51 clockworkpi-a06 systemd[1]: devterm-keyboard.service: Failed with result 'exit-code'.
Aug 04 08:29:51 clockworkpi-a06 systemd[1]: Failed to start devterm keyboard service.

Thought so.

sudoedit /usr/local/bin/devterm_keyboard.py, and you can remove gear-related logic like this:

  • Line 7, # import devterm_gearbox, comment out by placing a “#” in the front.
  • Line 28, # devterm_gearbox.devterm.set_gear(gear)
  • Line 30, # devterm_gearbox.echo(gear, gear_file)
  • Line 80, # devterm_gearbox.devterm.set_gear(gear)

Won’t this disable Gear shifting completely? Any chance of just getting the gearshifting into the correct location? Am I wrong in thinking it’s a python script?

Yes it will. Just want to make sure all other perspectives works before we dive deeper…

To have gear switching to work you’ll have to modify it (quite) a bit to allow interfacing with an external program efficiently.

All these services are python scripts. Gear shifting can be done by just shelling out and call the gearbox on command line. Tried that in earlier versions. Very slow when you’re on low gear. So I figure I can just import the gearbox as a python module.

Ah, ok. I will dive into this tomorrow, it’s fairly late here.

cpi@clockworkpi-a06:~$ systemctl status devterm-keyboard.service
● devterm-keyboard.service - devterm keyboard service
     Loaded: loaded (/etc/systemd/system/devterm-keyboard.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2022-08-04 19:08:33 UTC; 11s ago
   Main PID: 4438 (python3)
      Tasks: 1 (limit: 4459)
     Memory: 3.4M
        CPU: 163ms
     CGroup: /system.slice/devterm-keyboard.service
             └─4438 /usr/bin/python3 /usr/local/bin/devterm_keyboard.py

Aug 04 19:08:33 clockworkpi-a06 systemd[1]: Started devterm keyboard service.

Seems like that allows it to run, but:

cpi@clockworkpi-a06:~$ systemctl status devterm-keyboard.service
● devterm-keyboard.service - devterm keyboard service
     Loaded: loaded (/etc/systemd/system/devterm-keyboard.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2022-08-04 19:08:33 UTC; 6min ago
   Main PID: 4438 (python3)
      Tasks: 1 (limit: 4459)
     Memory: 3.4M
        CPU: 426ms
     CGroup: /system.slice/devterm-keyboard.service
             └─4438 /usr/bin/python3 /usr/local/bin/devterm_keyboard.py

Aug 04 19:13:18 clockworkpi-a06 python3[4607]: sudo: error initializing audit plugin sudoers_audit
Aug 04 19:13:19 clockworkpi-a06 sudo[4610]:     root : unknown user yatli ; PWD=/ ; USER=yatli ;
Aug 04 19:13:19 clockworkpi-a06 python3[4610]: sudo: unknown user yatli
Aug 04 19:13:19 clockworkpi-a06 python3[4610]: sudo: error initializing audit plugin sudoers_audit
Aug 04 19:13:19 clockworkpi-a06 sudo[4613]:     root : unknown user yatli ; PWD=/ ; USER=yatli ;
Aug 04 19:13:19 clockworkpi-a06 python3[4613]: sudo: unknown user yatli
Aug 04 19:13:19 clockworkpi-a06 python3[4613]: sudo: error initializing audit plugin sudoers_audit
Aug 04 19:13:19 clockworkpi-a06 sudo[4616]:     root : unknown user yatli ; PWD=/ ; USER=yatli ;
Aug 04 19:13:19 clockworkpi-a06 python3[4616]: sudo: unknown user yatli
Aug 04 19:13:19 clockworkpi-a06 python3[4616]: sudo: error initializing audit plugin sudoers_audit

After checking for the user:
root-notify-send.py has the user hard coded.
Looks like DBUS doesn’t handle things correctly for the address of the keyboard :

Aug 04 20:20:04 clockworkpi-a06 sudo[5751]: pam_unix(sudo:session): session closed for user cpi
Aug 04 20:20:05 clockworkpi-a06 sudo[5756]:     root : PWD=/ ; USER=cpi ; ENV=DISPLAY=:0.0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/100>
Aug 04 20:20:05 clockworkpi-a06 sudo[5756]: pam_unix(sudo:session): session opened for user cpi(uid=1000) by (uid=0)
Aug 04 20:20:05 clockworkpi-a06 python3[5757]: Could not connect: No such file or directory
Aug 04 20:20:05 clockworkpi-a06 sudo[5756]: pam_unix(sudo:session): session closed for user cpi
1 Like

Modifying the file /usr/local/bin/root-notify-send seems to let me dynamically set the user:

#!/bin/bash
cur_user=$(who | mawk '{print $1}')
cur_user_id=$(id -u $cur_user)
sudo -u $cur_user DISPLAY=:0.0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$cur_user_id/bus notify-send "$@"

But doesn’t actually work:

cpi@clockworkpi-a06:~$ systemctl status devterm-keyboard.service
● devterm-keyboard.service - devterm keyboard service
● devterm-keyboard.service - devterm keyboard service
     Loaded: loaded (/etc/systemd/system/devterm-keyboard.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2022-08-05 07:23:34 UTC; 38s ago
   Main PID: 10840 (python3)
      Tasks: 1 (limit: 4459)
     Memory: 3.4M
        CPU: 1.190s
     CGroup: /system.slice/devterm-keyboard.service
             └─10840 /usr/bin/python3 /usr/local/bin/devterm_keyboard.py

Aug 05 07:24:05 clockworkpi-a06 python3[10934]: Could not connect: No such file or directory
Aug 05 07:24:05 clockworkpi-a06 sudo[10933]: pam_unix(sudo:session): session closed for user cpi
Aug 05 07:24:06 clockworkpi-a06 sudo[10943]:     root : PWD=/ ; USER=cpi ; ENV=DISPLAY=:0.0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus ; COMMAND=/usr/bin/notify-send Selector = joystick
Aug 05 07:24:06 clockworkpi-a06 sudo[10943]: pam_unix(sudo:session): session opened for user cpi(uid=1000) by (uid=0)
Aug 05 07:24:06 clockworkpi-a06 python3[10944]: Could not connect: No such file or directory
Aug 05 07:24:06 clockworkpi-a06 sudo[10943]: pam_unix(sudo:session): session closed for user cpi
Aug 05 07:24:06 clockworkpi-a06 sudo[10952]:     root : PWD=/ ; USER=cpi ; ENV=DISPLAY=:0.0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus ; COMMAND=/usr/bin/notify-send Selector = gear
Aug 05 07:24:06 clockworkpi-a06 sudo[10952]: pam_unix(sudo:session): session opened for user cpi(uid=1000) by (uid=0)
Aug 05 07:24:06 clockworkpi-a06 python3[10953]: Could not connect: No such file or directory
Aug 05 07:24:06 clockworkpi-a06 sudo[10952]: pam_unix(sudo:session): session closed for user cpi

ugh… sorry about the mess. it was set up for ArchLinux so the DBUS path could be different here.
Try ls /run/user/1000 and see what’s in there?

Hrm, looks like they are enumerating dbus for some reason, so the dbus directory is
/run/user/1000/dbus-1 and there is a subfolder /run/user/1000/dbus-1/services/