Forráskód Böngészése

fix:完成UI 布局

梁健 9 hónapja
szülő
commit
1409f777bf

+ 0 - 1
module/Air8000/project/整机开发板出厂工程/user/airlcd.lua

@@ -45,7 +45,6 @@ function airLCD.lcd_init(sn)
         log.info("tp", "tp init")
         local function tp_callBack(tp_device,tp_data)
             sys.publish("TP",tp_device,tp_data)
-            log.info("TP",tp_data[1].x,tp_data[1].y,tp_data[1].event)
         end
 
         local i2c_id = 0

+ 118 - 0
module/Air8000/project/整机开发板出厂工程/user/airmusic.lua

@@ -0,0 +1,118 @@
+local airmusic = {}
+
+
+function airmusic.play(path)
+    gpio.setup(24, 1, gpio.PULLUP)          -- i2c工作的电压域
+
+
+
+    local i2c_id = 0            -- i2c_id 0
+
+    local pa_pin = 162           -- 喇叭pa功放脚
+    local power_pin = 27         -- es8311电源脚
+
+    local i2s_id = 0            -- i2s_id 0
+    local i2s_mode = 0          -- i2s模式 0 主机 1 从机
+    local i2s_sample_rate = 16000   -- 采样率
+    local i2s_bits_per_sample = 16  -- 数据位数
+    local i2s_channel_format = i2s.MONO_R   -- 声道, 0 左声道, 1 右声道, 2 立体声
+    local i2s_communication_format = i2s.MODE_LSB   -- 格式, 可选MODE_I2S, MODE_LSB, MODE_MSB
+    local i2s_channel_bits = 16     -- 声道的BCLK数量
+
+    local multimedia_id = 0         -- 音频通道 0
+    local pa_on_level = 1           -- PA打开电平 1 高电平 0 低电平
+    local power_delay = 3           -- 在DAC启动前插入的冗余时间,单位100ms
+    local pa_delay = 100            -- 在DAC启动后,延迟多长时间打开PA,单位1ms
+    local power_on_level = 1        -- 电源控制IO的电平,默认拉高
+    local power_time_delay = 100    -- 音频播放完毕时,PA与DAC关闭的时间间隔,单位1ms
+
+    local voice_vol = 70        -- 喇叭音量
+    local mic_vol = 80          -- 麦克风音量
+
+    gpio.setup(power_pin, 1, gpio.PULLUP)         
+    gpio.setup(pa_pin, 1, gpio.PULLUP)
+
+    function audio_setup()
+        pm.power(pm.LDO_CTL, false)  --开发板上ES8311由LDO_CTL控制上下电
+        sys.wait(100)
+        pm.power(pm.LDO_CTL, true)  --开发板上ES8311由LDO_CTL控制上下电
+
+        i2c.setup(i2c_id,i2c.FAST)      --设置i2c
+        i2s.setup(i2s_id, i2s_mode, i2s_sample_rate, i2s_bits_per_sample, i2s_channel_format, i2s_communication_format,i2s_channel_bits)    --设置i2s
+
+        audio.config(multimedia_id, pa_pin, pa_on_level, power_delay, pa_delay, power_pin, power_on_level, power_time_delay)
+        audio.setBus(multimedia_id, audio.BUS_I2S,{chip = "es8311",i2cid = i2c_id , i2sid = i2s_id, voltage = audio.VOLTAGE_1800})	--通道0的硬件输出通道设置为I2S
+
+        audio.vol(multimedia_id, voice_vol)
+        audio.micVol(multimedia_id, mic_vol)
+        sys.publish("AUDIO_READY")
+    end
+
+    -- 配置好audio外设
+    sys.taskInit(audio_setup)
+
+    local taskName = "task_audio"
+
+    local MSG_MD = "moreData"   -- 播放缓存有空余
+    local MSG_PD = "playDone"   -- 播放完成所有数据
+
+    audio.on(0, function(id, event)
+        --使用play来播放文件时只有播放完成回调
+        local succ,stop,file_cnt = audio.getError(0)
+        if not succ then
+            if stop then
+                log.info("用户停止播放")
+            else
+                log.info("第", file_cnt, "个文件解码失败")
+            end
+        end
+        sysplus.sendMsg(taskName, MSG_PD)
+    end)
+
+
+    local function audio_task()
+        local result    
+        sys.waitUntil("AUDIO_READY")
+        while true do
+            log.info("开始播放")
+            result = audio.play(0,path)
+            if result then
+            --等待音频通道的回调消息,或者切换歌曲的消息
+                while true do
+                    msg = sysplus.waitMsg(taskName, nil)
+                    if type(msg) == 'table' then
+                        if msg[1] == MSG_PD then
+                            log.info("播放结束")
+                            break
+                        end
+                    else
+                        log.error(type(msg), msg)
+                    end
+                end
+            else
+                log.debug("解码失败!")
+                sys.wait(1000)
+            end
+            if not audio.isEnd(0) then
+                log.info("手动关闭")
+                audio.playStop(0)
+            end
+            if audio.pm then
+                audio.pm(0,audio.STANDBY)       --PM模式 待机模式,PA断电,codec待机状态,系统不能进低功耗状态,如果PA不可控,codec进入静音模式
+            end
+            -- audio.pm(0,audio.SHUTDOWN)	--低功耗可以选择SHUTDOWN或者POWEROFF,如果codec无法断电用SHUTDOWN
+            log.info("mem", "sys", rtos.meminfo("sys"))
+            log.info("mem", "lua", rtos.meminfo("lua"))
+            sys.wait(1000)
+        end
+    end
+
+    sys.timerLoopStart(function()
+        log.info("mem.lua", rtos.meminfo())
+        log.info("mem.sys", rtos.meminfo("sys"))
+    end, 3000)
+
+    sysplus.taskInitEx(audio_task, taskName)
+end
+
+return airmusic

