local a=require('data.min')local b=require('battery.min')local c=require('camera.min')local d=require('code.min')local e=require('plain_text.min')TEXT_MSG=0x0b;CAPTURE_SETTINGS_MSG=0x0d;AUDIO_SUBS_MSG=0x30;TAP_SUBS_MSG=0x10;a.parsers[TEXT_MSG]=e.parse_plain_text;a.parsers[CAPTURE_SETTINGS_MSG]=c.parse_capture_settings;a.parsers[AUDIO_SUBS_MSG]=d.parse_code;a.parsers[TAP_SUBS_MSG]=d.parse_code;AUDIO_DATA_NON_FINAL_MSG=0x05;AUDIO_DATA_FINAL_MSG=0x06;TAP_MSG=0x09;function handle_tap()rc,err=pcall(frame.bluetooth.send,string.char(TAP_MSG))if rc==false then print(err)end end;function print_text()local f=0;for g in a.app_data[TEXT_MSG].string:gmatch("([^\n]*)\n?")do if g~=""then frame.display.text(g,1,f*60+1)f=f+1 end end end;function clear_display()frame.display.text(" ",1,1)frame.display.show()frame.sleep(0.04)end;function run_auto_exp_if_elapsed(h,i)local j=frame.time.utc()if h==0 or j-h>i then c.run_auto_exposure()return j else return h end end;function app_loop()clear_display()local k=0;local l=0;local m=false;local n=''local o=frame.bluetooth.max_length()if o%2==1 then o=o-1 end;while true do rc,err=pcall(function()local p=a.process_raw_items()if p>0 then if a.app_data[TEXT_MSG]~=nil and a.app_data[TEXT_MSG].string~=nil then print_text()frame.display.show()end;if a.app_data[TAP_SUBS_MSG]~=nil then if a.app_data[TAP_SUBS_MSG].value==1 then frame.imu.tap_callback(handle_tap)else frame.imu.tap_callback(nil)end;a.app_data[TAP_SUBS_MSG]=nil end;if a.app_data[CAPTURE_SETTINGS_MSG]~=nil then rc,err=pcall(c.capture_and_send,a.app_data[CAPTURE_SETTINGS_MSG])if rc==false then print(err)end;a.app_data[CAPTURE_SETTINGS_MSG]=nil end;if a.app_data[AUDIO_SUBS_MSG]~=nil then if a.app_data[AUDIO_SUBS_MSG].value==1 then n=''pcall(frame.microphone.start,{sample_rate=8000,bit_depth=16})m=true;frame.display.text("\u{F0010}",1,1)frame.display.show()else pcall(frame.microphone.stop)frame.display.text(" ",1,1)frame.display.show()end;a.app_data[AUDIO_SUBS_MSG]=nil end end end)if rc==false then print(err)frame.display.text(" ",1,1)frame.display.show()frame.sleep(0.04)break end;if m then for f=1,20 do n=frame.microphone.read(o)if n==nil then pcall(frame.bluetooth.send,string.char(AUDIO_DATA_FINAL_MSG))frame.sleep(0.0025)m=false;break elseif n~=''then pcall(frame.bluetooth.send,string.char(AUDIO_DATA_NON_FINAL_MSG)..n)frame.sleep(0.0025)end end end;l=run_auto_exp_if_elapsed(l,0.1)k=b.send_batt_if_elapsed(k,120)if not m then frame.sleep(0.1)end end end;app_loop()