UltimateHackingKeyboard / agent

Ultimate Hacking Keyboard configurator
https://ultimatehackingkeyboard.github.io/agent/
Other
702 stars 77 forks source link

Customize LED segment display #660

Open MattKunze opened 6 years ago

MattKunze commented 6 years ago

Currently the LED segments show the currently selected keymap ('QWM', etc). For me at least this is something that will rarely/never change, so the display doesn't really provide much information. It would be awesome if these could be overridden with a console utility (uhk --leds 'FOO') to display arbitrary text.

Why? This is the ultimate hacking keyboard, so mainly it just seems like stuff like that should be hackable ;) I could see writing a script to update it with the current CPU load, polling the outside temperature, hooking it up to the current terminal to display additional status, who knows.

Not sure if this belongs here or the firmware repo, thought I'd get the discussion started somewhere though.

mondalaci commented 6 years ago

Good point, and this is something that we planned. Now we also have an issue for it. Will do eventually. :)

luteijn commented 6 years ago

To expose the LED (and future expansions, like e.g. an i2c lcd display or other gadget) it might be useful to have the uhk also present itself as a usb-serial converter so scripts have something straight-forward to talk to. Alternatively/additionally agent could act as a proxy, but I guess you already have some ideas for this.

mondalaci commented 6 years ago

@luteijn Yep, the plan is to expose Agent as a proxy. Regarding communication, the already existing generic USB HID interface will be used. It's binary, but creating an additional USB serial interface would create a lot of bulk.

richrd commented 6 years ago

A command line tool for setting leds would be amazing! Not sure how easy and cross platform that would be though. I'd love to have it show various status info from my computer etc.

I'm curious whether the led display accepts just characters or can the segments be addressed individually?

PS just got my UHK today and gotta say it's even more fun than I expected! :)

mondalaci commented 6 years ago

@richrd Yep, the LED display segments will be individually controllable. This is much needed for showing characters that resemble the predator alphabet, and who are we to stop you from doing that. :)

So glad you're having fun with your UHK!

lrascao commented 6 years ago

👍 i would also like to see this, btw great job!

seanonthenet commented 5 years ago

Awesome.

norrs commented 5 years ago

This would be awesome, could use it for showing current xkbkeymap language, ie if Im currently using english keyboard or native norwegian.

FatBoyXPC commented 5 years ago

I think it would be neat if we could include some scripts to be stored on the keyboard, triggerable by the keyboard as well. Similar to how you can change layouts with the keyboard.

mondalaci commented 5 years ago

@FatBoyXPC This is not planned. Generally speaking, Agent is only meant to configure the UHK. You can achieve what you're after by setting up an unused shortcut (such as Ctrl+Alt+Shift+F13) for a key and bind it to your window manager to execute a script.

FatBoyXPC commented 5 years ago

Yeah, I figured that would be the immediate implementation but I was hoping having scripts there were movable with the keyboard would be on road map, too. It's not a big deal, though, as really my main use case for this is only with one computer anyway.

jsarbour commented 5 years ago

+1 to this FR. I'd love to use mine as a clock (and run the hours in Hexadecimal I guess on one digit)

BrianGaucher commented 5 years ago

Using it as a clock would be great. What if there was a LED display module?

mhantsch commented 4 years ago

The idea of an UHK clock inspired me: there are three positions in the display. If you consider only the segments pointing outwards from the center, you have 8 of those in 360 degrees. Does not work well for advanced the "hand" every hour, or every minute, but try this:

image

kareltucek commented 4 years ago

...I guess you could also make the brightness change independently per segment and make it "continuous"...

mondalaci commented 4 years ago

All of this will be possible as the individual segments and per-key backlights will be exposed via the UHK USB protocol. Writing must be possible by the host, but I'm wondering whether reading LED states would make sense.

csmote commented 4 years ago

Realize this isn't a priority, but just something to add.

As a (hopefully) soon, to be owner of an UHK, I'd love to see the LED show the current "modifier" level (for those that aren't already shown in the images in the same area), as I imagine was the original intent behind including it, i.e., MOD, FN, CTL, ALT, SUP, CMD, WIN, MOU, NUM, etc. and also love to be able to have those flash and control the rate of flash per code displayed. Particularly useful for getting a visual reminder to switch out of tenkey (Numlock) or arrow mode (especially arrow mode since that's going to be used often - I'd even have that flash all segs rapidly to really have a "warning" that not in standard alpha mode.)

Such a great piece of engineering. Keeping an eye on my resources to get an order together.

mhantsch commented 4 years ago

@csmote I configured my NumPad "layer" not as a layer, but as a keymap. When I switch to it, the LED display shows that I am on the NumPad map. I guess that's a little bit of what you wanted (although only for NumPad, not for all the other modifiers).

csmote commented 4 years ago

@mhantsch. Thanks for replying with your work-around - very slick! Understanding that the UHK is an evolving platform that's made tremendous progress so far!

stn1986 commented 2 years ago

