lighting.py 1021 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import re
  2. from pathlib import Path
  3. from qmk.json_schema import json_load
  4. def list_lighting_versions(feature):
  5. """Return available versions - sorted newest first
  6. """
  7. ret = []
  8. for file in Path('data/constants/lighting/').glob(f'{feature}_[0-9].[0-9].[0-9].hjson'):
  9. ret.append(file.stem.split('_')[-1])
  10. ret.sort(reverse=True)
  11. return ret
  12. def load_lighting_spec(feature, version='latest'):
  13. """Build lighting data from the requested spec file
  14. """
  15. if version == 'latest':
  16. version = list_lighting_versions(feature)[0]
  17. spec = json_load(Path(f'data/constants/lighting/{feature}_{version}.hjson'))
  18. # preprocess for gross rgblight "mode + n"
  19. for obj in spec.get('effects', {}).values():
  20. define = obj['key']
  21. offset = 0
  22. found = re.match('(.*)_(\\d+)$', define)
  23. if found:
  24. define = found.group(1)
  25. offset = int(found.group(2)) - 1
  26. obj['define'] = define
  27. obj['offset'] = offset
  28. return spec