ledmgr.go 1023 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package main
  2. //屏幕管理
  3. import (
  4. "context"
  5. "lc/common/mqtt"
  6. "lc/common/util"
  7. "sync"
  8. )
  9. var ledMgr *LedMgr
  10. var once sync.Once
  11. type LedMgr struct {
  12. ctx context.Context
  13. cancel context.CancelFunc
  14. downQueue *util.MlQueue
  15. mapTopicHandle map[string]func(m mqtt.Message)
  16. rwMutex sync.RWMutex
  17. mapLedDevice map[string]*LedDevice
  18. }
  19. func GetLedMgr() *LedMgr {
  20. once.Do(func() {
  21. ctx, cancel := context.WithCancel(context.Background())
  22. ledMgr = &LedMgr{
  23. ctx: ctx,
  24. cancel: cancel,
  25. mapTopicHandle: make(map[string]func(m mqtt.Message)),
  26. mapLedDevice: make(map[string]*LedDevice),
  27. }
  28. })
  29. return ledMgr
  30. }
  31. func (l *LedMgr) initAll() error {
  32. loadDevInfos()
  33. CreateLedDevs()
  34. return nil
  35. }
  36. func CreateLedDevs() {
  37. for _, info := range ledInfos {
  38. device := NewLedDevice(info)
  39. ledMgr.mapLedDevice[device.IP] = device
  40. }
  41. }
  42. // todo
  43. func (l *LedMgr) Update() error {
  44. return nil
  45. }
  46. func (l *LedMgr) HandleMessage(m mqtt.Message) {
  47. l.downQueue.Put(m)
  48. }