+ 130 - 0
module/Air8000/project/整机开发板出厂工程/user/airtts.lua

@@ -0,0 +1,130 @@
+local airtts = {}
+
+local i2c_id = 0            -- i2c_id 0
+
+
+local pa_pin = 162           -- 喇叭pa功放脚
+local power_pin = 164         -- es8311电源脚
+
+
+local i2s_id = 0            -- i2s_id 0
+local i2s_mode = 0          -- i2s模式 0 主机 1 从机
+local i2s_sample_rate = 16000   -- 采样率
+local i2s_bits_per_sample = 16  -- 数据位数
+local i2s_channel_format = i2s.MONO_R   -- 声道, 0 左声道, 1 右声道, 2 立体声
+local i2s_communication_format = i2s.MODE_LSB   -- 格式, 可选MODE_I2S, MODE_LSB, MODE_MSB
+local i2s_channel_bits = 16     -- 声道的BCLK数量
+
+local multimedia_id = 0         -- 音频通道 0
+local pa_on_level = 1           -- PA打开电平 1 高电平 0 低电平
+local power_delay = 3           -- 在DAC启动前插入的冗余时间,单位100ms
+local pa_delay = 100            -- 在DAC启动后,延迟多长时间打开PA,单位1ms
+local power_on_level = 1        -- 电源控制IO的电平,默认拉高
+local power_time_delay = 100    -- 音频播放完毕时,PA与DAC关闭的时间间隔,单位1ms
+local taskName = "task_tts"
+
+local play_string = "降功耗,找合宙"
+local voice_vol = 70        -- 喇叭音量
+local mic_vol = 80          -- 麦克风音量
+
+function audio_setup()
+    pm.power(pm.LDO_CTL, false)  --开发板上ES8311由LDO_CTL控制上下电
+    sys.wait(100)
+    pm.power(pm.LDO_CTL, true)  --开发板上ES8311由LDO_CTL控制上下电
+
+    i2c.setup(i2c_id,i2c.FAST)
+    i2s.setup(i2s_id, i2s_mode, i2s_sample_rate, i2s_bits_per_sample, i2s_channel_format, i2s_communication_format,i2s_channel_bits)
+
+    audio.config(multimedia_id, pa_pin, pa_on_level, power_delay, pa_delay, power_pin, power_on_level, power_time_delay)
+    audio.setBus(multimedia_id, audio.BUS_I2S,{chip = "es8311",i2cid = i2c_id , i2sid = i2s_id, voltage = audio.VOLTAGE_1800})	--通道0的硬件输出通道设置为I2S
+
+    audio.vol(multimedia_id, voice_vol)
+    audio.micVol(multimedia_id, mic_vol)
+    sys.publish("AUDIO_READY")
+end
+
+local function audio_play()
+    local result    
+    sys.waitUntil("AUDIO_READY")
+    -- 初始化spi flash, 如果是极限版TTS_ONCHIP,就不需要初始化
+    if sfud then
+        spi_flash = spi.deviceSetup(1,12,0,0,8,25600000,spi.MSB,1,0)
+        local ret = sfud.init(spi_flash)
+        if ret then
+            log.info("sfud.init ok")
+        else
+            log.info("sfud.init error", ret)
+            return
+        end
+    else
+        log.info("tts", "TTS_ONCHIP?? skip sfud")
+    end
+
+    -- 本例子是按行播放 "千字文", 文本来源自wiki百科
+    local fd = nil
+    local line = nil
+    while true do
+        log.info("开始播放")
+        line = play_string
+        line = line:trim()
+        log.info("播放内容", line)
+        result = audio.tts(0, line)
+        if result then
+        --等待音频通道的回调消息,或者切换歌曲的消息
+            while true do
+                msg = sysplus.waitMsg(taskName, nil)
+                if type(msg) == 'table' then
+                    if msg[1] == MSG_PD then
+                        log.info("播放结束")
+                        break
+                    end
+                else
+                    log.error(type(msg), msg)
+                end
+            end
+        else
+            log.debug("解码失败!")
+            sys.wait(1000)
+        end
+        if not audio.isEnd(0) then
+            log.info("手动关闭")
+            audio.playStop(0)
+        end
+        if audio.pm then
+            audio.pm(0,audio.STANDBY)
+        end
+        -- audio.pm(0,audio.SHUTDOWN)	--低功耗可以选择SHUTDOWN或者POWEROFF,如果codec无法断电用SHUTDOWN
+        log.info("mem", "sys", rtos.meminfo("sys"))
+        log.info("mem", "lua", rtos.meminfo("lua"))
+        sys.wait(1000)
+    end
+    sysplus.taskDel(taskName)
+end
+
+local function audio_callback(id, event)
+    local succ,stop,file_cnt = audio.getError(0)
+    if not succ then
+        if stop then
+            log.info("用户停止播放")
+        else
+            log.info("第", file_cnt, "个文件解码失败")
+        end
+    end
+    sysplus.sendMsg(taskName, MSG_PD)
+end
+
+local function audio_task()
+    gpio.setup(24, 1, gpio.PULLUP)          -- i2c工作的电压域
+    gpio.setup(power_pin, 1, gpio.PULLUP)   -- 打开音频编解码供电
+    gpio.setup(pa_pin, 1, gpio.PULLUP)      -- 打开音频放大器
+    audio_setup()
+    audio.on(0, audio_callback)
+    audio_play(string)
+end
+
+function airtts.play(string)
+    play_string = string
+    sysplus.taskInitEx(audio_task, taskName)
+end
+
+return airtts

