BxAreaDynamic.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. package bx
  2. import (
  3. "bytes"
  4. "encoding/binary"
  5. )
  6. type BxAreaDynamic struct {
  7. BaseArea
  8. is5K bool
  9. //
  10. // id
  11. // 动态区域编号
  12. // 注意:该参数只对动态区有效,其他区域为默认
  13. // 值,动态区必须统一编号,编号从 0 开始递增。
  14. id byte
  15. // 行间距
  16. lineSpace byte
  17. // 动态区运行模式
  18. //0—动态区数据循环显示。
  19. //1—动态区数据显示完成后静止显示最后一页数
  20. //据。
  21. //2—动态区数据循环显示,超过设定时间后数据仍
  22. //未更新时不再显示
  23. //3—动态区数据循环显示,超过设定时间后数据仍
  24. //未更新时显示 Logo 信息,Logo 信息即为动态区域
  25. //的最后一页信息
  26. //4—动态区数据顺序显示,显示完最后一页后就不
  27. //再显示
  28. //5—动态区数据顺序显示,超过设定次数后数据仍
  29. //未更新时不再显示
  30. runMode byte
  31. // 动 态 区 数 据 超 时 时 间 , 单 位 为 秒 / 次 数 ( 若
  32. // RunMode=5,则表示更新次数)
  33. timeout int16
  34. // 是否使能语音播放
  35. //0 表示不使能语音
  36. //1 表示播放下文中 Data 部分内容
  37. //2 表示播放下文中 SoundData 部分内容
  38. soundMode byte
  39. soundPerson byte
  40. soundRepeat byte
  41. soundVolume byte //todo 默认值0x05
  42. soundSpeed byte
  43. SoundData []byte
  44. // extend para len
  45. extendParaLen byte
  46. // type setting
  47. // 属于 extend para
  48. //typeSetting byte
  49. // text alignment
  50. alignment byte
  51. // single line
  52. singleLine byte
  53. // 是否自动换行
  54. // 是否自动换行
  55. // 0x01——不自动换行,显示数据在换行时必须插入
  56. // 换行符
  57. // 0x02——自动换行,显示内容不需要换行符,但是
  58. // 只能使用统一的中文字体和英文字体
  59. autoNewLine byte
  60. // 显示方式
  61. //0x01——静止显示
  62. //0x02——快速打出
  63. //0x03——向左移动
  64. //0x04——向右移动
  65. //0x05——向上移动
  66. //0x06——向下移动
  67. dispMode byte
  68. exitMode byte
  69. speed byte
  70. holdTime byte
  71. data []byte
  72. }
  73. func NewBxAreaDynamic(id, runMode, dispMode byte, x uint16, y uint16, w uint16, h uint16, data []byte, is5K bool) *BxAreaDynamic {
  74. return &BxAreaDynamic{
  75. BaseArea: NewBxArea(0, x, y, w, h),
  76. id: id,
  77. data: data,
  78. is5K: is5K,
  79. timeout: 5,
  80. runMode: runMode,
  81. soundVolume: 0x05,
  82. soundSpeed: 0x05,
  83. singleLine: 0x02,
  84. autoNewLine: 0x01,
  85. dispMode: dispMode,
  86. speed: 0x0a,
  87. holdTime: 0x08,
  88. }
  89. }
  90. func (b *BxAreaDynamic) Length() int16 {
  91. return 27 + int16(len(b.data))
  92. }
  93. func (b *BxAreaDynamic) Build() []byte {
  94. w := bytes.NewBuffer(make([]byte, 0, 1024))
  95. binary.Write(w, binary.LittleEndian, b.typ)
  96. x8 := b.GetX()
  97. w8 := b.GetW()
  98. if b.is5K {
  99. x8 = b.x / 8
  100. w8 = b.w / 8
  101. }
  102. binary.Write(w, binary.LittleEndian, x8)
  103. binary.Write(w, binary.LittleEndian, b.GetY())
  104. binary.Write(w, binary.LittleEndian, w8)
  105. binary.Write(w, binary.LittleEndian, b.GetH())
  106. // 动态区编号
  107. binary.Write(w, binary.LittleEndian, b.id)
  108. // 行间距
  109. binary.Write(w, binary.LittleEndian, b.lineSpace)
  110. // 运行模式
  111. binary.Write(w, binary.LittleEndian, b.runMode)
  112. binary.Write(w, binary.LittleEndian, b.timeout)
  113. binary.Write(w, binary.LittleEndian, b.soundMode)
  114. if b.soundMode == 0x01 || b.soundMode == 0x02 {
  115. pr := ((b.soundRepeat << 4) & 0xf0) | (b.soundPerson & 0x0f)
  116. binary.Write(w, binary.LittleEndian, pr)
  117. binary.Write(w, binary.LittleEndian, b.soundVolume)
  118. binary.Write(w, binary.LittleEndian, b.soundSpeed)
  119. }
  120. if b.soundMode == 0x02 {
  121. soundDataLen := len(b.SoundData)
  122. binary.Write(w, binary.LittleEndian, int32(soundDataLen))
  123. binary.Write(w, binary.LittleEndian, b.SoundData)
  124. }
  125. // extendParaLen
  126. binary.Write(w, binary.LittleEndian, b.extendParaLen)
  127. binary.Write(w, binary.LittleEndian, b.alignment)
  128. binary.Write(w, binary.LittleEndian, b.singleLine)
  129. binary.Write(w, binary.LittleEndian, b.autoNewLine)
  130. binary.Write(w, binary.LittleEndian, b.dispMode)
  131. binary.Write(w, binary.LittleEndian, b.exitMode)
  132. binary.Write(w, binary.LittleEndian, b.speed)
  133. binary.Write(w, binary.LittleEndian, b.holdTime)
  134. binary.Write(w, binary.LittleEndian, int32(len(b.data)))
  135. binary.Write(w, binary.LittleEndian, b.data)
  136. return w.Bytes()
  137. }
  138. func (b *BxAreaDynamic) SetSoundMode(soundMode byte) {
  139. if soundMode > 2 {
  140. b.soundMode = 0x02
  141. } else {
  142. b.soundMode = soundMode
  143. }
  144. }
  145. func (b *BxAreaDynamic) SetSoundPerson(soundPerson byte) {
  146. if soundPerson > 5 {
  147. b.soundPerson = 0
  148. } else {
  149. b.soundPerson = soundPerson
  150. }
  151. }
  152. func (b *BxAreaDynamic) SetSoundRepeat(soundRepeat byte) {
  153. if soundRepeat > 15 {
  154. b.soundRepeat = 15
  155. } else {
  156. b.soundRepeat = soundRepeat
  157. }
  158. }
  159. func (b *BxAreaDynamic) SetSoundVolume(soundVolume byte) {
  160. if soundVolume > 10 {
  161. b.soundVolume = 10
  162. } else {
  163. b.soundVolume = soundVolume
  164. }
  165. }
  166. func (b *BxAreaDynamic) SetSoundSpeed(soundSpeed byte) {
  167. if soundSpeed < 1 {
  168. b.soundSpeed = 1
  169. } else if soundSpeed > 10 {
  170. b.soundSpeed = 10
  171. } else {
  172. b.soundSpeed = soundSpeed
  173. }
  174. }