While I don't actually own the keyboard yet (just ordered it) I was also wondering about this. I'd love for this tiny display to tell me the status of some of my projects, servers, emergencies, that sort of thing. I'm kinda bummed this LED is not directly programmable, but it's not a deal breaker. Anyway:

I see on YT you can create custom keymaps and name them, which is then displayed on the LED when activated. I only ever use one keymap, so my idea is to create a bunch of copies of that map, name them differently and switch them externally when some event is triggered.

Let's say I use the three digits as code. 000 = no problems, 100 = project 1 is in trouble, 010 = project 2 is in trouble and 003 = project 3 is in trouble. I create four duplicate keymaps that are exactly the same except for the name ("000", "100", etc). Let's assume I have some sort of code running externally that detects these problems and can run the same code the actual keyboard software uses to switch keymaps. In that case I can set the display to 000 and 100 and so on by automatically switching keymaps (which are actually the same so it doesn't impact my typing), right?

I'm not familiar with the maximum number of keymaps UHK supports. Using these scheme you can customize the LED up to whatever the maximum number of different keymaps is. I don't suppose it's 256^3 though..

Let me know if I'm talking out of my ass here. I'm a developer so I don't mind the code, but perhaps I'm fundamentally misunderstanding something else here.

PS: I see https://github.com/UltimateHackingKeyboard/agent/blob/4ecc3ef795e8d13b2ef2acead9066899f087b5c3/packages/uhk-usb/src/uhk-operations.ts#L447 is the code to switch keymaps. The codebase looks really clean by the way. Real easy to navigate.

kareltucek commented 2 years ago

Let me know if I'm talking out of my ass here.

In theory, it works. In practice, it would be extremely impractical.

Since you can code, just add new usb command similar to the referenced switchKeymap, and set the LED display to the desired text. It will not change until something else changes it - in practice, until next keymap switch.

Some references:

stn1986 commented 2 years ago

I was indeed wondering if I could write arbitrary strings there, but I assumed the device must know the name.

What is impractical about it? It sounds like I directly write any string to the display.

Edit: o.. I see, you mean my method. Yeah, of course, that's just a workaround. If I can write any string it'd be awesome.

stn1986 commented 2 years ago

Thanks @kareltucek !

kareltucek commented 2 years ago

You are welcome!

stn1986 commented 2 years ago

So sorry to keep hammering on this, but I see in the FW in led_display.c that I can control the segments individually, which is.. making me giddy like a little girl. I'm not familiar with "the scene" so to speak, but is there a tool or something already written by someone to control the display directly? To me it'd be really cool to do what I want with it. I guess I could be of service to the community here if I'd provide such a tool until the UHK teams releases their own implementation. If someone did not beat me to it that is, which would be awesome as well.

kareltucek commented 2 years ago

but is there a tool or something already written by someone to control the display directly?

I am not aware of it.

(edit: actually there is my fork of the firmware, which allows settings text from macros - which I don't consider relevant in this context.)

I guess I could be of service to the community here if I'd provide such a tool until the UHK teams releases their own implementation. If someone did not beat me to it that is, which would be awesome as well.

I am sure a PR will be welcome, just consult your API proposal with @mondalaci to make sure you are on the same page.

stn1986 commented 2 years ago

OK, cool. I'll mess around with it first when I get mine and I'll look at your fork. Thanks again.

maxbethke commented 1 year ago

Just wanted to add my +1 to this and drop some thoughts. I just got the UHK v2 and this is the only thing that puts me off about it.

As stated above, the keymap would rarely change for the most users, given that there are 10+ layers on each keymap, so I see no need to sacrifice the display for that info.

I fantasized about being able to toggle the state of the display using the modifier keys, so for example, in normal mode the display would show the current time, in mod the CPU Temperature, in fn the current value of the bitcoin and on mouse mode time left in my current pomodoro cycle or anything else.

mondalaci commented 1 year ago

@maxbethke Your use cases are interesting, and I'd like to support them, but we'll need to expose a sophisticated API to enable them.

  1. Currently, the setLedTxt smart macro command enables the override of the LED display text.
  2. https://github.com/UltimateHackingKeyboard/firmware/issues/531 will enable the execution of smart macros, such as setLedTxt via USB.
  3. We'll expose a nice TypeScript API on top of the USB commands to ease implementing custom behavior, as the one suggested. Currently, ${agentDirectory}/packages/usb contains some random scripts that will serve as the basis of such an API.
  4. We'll expose a dedicated USB command to set per-LED brightness (including the LED display and per-key LEDs) efficiently.
arcxio commented 3 months ago

This would be awesome, could use it for showing current xkbkeymap language, ie if Im currently using english keyboard or native norwegian.

for anyone using sway, I made a script that does this

#!/bin/sh
swaymsg -m -t subscribe '["input"]' |
    jq --unbuffered -r '.|select(.change == "xkb_layout")|.input.xkb_active_layout_name' |
    while read -r new_layout; do
        if [ "$new_layout" != "$prev_layout" ]; then
            prev_layout=$new_layout
            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]*')
            printf "\x14setLedTxt 0 %s" "$(printf %s "$new_layout" | cut -c-3)" >"/dev/$hidraw"
        fi
    done