demoss

lua-test

Dec 26th, 2024
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.26 KB | None | 0 0
  1. out1_up={0xA5,0xC3,0x3C,0x5A,0xFF,0x36,0x05,0x04,0x02,0x01,0x00,0x14,0xEE}   --примеры команд в байтах
  2. out2_up={0xA5,0xC3,0x3C,0x5A,0xFF,0x36,0x05,0x04,0x02,0x02,0x00,0x14,0xEE}
  3. out3_up={0xA5,0xC3,0x3C,0x5A,0xFF,0x36,0x05,0x04,0x02,0x03,0x00,0x14,0xEE}
  4. out4_up={0xA5,0xC3,0x3C,0x5A,0xFF,0x36,0x05,0x04,0x02,0x04,0x00,0x14,0xEE}
  5. out1_dw={0xA5,0xC3,0x3C,0x5A,0xFF,0x36,0x05,0x04,0x02,0x01,0x01,0x14,0xEE}
  6. out2_dw={0xA5,0xC3,0x3C,0x5A,0xFF,0x36,0x05,0x04,0x02,0x02,0x01,0x14,0xEE}
  7. out3_dw={0xA5,0xC3,0x3C,0x5A,0xFF,0x36,0x05,0x04,0x02,0x03,0x01,0x14,0xEE}
  8. out4_dw={0xA5,0xC3,0x3C,0x5A,0xFF,0x36,0x05,0x04,0x02,0x04,0x01,0x14,0xEE}
  9.  
  10. out1_mute={0xA5,0xC3,0x3C,0x5A,0xFF,0x36,0x03,0x03,0x02,0x01,0x01,0xEE}
  11. out2_mute={0xA5,0xC3,0x3C,0x5A,0xFF,0x36,0x03,0x03,0x02,0x02,0x01,0xEE}
  12. out3_mute={0xA5,0xC3,0x3C,0x5A,0xFF,0x36,0x03,0x03,0x02,0x03,0x01,0xEE}
  13. out4_mute={0xA5,0xC3,0x3C,0x5A,0xFF,0x36,0x03,0x03,0x02,0x04,0x01,0xEE}
  14.  
  15. out1_umute={0xA5,0xC3,0x3C,0x5A,0xFF,0x36,0x03,0x03,0x02,0x01,0x00,0xEE}
  16. out2_umute={0xA5,0xC3,0x3C,0x5A,0xFF,0x36,0x03,0x03,0x02,0x02,0x00,0xEE}
  17. out3_umute={0xA5,0xC3,0x3C,0x5A,0xFF,0x36,0x03,0x03,0x02,0x03,0x00,0xEE}
  18. out4_umute={0xA5,0xC3,0x3C,0x5A,0xFF,0x36,0x03,0x03,0x02,0x04,0x00,0xEE}
  19.  
  20. preset1={0xA5,0xC3,0x3C,0x5A,0xFF,0x36,0x02,0x01,0x02,0xEE}
  21. preset2={0xA5,0xC3,0x3C,0x5A,0xFF,0x36,0x02,0x01,0x03,0xEE}
  22.  
  23. clr={0xA5,0xC3,0x3C,0x5A,0xFF,0x36,0x09,0x03,0x01,0x01,0x00,0xEE} --заготовка для очистки матрицы
  24. mtx={0xA5,0xC3,0x3C,0x5A,0xFF,0x36,0x09,0x03,0x01,0x01,0x01,0xEE}  --заготовка для соединения матрицы
  25.  
  26. outv_set={0xA5,0xC3,0x3C,0x5A,0xFF,0x36,0x04,0x04,0x02,0x01,0x00,0x00,0xEE}
  27. data ={}
  28. z1dat={0x00,0x00}
  29. z2dat={0x00,0x00}
  30.  
  31. local z1v = 6 --зона звука 1
  32. local z2v = 6 --зона звука 2
  33. local z1max = 9
  34. local z1min = 0
  35. local z2max = 9
  36. local z2min = 0
  37. up="up"
  38. dw="dw"
  39. res=6
  40.  
  41. function z1vol(data) --гоняем звук туда-сюда
  42. if data =="up" then
  43. if z1v < z1max then
  44. z1v=z1v+1
  45. end
  46. end
  47. if data =="dw" then
  48. if z1v > z1min then
  49. z1v=z1v-1
  50. end
  51. end
  52. z1toHex(mapV(z1v)) --генерируем команды в НЕХ
  53. end
  54.  
  55. function z2vol(data)
  56. if data =="up" then
  57. if z2v < z2max then
  58. z2v=z2v+1
  59. end
  60. end
  61. if data =="dw" then
  62. if z2v > z1min then
  63. z2v=z2v-1
  64. end
  65. end
  66. z2toHex(mapV(z2v))
  67. end
  68.  
  69. function on_timer() --при тике таймера в 300мс шлем следующую команду в таблице
  70. if #data < 1 then return end
  71. usend(table.remove(data, 1))
  72. end
  73.  
  74. function on_control_notify(screen,control,value)
  75. if screen == 0 then
  76. if control ==1 and value==1 then
  77. z1vol(up)
  78. end
  79. if control ==2 and value==1 then
  80. z1vol(dw)
  81. end
  82. if control ==3 and value==1 then
  83. clr_z()
  84. mtx_z_f()
  85. end
  86. if control ==4 and value==1 then
  87. clr_z()
  88. mtx_z_djz()
  89. end
  90. if control ==5 and value==1 then
  91. clr_z()
  92. mtx_z_djs()
  93. end
  94. if control ==6 and value==1 then
  95. z2vol(up)
  96. end
  97. if control ==7 and value==1 then
  98. z2vol(dw)
  99. end
  100. if control ==8 and value==1 then
  101. clr_s()
  102. mtx_s_f()
  103. end
  104. if control ==9 and value==1 then
  105. clr_s()
  106. mtx_s_djz()
  107. end
  108. if control ==10 and value==1 then
  109. clr_s()
  110. mtx_s_djs()
  111. end
  112. end
  113. end
  114.  
  115. function usend(msg) -- выдаем команды в uart побйтово
  116.   local tmp = {}
  117.   for i = 1, #msg do
  118.     tmp[i-1] = msg[i]
  119.   end
  120.   uart_send_data(tmp)
  121. end
  122.  
  123. function on_init()
  124. uart_set_baudrate(115200)
  125. start_timer(1, 300, 1, 0)
  126. end
  127.  
  128. function z1toHex(dat)   --преобразуем int в hex 16LE
  129.     local int16Value = dat
  130.     if int16Value < 0 then
  131.         int16Value = int16Value + 65536
  132.     end
  133.     local lowByte = int16Value % 256
  134.     local highByte = math.floor(int16Value / 256)
  135.     for i=1,2 do
  136. vset[10] = i
  137. vset[11] = lowByte
  138. vset[12] = highByte
  139. table.insert(data, vset)
  140. end
  141. end
  142.  
  143. function z2toHex(dat)
  144.     local int16Value = dat
  145.     if int16Value < 0 then
  146.         int16Value = int16Value + 65536
  147.     end
  148.     local lowByte = int16Value % 256
  149.     local highByte = math.floor(int16Value / 256)
  150. outv_set[10] = 3
  151. outv_set[11] = lowByte
  152. outv_set[12] = highByte
  153. table.insert(data, outv_set)   
  154. end
  155.  
  156. function mapV(input)  --мапим диапазон 0-9 в диапазон -400+150
  157.     local output = -400 + (input * (150 + 400) / 9)
  158.     return math.ceil(output)
  159. end
  160.  
  161. function clr_z()  --итерируем очистку матрицы вход 1 - 4 от выхода 1-2
  162. for i=1,4 do
  163. for x=1,2 do
  164.     clr[9] = i
  165.     clr[10] = x
  166. table.insert(data, clr)
  167. end
  168. end
  169. end
  170.  
  171. function clr_s()
  172. for i=1,4 do
  173. x=3
  174.     clr[9] = i
  175.     clr[10] = x
  176. table.insert(data, clr)
  177. end
  178. end
  179.  
  180. function mtx_z_f()
  181. for i=1,2 do
  182. for x=1,2 do
  183.     mtx[9] = i
  184.     mtx[10] = x
  185. table.insert(data, mtx)
  186. end
  187. end
  188. end
  189.  
  190. function mtx_z_djz()
  191. i=3
  192. for x=1,2 do
  193.     mtx[9] = i
  194.     mtx[10] = x
  195. table.insert(data, mtx)
  196. end
  197. end
  198.  
  199. function mtx_z_djs()
  200. i=4
  201. for x=1,2 do
  202.     mtx[9] = i
  203.     mtx[10] = x
  204. table.insert(data, mtx)
  205. end
  206. end
  207.  
  208. function mtx_s_f()
  209. for i=1,2 do
  210. x=3
  211.     mtx[9] = i
  212.     mtx[10] = x
  213. table.insert(data, mtx)
  214. end
  215. end
  216.  
  217. function mtx_s_djz()
  218. i=3
  219. x=3
  220.     mtx[9] = i
  221.     mtx[10] = x
  222. table.insert(data, mtx)
  223. end
  224.  
  225. function mtx_s_djs()
  226. i=4
  227. x=3
  228.     mtx[9] = i
  229.     mtx[10] = x
  230. table.insert(data, mtx)
  231. end
  232.  
  233. function on_systick()
  234. set_text(0,15,z1v)
  235. set_text(0,16,z2v)
  236. end
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
Tags: lua
Advertisement
Add Comment
Please, Sign In to add comment