8 Step macro and profile switching fully working
This commit is contained in:
+27
-9
@@ -12,17 +12,18 @@ struct __attribute__((packed)) SAction {
|
||||
// Gesamt: 3 Bytes (packed! ohne packed wären es 4 durch Alignment)
|
||||
```
|
||||
|
||||
`packed` ist zwingend damit `sizeof(SDeviceConfig) == 223` mit der C#-Serialisierung in VersaGUI übereinstimmt.
|
||||
`packed` ist zwingend damit `sizeof(SDeviceConfig) == 740` mit der C#-Serialisierung in VersaGUI übereinstimmt.
|
||||
|
||||
## ActionType
|
||||
|
||||
| Typ | Bedeutung | data-Inhalt |
|
||||
|---|---|---|
|
||||
| `NONE` | Keine Aktion | — |
|
||||
| `HID_KEY` | Tastendruck via USB HID Keyboard | Low-Byte = HID Keycode, High-Byte = Modifier |
|
||||
| `HID_CONSUMER` | Consumer Control (Volume, Media, …) | Consumer Usage ID |
|
||||
| `HOST_COMMAND` | Event an VersaGUI senden, App führt aus | Command-ID (frei definiert) |
|
||||
| `MACRO` | Makro-Sequenz aus NVM-Tabelle | Slot-Index 0–31 |
|
||||
| Typ | Wert | Bedeutung | data-Inhalt |
|
||||
|---|---|---|---|
|
||||
| `NONE` | 0 | Keine Aktion | — |
|
||||
| `HID_KEY` | 1 | Tastendruck via USB HID Keyboard | Low-Byte = HID Keycode, High-Byte = Modifier |
|
||||
| `HID_CONSUMER` | 2 | Consumer Control (Volume, Media, …) | Consumer Usage ID |
|
||||
| `HOST_COMMAND` | 3 | Event an VersaGUI senden, App führt aus | Command-ID (frei definiert) |
|
||||
| `MACRO` | 4 | Makro-Sequenz aus NVM-Tabelle | Slot-Index 0–31 |
|
||||
| `PROFILE_SWITCH` | 5 | Aktives Profil wechseln | 0–2 = Ziel-Profil, 0xFF = nächstes Profil (Zyklus 0→1→2→0) |
|
||||
|
||||
## execute_action_down() — Taste gedrückt (Hold-Start)
|
||||
|
||||
@@ -32,6 +33,7 @@ struct __attribute__((packed)) SAction {
|
||||
| `HID_CONSUMER` | `usb_hid_send_consumer(usage_id)` — bleibt aktiv bis `execute_action_up()` |
|
||||
| `HOST_COMMAND` | `usb_serial_send(USB_EVT_KEY_DOWN, key_id)` |
|
||||
| `MACRO` | Volle Sequenz ausführen (Steps[slot], keycode==0 = Ende, delay 10+20 ms) |
|
||||
| `PROFILE_SWITCH` | NVM laden → `active_profile` setzen → CRC neu berechnen → NVM speichern → `init_buttons()` |
|
||||
| `NONE` | nop |
|
||||
|
||||
## execute_action_up() — Taste losgelassen (Hold-Ende)
|
||||
@@ -41,7 +43,23 @@ struct __attribute__((packed)) SAction {
|
||||
| `HID_KEY` | `usb_hid_release_key()` |
|
||||
| `HID_CONSUMER` | `usb_hid_release_consumer()` |
|
||||
| `HOST_COMMAND` | — (optional: könnte `USB_EVT_KEY_UP` senden) |
|
||||
| `MACRO`/`NONE` | nop |
|
||||
| `MACRO`/`PROFILE_SWITCH`/`NONE` | nop |
|
||||
|
||||
## PROFILE_SWITCH — Ablauf
|
||||
|
||||
```cpp
|
||||
SDeviceConfig cfg;
|
||||
nvm_config_load(cfg); // komplette Config aus NVM
|
||||
uint8_t target = (uint8_t)action.data;
|
||||
if (target == 0xFF)
|
||||
target = (cfg.active_profile + 1) % 3; // Zyklus
|
||||
cfg.active_profile = target;
|
||||
cfg.crc = nvm_config_crc(cfg); // CRC MUSS nach Änderung neu berechnet werden!
|
||||
if (nvm_config_save(cfg)) // bool: false = NVM-Timeout
|
||||
init_buttons();
|
||||
```
|
||||
|
||||
> **Wichtig:** `active_profile` liegt im CRC-geschützten Bereich (ab Byte 7). Wird die CRC nicht aktualisiert, findet das nächste `nvm_config_load()` einen CRC-Fehler und lädt die Defaults (alle Aktionen NONE, alle LEDs Regenbogen).
|
||||
|
||||
## Hold-Modell (HID-Keys und Consumer Controls)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user