zones.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package main
  2. import (
  3. intrgb "netdome.biz/paul/qmk-rgb/internal/rgb"
  4. "netdome.biz/paul/qmk-rgb/internal/via"
  5. )
  6. func selectedZones() ([]intrgb.Zone, error) {
  7. if targetZone == "" {
  8. return intrgb.AllZones(), nil
  9. }
  10. zone, err := intrgb.ParseZone(targetZone)
  11. if err != nil {
  12. return nil, err
  13. }
  14. return []intrgb.Zone{zone}, nil
  15. }
  16. func zoneChannels(zones []intrgb.Zone) []via.LEDType {
  17. var channels []via.LEDType
  18. for _, zone := range zones {
  19. channels = append(channels, via.LEDType(zone.Channel()))
  20. }
  21. return channels
  22. }
  23. // filterZones keeps the zones that appear in selected, preserving the order
  24. // of candidates. It neither adds nor removes zones on its own: a zone the
  25. // caller does not offer stays absent, so a profile that omits a zone is not
  26. // padded with defaults.
  27. func filterZones(candidates, selected []intrgb.Zone) []intrgb.Zone {
  28. keep := make(map[intrgb.Zone]bool, len(selected))
  29. for _, zone := range selected {
  30. keep[zone] = true
  31. }
  32. filtered := make([]intrgb.Zone, 0, len(candidates))
  33. for _, zone := range candidates {
  34. if keep[zone] {
  35. filtered = append(filtered, zone)
  36. }
  37. }
  38. return filtered
  39. }