Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- out1_up={0xA5,0xC3,0x3C,0x5A,0xFF,0x36,0x05,0x04,0x02,0x01,0x00,0x14,0xEE} --примеры команд в байтах
- out2_up={0xA5,0xC3,0x3C,0x5A,0xFF,0x36,0x05,0x04,0x02,0x02,0x00,0x14,0xEE}
- out3_up={0xA5,0xC3,0x3C,0x5A,0xFF,0x36,0x05,0x04,0x02,0x03,0x00,0x14,0xEE}
- out4_up={0xA5,0xC3,0x3C,0x5A,0xFF,0x36,0x05,0x04,0x02,0x04,0x00,0x14,0xEE}
- out1_dw={0xA5,0xC3,0x3C,0x5A,0xFF,0x36,0x05,0x04,0x02,0x01,0x01,0x14,0xEE}
- out2_dw={0xA5,0xC3,0x3C,0x5A,0xFF,0x36,0x05,0x04,0x02,0x02,0x01,0x14,0xEE}
- out3_dw={0xA5,0xC3,0x3C,0x5A,0xFF,0x36,0x05,0x04,0x02,0x03,0x01,0x14,0xEE}
- out4_dw={0xA5,0xC3,0x3C,0x5A,0xFF,0x36,0x05,0x04,0x02,0x04,0x01,0x14,0xEE}
- out1_mute={0xA5,0xC3,0x3C,0x5A,0xFF,0x36,0x03,0x03,0x02,0x01,0x01,0xEE}
- out2_mute={0xA5,0xC3,0x3C,0x5A,0xFF,0x36,0x03,0x03,0x02,0x02,0x01,0xEE}
- out3_mute={0xA5,0xC3,0x3C,0x5A,0xFF,0x36,0x03,0x03,0x02,0x03,0x01,0xEE}
- out4_mute={0xA5,0xC3,0x3C,0x5A,0xFF,0x36,0x03,0x03,0x02,0x04,0x01,0xEE}
- out1_umute={0xA5,0xC3,0x3C,0x5A,0xFF,0x36,0x03,0x03,0x02,0x01,0x00,0xEE}
- out2_umute={0xA5,0xC3,0x3C,0x5A,0xFF,0x36,0x03,0x03,0x02,0x02,0x00,0xEE}
- out3_umute={0xA5,0xC3,0x3C,0x5A,0xFF,0x36,0x03,0x03,0x02,0x03,0x00,0xEE}
- out4_umute={0xA5,0xC3,0x3C,0x5A,0xFF,0x36,0x03,0x03,0x02,0x04,0x00,0xEE}
- preset1={0xA5,0xC3,0x3C,0x5A,0xFF,0x36,0x02,0x01,0x02,0xEE}
- preset2={0xA5,0xC3,0x3C,0x5A,0xFF,0x36,0x02,0x01,0x03,0xEE}
- clr={0xA5,0xC3,0x3C,0x5A,0xFF,0x36,0x09,0x03,0x01,0x01,0x00,0xEE} --заготовка для очистки матрицы
- mtx={0xA5,0xC3,0x3C,0x5A,0xFF,0x36,0x09,0x03,0x01,0x01,0x01,0xEE} --заготовка для соединения матрицы
- outv_set={0xA5,0xC3,0x3C,0x5A,0xFF,0x36,0x04,0x04,0x02,0x01,0x00,0x00,0xEE}
- data ={}
- z1dat={0x00,0x00}
- z2dat={0x00,0x00}
- local z1v = 6 --зона звука 1
- local z2v = 6 --зона звука 2
- local z1max = 9
- local z1min = 0
- local z2max = 9
- local z2min = 0
- up="up"
- dw="dw"
- res=6
- function z1vol(data) --гоняем звук туда-сюда
- if data =="up" then
- if z1v < z1max then
- z1v=z1v+1
- end
- end
- if data =="dw" then
- if z1v > z1min then
- z1v=z1v-1
- end
- end
- z1toHex(mapV(z1v)) --генерируем команды в НЕХ
- end
- function z2vol(data)
- if data =="up" then
- if z2v < z2max then
- z2v=z2v+1
- end
- end
- if data =="dw" then
- if z2v > z1min then
- z2v=z2v-1
- end
- end
- z2toHex(mapV(z2v))
- end
- function on_timer() --при тике таймера в 300мс шлем следующую команду в таблице
- if #data < 1 then return end
- usend(table.remove(data, 1))
- end
- function on_control_notify(screen,control,value)
- if screen == 0 then
- if control ==1 and value==1 then
- z1vol(up)
- end
- if control ==2 and value==1 then
- z1vol(dw)
- end
- if control ==3 and value==1 then
- clr_z()
- mtx_z_f()
- end
- if control ==4 and value==1 then
- clr_z()
- mtx_z_djz()
- end
- if control ==5 and value==1 then
- clr_z()
- mtx_z_djs()
- end
- if control ==6 and value==1 then
- z2vol(up)
- end
- if control ==7 and value==1 then
- z2vol(dw)
- end
- if control ==8 and value==1 then
- clr_s()
- mtx_s_f()
- end
- if control ==9 and value==1 then
- clr_s()
- mtx_s_djz()
- end
- if control ==10 and value==1 then
- clr_s()
- mtx_s_djs()
- end
- end
- end
- function usend(msg) -- выдаем команды в uart побйтово
- local tmp = {}
- for i = 1, #msg do
- tmp[i-1] = msg[i]
- end
- uart_send_data(tmp)
- end
- function on_init()
- uart_set_baudrate(115200)
- start_timer(1, 300, 1, 0)
- end
- function z1toHex(dat) --преобразуем int в hex 16LE
- local int16Value = dat
- if int16Value < 0 then
- int16Value = int16Value + 65536
- end
- local lowByte = int16Value % 256
- local highByte = math.floor(int16Value / 256)
- for i=1,2 do
- vset[10] = i
- vset[11] = lowByte
- vset[12] = highByte
- table.insert(data, vset)
- end
- end
- function z2toHex(dat)
- local int16Value = dat
- if int16Value < 0 then
- int16Value = int16Value + 65536
- end
- local lowByte = int16Value % 256
- local highByte = math.floor(int16Value / 256)
- outv_set[10] = 3
- outv_set[11] = lowByte
- outv_set[12] = highByte
- table.insert(data, outv_set)
- end
- function mapV(input) --мапим диапазон 0-9 в диапазон -400+150
- local output = -400 + (input * (150 + 400) / 9)
- return math.ceil(output)
- end
- function clr_z() --итерируем очистку матрицы вход 1 - 4 от выхода 1-2
- for i=1,4 do
- for x=1,2 do
- clr[9] = i
- clr[10] = x
- table.insert(data, clr)
- end
- end
- end
- function clr_s()
- for i=1,4 do
- x=3
- clr[9] = i
- clr[10] = x
- table.insert(data, clr)
- end
- end
- function mtx_z_f()
- for i=1,2 do
- for x=1,2 do
- mtx[9] = i
- mtx[10] = x
- table.insert(data, mtx)
- end
- end
- end
- function mtx_z_djz()
- i=3
- for x=1,2 do
- mtx[9] = i
- mtx[10] = x
- table.insert(data, mtx)
- end
- end
- function mtx_z_djs()
- i=4
- for x=1,2 do
- mtx[9] = i
- mtx[10] = x
- table.insert(data, mtx)
- end
- end
- function mtx_s_f()
- for i=1,2 do
- x=3
- mtx[9] = i
- mtx[10] = x
- table.insert(data, mtx)
- end
- end
- function mtx_s_djz()
- i=3
- x=3
- mtx[9] = i
- mtx[10] = x
- table.insert(data, mtx)
- end
- function mtx_s_djs()
- i=4
- x=3
- mtx[9] = i
- mtx[10] = x
- table.insert(data, mtx)
- end
- function on_systick()
- set_text(0,15,z1v)
- set_text(0,16,z2v)
- end
Advertisement
Add Comment
Please, Sign In to add comment