blob: 2b1ea30f6a6fa5e0382adb110c869c819f5333ee (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
|
# ZMK BattMan
A lightweight system tray application for monitoring battery levels of ZMK split keyboards on Linux. Displays both left (central) and right (peripheral) battery percentages with configurable low battery notifications.
## Features
- **Dual Battery Monitoring** - Shows battery levels for both keyboard halves
- **System Tray Integration** - Clean, minimal tray icon with battery percentages
- **Desktop Notifications** - Configurable low battery alerts
- **CLI Configuration** - Easy setup and management via command line
### ZMK Configuration Required
Your ZMK config must have these configuration options enabled:
```
CONFIG_ZMK_SPLIT_BLE_CENTRAL_BATTERY_LEVEL_PROXY=y
CONFIG_ZMK_SPLIT_BLE_CENTRAL_BATTERY_LEVEL_FETCHING=y
```
## Installation
Place the `zmk-battman` binary in anywhere in your PATH.
### Build from Source
```bash
# Clone the repository
git clone https://git.tablaster.dev/blaster4385/zmk-battman
cd zmk-battery-monitor
# Build the app
make battman
```
## Quick Start
### 1. Initial Setup
```bash
# Run the interactive setup
./zmk-battman --setup
```
This will guide you through:
- Selecting your ZMK keyboard from available Bluetooth devices
- Setting the update interval (default: 30 seconds)
- Configuring notifications (default: enabled)
- Setting low battery threshold (default: 20%)
### 2. Start Monitoring
```bash
./zmk-battman
```
The application will start in the system tray and begin monitoring your keyboard's battery levels.
### 3. Autostart (Optional)
Add to your window manager configuration:
**Hyprland** (`~/.config/hypr/hyprland.conf`):
```bash
exec-once = /path/to/zmk-battman
```
**i3/sway** (`~/.config/i3/config`):
```bash
exec --no-startup-id /path/to/zmk-battman
```
## Usage
### Command Line Options
```bash
./zmk-battman [OPTIONS]
Options:
--setup Run interactive setup wizard
--config Display current configuration
--device ADDRESS Set keyboard device by Bluetooth address
--interval SECONDS Set update interval (5-300 seconds)
--threshold PERCENT Set low battery threshold (5-50%)
--notify true/false Enable/disable desktop notifications
```
### Examples
```bash
# Initial configuration
./zmk-battman --setup
# Quick device configuration
./zmk-battman --device "AA:BB:CC:DD:EE:FF"
# Set low battery threshold to 15%
./zmk-battman --threshold 15
# Enable notifications with 10% threshold
./zmk-battman --notify true --threshold 10
# View current settings
./zmk-battman --config
# Start the app
./zmk-battman
```
## Configuration
Configuration is stored at `~/.config/zmk-battman/config.json`:
```json
{
"name": "My ZMK Keyboard",
"address": "AA:BB:CC:DD:EE:FF",
"update_interval": 30,
"low_battery_threshold": 20,
"show_notifications": true
}
```
### Configuration Options
| Option | Default | Range | Description |
| :-- | :-- | :-- | :-- |
| `update_interval` | 30 | 5-300 | Battery check interval in seconds |
| `low_battery_threshold` | 20 | 5-50 | Battery percentage for low battery alerts |
| `show_notifications` | true | true/false | Enable desktop notifications |
## System Tray Display
The system tray icon shows:
- **Title**: Battery percentages (e.g., "85%/72%" for left/right)
- **Tooltip**: Detailed status including device name, connection status, and last update time
- **Menu**:
- Connection status
- Individual battery levels for left/right halves
- Manual refresh
- Quit
## Notifications
Desktop notifications are sent for:
- **Low Battery Warning**: When either keyboard half drops to/below the threshold
- **Connection Changes**: When keyboard connects or disconnects
- **Critical Battery Level**: Extra urgent notification for battery levels ≤10%
Notifications are rate-limited to prevent spam (10-minute delay between identical alerts).
## Technical Details
### ZMK Battery Service Detection
The monitor detects ZMK split keyboard batteries by:
1. **Multiple Battery Services**: Looks for multiple instances of the standard Bluetooth Battery Service (UUID: `0000180f-0000-1000-8000-00805f9b34fb`)
2. **Service Ordering**: First service = left (central), second service = right (peripheral)
3. **Fallback Support**: Falls back to legacy `org.bluez.Battery1` interface for single-service keyboards
### Architecture
```
zmk-battery-monitor/
├── main.go # CLI interface and application lifecycle
├── internal/
│ ├── types.go # Data structures
│ ├── bluetooth.go # Bluetooth device scanning and communication
│ ├── monitor.go # Battery level monitoring logic
│ ├── config.go # Configuration management
│ ├── notifications.go # Desktop notification system
│ └── tray.go # System tray interface
└── assets/
├── keyboard-icon.png # icon (embedded at build time)
└── icon.go # Embed icon into binary
```
## Troubleshooting
### Keyboard Not Found
- Ensure your ZMK keyboard is paired and connected via Bluetooth
- Check that the keyboard appears in `bluetoothctl list` or similar
### No Battery Information
- Your ZMK config must have these configuration options enabled:
```
CONFIG_ZMK_SPLIT_BLE_CENTRAL_BATTERY_LEVEL_PROXY=y
CONFIG_ZMK_SPLIT_BLE_CENTRAL_BATTERY_LEVEL_FETCHING=y
```
- Some keyboards may need some time after connection before battery data is available
- Check system logs for D-Bus connection errors
### System Tray Not Appearing
- Ensure that your desktop environment supports system tray (most modern DEs do)
- Check that the application is running: `ps aux | grep zmk-battman`
- Try running in foreground (not autostart) to see error messages
### Notifications Not Working
- Verify your system supports freedesktop notifications
- Test with: `notify-send "Test" "This is a test notification"`
- Check if notifications are enabled: `./zmk-battman --config`
## Development
### Building
```bash
go build -o zmk-battman
```
### Dependencies
- `github.com/getlantern/systray` - System tray functionality
- `github.com/godbus/dbus/v5` - D-Bus communication for Bluetooth and notifications
### Contributing
Contributions are welcome but idk how. Try contacting me on my email if you want to contribute something here. Or just feel free to fork this to your github or whatever and do whatever you want. Just ensure to provide proper credits and adhere to the license.
## License
This project is licensed under the GPLv2 License - see the [LICENSE](LICENSE) file for details.
|