+ 127 - 163
module/Air8000/project/整机开发板出厂工程/user/main.lua

@@ -5,21 +5,16 @@ log.info("main", PROJECT, VERSION)
 
 -- sys库是标配
 sys = require("sys")
-
+-- local airgps = require "airgps"
 local airlcd = require "airlcd"
+local airmusic = require "airmusic"
+local airtts  = require "airtts"
 local aircam = require "camera8000_simple"
 local airrus = require "russia"
 local airstatus = require "statusbar"
 local airtestwlan = require "test_wlan"
 local airbuzzer = require "airbuzzer"
 
-local key = ""      
-
-local powertick = 0
-local boottick = 0
-local SWITCH_LONG_TIME = 500
-local ROT_LONG_TIME = 300
-local QUIT_LONG_TIME = 3000
 
 local sid = 0
 
@@ -55,12 +50,6 @@ local sid = 0
 -- "uart":      串口输出
 -- "232":       232
 
-
-
-
-
-
-
 local cur_fun = "main"
 local cur_sel = 0
 
@@ -92,138 +81,117 @@ local function QuitCam()
   airlcd.lcd_init("AirLCD_1001")
 end
 
-local function keypressed()
-  if key == "" then
-    return
-  end
-  
-  log.info("keypressed : ", key, cur_fun)
 
