Setup Menu Uses Text Editor Hack

Source Node: 1883362

Many embedded devices that require a setup menu will use a USB serial port which you connect to your favorite terminal emulator. But we recently encountered a generic USB knob that did setup using a text editor, like Notepad or even Vim (although that was a bit ugly). A company called iWit makes several kinds of USB knobs which end up in many such products.

These generic USB knobs are normally just plug-and-play, and are used to control your PC’s volume and muting. Some models, like the iWit, the user can configure the mapping within the device. For example, knob rotation can be set to generate up and down arrow keys, and knob press could be ENTER. One could do this kind of mapping on the PC, but many of these USB knobs can do it for you. The crux of the setup is this menu (which you can see in action in the first 30 seconds of the video below).

- WINDOWS MODE - 1 Clockwise : Up Key 2 Counterclockwise : Down Key 3 Press : Enter 4 Press+Clockwise : Next 5 Press+Counterclockwise : Previous 6 Long Press : Play/Pause [RESTORE DEFAULT] [SAVE & QUIT]

That’s nice, of course, but the surprising point is how the setup menu is implemented in the first place. The knob, already being an HID, spews forth the setup menu as if it were being typed from a keyboard. Turning the knob to select an option generates ANSI escape sequences for up and down cursor movement and somehow highlights the current line. Looking at the stream, you can see that the menus are proceeded with these codes:

ESC [ 4 ~ Private code? ESC [ 1 ; 2 H Cursor row 1, col 2 ESC [ D Cursor back one column ESC [ 3 ~ Private code?

and item selection is simply the up and down cursor movement codes:

ESC [ A Cursor up one row ESC [ B Cursor down one row

This makes sense, if we were talking to a terminal. But it’s not entirely clear how the typical text editor handles ANSI escape sequences. It’s not a big stretch to imagine that up and down cursor codes would be interpreted as arrow keys by either the operating system or the editor itself, but the highlighting remains a bit of a mystery. If you have any ideas, or have done anything similar yourself, let us know in the comments below.

The video below was found on [Nelson Chu]’s Expresii blog, an artist who specializes in simulating organic brush strokes in computer graphics systems. The particular knob used in this article was branded DROK, so you might have this capability in your USB knob even though it doesn’t say iWit on the label. If you’d like full control of your USB knob, build your own as we wrote about in this article from 2020.

Source: https://hackaday.com/2022/01/20/setup-menu-uses-text-editor-hack/

Time Stamp:

More from Hackaday