Public facing docs and changes added.
This commit is contained in:
130
README.md
130
README.md
@@ -1,47 +1,123 @@
|
||||
# desk-reminder
|
||||
|
||||
Simple C program that listens for events from the Alcor Micro AU9540 USB smartcard reader.
|
||||

|
||||
|
||||
- USB device: `058f:9540` (Alcor Micro Corp. AU9540 Smartcard Reader)
|
||||
- Implementation: raw USB using `libusb-1.0`
|
||||
Small Linux utility that enforces periodic standing desk adjustments. After 20 minutes
|
||||
sitting, the screen is locked until the user switches to standing mode on their adjustable
|
||||
standing desk. This works via an ecard reader attached to the back of the computer
|
||||
screen and the wall, which allows this program to detect when the user is standing or
|
||||
sitting.
|
||||
|
||||
The program opens the reader by VID/PID, locates the first interrupt IN endpoint, and prints any data received (typically slot change / card insertion or removal notifications). It does **not** implement full CCID or smartcard protocols, but is useful for observing low-level traffic.
|
||||
## What It Does
|
||||
|
||||
- Grabs a specific input keyboard device with `EVIOCGRAB`, so key events from that device are hidden from other applications.
|
||||
- Reads digit key presses (`0-9`) until `Enter`.
|
||||
- Hashes the entered numeric string with SHA-256 and compares the first 8 bytes (as a 64-bit number) against a hardcoded value.
|
||||
- If the hash matches, it resets the standing timer, kills `i3lock`, and re-enables keyboards.
|
||||
- A background watcher thread checks elapsed time every second.
|
||||
- Once elapsed time reaches the configured interval, it disables keyboard devices via `xinput` and starts `i3lock` with a lockscreen image.
|
||||
|
||||
Default interval is 20 minutes.
|
||||
|
||||
## Dependencies
|
||||
|
||||
Build-time:
|
||||
|
||||
- GCC
|
||||
- OpenSSL development headers/libraries (`libssl-dev` on Debian/Ubuntu)
|
||||
- POSIX threads (`pthread`)
|
||||
- Linux input headers (`linux/input.h`)
|
||||
|
||||
Runtime:
|
||||
|
||||
- `xinput`
|
||||
- `i3lock`
|
||||
- X11 session (because keyboard disabling uses `xinput`)
|
||||
- Permission to read the target input device in `/dev/input/by-id/...`
|
||||
|
||||
## Build
|
||||
|
||||
On Debian/Ubuntu and similar, install the development package:
|
||||
The current `Makefile` does not match the source filename in this repository (`desk-reminder.c`), so compile directly:
|
||||
|
||||
```sh
|
||||
sudo apt-get update
|
||||
sudo apt-get install libusb-1.0-0-dev
|
||||
```bash
|
||||
gcc -Wall -Wextra -O2 desk-reminder.c -o desk-reminder -lssl -lcrypto -lpthread
|
||||
```
|
||||
|
||||
Then build the program:
|
||||
## Configure
|
||||
|
||||
```sh
|
||||
cd desk-reminder
|
||||
make
|
||||
Edit the hardcoded device path in `desk-reminder.c`:
|
||||
|
||||
```c
|
||||
const char *dev = "/dev/input/by-id/usb-IC_Reader_IC_Reader_08FF20171101-event-kbd";
|
||||
```
|
||||
|
||||
This produces a `desk_reminder` binary.
|
||||
Use one of these to find your device path:
|
||||
|
||||
## Run
|
||||
|
||||
You may need root or appropriate udev rules to access USB devices directly:
|
||||
|
||||
```sh
|
||||
cd desk-reminder
|
||||
sudo ./desk_reminder
|
||||
```bash
|
||||
ls -l /dev/input/by-id/
|
||||
cat /proc/bus/input/devices
|
||||
```
|
||||
|
||||
Expected behavior:
|
||||
## Usage
|
||||
|
||||
- The program prints which bus/device it opened.
|
||||
- It reports which interrupt IN endpoint it is listening on.
|
||||
- When the AU9540 reports an event (for example, card insertion/removal), the program prints the raw bytes received.
|
||||
Run with default interval (20 minutes):
|
||||
|
||||
Press `Ctrl+C` to stop the program.
|
||||
```bash
|
||||
./desk-reminder
|
||||
```
|
||||
|
||||
## Notes
|
||||
Set interval explicitly:
|
||||
|
||||
```bash
|
||||
./desk-reminder -i 20m
|
||||
./desk-reminder -i 1200s
|
||||
```
|
||||
|
||||
`-i` accepts a positive integer and optional unit suffix:
|
||||
|
||||
- `s` for seconds
|
||||
- `m` for minutes (default if no suffix)
|
||||
|
||||
Examples:
|
||||
|
||||
- `-i 30` means 30 minutes
|
||||
- `-i 30m` means 30 minutes
|
||||
- `-i 45s` means 45 seconds
|
||||
|
||||
## Operational Notes
|
||||
|
||||
- This program grabs the configured device exclusively.
|
||||
- When timeout is reached, keyboard devices are disabled using:
|
||||
|
||||
- `xinput --list --short | grep -i keyboard | grep -v XTEST | ... | xinput disable`
|
||||
|
||||
- On successful reset code entry, keyboards are re-enabled with the matching `xinput enable` pipeline.
|
||||
- Screen lock image is hardcoded to:
|
||||
|
||||
- `/usr/local/share/lockscreens/standing_gopher.png`
|
||||
|
||||
Ensure this file exists, or adjust the command in source.
|
||||
|
||||
## Safety / Recovery
|
||||
|
||||
- Keep another input method available during testing (for example, a second terminal/TTY).
|
||||
- Test with a short interval first (`-i 30s`) to verify behavior.
|
||||
- If something goes wrong and keyboards remain disabled, use another session/input device to run:
|
||||
|
||||
```bash
|
||||
xinput --list --short | grep -i keyboard | grep -v XTEST | sed -E 's/.*id=([0-9]+).*/\1/' | xargs -r -n1 xinput enable
|
||||
pkill i3lock
|
||||
```
|
||||
|
||||
## Limitations
|
||||
|
||||
- Linux-only.
|
||||
- X11-specific keyboard management (not Wayland-native).
|
||||
- Input device path, reset hash target, and lockscreen path are all hardcoded.
|
||||
- No systemd service/unit is included in this repository.
|
||||
|
||||
## License
|
||||
|
||||
This project is licensed under the GNU General Public License, version 3.
|
||||
See `LICENSE` for the full text.
|
||||
|
||||
For higher-level smartcard operations (APDU exchange, PIN verification, etc.), you would typically use PC/SC (`pcscd`, `libpcsclite`) instead of talking to the reader via raw USB. This example focuses on listening to the USB interrupt endpoint.
|
||||
|
||||
Reference in New Issue
Block a user