+local function update()
   if cur_fun == "russia" then
-      if key == "quit" then
-          cur_fun = "main"
-      else
-          airrus.keypressed(key)
-      end
-      return
+    airrus.updaterus()
   end
 
-  if key == "switch" then
-    if cur_fun == "main" then
-      cur_sel = cur_sel + 1
-      if cur_sel > 9 then
-        cur_sel = 1
-      end
-      log.info("select num:", cur_sel)
-    end
-    key = ""
-  elseif key == "enter" or key == "quit" then
-    if cur_fun == "main" then
-      cur_fun = funlist[cur_sel]
-      if cur_fun == "camshow" then
-        StartCam()
-      elseif cur_fun == "russia" then
-        airrus.initrus()
-      elseif cur_fun == "LAN" then
-        
-      elseif cur_fun == "WAN" then
-        sys.taskInit(airtestwlan.test_wan)
-      elseif cur_fun == "selftest" then
-
-      elseif cur_fun == "modbusTCP" then
-
-      elseif cur_fun == "modbusRTU" then
-
-      elseif cur_fun == "CAN" then
-      end
-    else
-      cur_fun = "main"
-      if not aircam.isquit then
-        QuitCam()
-      end
-    end
-    key = ""
+  if not airstatus.data.weather.result and ((sid % 50) == 0)  then
+    airstatus.get_sig_strength()
+    airstatus.get_weather()
+  end
+  if airstatus.data.bat_level == 0 then
+    airstatus.get_bat_level()
   end
 end
 
-local function PowerInterrupt()
-    local s1 = 0
-    local s2 = 0
-    local v = gpio.get(gpio.PWR_KEY)
-    log.info("pwrkey:", v, powertick)
-    if v == 0 then
-      powertick = mcu.ticks()
-      airbuzzer.start_buzzer()
-    elseif  v == 1 then
-      s1 = mcu.ticks()
-      airbuzzer.stop_buzzer()
-      local s2 = s1 - powertick
-      if s2 < SWITCH_LONG_TIME then
-          key = "switch"
-          if cur_fun == "russia" then
-            key = "left"
-          end
-      elseif s2 < QUIT_LONG_TIME then
-          key = "enter"
-          if cur_fun == "russia" then
-            key = "fast"
-          end
-      else
-          key = "quit"
-      end
-      powertick = s1
-      --if cur_fun == "russia" then
-      --  airrus.keypressed(key)
-      --end
-      log.info("power key:", v, powertick,s2,key)
-    end
+
+
+local lock_push = 1
+local function main_local(x,y)
+  if x > 0 and  x < 100 and y > 64  and  y < 192 then
+    return 1
+  elseif x > 100 and  x < 200 and y > 64  and  y < 192 then
+    return 2
+  elseif x > 200 and  x < 300 and y > 64  and  y < 192 then
+    return 3
+  elseif x > 0 and  x < 100 and y > 192  and  y < 320 then
+    return 4
+  elseif x > 100 and  x < 200 and y > 192  and  y < 320 then
+    return 5
+  elseif x > 200 and  x < 300 and y > 192  and  y < 320 then
+    return 6
+  elseif x > 0 and  x < 100 and y > 320  and  y < 448 then
+    return 7
+  elseif x > 100 and  x < 200 and y > 320  and  y < 448 then
+    return 8
+  elseif x > 200 and  x < 300 and y > 320  and  y < 448 then
+    return 9
+  end
 end
 
