8 Step macro and profile switching fully working

This commit is contained in:
2026-04-13 22:34:49 +02:00
parent e01666ab59
commit 24fe162833
8 changed files with 185 additions and 58 deletions
+44 -28
View File
@@ -14,55 +14,71 @@ C#-Spiegel der Firmware-Structs. Muss byte-kompatibel mit `SDeviceConfig` (nvm_c
| Feld | Typ | Inhalt |
|---|---|---|
| `MxActions[20]` | `DeviceAction[]` | Aktionen für MX-Buttons 019 |
| `EncActions[4,3]` | `DeviceAction[,]` | Encoder [03][SW=0/CW=1/CCW=2] |
| `LedBase[20]` | `Color[]` | RGB-Basis-LED-Farbe je Button |
| `LedAnim[20]` | `LedAnimType[]` | Animation je Button |
| `LedPeriod[20]` | `ushort[]` | Animationsperiode in ms |
| `ActiveProfileIndex` | `byte` | Aktives Profil (02) |
| `GlobalBrightness` | `byte` | Globale LED-Helligkeit (0255) |
| `MxActions[20]` | `DeviceAction[]` | Aktionen für MX-Buttons 019 (aus aktivem Profil) |
| `EncActions[4,3]` | `DeviceAction[,]` | Encoder [03][SW=0/CW=1/CCW=2] (aus aktivem Profil) |
| `LedBase[20]` | `Color[]` | RGB-Basis-LED-Farbe je Button (aus aktivem Profil) |
| `LedAnim[20]` | `LedAnimType[]` | Animation je Button (aus aktivem Profil) |
| `LedPeriod[20]` | `ushort[]` | Animationsperiode in ms (aus aktivem Profil) |
### Serialisierungs-Layout (ToBytes / FromBytes, 223 B)
### Serialisierungs-Layout (ToBytes / FromBytes, 740 B)
```
Offset 0 4B Magic 0x56503202 (little-endian)
Offset 4 1B Version = 2
Offset 5 2B CRC16-CCITT über Bytes 7222 (little-endian)
Offset 7 60B MxActions[20] je 3B: type(1) + data_lo(1) + data_hi(1)
Offset 67 36B EncActions[4][3] je 3B
Offset103 20B LedBase[i].R
Offset123 20B LedBase[i].G
Offset143 20B LedBase[i].B
Offset163 20B LedAnim[i] als byte
Offset183 40B LedPeriod[i] als uint16 little-endian
Offset 0 4B Magic 0x56503203 (little-endian)
Offset 4 1B Version = 3
Offset 5 2B CRC16-CCITT über Bytes 7739 (little-endian)
Offset 7 1B active_profile (02)
Offset 8 1B global_brightness
Offset 9 4B enc_sensitivity[4]
Offset 13 19B Reserve (_reserve)
Profil 0 (Offset 32, 236 B):
Offset 32 60B MxActions[20] je 3B: type(1) + data_lo(1) + data_hi(1)
Offset 92 36B EncActions[4][3] je 3B
Offset 128 20B LedBase[i].R
Offset 148 20B LedBase[i].G
Offset 168 20B LedBase[i].B
Offset 188 20B LedBrightness[i]
Offset 208 20B LedAnim[i] als byte
Offset 228 40B LedPeriod[i] als uint16 little-endian
Profil 1 (Offset 268, 236 B): identisches Layout
Profil 2 (Offset 504, 236 B): identisches Layout
```
### CRC16-CCITT
Polynom `0x1021`, Init `0xFFFF`, über Bytes 7222 (nach dem CRC-Feld selbst). Muss identisch mit Firmware-Implementierung sein. `DeviceConfig.Crc16()` ist statisch und direkt testbar.
Polynom `0x1021`, Init `0xFFFF`, über Bytes 7739 (nach dem CRC-Feld selbst, einschließlich `active_profile`). Muss identisch mit Firmware-Implementierung sein. `DeviceConfig.Crc16()` ist statisch und direkt testbar.
### Defaults (entspricht Firmware-Defaults)
- Alle Aktionen: `None`
- LEDs: warm-weiß (R=80, G=40, B=0)
- LEDs: warm-weiß (R=80, G=40, B=0), Helligkeit 255
- Animation: `ColorCycle` (Regenbogen), Period 4000 ms
- `active_profile = 0`, `global_brightness = 255`
---
## DeviceAction
```csharp
public enum ActionType : byte { None=0, HidKey=1, HidConsumer=2, HostCommand=3, Macro=4 }
public enum ActionType : byte {
None=0, HidKey=1, HidConsumer=2, HostCommand=3, Macro=4, ProfileSwitch=5
}
public class DeviceAction {
public ActionType Type { get; set; }
public ushort Data { get; set; }
// HidKey: Low-Byte = HID Keycode, High-Byte = Modifier
// HidConsumer: Consumer Usage ID
// HostCommand: Command-ID
// Macro: Slot-Index 031
// HidKey: Low-Byte = HID Keycode, High-Byte = Modifier
// HidConsumer: Consumer Usage ID
// HostCommand: Command-ID
// Macro: Slot-Index 031
// ProfileSwitch: 02 = Ziel-Profil, 0xFFFF = nächstes Profil (Zyklus)
}
```
`DeviceAction.Display` gibt einen lesbaren String zurück (z.B. `"Strg+C"`, `"Play/Pause"`, `"Makro 3"`).
`DeviceAction.Display` gibt einen lesbaren String zurück (z.B. `"Strg+C"`, `"Play/Pause"`, `"→ Profil 2"`, `"→ Nächstes Profil"`).
---
@@ -71,7 +87,7 @@ public class DeviceAction {
```csharp
public class MacroTable {
public const int Slots = 32;
public const int MaxSteps = 4;
public const int MaxSteps = 8;
public MacroStep[,] Steps { get; } // [slot][step]
}
public class MacroStep {
@@ -87,9 +103,9 @@ public class MacroStep {
| 019 | MX-Button `mxIdx` (`MacroTable.SlotForMx(mxIdx)`) |
| 2031 | Encoder: `20 + enc * 3 + actIdx` (`MacroTable.SlotForEncoder(enc, actIdx)`) |
### Serialisierung (256 B)
### Serialisierung (512 B)
32 Slots × 4 Steps × 2 B = 256 B. Keycode zuerst, dann Modifier. Kein Magic/CRC (Board akzeptiert jeden Inhalt).
32 Slots × 8 Steps × 2 B = 512 B. Keycode zuerst, dann Modifier. Kein Magic/CRC (Board akzeptiert jeden Inhalt).
---
@@ -101,4 +117,4 @@ public enum LedAnimType : byte {
}
```
Werte entsprechen `LEDAnim` in der Firmware. `FADE_IN` (3) und `FADE_OUT` (4) existieren in der Firmware aber nicht in der GUI (nicht konfigurierbar, nur `COLOR_FADE` intern).
Werte entsprechen `LEDAnim` in der Firmware. `FADE_IN` (3) und `FADE_OUT` (4) existieren in der Firmware aber nicht in der GUI (nicht konfigurierbar).