AMacroPad
Android/Linux Macropad that uses Bluetooth SPP
Install / Use
/learn @wd5gnr/AMacroPadREADME
This is part of a "DIY Macropad Kit" that uses an Android phone or tablet.
Here's how it works. The C part creates a Bluetooth Serial Port server on linux. An Android app talks to it (see the APK in this directory).
The AIA file can be imported into App Inventor and you will almost certainly want to do that.
The app has a single "screen". The Pages container has a bunch of table layouts, which, of course, have more layouts inside. The program hides all the layouts but the active one.
By default there is a configuration page (you probably won't change that). Then there are two pages of buttons and a web browser page that is used twice. There's also a top bar that doesn't switch.
There are several things you can do. First, you can add/delete or modify pages. They don't have to look at all like these, but they do need to live in a hidden table layout (even if it is a 1x1 table) so it can be switched on and off.
You can also change what's on each page. What you do is up to you. Since the web browser is "heavy" there is a way to switch to one page and make it do multiple things.
There are three global variables that control the page system:
- screens - A list of all screens in order
- screenName - The name of each screen (in order)
- webcontext - Extra data for the web screen although you can use it for what you like or make more "parallel" lists. For the base code, if present, this is the URL the webbrowser is sent to when the page enters.
Note that you can repeat a page in the screens list and just give it a different title and webcontent (or the same, but why would you do that?).
To send a command to the PC use send() or SendCmd() or SendCmdLine().
- send - Just send data
- SendCmd - Send a numbered command with or without arguments
- SendCmdLine - Send an arbitrary command like (e.g., emacs foo.txt).
You can also query the server and get one line of results back (the first line). This is through sendQuery()
There is a timeout global if you want to timeout in milliseconds or set to zero for none.
The server accepts several types of commands.
- Numbered commands from ~/.config/amacropad/commands.txt. The numbers don't have to be consecutive or in order. So you can do something like 1xx commands are for file systems and 2xx commands are for keyboard macros, etc.
- If enabled, you can send command line arguments to the numbered commands.
- Command #s over 1000 (configurable) are internal and you can create code in the server to reply (or do something). There are two examples: 1000 prints a line of info and 1001 returns a simple string. You'd replace these, of course.
- If enabled, an arbitrary command line.
- A query which must be a number. The server may or may not allow arguments, at your option.
Here's a sample command file:
# These are the tagged tools for amacropad
# The format is tag:command
# tags are positive integer numbers (0 to 499 unless you change in source)
# Comments are like this (# ignores line)
# tags don't have to be in order if you like chaos
# They also don't have to be in sequence
# Note that the pad can send arguments to these which
# You can use or ignore
# Note you can use >> to run any command (if enabled)
# Or if you put a tag in here for, say bash -c you could
# do it that way.
# >#20 runs tag 20
# >#20 xyz.txt also runs tag 20 but includes xyz.txt argument
# >?11 runs tag 11 and sends back the first line of output to the pad
# >?11 xyz.txt (same but with argument)
# Note that >? always prefixes the line with <! which
# the pad code removes
1:xdotool
2:xdotool type
3:xdg-open
4:dbus-send
6:wmctrl
7:fortune|tr '\n' ' '| tr -s '[:space:]' ' '
# temperature
8:sensors | grep CPUTIN | tr -s ' ' | cut -d ' ' -f 2
# mute (yes or no; only for pulseaudio, though)
9:"pactl get-sink-mute `pactl get-default-sink`" | cut -d ' ' -f 2
10:dolphin
11:emacs
20:xdg-open http://www.hackaday.com
Note that if you change commands.txt you will need to reload the server.
The Android app has wrappers for the commands like >#20 so you just send 20. But you could write even more wrappers if you "know" what's in command text. So, you could easily make a proceudre called call_dolphin that sent command 10, for instance.
Note there are small labels at key parts of the layouts to act as spacers. Also, the text layouts are funny so if your text wraps a line, the buttons may go wacky. Your best bet it so make graphic icons (with or without text) for each button. There are examples of all of this. You could also make more complex layouts with a button and a separate text field.
There are several complexities involved with hiding and showing the web viewer. Also, the design size in the App Inventor interface is too small. I suggest setting it to Monitor or Tablet and then trying your layouts on the real device.
Note the example buttons depend on commands #1, #2, #3, #7, #8, #9 and probably some of the others, too for specific buttons (e.g., #11)
Notes: Turn off all the layouts except topbar, Pages, and config unless you are editing them.
qdbus can be useful. For example qdbus org.kde.plasmashell /org/kde/osdService org.kde.osdService.showText dialog-information Connected! would give you a OSD popup.
