IDevice.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. S Screener
  35. L Loudspeaker
  36. }
  37. func (id *IntersectionDevice) Call() {
  38. id.L.Speak()
  39. id.S.Display("P001")
  40. }
  41. func (id *IntersectionDevice) Rollback() {
  42. id.S.Display("P000")
  43. }
  44. func (id *IntersectionDevice) Reconnect() {
  45. DoReconnect(id.S)
  46. DoReconnect(id.L)
  47. }
  48. func (id *IntersectionDevice) Correct() {
  49. DoCorrectTime(id.S)
  50. DoCorrectTime(id.L)
  51. }