IDevice.go 966 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package lc
  2. import (
  3. "lc-smartX/util"
  4. )
  5. // CorrectTimer 校时器接口
  6. type CorrectTimer interface {
  7. Correct()
  8. }
  9. func DoCorrectTime(a any) {
  10. if c, ok := a.(CorrectTimer); ok {
  11. c.Correct()
  12. }
  13. }
  14. // ReConnector 重连器接口
  15. type ReConnector interface {
  16. Reconnect()
  17. }
  18. func DoReconnect(a any) {
  19. if c, ok := a.(ReConnector); ok {
  20. c.Reconnect()
  21. }
  22. }
  23. // IDevice 抽象设备,包含屏和扬声器
  24. type IDevice interface {
  25. // Call 通知输出设备,输出信息。屏显示来车警告信息,扬声器语音提示
  26. Call()
  27. // Rollback 屏回滚到初始状态
  28. Rollback()
  29. ReConnector
  30. CorrectTimer
  31. }
  32. type IntersectionDevice struct {
  33. Info util.OutputDevice
  34. Screen Screener
  35. }
  36. func (id *IntersectionDevice) Call() {
  37. id.Screen.Display(1)
  38. }
  39. func (id *IntersectionDevice) Rollback() {
  40. id.Screen.Display(0)
  41. }
  42. func (id *IntersectionDevice) Reconnect() {
  43. DoReconnect(id.Screen)
  44. }
  45. func (id *IntersectionDevice) Correct() {
  46. DoCorrectTime(id.Screen)
  47. }