IDevice.go 1012 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package lc
  2. type Notifier interface {
  3. Notify()
  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 interface{}
  34. Screen Screener
  35. Speaker Loudspeaker
  36. }
  37. func (id *IntersectionDevice) Call() {
  38. id.Screen.Display(1)
  39. id.Speaker.Speak()
  40. }
  41. func (id *IntersectionDevice) Rollback() {
  42. id.Screen.Display(0)
  43. }
  44. func (id *IntersectionDevice) Reconnect() {
  45. DoReconnect(id.Screen)
  46. }
  47. func (id *IntersectionDevice) Correct() {
  48. DoCorrectTime(id.Screen)
  49. }