Files
VersaGUI/doc/06_config_json.md
T

66 lines
1.8 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": 3,
"profile": 0,
"buttons": [
{
"index": 0,
"action": { "type": "HidKey", "data": 260 },
"led": {
"r": 80,
"g": 40,
"b": 0,
"brightness": 255,
"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 und vier
Encoder des aktuell aktiven Profils vollständig, einschließlich
Per-LED-Helligkeit.
## Deserialisierung
`ConfigJson.Deserialize(json, cfg)`:
- Prüft `version` wirft `InvalidDataException` bei Mismatch
- prüft und übernimmt `profile` im Bereich `0..2`
- validiert Actions, LED-Enums und die Mindestperiode für `Pulse`
- 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)
- globale Helligkeit und Encoder-Sensitivität werden nicht exportiert
- `profile` wählt das Zielprofil aus und macht es gleichzeitig zum aktiven
Profil; die beiden anderen Profile bleiben unverändert
- `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
- Ein ungültiger Wert wird vor dem Anwenden mit `InvalidDataException`
abgelehnt