-local function BootInterrupt()
-    local v = gpio.get(0)
-    log.info("gpio0:", v, boottick)
-    if v == 1 then
-      boottick = mcu.ticks()
-    elseif  v == 0 then
-      s1 = mcu.ticks()
-      local s2 = s1 - boottick
-      if s2 < ROT_LONG_TIME then
-        key = "right"
-      else
-        key = "up"
-      end
-      boottick = s1
-      --if cur_fun == "russia" then
-      --  airrus.keypressed(key)
-      --end
-      log.info("gpio0 key:", v, boottick,s2,key)
-    end
+local function handal_main(x,y)
+  key =  main_local(x,y) 
+  log.info("tp_handal key",key)
+  if key == 1 then
+  elseif key == 2 then
+  elseif key == 3 then
+  elseif key == 4 then
+  elseif key == 5 then
+  elseif key == 6 then
+  elseif key == 7 then
+  elseif key == 8 then    --  tts
+    airtts.play("支持 4G + 卫星定位 + WiFi + 蓝牙,5秒极速联网,51个可编程IO/4个UART/4个通用ADC/1个CAN接口,支持LuatOS二次开发,源码开放例程丰富,支持485/232/充电/以太网驱动/多网融合/VoLTE通话")
+  elseif key == 9 then
+    cur_fun = "main1"
+  end
 end
 
-local function KeyInit()
-    if not gpio.PWR_KEY then
-      log.info("bsp not support powerkey")
-      return
-    end
-  
-    gpio.setup(gpio.PWR_KEY, PowerInterrupt, gpio.PULLUP, gpio.BOTH)
-    gpio.setup(0, BootInterrupt, gpio.PULLDOWN, gpio.BOTH)
+local function handal_main1(x,y)
+  key =  main_local(x,y) 
+  log.info("tp_handal key",key)
+  if key == 1 then
+  elseif key == 2 then
+    airmusic.play("/luadb/1.mp3")
+  elseif key == 3 then
+  elseif key == 4 then
+  elseif key == 5 then
+  elseif key == 6 then
+  elseif key == 7 then
+    cur_fun = "main"
+  elseif key == 8 then
+  elseif key == 9 then
+    cur_fun = "main2"
+  end
 end
 
-local function update()
-  if cur_fun == "russia" then
-    airrus.updaterus()
+local function handal_main2(x,y)
+  key =  main_local(x,y) 
+  log.info("tp_handal key",key)
+  if key == 1 then
+  
+  elseif key == 2 then
+  elseif key == 3 then
+  elseif key == 4 then
+  elseif key == 5 then
+  elseif key == 6 then
+  elseif key == 7 then
+    cur_fun = "main1"
+  elseif key == 8 then
+  elseif key == 9 then
+    cur_fun = "main"
   end
+end
 
-  if not airstatus.data.weather.result and ((sid % 50) == 0)  then
-    airstatus.get_sig_strength()
-    airstatus.get_weather()
+local function  tp_handal(tp_device,tp_data)
+  log.info("tp_handal",tp_data[1].x,tp_data[1].y,tp_data[1].event)
+  if tp_data[1].event == 1 then
+    lock_push = 0
   end
