Compare commits
No commits in common. "24fe16283365a74eef199f5eba458324fa9d420e" and "96f00f0893e6a34f8aae0ac8df6fc9015b7dac30" have entirely different histories.
24fe162833
...
96f00f0893
@ -61,7 +61,6 @@ Die App erscheint als Icon in der Windows-Taskleiste (System Tray). Kein Hauptfe
|
|||||||
| 2.4 | **Layout-unabhängige Erfassung** via PS/2-Scan-Code → HID-Usage; Ö/Ä/Ü auf QWERTZ korrekt | ✅ |
|
| 2.4 | **Layout-unabhängige Erfassung** via PS/2-Scan-Code → HID-Usage; Ö/Ä/Ü auf QWERTZ korrekt | ✅ |
|
||||||
| 2.5 | Taste-Name wird laut **aktivem Windows-Layout** angezeigt (`GetKeyNameText`) | ✅ |
|
| 2.5 | Taste-Name wird laut **aktivem Windows-Layout** angezeigt (`GetKeyNameText`) | ✅ |
|
||||||
| 2.6 | Board führt Tastendruck als **USB-HID-Tastatureingabe** aus (funktioniert ohne laufende App) | ✅ |
|
| 2.6 | Board führt Tastendruck als **USB-HID-Tastatureingabe** aus (funktioniert ohne laufende App) | ✅ |
|
||||||
| 2.7 | **Hold-Semantik**: Taste bleibt gedrückt solange physisch gehalten (OS initiiert Repeat nach ~500ms) | ✅ |
|
|
||||||
|
|
||||||
### 3 Tastenbelegung – HID Consumer / Medientasten
|
### 3 Tastenbelegung – HID Consumer / Medientasten
|
||||||
|
|
||||||
@ -69,7 +68,6 @@ Die App erscheint als Icon in der Windows-Taskleiste (System Tray). Kein Hauptfe
|
|||||||
|---|-------------|--------|
|
|---|-------------|--------|
|
||||||
| 3.1 | Auswahl per **Dropdown** mit Klartext-Namen | ✅ |
|
| 3.1 | Auswahl per **Dropdown** mit Klartext-Namen | ✅ |
|
||||||
| 3.2 | Unterstützte Aktionen: Play/Pause, Nächster/Vorheriger Titel, Stop, Lauter/Leiser, Mute, Taschenrechner, Browser Zurück/Vor | ✅ |
|
| 3.2 | Unterstützte Aktionen: Play/Pause, Nächster/Vorheriger Titel, Stop, Lauter/Leiser, Mute, Taschenrechner, Browser Zurück/Vor | ✅ |
|
||||||
| 3.3 | **Hold-Semantik**: Media-Control bleibt aktiv solange Taste gehalten wird (z.B. Lautstärke-Wiederholung) | ✅ |
|
|
||||||
|
|
||||||
### 4 Tastenbelegung – Makros
|
### 4 Tastenbelegung – Makros
|
||||||
|
|
||||||
@ -88,8 +86,6 @@ Die App erscheint als Icon in der Windows-Taskleiste (System Tray). Kein Hauptfe
|
|||||||
|---|-------------|--------|
|
|---|-------------|--------|
|
||||||
| 5.1 | **4 Encoder**, je 3 Aktionen: SW (Drücken), CW (Rechts), CCW (Links) | ✅ |
|
| 5.1 | **4 Encoder**, je 3 Aktionen: SW (Drücken), CW (Rechts), CCW (Links) | ✅ |
|
||||||
| 5.2 | Gleiche Aktionstypen wie Tasten (HID Key, Consumer, Makro, Host Command) | ✅ |
|
| 5.2 | Gleiche Aktionstypen wie Tasten (HID Key, Consumer, Makro, Host Command) | ✅ |
|
||||||
| 5.3 | **Encoder-SW**: Hold-Semantik wie normale Tasten (Taste bleibt gedrückt) | ✅ |
|
|
||||||
| 5.4 | **Encoder-CW/CCW**: Tap-Modell (diskrete Ereignisse, atomare down+delay+up Sequenzen, kein Hold möglich) | ✅ |
|
|
||||||
|
|
||||||
### 6 LED-Konfiguration
|
### 6 LED-Konfiguration
|
||||||
|
|
||||||
|
|||||||
@ -8,7 +8,6 @@
|
|||||||
- Verbindungsaufbau und automatischer Reconnect
|
- Verbindungsaufbau und automatischer Reconnect
|
||||||
- Hintergrund-Lese-Thread mit Paket-Assembler
|
- Hintergrund-Lese-Thread mit Paket-Assembler
|
||||||
- Sende-Methoden für alle Protokoll-Operationen
|
- Sende-Methoden für alle Protokoll-Operationen
|
||||||
- ACK/NACK-Synchronisation zwischen ReadLoop-Thread und `SendConfig`/`SendMacros`-Task
|
|
||||||
|
|
||||||
## COM-Port-Erkennung
|
## COM-Port-Erkennung
|
||||||
|
|
||||||
@ -53,38 +52,20 @@ Bei IOException:
|
|||||||
else: break → Disconnect
|
else: break → Disconnect
|
||||||
```
|
```
|
||||||
|
|
||||||
## ACK/NACK-Synchronisation
|
|
||||||
|
|
||||||
`SendConfig` und `SendMacros` blockieren nach COMMIT auf ein `SemaphoreSlim`-Gate bis das Board antwortet:
|
|
||||||
|
|
||||||
```
|
|
||||||
_configAckGate / _macroAckGate – SemaphoreSlim(0, 1)
|
|
||||||
_configAckOk / _macroAckOk – volatile bool (true = ACK, false = NACK)
|
|
||||||
```
|
|
||||||
|
|
||||||
| Methode | Aufruf durch | Wirkung |
|
|
||||||
|---|---|---|
|
|
||||||
| `SignalConfigAck()` | TrayApp bei EvtConfigAck | `_configAckOk = true`, Gate freigeben |
|
|
||||||
| `SignalConfigNack()` | TrayApp bei EvtConfigNack | `_configAckOk = false`, Gate freigeben |
|
|
||||||
| `SignalMacroAck()` | TrayApp bei EvtMacroAck | `_macroAckOk = true`, Gate freigeben |
|
|
||||||
| `SignalMacroNack()` | TrayApp bei EvtMacroNack | `_macroAckOk = false`, Gate freigeben |
|
|
||||||
|
|
||||||
`SendConfig()` und `SendMacros()` geben `bool` zurück (`true` = ACK erhalten, `false` = NACK oder Timeout nach 3 s).
|
|
||||||
|
|
||||||
## Sende-Methoden
|
## Sende-Methoden
|
||||||
|
|
||||||
| Methode | Rückgabe | Funktion |
|
| Methode | Funktion |
|
||||||
|---|---|---|
|
|---|---|
|
||||||
| `Send(pkt)` | void | Rohe 8-Byte-Übertragung (fire-and-forget) |
|
| `Send(pkt)` | Rohe 8-Byte-Übertragung (fire-and-forget, ignoriert Sendefehler) |
|
||||||
| `SetLedOverride(keyId, r, g, b)` | void | CMD 0x01 |
|
| `SetLedOverride(keyId, r, g, b)` | CMD 0x01 |
|
||||||
| `ClearLedOverride(keyId)` | void | CMD 0x02 |
|
| `ClearLedOverride(keyId)` | CMD 0x02 |
|
||||||
| `SetLedBase(keyId, r, g, b)` | void | CMD 0x03 |
|
| `SetLedBase(keyId, r, g, b)` | CMD 0x03 |
|
||||||
| `RequestConfig()` | void | CMD 0x13 – Board antwortet mit Config-Dump |
|
| `RequestConfig()` | CMD 0x13 – Board antwortet mit Config-Dump |
|
||||||
| `RequestMacros()` | void | CMD 0x23 – Board antwortet mit Makro-Dump |
|
| `RequestMacros()` | CMD 0x23 – Board antwortet mit Makro-Dump |
|
||||||
| `SendConfig(cfg)` | bool | BEGIN(0x10) → 124×DATA(0x11) → COMMIT(0x12), 5 ms zwischen Chunks, wartet auf ACK/NACK |
|
| `SendConfig(cfg)` | BEGIN(0x10) → 38×DATA(0x11) → COMMIT(0x12), 5 ms zwischen Chunks |
|
||||||
| `SendMacros(macros)` | bool | BEGIN(0x20) → 86×DATA(0x21) → COMMIT(0x22), 5 ms zwischen Chunks, wartet auf ACK/NACK |
|
| `SendMacros(macros)` | BEGIN(0x20) → 43×DATA(0x21) → COMMIT(0x22), 5 ms zwischen Chunks |
|
||||||
|
|
||||||
`SendConfig` und `SendMacros` blockieren ~1,5 s (Chunks + NVM-Zeit) → werden in `Task.Run()` aus `ConfigForm.OnSave()` aufgerufen.
|
`SendConfig` und `SendMacros` blockieren ~400 ms → werden in `Task.Run()` aus `ConfigForm.OnSave()` aufgerufen.
|
||||||
|
|
||||||
## Events
|
## Events
|
||||||
|
|
||||||
|
|||||||
@ -14,58 +14,43 @@ C#-Spiegel der Firmware-Structs. Muss byte-kompatibel mit `SDeviceConfig` (nvm_c
|
|||||||
|
|
||||||
| Feld | Typ | Inhalt |
|
| Feld | Typ | Inhalt |
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
| `ActiveProfileIndex` | `byte` | Aktives Profil (0–2) |
|
| `MxActions[20]` | `DeviceAction[]` | Aktionen für MX-Buttons 0–19 |
|
||||||
| `GlobalBrightness` | `byte` | Globale LED-Helligkeit (0–255) |
|
| `EncActions[4,3]` | `DeviceAction[,]` | Encoder [0–3][SW=0/CW=1/CCW=2] |
|
||||||
| `MxActions[20]` | `DeviceAction[]` | Aktionen für MX-Buttons 0–19 (aus aktivem Profil) |
|
| `LedBase[20]` | `Color[]` | RGB-Basis-LED-Farbe je Button |
|
||||||
| `EncActions[4,3]` | `DeviceAction[,]` | Encoder [0–3][SW=0/CW=1/CCW=2] (aus aktivem Profil) |
|
| `LedAnim[20]` | `LedAnimType[]` | Animation je Button |
|
||||||
| `LedBase[20]` | `Color[]` | RGB-Basis-LED-Farbe je Button (aus aktivem Profil) |
|
| `LedPeriod[20]` | `ushort[]` | Animationsperiode in ms |
|
||||||
| `LedAnim[20]` | `LedAnimType[]` | Animation je Button (aus aktivem Profil) |
|
|
||||||
| `LedPeriod[20]` | `ushort[]` | Animationsperiode in ms (aus aktivem Profil) |
|
|
||||||
|
|
||||||
### Serialisierungs-Layout (ToBytes / FromBytes, 740 B)
|
### Serialisierungs-Layout (ToBytes / FromBytes, 223 B)
|
||||||
|
|
||||||
```
|
```
|
||||||
Offset 0 4B Magic 0x56503203 (little-endian)
|
Offset 0 4B Magic 0x56503202 (little-endian)
|
||||||
Offset 4 1B Version = 3
|
Offset 4 1B Version = 2
|
||||||
Offset 5 2B CRC16-CCITT über Bytes 7–739 (little-endian)
|
Offset 5 2B CRC16-CCITT über Bytes 7–222 (little-endian)
|
||||||
Offset 7 1B active_profile (0–2)
|
Offset 7 60B MxActions[20] je 3B: type(1) + data_lo(1) + data_hi(1)
|
||||||
Offset 8 1B global_brightness
|
Offset 67 36B EncActions[4][3] je 3B
|
||||||
Offset 9 4B enc_sensitivity[4]
|
Offset103 20B LedBase[i].R
|
||||||
Offset 13 19B Reserve (_reserve)
|
Offset123 20B LedBase[i].G
|
||||||
|
Offset143 20B LedBase[i].B
|
||||||
Profil 0 (Offset 32, 236 B):
|
Offset163 20B LedAnim[i] als byte
|
||||||
Offset 32 60B MxActions[20] je 3B: type(1) + data_lo(1) + data_hi(1)
|
Offset183 40B LedPeriod[i] als uint16 little-endian
|
||||||
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
|
### CRC16-CCITT
|
||||||
|
|
||||||
Polynom `0x1021`, Init `0xFFFF`, über Bytes 7–739 (nach dem CRC-Feld selbst, einschließlich `active_profile`). Muss identisch mit Firmware-Implementierung sein. `DeviceConfig.Crc16()` ist statisch und direkt testbar.
|
Polynom `0x1021`, Init `0xFFFF`, über Bytes 7–222 (nach dem CRC-Feld selbst). Muss identisch mit Firmware-Implementierung sein. `DeviceConfig.Crc16()` ist statisch und direkt testbar.
|
||||||
|
|
||||||
### Defaults (entspricht Firmware-Defaults)
|
### Defaults (entspricht Firmware-Defaults)
|
||||||
|
|
||||||
- Alle Aktionen: `None`
|
- Alle Aktionen: `None`
|
||||||
- LEDs: warm-weiß (R=80, G=40, B=0), Helligkeit 255
|
- LEDs: warm-weiß (R=80, G=40, B=0)
|
||||||
- Animation: `ColorCycle` (Regenbogen), Period 4000 ms
|
- Animation: `ColorCycle` (Regenbogen), Period 4000 ms
|
||||||
- `active_profile = 0`, `global_brightness = 255`
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## DeviceAction
|
## DeviceAction
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
public enum ActionType : byte {
|
public enum ActionType : byte { None=0, HidKey=1, HidConsumer=2, HostCommand=3, Macro=4 }
|
||||||
None=0, HidKey=1, HidConsumer=2, HostCommand=3, Macro=4, ProfileSwitch=5
|
|
||||||
}
|
|
||||||
|
|
||||||
public class DeviceAction {
|
public class DeviceAction {
|
||||||
public ActionType Type { get; set; }
|
public ActionType Type { get; set; }
|
||||||
@ -74,11 +59,10 @@ public class DeviceAction {
|
|||||||
// HidConsumer: Consumer Usage ID
|
// HidConsumer: Consumer Usage ID
|
||||||
// HostCommand: Command-ID
|
// HostCommand: Command-ID
|
||||||
// Macro: Slot-Index 0–31
|
// Macro: Slot-Index 0–31
|
||||||
// ProfileSwitch: 0–2 = Ziel-Profil, 0xFFFF = nächstes Profil (Zyklus)
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
`DeviceAction.Display` gibt einen lesbaren String zurück (z.B. `"Strg+C"`, `"Play/Pause"`, `"→ Profil 2"`, `"→ Nächstes Profil"`).
|
`DeviceAction.Display` gibt einen lesbaren String zurück (z.B. `"Strg+C"`, `"Play/Pause"`, `"Makro 3"`).
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@ -87,7 +71,7 @@ public class DeviceAction {
|
|||||||
```csharp
|
```csharp
|
||||||
public class MacroTable {
|
public class MacroTable {
|
||||||
public const int Slots = 32;
|
public const int Slots = 32;
|
||||||
public const int MaxSteps = 8;
|
public const int MaxSteps = 4;
|
||||||
public MacroStep[,] Steps { get; } // [slot][step]
|
public MacroStep[,] Steps { get; } // [slot][step]
|
||||||
}
|
}
|
||||||
public class MacroStep {
|
public class MacroStep {
|
||||||
@ -103,9 +87,9 @@ public class MacroStep {
|
|||||||
| 0–19 | MX-Button `mxIdx` (`MacroTable.SlotForMx(mxIdx)`) |
|
| 0–19 | MX-Button `mxIdx` (`MacroTable.SlotForMx(mxIdx)`) |
|
||||||
| 20–31 | Encoder: `20 + enc * 3 + actIdx` (`MacroTable.SlotForEncoder(enc, actIdx)`) |
|
| 20–31 | Encoder: `20 + enc * 3 + actIdx` (`MacroTable.SlotForEncoder(enc, actIdx)`) |
|
||||||
|
|
||||||
### Serialisierung (512 B)
|
### Serialisierung (256 B)
|
||||||
|
|
||||||
32 Slots × 8 Steps × 2 B = 512 B. Keycode zuerst, dann Modifier. Kein Magic/CRC (Board akzeptiert jeden Inhalt).
|
32 Slots × 4 Steps × 2 B = 256 B. Keycode zuerst, dann Modifier. Kein Magic/CRC (Board akzeptiert jeden Inhalt).
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@ -117,4 +101,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).
|
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).
|
||||||
|
|||||||
@ -8,7 +8,6 @@
|
|||||||
- Tray-Icon mit Verbindungsstatus und Kontextmenü
|
- Tray-Icon mit Verbindungsstatus und Kontextmenü
|
||||||
- Empfang und Routing aller Board-Events (via `SerialManager.PacketReceived`)
|
- Empfang und Routing aller Board-Events (via `SerialManager.PacketReceived`)
|
||||||
- Config/Makro-Dump-Empfang (chunked, via `_rxConfigBuf` / `_rxMacroBuf`)
|
- Config/Makro-Dump-Empfang (chunked, via `_rxConfigBuf` / `_rxMacroBuf`)
|
||||||
- ACK/NACK-Weiterleitung an SerialManager
|
|
||||||
- Öffnen des `ConfigForm` (nur eine Instanz gleichzeitig)
|
- Öffnen des `ConfigForm` (nur eine Instanz gleichzeitig)
|
||||||
|
|
||||||
## Tray-Menü
|
## Tray-Menü
|
||||||
@ -31,22 +30,19 @@ Icon und Tooltip spiegeln den Verbindungsstatus:
|
|||||||
|
|
||||||
| Event-ID | Aktion |
|
| Event-ID | Aktion |
|
||||||
|---|---|
|
|---|---|
|
||||||
| `EvtConfigBegin` | `_rxConfigBuf = new byte[740]` |
|
| `EvtConfigBegin` | `_rxConfigBuf = new byte[223]` |
|
||||||
| `EvtConfigData` | Chunk in `_rxConfigBuf` eintragen (`KeyId * 6` = Byte-Offset) |
|
| `EvtConfigData` | Chunk in `_rxConfigBuf` eintragen (`KeyId * 6` = Byte-Offset) |
|
||||||
| `EvtConfigEnd` | `DeviceConfig.FromBytes()` → `ConfigForm.RefreshAll()` |
|
| `EvtConfigEnd` | `DeviceConfig.FromBytes()` → `ConfigForm.RefreshAll()` |
|
||||||
| `EvtConfigAck` | `serial.SignalConfigAck()` — gibt SendConfig()-Thread frei |
|
| `EvtMacroBegin` | `_rxMacroBuf = new byte[256]` |
|
||||||
| `EvtConfigNack` | `serial.SignalConfigNack()` — gibt SendConfig()-Thread frei (Fehler) |
|
|
||||||
| `EvtMacroBegin` | `_rxMacroBuf = new byte[512]` |
|
|
||||||
| `EvtMacroData` | Chunk in `_rxMacroBuf` eintragen |
|
| `EvtMacroData` | Chunk in `_rxMacroBuf` eintragen |
|
||||||
| `EvtMacroEnd` | `MacroTable.FromBytes()` |
|
| `EvtMacroEnd` | `MacroTable.FromBytes()` |
|
||||||
| `EvtMacroAck` | `serial.SignalMacroAck()` — gibt SendMacros()-Thread frei |
|
|
||||||
| `EvtMacroNack` | `serial.SignalMacroNack()` — gibt SendMacros()-Thread frei (Fehler) |
|
|
||||||
| `EvtPong` | MessageBox "Ping OK" |
|
| `EvtPong` | MessageBox "Ping OK" |
|
||||||
|
| `EvtConfigAck` | MessageBox "Config gespeichert" |
|
||||||
|
| `EvtConfigNack` | MessageBox "Config FEHLER" |
|
||||||
|
| `EvtMacroAck` | MessageBox "Makros gespeichert" |
|
||||||
| `EvtKeyDown` | TODO: HOST_COMMAND-Aktion ausführen |
|
| `EvtKeyDown` | TODO: HOST_COMMAND-Aktion ausführen |
|
||||||
| `EvtEncCw/Ccw` | TODO: Encoder HOST_COMMAND |
|
| `EvtEncCw/Ccw` | TODO: Encoder HOST_COMMAND |
|
||||||
|
|
||||||
ACK/NACK-Events zeigen keine eigene MessageBox mehr — das Ergebnis wird nach Abschluss beider Transfers gebündelt in `ConfigForm.OnSave()` angezeigt.
|
|
||||||
|
|
||||||
## Verbindungslebenszyklus
|
## Verbindungslebenszyklus
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|||||||
@ -22,34 +22,13 @@ public ushort ResultPeriod { get; } // Periode in ms
|
|||||||
| HID Tastatur | `_hidKeyPanel` | Capture-Button + Strg/Shift/Alt/Win-Checkboxen |
|
| HID Tastatur | `_hidKeyPanel` | Capture-Button + Strg/Shift/Alt/Win-Checkboxen |
|
||||||
| HID Consumer | `_consumerPanel` | Dropdown mit 12 Medien-Aktionen |
|
| HID Consumer | `_consumerPanel` | Dropdown mit 12 Medien-Aktionen |
|
||||||
| Host Command | `_cmdPanel` | TextBox für numerische Command-ID |
|
| Host Command | `_cmdPanel` | TextBox für numerische Command-ID |
|
||||||
| Makro | `_macroPanel` | 8 Step-Buttons + je Strg/Shift/Alt-Checkboxen |
|
| Makro | `_macroPanel` | 4 Step-Buttons + je Strg/Shift/Alt-Checkboxen |
|
||||||
| Profil wechseln | `_profilePanel` | Dropdown: "Nächstes Profil (Zyklus)" / "Profil 1" / "Profil 2" / "Profil 3" |
|
|
||||||
| Keine | — | Alle Panels ausgeblendet |
|
| Keine | — | Alle Panels ausgeblendet |
|
||||||
|
|
||||||
LED-Panels (`_colorPanel`, `_animPanel`) erscheinen zusätzlich wenn `showColor=true` (nur MX-Buttons, nicht Encoder).
|
LED-Panels (`_colorPanel`, `_animPanel`) erscheinen zusätzlich wenn `showColor=true` (nur MX-Buttons, nicht Encoder).
|
||||||
|
|
||||||
`UpdateLayout()` repositioniert LED-Panels und passt `ClientSize` dynamisch an wenn der Typ gewechselt wird.
|
`UpdateLayout()` repositioniert LED-Panels und passt `ClientSize` dynamisch an wenn der Typ gewechselt wird.
|
||||||
|
|
||||||
## Profil-Panel
|
|
||||||
|
|
||||||
```csharp
|
|
||||||
// Items in _profileCombo:
|
|
||||||
// Index 0: "Nächstes Profil (Zyklus)" → Data = 0xFFFF
|
|
||||||
// Index 1: "Profil 1" → Data = 0
|
|
||||||
// Index 2: "Profil 2" → Data = 1
|
|
||||||
// Index 3: "Profil 3" → Data = 2
|
|
||||||
|
|
||||||
// Initialbelegung:
|
|
||||||
_profileCombo.SelectedIndex = action.Data == 0xFFFF ? 0 : action.Data + 1;
|
|
||||||
|
|
||||||
// In OnOk():
|
|
||||||
data = _profileCombo.SelectedIndex == 0
|
|
||||||
? (ushort)0xFFFF
|
|
||||||
: (ushort)(_profileCombo.SelectedIndex - 1);
|
|
||||||
```
|
|
||||||
|
|
||||||
Im Board wird `0xFFFF` als `(uint8_t)0xFF` gespeichert und in der Firmware als "nächstes Profil" interpretiert.
|
|
||||||
|
|
||||||
## Tasten-Capture (HID-Modus)
|
## Tasten-Capture (HID-Modus)
|
||||||
|
|
||||||
1. Benutzer klickt "Taste drücken..."
|
1. Benutzer klickt "Taste drücken..."
|
||||||
@ -62,7 +41,7 @@ WinForms behandelt Pfeil- und Enter-Tasten als "Dialog Keys" in `ProcessDialogKe
|
|||||||
|
|
||||||
## Makro-Capture
|
## Makro-Capture
|
||||||
|
|
||||||
Jeder der 8 Steps hat einen eigenen Capture-Button. `_captureStep` (0–7, -1 = inaktiv) zeigt welcher Step gerade aufnimmt. Capture-Logik identisch mit HID-Modus, schreibt in `_stepKeycodes[captureStep]`.
|
Jeder der 4 Steps hat einen eigenen Capture-Button. `_captureStep` (0–3, -1 = inaktiv) zeigt welcher Step gerade aufnimmt. Capture-Logik identisch mit HID-Modus, schreibt in `_stepKeycodes[captureStep]`.
|
||||||
|
|
||||||
## Schlüssellookup (layout-unabhängig)
|
## Schlüssellookup (layout-unabhängig)
|
||||||
|
|
||||||
|
|||||||
@ -35,10 +35,6 @@ public class ActionDialog : Form
|
|||||||
private readonly Panel _cmdPanel;
|
private readonly Panel _cmdPanel;
|
||||||
private readonly TextBox _cmdBox;
|
private readonly TextBox _cmdBox;
|
||||||
|
|
||||||
// Profil wechseln
|
|
||||||
private readonly Panel _profilePanel;
|
|
||||||
private readonly ComboBox _profileCombo;
|
|
||||||
|
|
||||||
// LED-Farbe
|
// LED-Farbe
|
||||||
private readonly Panel _colorPanel;
|
private readonly Panel _colorPanel;
|
||||||
private readonly Button _colorBtn;
|
private readonly Button _colorBtn;
|
||||||
@ -54,11 +50,11 @@ public class ActionDialog : Form
|
|||||||
private readonly MacroTable _macros;
|
private readonly MacroTable _macros;
|
||||||
private readonly int _macroSlot;
|
private readonly int _macroSlot;
|
||||||
// Je Step: [CaptureBtn, CheckCtrl, CheckShift, CheckAlt]
|
// Je Step: [CaptureBtn, CheckCtrl, CheckShift, CheckAlt]
|
||||||
private readonly Button[] _stepBtns = new Button[8];
|
private readonly Button[] _stepBtns = new Button[4];
|
||||||
private readonly CheckBox[] _stepCtrl = new CheckBox[8];
|
private readonly CheckBox[] _stepCtrl = new CheckBox[4];
|
||||||
private readonly CheckBox[] _stepShift = new CheckBox[8];
|
private readonly CheckBox[] _stepShift = new CheckBox[4];
|
||||||
private readonly CheckBox[] _stepAlt = new CheckBox[8];
|
private readonly CheckBox[] _stepAlt = new CheckBox[4];
|
||||||
private readonly byte[] _stepKeycodes = new byte[8];
|
private readonly byte[] _stepKeycodes = new byte[4];
|
||||||
private int _captureStep = -1; // -1 = nicht im Capture-Modus
|
private int _captureStep = -1; // -1 = nicht im Capture-Modus
|
||||||
|
|
||||||
// Capture-Zustand
|
// Capture-Zustand
|
||||||
@ -224,7 +220,7 @@ public class ActionDialog : Form
|
|||||||
_showColor = showColor;
|
_showColor = showColor;
|
||||||
|
|
||||||
// Bestehende Makro-Steps aus der Tabelle laden
|
// Bestehende Makro-Steps aus der Tabelle laden
|
||||||
for (int i = 0; i < 8; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
_stepKeycodes[i] = _macros.Steps[_macroSlot, i].Keycode;
|
_stepKeycodes[i] = _macros.Steps[_macroSlot, i].Keycode;
|
||||||
|
|
||||||
// Formular-Grundeinstellungen
|
// Formular-Grundeinstellungen
|
||||||
@ -244,7 +240,7 @@ public class ActionDialog : Form
|
|||||||
DropDownStyle = ComboBoxStyle.DropDownList,
|
DropDownStyle = ComboBoxStyle.DropDownList,
|
||||||
};
|
};
|
||||||
_typeCombo.Items.AddRange(new object[]
|
_typeCombo.Items.AddRange(new object[]
|
||||||
{ "Keine Aktion", "HID Tastatur", "HID Consumer", "Host Command", "Makro", "Profil wechseln" });
|
{ "Keine Aktion", "HID Tastatur", "HID Consumer", "Host Command", "Makro" });
|
||||||
_typeCombo.SelectedIndex = (int)action.Type;
|
_typeCombo.SelectedIndex = (int)action.Type;
|
||||||
_typeCombo.SelectedIndexChanged += OnTypeChanged;
|
_typeCombo.SelectedIndexChanged += OnTypeChanged;
|
||||||
|
|
||||||
@ -324,22 +320,6 @@ public class ActionDialog : Form
|
|||||||
};
|
};
|
||||||
_cmdPanel.Controls.AddRange(new Control[] { cmdLabel, _cmdBox });
|
_cmdPanel.Controls.AddRange(new Control[] { cmdLabel, _cmdBox });
|
||||||
|
|
||||||
// ── Profil-Panel ──────────────────────────────────────────────────────
|
|
||||||
_profilePanel = new Panel { Location = new Point(12, 48), Size = new Size(396, 30) };
|
|
||||||
var profileLabel = new Label { Text = "Ziel-Profil:", Location = new Point(0, 8), AutoSize = true };
|
|
||||||
_profileCombo = new ComboBox
|
|
||||||
{
|
|
||||||
Location = new Point(90, 4),
|
|
||||||
Width = 200,
|
|
||||||
DropDownStyle = ComboBoxStyle.DropDownList,
|
|
||||||
};
|
|
||||||
_profileCombo.Items.AddRange(new object[]
|
|
||||||
{ "Nächstes Profil (Zyklus)", "Profil 1", "Profil 2", "Profil 3" });
|
|
||||||
_profileCombo.SelectedIndex = action.Type == ActionType.ProfileSwitch
|
|
||||||
? (action.Data == 0xFFFF ? 0 : Math.Clamp((int)action.Data + 1, 1, 3))
|
|
||||||
: 0;
|
|
||||||
_profilePanel.Controls.AddRange(new Control[] { profileLabel, _profileCombo });
|
|
||||||
|
|
||||||
// ── Farb-Panel ────────────────────────────────────────────────────────
|
// ── Farb-Panel ────────────────────────────────────────────────────────
|
||||||
_colorPanel = new Panel
|
_colorPanel = new Panel
|
||||||
{
|
{
|
||||||
@ -398,8 +378,8 @@ public class ActionDialog : Form
|
|||||||
_animPanel.Controls.AddRange(new Control[]
|
_animPanel.Controls.AddRange(new Control[]
|
||||||
{ animLabel, _animCombo, periodLabel, _periodCombo });
|
{ animLabel, _animCombo, periodLabel, _periodCombo });
|
||||||
|
|
||||||
// ── Makro-Panel (8 Steps) ─────────────────────────────────────────────
|
// ── Makro-Panel (4 Steps) ─────────────────────────────────────────────
|
||||||
_macroPanel = new Panel { Location = new Point(12, 48), Size = new Size(396, 8 * 30 + 22) };
|
_macroPanel = new Panel { Location = new Point(12, 48), Size = new Size(396, 4 * 30 + 22) };
|
||||||
|
|
||||||
var macroHint = new Label
|
var macroHint = new Label
|
||||||
{
|
{
|
||||||
@ -411,7 +391,7 @@ public class ActionDialog : Form
|
|||||||
};
|
};
|
||||||
_macroPanel.Controls.Add(macroHint);
|
_macroPanel.Controls.Add(macroHint);
|
||||||
|
|
||||||
for (int step = 0; step < 8; step++)
|
for (int step = 0; step < 4; step++)
|
||||||
{
|
{
|
||||||
int s = step;
|
int s = step;
|
||||||
int y2 = 30 + step * 30;
|
int y2 = 30 + step * 30;
|
||||||
@ -474,7 +454,7 @@ public class ActionDialog : Form
|
|||||||
Controls.AddRange(new Control[]
|
Controls.AddRange(new Control[]
|
||||||
{
|
{
|
||||||
typeLabel, _typeCombo,
|
typeLabel, _typeCombo,
|
||||||
_hidKeyPanel, _consumerPanel, _cmdPanel, _profilePanel, _macroPanel,
|
_hidKeyPanel, _consumerPanel, _cmdPanel, _macroPanel,
|
||||||
_colorPanel, _animPanel,
|
_colorPanel, _animPanel,
|
||||||
_okBtn, _cancelBtn,
|
_okBtn, _cancelBtn,
|
||||||
});
|
});
|
||||||
@ -501,7 +481,6 @@ public class ActionDialog : Form
|
|||||||
_hidKeyPanel.Visible = t == ActionType.HidKey;
|
_hidKeyPanel.Visible = t == ActionType.HidKey;
|
||||||
_consumerPanel.Visible = t == ActionType.HidConsumer;
|
_consumerPanel.Visible = t == ActionType.HidConsumer;
|
||||||
_cmdPanel.Visible = t == ActionType.HostCommand;
|
_cmdPanel.Visible = t == ActionType.HostCommand;
|
||||||
_profilePanel.Visible = t == ActionType.ProfileSwitch;
|
|
||||||
_macroPanel.Visible = t == ActionType.Macro;
|
_macroPanel.Visible = t == ActionType.Macro;
|
||||||
_colorPanel.Visible = _showColor;
|
_colorPanel.Visible = _showColor;
|
||||||
_animPanel.Visible = _showColor;
|
_animPanel.Visible = _showColor;
|
||||||
@ -520,8 +499,7 @@ public class ActionDialog : Form
|
|||||||
ActionType.HidKey => 110,
|
ActionType.HidKey => 110,
|
||||||
ActionType.HidConsumer => 30,
|
ActionType.HidConsumer => 30,
|
||||||
ActionType.HostCommand => 30,
|
ActionType.HostCommand => 30,
|
||||||
ActionType.ProfileSwitch => 30,
|
ActionType.Macro => 4 * 30 + 22,
|
||||||
ActionType.Macro => 8 * 30 + 22,
|
|
||||||
_ => 0,
|
_ => 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -732,18 +710,12 @@ public class ActionDialog : Form
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ActionType.ProfileSwitch:
|
|
||||||
data = _profileCombo.SelectedIndex == 0
|
|
||||||
? (ushort)0xFFFF // Zyklus: Firmware rechnet (current+1)%3
|
|
||||||
: (ushort)(_profileCombo.SelectedIndex - 1); // Profil 0/1/2
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == ActionType.Macro)
|
if (type == ActionType.Macro)
|
||||||
{
|
{
|
||||||
// Steps in die Makro-Tabelle schreiben
|
// Steps in die Makro-Tabelle schreiben
|
||||||
for (int i = 0; i < 8; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
byte mod = 0;
|
byte mod = 0;
|
||||||
if (_stepCtrl[i].Checked) mod |= 0x01;
|
if (_stepCtrl[i].Checked) mod |= 0x01;
|
||||||
|
|||||||
@ -26,7 +26,6 @@ public class ConfigForm : Form
|
|||||||
private readonly Button[] _btnGrid = new Button[20];
|
private readonly Button[] _btnGrid = new Button[20];
|
||||||
private readonly Button[,] _encBtns = new Button[4, 3];
|
private readonly Button[,] _encBtns = new Button[4, 3];
|
||||||
private Button _saveBtn = null!;
|
private Button _saveBtn = null!;
|
||||||
private ComboBox _profileCombo = null!;
|
|
||||||
|
|
||||||
public ConfigForm(DeviceConfig config, MacroTable macros, SerialManager serial)
|
public ConfigForm(DeviceConfig config, MacroTable macros, SerialManager serial)
|
||||||
{
|
{
|
||||||
@ -41,7 +40,6 @@ public class ConfigForm : Form
|
|||||||
ClientSize = new Size(520, 480);
|
ClientSize = new Size(520, 480);
|
||||||
|
|
||||||
int y = 12;
|
int y = 12;
|
||||||
y = BuildProfileBar(y);
|
|
||||||
y = BuildButtonGrid(y);
|
y = BuildButtonGrid(y);
|
||||||
y = BuildEncoderPanel(y);
|
y = BuildEncoderPanel(y);
|
||||||
BuildFooter(y);
|
BuildFooter(y);
|
||||||
@ -52,35 +50,6 @@ public class ConfigForm : Form
|
|||||||
_saveBtn.Enabled = _serial.IsConnected;
|
_saveBtn.Enabled = _serial.IsConnected;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Profil-Leiste ─────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
private int BuildProfileBar(int startY)
|
|
||||||
{
|
|
||||||
var label = new Label
|
|
||||||
{
|
|
||||||
Text = "Profil:",
|
|
||||||
Location = new Point(12, startY + 4),
|
|
||||||
AutoSize = true,
|
|
||||||
};
|
|
||||||
|
|
||||||
_profileCombo = new ComboBox
|
|
||||||
{
|
|
||||||
Location = new Point(60, startY),
|
|
||||||
Width = 160,
|
|
||||||
DropDownStyle = ComboBoxStyle.DropDownList,
|
|
||||||
};
|
|
||||||
_profileCombo.Items.AddRange(new object[] { "Profil 1", "Profil 2", "Profil 3" });
|
|
||||||
_profileCombo.SelectedIndex = _config.ActiveProfileIndex;
|
|
||||||
_profileCombo.SelectedIndexChanged += (_, _) =>
|
|
||||||
{
|
|
||||||
_config.ActiveProfileIndex = (byte)_profileCombo.SelectedIndex;
|
|
||||||
RefreshAll();
|
|
||||||
};
|
|
||||||
|
|
||||||
Controls.AddRange(new Control[] { label, _profileCombo });
|
|
||||||
return startY + 34;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Tasten-Grid (4 Spalten × 5 Zeilen) ───────────────────────────────────
|
// ── Tasten-Grid (4 Spalten × 5 Zeilen) ───────────────────────────────────
|
||||||
|
|
||||||
private int BuildButtonGrid(int startY)
|
private int BuildButtonGrid(int startY)
|
||||||
@ -291,25 +260,13 @@ public class ConfigForm : Form
|
|||||||
// SendConfig + SendMacros blockieren ~400ms → Background-Thread
|
// SendConfig + SendMacros blockieren ~400ms → Background-Thread
|
||||||
Task.Run(() =>
|
Task.Run(() =>
|
||||||
{
|
{
|
||||||
bool cfgOk = _serial.SendConfig(_config); // wartet intern auf CONFIG_ACK/NACK
|
_serial.SendConfig(_config);
|
||||||
bool macroOk = _serial.SendMacros(_macros); // wartet intern auf MACRO_ACK/NACK
|
Thread.Sleep(50); // kurze Pause zwischen Config- und Makro-Transfer
|
||||||
|
_serial.SendMacros(_macros);
|
||||||
InvokeOnUi(() =>
|
InvokeOnUi(() =>
|
||||||
{
|
{
|
||||||
_saveBtn.Text = "Auf Board speichern";
|
_saveBtn.Text = "Auf Board speichern";
|
||||||
_saveBtn.Enabled = _serial.IsConnected;
|
_saveBtn.Enabled = _serial.IsConnected;
|
||||||
if (cfgOk && macroOk)
|
|
||||||
{
|
|
||||||
MessageBox.Show("Konfiguration erfolgreich gespeichert.",
|
|
||||||
"VersaPad", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
string detail = (!cfgOk && !macroOk) ? "Config und Makros"
|
|
||||||
: !cfgOk ? "Config"
|
|
||||||
: "Makros";
|
|
||||||
MessageBox.Show($"Speichern fehlgeschlagen ({detail}).\nBoard hat NACK gesendet oder nicht geantwortet.",
|
|
||||||
"VersaPad – Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -436,8 +393,6 @@ internal static class Extensions
|
|||||||
ActionType.HidKey => "HID Tastatur-Keycode",
|
ActionType.HidKey => "HID Tastatur-Keycode",
|
||||||
ActionType.HidConsumer => "HID Consumer Control (Media/Volume)",
|
ActionType.HidConsumer => "HID Consumer Control (Media/Volume)",
|
||||||
ActionType.HostCommand => "Host Command – App führt aus",
|
ActionType.HostCommand => "Host Command – App führt aus",
|
||||||
ActionType.Macro => "Makro-Sequenz",
|
|
||||||
ActionType.ProfileSwitch => "Profil wechseln",
|
|
||||||
_ => "Keine Aktion",
|
_ => "Keine Aktion",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,14 +1,12 @@
|
|||||||
// ConfigJson.cs
|
// ConfigJson.cs
|
||||||
// JSON-Import/Export für DeviceConfig.
|
// JSON-Import/Export für DeviceConfig.
|
||||||
//
|
//
|
||||||
// Format (menschenlesbar):
|
// Format (menschenlesbar, kommentiert mit Feldnamen):
|
||||||
// {
|
// {
|
||||||
// "version": 3,
|
// "version": 2,
|
||||||
// "profile": 0,
|
|
||||||
// "buttons": [
|
// "buttons": [
|
||||||
// { "index": 0, "action": { "type": "HidKey", "data": 260 },
|
// { "index": 0, "action": { "type": "HidKey", "data": 260 },
|
||||||
// "led": { "r": 80, "g": 40, "b": 0, "brightness": 255,
|
// "led": { "r": 80, "g": 40, "b": 0, "anim": "ColorCycle", "period_ms": 4000 } },
|
||||||
// "anim": "ColorCycle", "period_ms": 4000 } },
|
|
||||||
// ...
|
// ...
|
||||||
// ],
|
// ],
|
||||||
// "encoders": [
|
// "encoders": [
|
||||||
@ -19,8 +17,6 @@
|
|||||||
// ...
|
// ...
|
||||||
// ]
|
// ]
|
||||||
// }
|
// }
|
||||||
//
|
|
||||||
// Import/Export bezieht sich immer auf das aktive Profil.
|
|
||||||
|
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
@ -41,7 +37,6 @@ internal static class ConfigJson
|
|||||||
var doc = new ConfigJsonDoc
|
var doc = new ConfigJsonDoc
|
||||||
{
|
{
|
||||||
Version = DeviceConfig.Version,
|
Version = DeviceConfig.Version,
|
||||||
Profile = cfg.ActiveProfileIndex,
|
|
||||||
Buttons = new ButtonEntry[20],
|
Buttons = new ButtonEntry[20],
|
||||||
Encoders = new EncoderEntry[4],
|
Encoders = new EncoderEntry[4],
|
||||||
};
|
};
|
||||||
@ -57,7 +52,6 @@ internal static class ConfigJson
|
|||||||
R = cfg.LedBase[i].R,
|
R = cfg.LedBase[i].R,
|
||||||
G = cfg.LedBase[i].G,
|
G = cfg.LedBase[i].G,
|
||||||
B = cfg.LedBase[i].B,
|
B = cfg.LedBase[i].B,
|
||||||
Brightness = cfg.LedBrightness[i],
|
|
||||||
Anim = cfg.LedAnim[i],
|
Anim = cfg.LedAnim[i],
|
||||||
PeriodMs = cfg.LedPeriod[i],
|
PeriodMs = cfg.LedPeriod[i],
|
||||||
},
|
},
|
||||||
@ -96,7 +90,6 @@ internal static class ConfigJson
|
|||||||
if (b.Led != null)
|
if (b.Led != null)
|
||||||
{
|
{
|
||||||
cfg.LedBase[b.Index] = Color.FromArgb(b.Led.R, b.Led.G, b.Led.B);
|
cfg.LedBase[b.Index] = Color.FromArgb(b.Led.R, b.Led.G, b.Led.B);
|
||||||
cfg.LedBrightness[b.Index] = b.Led.Brightness;
|
|
||||||
cfg.LedAnim[b.Index] = b.Led.Anim;
|
cfg.LedAnim[b.Index] = b.Led.Anim;
|
||||||
cfg.LedPeriod[b.Index] = b.Led.PeriodMs;
|
cfg.LedPeriod[b.Index] = b.Led.PeriodMs;
|
||||||
}
|
}
|
||||||
@ -132,7 +125,6 @@ internal static class ConfigJson
|
|||||||
private class ConfigJsonDoc
|
private class ConfigJsonDoc
|
||||||
{
|
{
|
||||||
[JsonPropertyName("version")] public byte Version { get; set; }
|
[JsonPropertyName("version")] public byte Version { get; set; }
|
||||||
[JsonPropertyName("profile")] public byte Profile { get; set; }
|
|
||||||
[JsonPropertyName("buttons")] public ButtonEntry[]? Buttons { get; set; }
|
[JsonPropertyName("buttons")] public ButtonEntry[]? Buttons { get; set; }
|
||||||
[JsonPropertyName("encoders")] public EncoderEntry[]? Encoders { get; set; }
|
[JsonPropertyName("encoders")] public EncoderEntry[]? Encoders { get; set; }
|
||||||
}
|
}
|
||||||
@ -163,7 +155,6 @@ internal static class ConfigJson
|
|||||||
[JsonPropertyName("r")] public byte R { get; set; }
|
[JsonPropertyName("r")] public byte R { get; set; }
|
||||||
[JsonPropertyName("g")] public byte G { get; set; }
|
[JsonPropertyName("g")] public byte G { get; set; }
|
||||||
[JsonPropertyName("b")] public byte B { get; set; }
|
[JsonPropertyName("b")] public byte B { get; set; }
|
||||||
[JsonPropertyName("brightness")] public byte Brightness { get; set; } = 255;
|
|
||||||
[JsonPropertyName("anim")] public LedAnimType Anim { get; set; }
|
[JsonPropertyName("anim")] public LedAnimType Anim { get; set; }
|
||||||
[JsonPropertyName("period_ms")] public ushort PeriodMs { get; set; }
|
[JsonPropertyName("period_ms")] public ushort PeriodMs { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,32 +1,17 @@
|
|||||||
// DeviceConfig.cs
|
// DeviceConfig.cs
|
||||||
// C#-Spiegel der Firmware-Structs. Muss byte-kompatibel mit SDeviceConfig (nvm_config.h)
|
// C#-Spiegel der SDeviceConfig-Struktur aus der Firmware (nvm_config.h).
|
||||||
// und SMacroTable (macro_config.h) sein.
|
|
||||||
//
|
//
|
||||||
// Serialisiertes Config-Layout (740 B, packed):
|
// Serialisiertes Layout (packed, 223 Bytes):
|
||||||
// ── Globaler Header (32B) ──────────────────────────────────────────────────
|
// Offset 0 4B Magic 0x56503202
|
||||||
// Offset 0 4B Magic 0x56503203
|
// Offset 4 1B Version 2
|
||||||
// Offset 4 1B Version = 3
|
// Offset 5 2B CRC16 (CCITT über Bytes 7–222)
|
||||||
// Offset 5 2B CRC16-CCITT über Bytes 7–739
|
// Offset 7 60B mx_actions[20] je 3B: type(1) + data_lo(1) + data_hi(1)
|
||||||
// Offset 7 1B ActiveProfile (0–2)
|
// Offset 67 36B enc_actions[4][3] je 3B
|
||||||
// Offset 8 1B GlobalBrightness (0–255)
|
// Offset103 20B led_r[20]
|
||||||
// Offset 9 4B EncSensitivity[4]
|
// Offset123 20B led_g[20]
|
||||||
// Offset 13 19B Reserve
|
// Offset143 20B led_b[20]
|
||||||
// ── Profil 0 (236B, ab Offset 32) ─────────────────────────────────────────
|
// Offset163 20B led_anim[20] je 1B (LedAnimType)
|
||||||
// ── Profil 1 (236B, ab Offset 268) ────────────────────────────────────────
|
// Offset183 40B led_period_ms[20] je 2B (uint16, little-endian)
|
||||||
// ── Profil 2 (236B, ab Offset 504) ────────────────────────────────────────
|
|
||||||
//
|
|
||||||
// Pro Profil (236B):
|
|
||||||
// Offset 0 60B MxActions[20] je 3B: type(1) + data_lo(1) + data_hi(1)
|
|
||||||
// Offset 60 36B EncActions[4][3] je 3B
|
|
||||||
// Offset 96 20B LedBase[i].R
|
|
||||||
// Offset116 20B LedBase[i].G
|
|
||||||
// Offset136 20B LedBase[i].B
|
|
||||||
// Offset156 20B LedBrightness[i] per-LED 0–255
|
|
||||||
// Offset176 20B LedAnim[i]
|
|
||||||
// Offset196 40B LedPeriod[i] uint16 little-endian
|
|
||||||
//
|
|
||||||
// MacroTable-Layout (512 B):
|
|
||||||
// 32 Slots × 8 Steps × 2B = 512B
|
|
||||||
|
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
|
||||||
@ -39,7 +24,6 @@ public enum ActionType : byte
|
|||||||
HidConsumer = 2, // data = HID Consumer Usage ID
|
HidConsumer = 2, // data = HID Consumer Usage ID
|
||||||
HostCommand = 3, // data = Command-ID → App führt aus
|
HostCommand = 3, // data = Command-ID → App führt aus
|
||||||
Macro = 4, // data = Makro-Slot-Index (0–31)
|
Macro = 4, // data = Makro-Slot-Index (0–31)
|
||||||
ProfileSwitch = 5, // data = Profil-Index (0–2)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ein Step in einem Makro (keycode=0 → leerer/letzter Step)
|
// Ein Step in einem Makro (keycode=0 → leerer/letzter Step)
|
||||||
@ -52,11 +36,11 @@ public class MacroStep
|
|||||||
public MacroStep Clone() => new() { Keycode = Keycode, Modifier = Modifier };
|
public MacroStep Clone() => new() { Keycode = Keycode, Modifier = Modifier };
|
||||||
}
|
}
|
||||||
|
|
||||||
// Makro-Tabelle: 32 Slots × 8 Steps (spiegelt SMacroTable aus macro_config.h)
|
// Makro-Tabelle: 32 Slots × 4 Steps (spiegelt SMacroTable aus macro_config.h)
|
||||||
public class MacroTable
|
public class MacroTable
|
||||||
{
|
{
|
||||||
public const int Slots = 32;
|
public const int Slots = 32;
|
||||||
public const int MaxSteps = 8;
|
public const int MaxSteps = 4;
|
||||||
|
|
||||||
// [slot][step]
|
// [slot][step]
|
||||||
public MacroStep[,] Steps { get; } = new MacroStep[Slots, MaxSteps];
|
public MacroStep[,] Steps { get; } = new MacroStep[Slots, MaxSteps];
|
||||||
@ -69,13 +53,13 @@ public class MacroTable
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Slot-Index für MX-Buttons und Encoder-Aktionen
|
// Slot-Index für MX-Buttons und Encoder-Aktionen
|
||||||
public static int SlotForMx(int mxIdx) => mxIdx;
|
public static int SlotForMx(int mxIdx) => mxIdx; // 0–19
|
||||||
public static int SlotForEncoder(int enc, int actIdx) => 20 + enc * 3 + actIdx;
|
public static int SlotForEncoder(int enc, int actIdx) => 20 + enc * 3 + actIdx; // 20–31
|
||||||
|
|
||||||
// Serialisierung: 32 × 8 × 2 = 512 Bytes
|
// Serialisierung: 32 × 4 × 2 = 256 Bytes
|
||||||
public byte[] ToBytes()
|
public byte[] ToBytes()
|
||||||
{
|
{
|
||||||
var buf = new byte[512];
|
var buf = new byte[256];
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
for (int s = 0; s < Slots; s++)
|
for (int s = 0; s < Slots; s++)
|
||||||
for (int i = 0; i < MaxSteps; i++)
|
for (int i = 0; i < MaxSteps; i++)
|
||||||
@ -88,7 +72,7 @@ public class MacroTable
|
|||||||
|
|
||||||
public void FromBytes(byte[] buf)
|
public void FromBytes(byte[] buf)
|
||||||
{
|
{
|
||||||
if (buf.Length < 512) return;
|
if (buf.Length < 256) return;
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
for (int s = 0; s < Slots; s++)
|
for (int s = 0; s < Slots; s++)
|
||||||
for (int i = 0; i < MaxSteps; i++)
|
for (int i = 0; i < MaxSteps; i++)
|
||||||
@ -99,13 +83,13 @@ public class MacroTable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Spiegelt LEDAnim aus CButton.h
|
// Spiegelt LEDAnim aus CButton.h – nur die in der GUI konfigurierbaren Werte
|
||||||
public enum LedAnimType : byte
|
public enum LedAnimType : byte
|
||||||
{
|
{
|
||||||
Static = 0,
|
Static = 0,
|
||||||
Blink = 1,
|
Blink = 1,
|
||||||
Pulse = 2,
|
Pulse = 2,
|
||||||
ColorCycle = 5,
|
ColorCycle = 5, // Regenbogen (entspricht LEDAnim::COLOR_CYCLE in Firmware)
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DeviceAction
|
public class DeviceAction
|
||||||
@ -146,8 +130,6 @@ public class DeviceAction
|
|||||||
}
|
}
|
||||||
if (Type == ActionType.Macro)
|
if (Type == ActionType.Macro)
|
||||||
return $"Makro {Data}";
|
return $"Makro {Data}";
|
||||||
if (Type == ActionType.ProfileSwitch)
|
|
||||||
return Data == 0xFFFF ? "→ Nächstes Profil" : $"→ Profil {Data + 1}";
|
|
||||||
return $"CMD {Data}";
|
return $"CMD {Data}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -170,19 +152,31 @@ public class DeviceAction
|
|||||||
public DeviceAction Clone() => new() { Type = Type, Data = Data };
|
public DeviceAction Clone() => new() { Type = Type, Data = Data };
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Pro-Profil-Daten (spiegelt SDeviceProfile) ────────────────────────────────
|
public class DeviceConfig
|
||||||
|
|
||||||
public class DeviceProfile
|
|
||||||
{
|
{
|
||||||
|
public const uint Magic = 0x56503202;
|
||||||
|
public const byte Version = 2;
|
||||||
|
|
||||||
|
public const int EncSw = 0;
|
||||||
|
public const int EncCw = 1;
|
||||||
|
public const int EncCcw = 2;
|
||||||
|
|
||||||
public DeviceAction[] MxActions { get; } =
|
public DeviceAction[] MxActions { get; } =
|
||||||
Enumerable.Range(0, 20).Select(_ => new DeviceAction()).ToArray();
|
Enumerable.Range(0, 20).Select(_ => new DeviceAction()).ToArray();
|
||||||
|
|
||||||
public DeviceAction[,] EncActions { get; } = InitEncActions();
|
public DeviceAction[,] EncActions { get; } = InitEncActions();
|
||||||
|
|
||||||
public Color[] LedBase { get; } = Enumerable.Repeat(Color.FromArgb(80, 40, 0), 20).ToArray();
|
// Base-LED-Farben (Default: warm-weiß wie Firmware)
|
||||||
public byte[] LedBrightness { get; } = Enumerable.Repeat((byte)255, 20).ToArray();
|
public Color[] LedBase { get; } =
|
||||||
public LedAnimType[] LedAnim { get; } = Enumerable.Repeat(LedAnimType.ColorCycle, 20).ToArray();
|
Enumerable.Repeat(Color.FromArgb(80, 40, 0), 20).ToArray();
|
||||||
public ushort[] LedPeriod { get; } = Enumerable.Repeat((ushort)4000, 20).ToArray();
|
|
||||||
|
// LED-Animationen (Default: Regenbogen)
|
||||||
|
public LedAnimType[] LedAnim { get; } =
|
||||||
|
Enumerable.Repeat(LedAnimType.ColorCycle, 20).ToArray();
|
||||||
|
|
||||||
|
// Animationsperiode in ms (Default: 4000ms)
|
||||||
|
public ushort[] LedPeriod { get; } =
|
||||||
|
Enumerable.Repeat((ushort)4000, 20).ToArray();
|
||||||
|
|
||||||
private static DeviceAction[,] InitEncActions()
|
private static DeviceAction[,] InitEncActions()
|
||||||
{
|
{
|
||||||
@ -193,43 +187,79 @@ public class DeviceProfile
|
|||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Serialisiert ein Profil in 236 Bytes
|
// ── Serialisierung ────────────────────────────────────────────────────────
|
||||||
public void ToBytes(byte[] buf, int offset)
|
|
||||||
|
public byte[] ToBytes()
|
||||||
{
|
{
|
||||||
int pos = offset;
|
const int size = 223;
|
||||||
foreach (var a in MxActions) WriteAction(buf, ref pos, a);
|
var buf = new byte[size];
|
||||||
|
int pos = 0;
|
||||||
|
|
||||||
|
WriteU32(buf, ref pos, Magic);
|
||||||
|
buf[pos++] = Version;
|
||||||
|
int crcOffset = pos;
|
||||||
|
pos += 2;
|
||||||
|
|
||||||
|
foreach (var a in MxActions)
|
||||||
|
WriteAction(buf, ref pos, a);
|
||||||
|
|
||||||
for (int e = 0; e < 4; e++)
|
for (int e = 0; e < 4; e++)
|
||||||
for (int i = 0; i < 3; i++) WriteAction(buf, ref pos, EncActions[e, i]);
|
for (int i = 0; i < 3; i++)
|
||||||
|
WriteAction(buf, ref pos, EncActions[e, i]);
|
||||||
|
|
||||||
for (int i = 0; i < 20; i++) buf[pos++] = LedBase[i].R;
|
for (int i = 0; i < 20; i++) buf[pos++] = LedBase[i].R;
|
||||||
for (int i = 0; i < 20; i++) buf[pos++] = LedBase[i].G;
|
for (int i = 0; i < 20; i++) buf[pos++] = LedBase[i].G;
|
||||||
for (int i = 0; i < 20; i++) buf[pos++] = LedBase[i].B;
|
for (int i = 0; i < 20; i++) buf[pos++] = LedBase[i].B;
|
||||||
for (int i = 0; i < 20; i++) buf[pos++] = LedBrightness[i];
|
|
||||||
for (int i = 0; i < 20; i++) buf[pos++] = (byte)LedAnim[i];
|
for (int i = 0; i < 20; i++) buf[pos++] = (byte)LedAnim[i];
|
||||||
|
|
||||||
for (int i = 0; i < 20; i++)
|
for (int i = 0; i < 20; i++)
|
||||||
{
|
{
|
||||||
buf[pos++] = (byte)(LedPeriod[i] & 0xFF);
|
buf[pos++] = (byte)(LedPeriod[i] & 0xFF);
|
||||||
buf[pos++] = (byte)(LedPeriod[i] >> 8);
|
buf[pos++] = (byte)(LedPeriod[i] >> 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ushort crc = Crc16(buf, 7, size - 7);
|
||||||
|
buf[crcOffset] = (byte)(crc & 0xFF);
|
||||||
|
buf[crcOffset + 1] = (byte)(crc >> 8);
|
||||||
|
|
||||||
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deserialisiert ein Profil aus 236 Bytes
|
public bool FromBytes(byte[] buf)
|
||||||
public void FromBytes(byte[] buf, int offset)
|
|
||||||
{
|
{
|
||||||
int pos = offset;
|
if (buf.Length < 223) return false;
|
||||||
|
|
||||||
|
uint magic = ReadU32(buf, 0);
|
||||||
|
if (magic != Magic) return false;
|
||||||
|
if (buf[4] != Version) return false;
|
||||||
|
|
||||||
|
ushort storedCrc = (ushort)(buf[5] | (buf[6] << 8));
|
||||||
|
ushort computedCrc = Crc16(buf, 7, 223 - 7);
|
||||||
|
if (storedCrc != computedCrc) return false;
|
||||||
|
|
||||||
|
int pos = 7;
|
||||||
for (int i = 0; i < 20; i++) ReadAction(buf, ref pos, MxActions[i]);
|
for (int i = 0; i < 20; i++) ReadAction(buf, ref pos, MxActions[i]);
|
||||||
for (int e = 0; e < 4; e++)
|
for (int e = 0; e < 4; e++)
|
||||||
for (int i = 0; i < 3; i++) ReadAction(buf, ref pos, EncActions[e, i]);
|
for (int i = 0; i < 3; i++)
|
||||||
|
ReadAction(buf, ref pos, EncActions[e, i]);
|
||||||
|
|
||||||
for (int i = 0; i < 20; i++) LedBase[i] = Color.FromArgb(buf[pos + i], buf[pos + 20 + i], buf[pos + 40 + i]);
|
for (int i = 0; i < 20; i++) LedBase[i] = Color.FromArgb(buf[pos + i], buf[pos + 20 + i], buf[pos + 40 + i]);
|
||||||
pos += 60;
|
pos += 60;
|
||||||
for (int i = 0; i < 20; i++) LedBrightness[i] = buf[pos++];
|
|
||||||
for (int i = 0; i < 20; i++) LedAnim[i] = (LedAnimType)buf[pos++];
|
for (int i = 0; i < 20; i++) LedAnim[i] = (LedAnimType)buf[pos++];
|
||||||
|
|
||||||
for (int i = 0; i < 20; i++)
|
for (int i = 0; i < 20; i++)
|
||||||
{
|
{
|
||||||
LedPeriod[i] = (ushort)(buf[pos] | (buf[pos + 1] << 8));
|
LedPeriod[i] = (ushort)(buf[pos] | (buf[pos + 1] << 8));
|
||||||
pos += 2;
|
pos += 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── Hilfsmethoden ─────────────────────────────────────────────────────────
|
||||||
|
|
||||||
private static void WriteAction(byte[] buf, ref int pos, DeviceAction a)
|
private static void WriteAction(byte[] buf, ref int pos, DeviceAction a)
|
||||||
{
|
{
|
||||||
buf[pos++] = (byte)a.Type;
|
buf[pos++] = (byte)a.Type;
|
||||||
@ -243,92 +273,6 @@ public class DeviceProfile
|
|||||||
a.Data = (ushort)(buf[pos] | (buf[pos + 1] << 8));
|
a.Data = (ushort)(buf[pos] | (buf[pos + 1] << 8));
|
||||||
pos += 2;
|
pos += 2;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// ── Gesamt-Config (spiegelt SDeviceConfig) ────────────────────────────────────
|
|
||||||
|
|
||||||
public class DeviceConfig
|
|
||||||
{
|
|
||||||
public const uint Magic = 0x56503203;
|
|
||||||
public const byte Version = 3;
|
|
||||||
|
|
||||||
public const int EncSw = 0;
|
|
||||||
public const int EncCw = 1;
|
|
||||||
public const int EncCcw = 2;
|
|
||||||
|
|
||||||
// Globale Felder
|
|
||||||
public byte ActiveProfileIndex { get; set; } = 0;
|
|
||||||
public byte GlobalBrightness { get; set; } = 255;
|
|
||||||
public byte[] EncSensitivity { get; } = new byte[] { 1, 1, 1, 1 };
|
|
||||||
|
|
||||||
// 3 Profile
|
|
||||||
public DeviceProfile[] Profiles { get; } =
|
|
||||||
Enumerable.Range(0, 3).Select(_ => new DeviceProfile()).ToArray();
|
|
||||||
|
|
||||||
// ── Shortcuts auf aktives Profil (ConfigForm braucht keine Änderung) ──────
|
|
||||||
|
|
||||||
public DeviceAction[] MxActions => Profiles[ActiveProfileIndex].MxActions;
|
|
||||||
public DeviceAction[,] EncActions => Profiles[ActiveProfileIndex].EncActions;
|
|
||||||
public Color[] LedBase => Profiles[ActiveProfileIndex].LedBase;
|
|
||||||
public byte[] LedBrightness => Profiles[ActiveProfileIndex].LedBrightness;
|
|
||||||
public LedAnimType[] LedAnim => Profiles[ActiveProfileIndex].LedAnim;
|
|
||||||
public ushort[] LedPeriod => Profiles[ActiveProfileIndex].LedPeriod;
|
|
||||||
|
|
||||||
// ── Serialisierung ────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
public byte[] ToBytes()
|
|
||||||
{
|
|
||||||
const int size = 740;
|
|
||||||
var buf = new byte[size];
|
|
||||||
int pos = 0;
|
|
||||||
|
|
||||||
WriteU32(buf, ref pos, Magic);
|
|
||||||
buf[pos++] = Version;
|
|
||||||
int crcOffset = pos;
|
|
||||||
pos += 2; // CRC-Platzhalter
|
|
||||||
|
|
||||||
buf[pos++] = ActiveProfileIndex;
|
|
||||||
buf[pos++] = GlobalBrightness;
|
|
||||||
for (int i = 0; i < 4; i++) buf[pos++] = EncSensitivity[i];
|
|
||||||
pos += 19; // Reserve (bleibt 0)
|
|
||||||
|
|
||||||
// 3 Profile à 236B
|
|
||||||
for (int p = 0; p < 3; p++)
|
|
||||||
Profiles[p].ToBytes(buf, pos + p * 236);
|
|
||||||
pos += 3 * 236;
|
|
||||||
|
|
||||||
ushort crc = Crc16(buf, 7, size - 7);
|
|
||||||
buf[crcOffset] = (byte)(crc & 0xFF);
|
|
||||||
buf[crcOffset + 1] = (byte)(crc >> 8);
|
|
||||||
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool FromBytes(byte[] buf)
|
|
||||||
{
|
|
||||||
if (buf.Length < 740) return false;
|
|
||||||
|
|
||||||
uint magic = ReadU32(buf, 0);
|
|
||||||
if (magic != Magic) return false;
|
|
||||||
if (buf[4] != Version) return false;
|
|
||||||
|
|
||||||
ushort storedCrc = (ushort)(buf[5] | (buf[6] << 8));
|
|
||||||
ushort computedCrc = Crc16(buf, 7, 740 - 7);
|
|
||||||
if (storedCrc != computedCrc) return false;
|
|
||||||
|
|
||||||
int pos = 7;
|
|
||||||
ActiveProfileIndex = Math.Min(buf[pos++], (byte)2);
|
|
||||||
GlobalBrightness = buf[pos++];
|
|
||||||
for (int i = 0; i < 4; i++) EncSensitivity[i] = buf[pos++];
|
|
||||||
pos += 19; // Reserve überspringen
|
|
||||||
|
|
||||||
for (int p = 0; p < 3; p++)
|
|
||||||
Profiles[p].FromBytes(buf, pos + p * 236);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Hilfsmethoden ─────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
private static void WriteU32(byte[] buf, ref int pos, uint v)
|
private static void WriteU32(byte[] buf, ref int pos, uint v)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -51,7 +51,6 @@ public static class Protocol
|
|||||||
public const byte EvtMacroBegin = 0x96; // Beginn Makro-Dump (Data[1] = Chunks)
|
public const byte EvtMacroBegin = 0x96; // Beginn Makro-Dump (Data[1] = Chunks)
|
||||||
public const byte EvtMacroData = 0x97; // Makro-Chunk (Data[1] = Index, Data[2..7] = 6B)
|
public const byte EvtMacroData = 0x97; // Makro-Chunk (Data[1] = Index, Data[2..7] = 6B)
|
||||||
public const byte EvtMacroEnd = 0x98; // Makro-Dump vollständig
|
public const byte EvtMacroEnd = 0x98; // Makro-Dump vollständig
|
||||||
public const byte EvtMacroNack = 0x99; // Makro-Tabelle: NVM-Fehler
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ein 8-Byte-Paket mit benannten Accessoren.
|
// Ein 8-Byte-Paket mit benannten Accessoren.
|
||||||
|
|||||||
@ -39,12 +39,6 @@ public class SerialManager : IDisposable
|
|||||||
private bool _disposed;
|
private bool _disposed;
|
||||||
private bool _waitingAfterDisconnect; // Backoff nach Trennung aktiv
|
private bool _waitingAfterDisconnect; // Backoff nach Trennung aktiv
|
||||||
|
|
||||||
// Synchronisation: Board-ACK/NACK abwarten bevor nächster Transfer startet
|
|
||||||
private readonly SemaphoreSlim _configAckGate = new(0, 1);
|
|
||||||
private readonly SemaphoreSlim _macroAckGate = new(0, 1);
|
|
||||||
private volatile bool _configAckOk;
|
|
||||||
private volatile bool _macroAckOk;
|
|
||||||
|
|
||||||
public bool IsConnected => _port?.IsOpen == true;
|
public bool IsConnected => _port?.IsOpen == true;
|
||||||
|
|
||||||
public SerialManager()
|
public SerialManager()
|
||||||
@ -227,35 +221,8 @@ public class SerialManager : IDisposable
|
|||||||
public void RequestMacros()
|
public void RequestMacros()
|
||||||
=> Send(new SerialPacket(Protocol.CmdMacroRead));
|
=> Send(new SerialPacket(Protocol.CmdMacroRead));
|
||||||
|
|
||||||
// Wird von TrayApp aufgerufen wenn das Board CONFIG_ACK/NACK oder MACRO_ACK/NACK sendet.
|
|
||||||
// Gibt den wartenden SendConfig()/SendMacros()-Thread frei.
|
|
||||||
public void SignalConfigAck()
|
|
||||||
{
|
|
||||||
_configAckOk = true;
|
|
||||||
if (_configAckGate.CurrentCount == 0) _configAckGate.Release();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SignalConfigNack()
|
|
||||||
{
|
|
||||||
_configAckOk = false;
|
|
||||||
if (_configAckGate.CurrentCount == 0) _configAckGate.Release();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SignalMacroAck()
|
|
||||||
{
|
|
||||||
_macroAckOk = true;
|
|
||||||
if (_macroAckGate.CurrentCount == 0) _macroAckGate.Release();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SignalMacroNack()
|
|
||||||
{
|
|
||||||
_macroAckOk = false;
|
|
||||||
if (_macroAckGate.CurrentCount == 0) _macroAckGate.Release();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Makro-Tabelle (256 Bytes) in 6-Byte-Chunks senden.
|
// Makro-Tabelle (256 Bytes) in 6-Byte-Chunks senden.
|
||||||
// Gibt true zurück wenn das Board MACRO_ACK gesendet hat.
|
public void SendMacros(MacroTable macros)
|
||||||
public bool SendMacros(MacroTable macros)
|
|
||||||
{
|
{
|
||||||
byte[] data = macros.ToBytes();
|
byte[] data = macros.ToBytes();
|
||||||
const int payload = 6;
|
const int payload = 6;
|
||||||
@ -285,24 +252,14 @@ public class SerialManager : IDisposable
|
|||||||
File.AppendAllText(Path.Combine(Path.GetTempPath(), "versapad_rx.txt"),
|
File.AppendAllText(Path.Combine(Path.GetTempPath(), "versapad_rx.txt"),
|
||||||
$"{DateTime.Now:HH:mm:ss.fff} TX MacroCommit (sent {chunks} chunks)\n");
|
$"{DateTime.Now:HH:mm:ss.fff} TX MacroCommit (sent {chunks} chunks)\n");
|
||||||
|
|
||||||
// Sicherstellen dass das Gate leer ist bevor wir warten
|
|
||||||
while (_macroAckGate.CurrentCount > 0) _macroAckGate.Wait(0);
|
|
||||||
|
|
||||||
Thread.Sleep(10);
|
Thread.Sleep(10);
|
||||||
Send(new SerialPacket(Protocol.CmdMacroCommit));
|
Send(new SerialPacket(Protocol.CmdMacroCommit));
|
||||||
|
|
||||||
// Auf MACRO_ACK/NACK warten – Board braucht bis zu ~600ms für NVM-Erase + Write (2 Rows)
|
|
||||||
bool gateAcquired = _macroAckGate.Wait(3000);
|
|
||||||
bool success = gateAcquired && _macroAckOk;
|
|
||||||
File.AppendAllText(Path.Combine(Path.GetTempPath(), "versapad_rx.txt"),
|
|
||||||
$"{DateTime.Now:HH:mm:ss.fff} TX MacroAck gateAcquired={gateAcquired} ok={success}\n");
|
|
||||||
return success;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Config in 6-Byte-Chunks an das Board senden.
|
// Config in 6-Byte-Chunks an das Board senden.
|
||||||
// Protokoll: BEGIN → n×DATA → COMMIT
|
// Protokoll: BEGIN → n×DATA → COMMIT
|
||||||
// Gibt true zurück wenn das Board CONFIG_ACK gesendet hat.
|
// Board schreibt nach COMMIT in den NVM (Firmware-Seite noch TODO).
|
||||||
public bool SendConfig(DeviceConfig config)
|
public void SendConfig(DeviceConfig config)
|
||||||
{
|
{
|
||||||
byte[] data = config.ToBytes();
|
byte[] data = config.ToBytes();
|
||||||
const int payload = 6; // Nutzbytes pro Paket (8 - 2 Header-Bytes)
|
const int payload = 6; // Nutzbytes pro Paket (8 - 2 Header-Bytes)
|
||||||
@ -332,18 +289,8 @@ public class SerialManager : IDisposable
|
|||||||
File.AppendAllText(Path.Combine(Path.GetTempPath(), "versapad_rx.txt"),
|
File.AppendAllText(Path.Combine(Path.GetTempPath(), "versapad_rx.txt"),
|
||||||
$"{DateTime.Now:HH:mm:ss.fff} TX ConfigCommit (sent {chunks} chunks)\n");
|
$"{DateTime.Now:HH:mm:ss.fff} TX ConfigCommit (sent {chunks} chunks)\n");
|
||||||
|
|
||||||
// Sicherstellen dass das Gate leer ist bevor wir warten
|
|
||||||
while (_configAckGate.CurrentCount > 0) _configAckGate.Wait(0);
|
|
||||||
|
|
||||||
Thread.Sleep(10);
|
Thread.Sleep(10);
|
||||||
Send(new SerialPacket(Protocol.CmdConfigCommit));
|
Send(new SerialPacket(Protocol.CmdConfigCommit));
|
||||||
|
|
||||||
// Auf CONFIG_ACK/NACK warten – Board braucht bis zu ~1s für NVM-Erase + Write (3 Rows)
|
|
||||||
bool gateAcquired = _configAckGate.Wait(3000);
|
|
||||||
bool success = gateAcquired && _configAckOk;
|
|
||||||
File.AppendAllText(Path.Combine(Path.GetTempPath(), "versapad_rx.txt"),
|
|
||||||
$"{DateTime.Now:HH:mm:ss.fff} TX ConfigAck gateAcquired={gateAcquired} ok={success}\n");
|
|
||||||
return success;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── IDisposable ───────────────────────────────────────────────────────────
|
// ── IDisposable ───────────────────────────────────────────────────────────
|
||||||
|
|||||||
@ -128,16 +128,18 @@ public class TrayApp : ApplicationContext
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case Protocol.EvtConfigAck:
|
case Protocol.EvtConfigAck:
|
||||||
_serial.SignalConfigAck(); // SendConfig()-Thread freigeben
|
MessageBox.Show("Config erfolgreich gespeichert!",
|
||||||
|
"VersaPad", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Protocol.EvtConfigNack:
|
case Protocol.EvtConfigNack:
|
||||||
_serial.SignalConfigNack(); // SendConfig()-Thread freigeben (Fehler)
|
MessageBox.Show("Config FEHLER: CRC/Magic ungültig.\nÜbertragung fehlgeschlagen.",
|
||||||
|
"VersaPad", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// ── Config-Dump vom Board ─────────────────────────────────────────
|
// ── Config-Dump vom Board ─────────────────────────────────────────
|
||||||
case Protocol.EvtConfigBegin:
|
case Protocol.EvtConfigBegin:
|
||||||
_rxConfigBuf = new byte[740]; // sizeof(SDeviceConfig) = 740 (Version 3)
|
_rxConfigBuf = new byte[223]; // sizeof(SDeviceConfig) = 223 (Version 2)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Protocol.EvtConfigData:
|
case Protocol.EvtConfigData:
|
||||||
@ -161,15 +163,12 @@ public class TrayApp : ApplicationContext
|
|||||||
|
|
||||||
// ── Makro-Dump vom Board ──────────────────────────────────────────
|
// ── Makro-Dump vom Board ──────────────────────────────────────────
|
||||||
case Protocol.EvtMacroAck:
|
case Protocol.EvtMacroAck:
|
||||||
_serial.SignalMacroAck(); // SendMacros()-Thread freigeben
|
MessageBox.Show("Makros erfolgreich gespeichert!",
|
||||||
break;
|
"VersaPad", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
|
||||||
case Protocol.EvtMacroNack:
|
|
||||||
_serial.SignalMacroNack(); // SendMacros()-Thread freigeben (Fehler)
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Protocol.EvtMacroBegin:
|
case Protocol.EvtMacroBegin:
|
||||||
_rxMacroBuf = new byte[512]; // sizeof(SMacroTable) = 512 (8 Steps)
|
_rxMacroBuf = new byte[256];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Protocol.EvtMacroData:
|
case Protocol.EvtMacroData:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user