BxAreaDynamic.go 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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,
  74. soundData []byte, is5K bool) *BxAreaDynamic {
  75. return &BxAreaDynamic{
  76. BaseArea: NewBxArea(0, x, y, w, h),
  77. id: id,
  78. data: data,
  79. soundData: soundData,
  80. is5K: is5K,
  81. timeout: 5,
  82. runMode: runMode,
  83. soundMode: 0x02,
  84. soundPerson: 0x00,
  85. soundVolume: 0x01,
  86. soundRepeat: 0x00,
  87. soundSpeed: 0x05,
  88. singleLine: 0x02,
  89. autoNewLine: 0x01,
  90. dispMode: dispMode,
  91. speed: 0x0a,
  92. holdTime: 0x08,
  93. }
  94. }
  95. func NewBxAreaProgram(id, runMode, dispMode byte, x uint16, y uint16, w uint16, h uint16, data []byte,
  96. is5K bool) *BxAreaDynamic {
  97. return &BxAreaDynamic{
  98. BaseArea: NewBxArea(0, x, y, w, h),
  99. id: id,
  100. data: data,
  101. is5K: is5K,
  102. timeout: 5,
  103. runMode: runMode,
  104. soundVolume: 0x05,
  105. soundSpeed: 0x05,
  106. singleLine: 0x02,
  107. autoNewLine: 0x01,
  108. dispMode: dispMode,
  109. speed: 0x0a,
  110. holdTime: 0x08,
  111. }
  112. }
  113. func (b *BxAreaDynamic) Length() int16 {
  114. return 27 + int16(len(b.data))
  115. }
  116. func (b *BxAreaDynamic) Build() []byte {
  117. w := bytes.NewBuffer(make([]byte, 0, 1024))
  118. binary.Write(w, binary.LittleEndian, b.typ)
  119. x8 := b.GetX()
  120. w8 := b.GetW()
  121. if b.is5K {
  122. x8 = b.x / 8
  123. w8 = b.w / 8
  124. }
  125. binary.Write(w, binary.LittleEndian, x8)
  126. binary.Write(w, binary.LittleEndian, b.GetY())
  127. binary.Write(w, binary.LittleEndian, w8)
  128. binary.Write(w, binary.LittleEndian, b.GetH())
  129. // 动态区编号
  130. binary.Write(w, binary.LittleEndian, b.id)
  131. // 行间距
  132. binary.Write(w, binary.LittleEndian, b.lineSpace)
  133. // 运行模式
  134. binary.Write(w, binary.LittleEndian, b.runMode)
  135. binary.Write(w, binary.LittleEndian, b.timeout)
  136. binary.Write(w, binary.LittleEndian, b.soundMode)
  137. if b.soundMode == 0x01 || b.soundMode == 0x02 {
  138. pr := ((b.soundRepeat << 4) & 0xf0) | (b.soundPerson & 0x0f)
  139. binary.Write(w, binary.LittleEndian, pr)
  140. binary.Write(w, binary.LittleEndian, b.soundVolume)
  141. binary.Write(w, binary.LittleEndian, b.soundSpeed)
  142. }
  143. if b.soundMode == 0x02 {
  144. soundDataLen := len(b.soundData)
  145. binary.Write(w, binary.LittleEndian, int32(soundDataLen))
  146. binary.Write(w, binary.LittleEndian, b.soundData)
  147. }
  148. // extendParaLen
  149. binary.Write(w, binary.LittleEndian, b.extendParaLen)
  150. binary.Write(w, binary.LittleEndian, b.alignment)
  151. binary.Write(w, binary.LittleEndian, b.singleLine)
  152. binary.Write(w, binary.LittleEndian, b.autoNewLine)
  153. binary.Write(w, binary.LittleEndian, b.dispMode)
  154. binary.Write(w, binary.LittleEndian, b.exitMode)
  155. binary.Write(w, binary.LittleEndian, b.speed)
  156. binary.Write(w, binary.LittleEndian, b.holdTime)
  157. binary.Write(w, binary.LittleEndian, int32(len(b.data)))
  158. binary.Write(w, binary.LittleEndian, b.data)
  159. return w.Bytes()
  160. }
  161. func (b *BxAreaDynamic) SetSoundMode(soundMode byte) {
  162. if soundMode > 2 {
  163. b.soundMode = 0x02
  164. } else {
  165. b.soundMode = soundMode
  166. }
  167. }
  168. func (b *BxAreaDynamic) SetSoundPerson(soundPerson byte) {
  169. if soundPerson > 5 {
  170. b.soundPerson = 0
  171. } else {
  172. b.soundPerson = soundPerson
  173. }
  174. }
  175. func (b *BxAreaDynamic) SetSoundRepeat(soundRepeat byte) {
  176. if soundRepeat > 15 {
  177. b.soundRepeat = 15
  178. } else {
  179. b.soundRepeat = soundRepeat
  180. }
  181. }
  182. func (b *BxAreaDynamic) SetSoundVolume(soundVolume byte) {
  183. if soundVolume > 10 {
  184. b.soundVolume = 10
  185. } else {
  186. b.soundVolume = soundVolume
  187. }
  188. }
  189. func (b *BxAreaDynamic) SetSoundSpeed(soundSpeed byte) {
  190. if soundSpeed < 1 {
  191. b.soundSpeed = 1
  192. } else if soundSpeed > 10 {
  193. b.soundSpeed = 10
  194. } else {
  195. b.soundSpeed = soundSpeed
  196. }
  197. }