testheadset.lua 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. --- 模块功能:headset功能测试.
  2. -- @author openLuat
  3. -- @module adc.testAdc
  4. -- @license MIT
  5. -- @copyright openLuat
  6. -- @release 2021.02.02
  7. module(...,package.seeall)
  8. require "audio"
  9. require "rtos"
  10. require "sys"
  11. function headsetCB(msg)
  12. log.info("msg.type====",msg.type)
  13. log.info("msg.param====",msg.param)
  14. --拔出,普通
  15. if msg.type==1 then
  16. log.info(" ==========耳机============ headset true 111111")
  17. if msg.param == 2 or msg.param == 3 then
  18. audiocore.head_plug(1)
  19. log.info("head_pulg INSERT4P")
  20. elseif msg.param == 1 then
  21. audiocore.head_plug(2)
  22. log.info("head_pulg INSERT3P")
  23. end
  24. audio.setChannel(0)
  25. elseif msg.type==2 then
  26. log.info("==========耳机============ headset false 00000000")
  27. audiocore.head_plug(0)
  28. audio.setChannel(1)
  29. end
  30. end
  31. rtos.sleep(3000)
  32. if audiocore.headsetinit then
  33. rtos.on(rtos.MSG_HEADSET,headsetCB)
  34. audiocore.headsetinit(0)
  35. audio.setChannel(0)
  36. else
  37. sys.taskInit(function()
  38. sys.wait(3000)
  39. log.info("耳机不兼容")
  40. end)
  41. end