-  if airstatus.data.bat_level == 0 then
-    airstatus.get_bat_level()
+  if tp_data[1].event == 2  and   lock_push == 0 then
+    if cur_fun == "main" then
+      handal_main(tp_data[1].x,tp_data[1].y)
+    elseif cur_fun == "main1" then
+      handal_main1(tp_data[1].x,tp_data[1].y)
+    elseif cur_fun == "main2" then
+      handal_main2(tp_data[1].x,tp_data[1].y)
+    end
+    lock_push = 1
   end
 end
 
+
 -- 画状态栏
 local function draw_statusbar()
   lcd.showImage(0, 0, "/luadb/signal" .. airstatus.data.sig_stren .. ".jpg")
@@ -242,31 +210,31 @@ local function draw_statusbar()
   end
 end
 
-local function draw_wan()
-  lcd.showImage(0, 65, "/luadb/function5.jpg")
-end
+-- local function draw_wan()
+--   lcd.showImage(0, 65, "/luadb/function5.jpg")
+-- end
 
-local function draw_lan()
-  lcd.showImage(0, 65, "/luadb/function4.jpg")
-end
+-- local function draw_lan()
+--   lcd.showImage(0, 65, "/luadb/function4.jpg")
+-- end
 
-local function draw_selftest()
-  lcd.showImage(0, 65, "/luadb/choose1.jpg")
-  lcd.showImage(0, 194, "/luadb/choose2.jpg")
-  lcd.showImage(0, 322, "/luadb/choose3.jpg")
-end
+-- local function draw_selftest()
+--   lcd.showImage(0, 65, "/luadb/choose1.jpg")
+--   lcd.showImage(0, 194, "/luadb/choose2.jpg")
+--   lcd.showImage(0, 322, "/luadb/choose3.jpg")
+-- end
 
-local function draw_modbusRTU()
-  lcd.showImage(0, 65, "/luadb/final_function.jpg")
-end
+-- local function draw_modbusRTU()
+--   lcd.showImage(0, 65, "/luadb/final_function.jpg")
+-- end
 
-local function draw_modbusTCP()
-  lcd.showImage(0, 65, "/luadb/final_function.jpg")
-end
+-- local function draw_modbusTCP()
+--   lcd.showImage(0, 65, "/luadb/final_function.jpg")
+-- end
 
-local function draw_CAN()
-  lcd.showImage(0, 65, "/luadb/final_function.jpg")
-end
+-- local function draw_CAN()
+--   lcd.showImage(0, 65, "/luadb/final_function.jpg")
+-- end
 
 --画九宫格界面
 local function draw_main()
@@ -288,7 +256,7 @@ local function draw_main()
   end      
 end
 
-local function draw_main2()
+local function draw_main1()
   local i = 0
   local j = 0 
   local x,y
@@ -307,7 +275,7 @@ local function draw_main2()
   end      
 end
 
-local function draw_main3()
+local function draw_main2()
   local i = 0
   local j = 0 
   local x,y
@@ -341,10 +309,10 @@ local function draw()
   
   if cur_fun == "main" then
     draw_main()
+  elseif cur_fun == "main1" then
+    draw_main1()
   elseif cur_fun == "main2" then
     draw_main2()
-  elseif cur_fun == "main3" then
-    draw_main3()
   elseif cur_fun == "picshow" then
     draw_pic()
   elseif cur_fun == "russia" then
@@ -373,23 +341,19 @@ wdtInit()
 
 local function UITask()
     airlcd.lcd_init("AirLCD_1001")
+    sys.subscribe("TP",tp_handal)
 
-    KeyInit()
     log.info("合宙 8000 startup v13:" .. sid)
 
     while 1 do
-        keypressed()
-        
-        update()
-
-        draw()
-
-        if ((sid % 10) == 0) then
-          log.info("sid: ", sid, cur_fun)
-        end
+      update()
+      draw()
+      if ((sid % 10) == 0) then
+        log.info("sid: ", sid, cur_fun)
+      end
 
-        sid = sid + 1
-        sys.wait(10)
+      sid = sid + 1
+      sys.wait(10)
     end
 
 end