VersaGUI/doc/06_config_json.md
2026-03-30 19:51:38 +02:00

49 lines
1.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# ConfigJson (Import / Export)
**Datei:** `ConfigJson.cs`
## Format
Menschenlesbares JSON mit `System.Text.Json` (`WriteIndented=true`, Enums als Strings via `JsonStringEnumConverter`).
```json
{
"version": 2,
"buttons": [
{
"index": 0,
"action": { "type": "HidKey", "data": 260 },
"led": { "r": 80, "g": 40, "b": 0, "anim": "ColorCycle", "period_ms": 4000 }
},
...
],
"encoders": [
{
"index": 0,
"sw": { "type": "None", "data": 0 },
"cw": { "type": "None", "data": 0 },
"ccw": { "type": "None", "data": 0 }
},
...
]
}
```
## Serialisierung
`ConfigJson.Serialize(cfg)` → JSON-String. Exportiert alle 20 Buttons + 4 Encoder vollständig.
## Deserialisierung
`ConfigJson.Deserialize(json, cfg)`:
- Prüft `version` wirft `InvalidDataException` bei Mismatch
- Schreibt in bestehendes `DeviceConfig`-Objekt (kein `new`)
- Fehlende `buttons`/`encoders`-Arrays werden ignoriert (partial import möglich)
- Ungültige `index`-Werte werden übersprungen
## Anmerkungen
- `MacroTable` wird **nicht** exportiert (kein JSON-Format für Makros definiert)
- `data` enthält den `ushort`-Wert direkt (für HidKey z.B. `Keycode | (Modifier << 8)`)
- Die Datei ist kein Binärformat und kann manuell bearbeitet werden