--- /dev/null
+import osTimer
+import lvgl as lv
+from ext import EventMesh
+import osTimer
+from ext import constants
+import ujson
+import ql_fs
+import audio
+from machine import Pin
+from ext.ui import style_font_youyuan_20,style_screen,Screen,style_font_youyuan_20_black,style_contact_btn
+import audio
+from machine import Pin
+from ext.protocol import ProtoCol
+
+style_wechat_r_btn = lv.style_t()
+style_wechat_r_btn.init()
+style_wechat_r_btn.set_bg_color(lv.color_make(0x26, 0xf6, 0x23))
+style_wechat_r_btn.set_border_width(0)
+style_wechat_r_btn.set_shadow_opa(0)
+
+
+style_wechat_s_btn = lv.style_t()
+style_wechat_s_btn.init()
+style_wechat_s_btn.set_bg_color(lv.color_make(0xff, 0xff, 0xff))
+style_wechat_s_btn.set_border_width(0)
+style_wechat_s_btn.set_shadow_opa(0)
+
+style_common_bg_rect_btn_pressed = lv.style_t()
+style_common_bg_rect_btn_pressed.init()
+style_common_bg_rect_btn_pressed.set_bg_color(lv.color_make(0x1E, 0x26, 0xff))
+style_common_bg_rect_btn_pressed.set_bg_opa(100)
+style_common_bg_rect_btn_pressed.set_border_width(0)
+style_common_bg_rect_btn_pressed.set_shadow_opa(0)
+
+style_wechat_btn = lv.style_t()
+style_wechat_btn.init()
+style_wechat_btn.set_bg_color(lv.color_make(0x1E, 0x26, 0xff))
+style_wechat_btn.set_border_width(0)
+style_wechat_btn.set_shadow_opa(0)
+
+# -------------------------------------------wechat screen----------------------------------------------------------
+wechat_screen = lv.obj()
+wechat = lv.obj(wechat_screen)
+wechat.center()
+wechat.set_size(240, 320)
+wechat.add_style(style_screen, lv.PART.MAIN | lv.STATE.DEFAULT)
+
+wechat_press_btn = lv.btn(wechat)
+wechat_press_btn.set_pos(10, 260)
+wechat_press_btn.set_size(220, 56)
+wechat_press_btn.add_style(style_wechat_btn, lv.PART.MAIN | lv.STATE.DEFAULT)
+wechat_press_btn.add_style(style_common_bg_rect_btn_pressed, lv.PART.MAIN | lv.STATE.PRESSED)
+wechat_press_btn.set_style_radius(30,0)
+
+wechat_press_label = lv.label(wechat_press_btn)
+wechat_press_label.set_text("请按住说话")
+wechat_press_label.align(lv.ALIGN.CENTER, 10, 0)
+wechat_press_label.add_style(style_font_youyuan_20, lv.PART.MAIN | lv.STATE.DEFAULT)
+
+wechat_label = lv.label(wechat)
+wechat_label.center()
+wechat_label.set_size(240, 40)
+wechat_label.set_long_mode(lv.label.LONG.WRAP)
+wechat_label.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0)
+wechat_label.add_style(style_font_youyuan_20, lv.PART.MAIN | lv.STATE.DEFAULT)
+
+
+wechat_press_label_countdown = lv.label(wechat)
+wechat_press_label_countdown.set_pos(100, 100)
+wechat_press_label_countdown.set_size(40, 40)
+wechat_press_label_countdown.set_text(" ")
+wechat_press_label_countdown.add_style(style_font_youyuan_20, lv.PART.MAIN | lv.STATE.DEFAULT)
+wechat_press_label_countdown.set_long_mode(lv.label.LONG.WRAP)
+wechat_press_label_countdown.set_style_text_align(lv.TEXT_ALIGN.RIGHT, 0)
+
+
+
+
+
+class WechatScreen(Screen):
+ NAME = "wechat"
+
+ def __init__(self):
+ super().__init__()
+ self.MXA_MSG = 10
+ self.wechat_recode_list = {}
+ self.wechat_num = 0
+ check_txt = ql_fs.path_exists("/ext/static/audio_amr/num.txt")
+ if check_txt == True :
+ with open("/ext/static/audio_amr/num.txt","r") as fd:
+ num_tmp = fd.read()
+ if not num_tmp:
+ self.wechat_num = 0
+ else:
+ self.wechat_num = int(num_tmp)#
+ if self.wechat_num != 0:
+ with open("ext/static/audio_amr/record.json","r",encoding="utf-8") as fd:
+ self.wechat_recode_list = ujson.load(fd)#读取每一个amr音频文件的时长
+
+ self.record_test = audio.Record()
+ self.aud = audio.Audio(0)
+ self.aud.set_pa(Pin.GPIO29)
+ self.aud.setVolume(10)
+ self.meta = wechat_screen
+ self.countdown = 0
+ wechat_press_btn.add_event_cb(lambda e: self.talking(e),
+ lv.EVENT.LONG_PRESSED, None)
+ wechat_press_btn.add_event_cb(lambda e: self.sending(e),
+ lv.EVENT.RELEASED, None)
+ self.timer = osTimer()
+ self.second_timer = osTimer()
+ wechat_label.set_text(" ")
+
+ self.startX = 0
+ self.check_json = 0
+ self.wechat_list =lv.obj()
+ EventMesh.subscribe("wechat_updata_list_show", self.wechat_updata_list_show)
+ EventMesh.subscribe("get_wechat_data", self.get_wechat_data)
+ EventMesh.subscribe("set_wechat_data", self.set_wechat_data)
+ self.countdown = 1
+
+ def get_wechat_data(self,event, msg):
+ return [self.MXA_MSG,self.wechat_num ,self.wechat_recode_list]
+
+ def set_wechat_data(self, event, msg):
+ self.MXA_MSG = msg[0]
+ self.wechat_num = msg[1]
+ self.wechat_recode_list = msg[2]
+ with open("ext/static/audio_amr/record.json","w",encoding="utf-8") as fd:
+ ujson.dump(self.wechat_recode_list,fd)
+ #写编号
+ with open("/ext/static/audio_amr/num.txt","w") as fd:
+ fd.write("{}".format(self.wechat_num))
+ #print("self.MXA_MSG:{} self.wechat_num:{} self.wechat_recode_list:{}".format(self.MXA_MSG,self.wechat_num,self.wechat_recode_list))
+
+ def wechat_updata_list_show(self, event, msg):
+ if (self.wechat_list.has_flag(lv.obj.FLAG.HIDDEN)) == False:
+ # tmp = EventMesh.publish("get_wechat_data")
+ # self.MXA_MSG = tmp[0]
+ # self.wechat_num = tmp[1]
+ # self.wechat_recode_list = tmp[2]
+ #print("wechat_updata_list_show self.MXA_MSG:{} self.wechat_num:{} self.wechat_recode_list:{}".format(self.MXA_MSG,self.wechat_num,self.wechat_recode_list))
+ self.updata_list_show(2)
+
+ def updata_list_show(self,index):
+
+ #print("self.wechat_list.get_hidden:{}".format(self.wechat_list.has_flag(lv.obj.FLAG.HIDDEN)))
+ if index == 2 or index == 0:
+ #读取json文件中的键作为label文本;
+
+ # print("self.wechat_recode_list:{}".format(self.wechat_recode_list))
+ self.wechat_list.delete()#先删除一次控件
+ self.wechat_list.clear_flag(lv.obj.FLAG.HIDDEN)#隐藏列表选项方框
+ self.wechat_list = lv.obj(wechat_screen)
+ self.wechat_list.set_pos(0, 0)
+ self.wechat_list.set_size(240, 250)
+ self.wechat_list.set_scrollbar_mode(lv.SCROLLBAR_MODE.OFF)
+ self.wechat_list.add_style(style_screen, lv.PART.MAIN | lv.STATE.DEFAULT)
+ #print("self.wechat_list.self.wechat_num:{}".format(self.wechat_num))
+ if self.wechat_num != 0:
+ j = 1
+ if len(self.wechat_recode_list) == self.MXA_MSG:
+ j = self.wechat_num+1
+ for i in range(self.MXA_MSG):
+ if j > self.MXA_MSG:
+ j = 1
+ key = "%02d"%(j)
+ if j > len(self.wechat_recode_list) :
+ break
+ j+=1
+ print("key :{}".format(key))
+ print("self.wechat_recode_list:{}".format(self.wechat_recode_list[key]))
+
+ value = self.wechat_recode_list[key]
+ msg_tmp = value[2:]
+ msg_tmp = int(msg_tmp)
+ startX = 20+msg_tmp*10
+ startY = 52*i
+ contact_btn = lv.btn(self.wechat_list)
+ if value.find("S:") != -1:
+ contact_btn.set_size(startX,50)
+ contact_btn.set_pos(10,startY )
+ contact_btn.add_style(style_wechat_s_btn, lv.PART.MAIN | lv.STATE.DEFAULT)
+ contact_btn.add_event_cb(lambda e: self.play_label(e),
+ lv.EVENT.CLICKED, None)
+
+ _btn_label1 = lv.label(contact_btn)
+ _btn_label1.set_long_mode(lv.label.LONG.DOT)
+ _btn_label1.set_text(str(msg_tmp))
+ _btn_label1.add_style(style_font_youyuan_20_black, lv.PART.MAIN | lv.STATE.DEFAULT)
+
+ _btn_label2 = lv.label(contact_btn)
+ _btn_label2.set_size(0, 0)
+ _btn_label2.set_text(key)
+ _btn_label2.set_long_mode(lv.label.LONG.DOT)
+
+ elif value.find("R:") != -1 :
+ contact_btn.set_size(startX,50)
+ contact_btn.set_pos(230-startX,startY )
+ contact_btn.add_style(style_wechat_r_btn, lv.PART.MAIN | lv.STATE.DEFAULT)
+ contact_btn.add_event_cb(lambda e: self.play_label(e),
+ lv.EVENT.CLICKED, None)
+
+ _btn_label1 = lv.label(contact_btn)
+ _btn_label1.set_long_mode(lv.label.LONG.DOT)
+ _btn_label1.set_text(str(msg_tmp))
+ _btn_label1.add_style(style_font_youyuan_20_black, lv.PART.MAIN | lv.STATE.DEFAULT)
+
+ _btn_label2 = lv.label(contact_btn)
+ _btn_label2.set_size(0, 0)
+ _btn_label2.set_text(key)
+ _btn_label2.set_long_mode(lv.label.LONG.DOT)
+ elif value.find("T:") != -1 :
+ pass
+
+ if index == 2:#为了加载的时候不要每次都从头开始显示
+ bottom_btn = self.wechat_list.get_child(-1)
+ bottom_btn.scroll_to_view(lv.ANIM.OFF)
+
+
+ def initialization(self):
+
+ wechat_label.add_flag(lv.obj.FLAG.HIDDEN)
+ wechat_press_label_countdown.add_flag(lv.obj.FLAG.HIDDEN)
+ self.wechat_list.clear_flag(lv.obj.FLAG.HIDDEN)#隐藏列表选项方框
+ #读取json文件中的字典放到self.phonebook中
+ #创建btn
+ self.updata_list_show(0)
+
+ def talking(self,e):
+ self.wechat_list.add_flag(lv.obj.FLAG.HIDDEN)#隐藏列表选项方框
+ self.countdown = 1
+ wechat_label.clear_flag(lv.obj.FLAG.HIDDEN)
+ wechat_label.set_text("松开发送")
+ wechat_press_label_countdown.clear_flag(lv.obj.FLAG.HIDDEN)
+ wechat_press_label_countdown.set_text("{}S".format(str(self.countdown)))
+
+
+ self.updata_list_show(1)#不需要显示语音列表
+ #按下说话
+ if self.wechat_num >= self.MXA_MSG:
+ self.wechat_num = 0
+ self.wechat_num += 1
+ print("talking self.wechat_num ...:{}".format(self.wechat_num))
+ #EventMesh.publish("set_wechat_data",[self.MXA_MSG,self.wechat_num,self.wechat_recode_list])
+
+ self.record_test.start("E:/static/audio_amr/amr/{}.amr".format(self.wechat_num),16)
+ self.second_timer.start(1000, 1, self.reduce_second)
+
+
+ def sending(self,e):
+
+ wechat_label.clear_flag(lv.obj.FLAG.HIDDEN)
+ wechat_label.set_text("发送中")
+ wechat_press_label_countdown.add_flag(lv.obj.FLAG.HIDDEN)
+ wechat_press_label_countdown.set_text(" ")
+
+ if self.countdown > 15:
+ self.countdown = 15
+ #松开发送数据
+ #num.txt为记录的最后编号
+ #record.json文件里的json元素为记录编号,json键值:"S:"开头为发送的语音,"R:"为接收的语音,后面跟随语音长度;"T:"为接收的文字信息。
+
+ #写序号
+ print("self.countdown :{} self.wechat_num:{}".format(self.countdown,self.wechat_num))
+ self.wechat_recode_list["%02d"%(self.wechat_num)] = "S:{}".format(str(self.countdown))
+ self.record_test.stop() #停止錄音
+ self.second_timer.stop() #停止计时器
+
+
+ with open("ext/static/audio_amr/num.txt","w") as fd:
+ fd.write(str(self.wechat_num))
+ self.timer.start(2 * 1000, 0, self.hide_label)
+ #print("self.countdown :{}".format(self.countdown))
+ #修改或添加词典键值
+
+ with open("ext/static/audio_amr/record.json","w",encoding="utf-8") as fd:
+ ujson.dump(self.wechat_recode_list,fd)
+ # print("WechatScreen:record:{}".format(self.wechat_recode_list))
+
+
+ def play_label(self,e):
+ num = e.get_target().get_child(1).get_text()
+ num = int(num)
+ a = audio.Audio(0)
+ a.play(1, 0, 'E:/static/audio_amr/amr/{}.amr'.format(num)) #文件名前面要加上路径
+
+ def hide_label(self,*args):
+ #读音频amr二进制数据
+ path = "/ext/static/audio_amr/amr/{}.amr".format(self.wechat_num)
+
+ with open(path,"rb") as fd:
+ buf = bytearray(ql_fs.path_getsize(path))
+ fd.readinto(buf)
+ print("hide_label self.countdown ...:{}".format(self.countdown))
+ senddata = [self.countdown,buf]
+ EventMesh.publish(constants.PROTOCOL.TK_SEND,senddata)
+
+ #隐藏显示文本 显示列表显示框
+ wechat_label.add_flag(lv.obj.FLAG.HIDDEN)
+ wechat_label.set_text(" ")
+ self.wechat_list.clear_flag(lv.obj.FLAG.HIDDEN)#隐藏列表选项方框
+ self.updata_list_show(2)
+
+
+ def reduce_second(self,*args):
+ if self.countdown < 15:
+ self.countdown += 1
+ else:
+ self.countdown = 15
+ self.sending(0)
+
+ if self.countdown >= 15:
+ self.countdown = 15
+ wechat_press_label_countdown.set_text("{}S".format(str(self.countdown)))
+
+ def done_return(self):
+ EventMesh.publish("load_screen", {"screen": "main_menu"})
+
+ def btn1_release(self):
+ EventMesh.publish("load_screen", {"screen": "watchface"})
+
+ def btn8_press(self):
+ EventMesh.publish("load_screen", {"screen": "watchface"})
+
+
+class TK_ProtoCol(ProtoCol):
+ """微聊"""
+ TYPE = "TK"
+
+
+ def send(self, event, msg):
+ # [SZKW*YYYYYYYYYYYYYYY*LEN*TK,AMR 格式音频数据]
+ #[XT*YYYYYYYYYYYYYYY*LEN*TKS,秒数(十进制),AMR 格式音频数据]
+ arm_data = msg[1]
+ arm_sec = msg[0]
+ print("TK_ProtoCol:msgtype:{} arm_sec:{}".format(type(msg),arm_sec))
+
+ arm = bytearray()
+ for i in range(len(arm_data)):
+ if arm_data[i] == 0x7d:
+ arm.extend(b'\x7d\x01')
+ elif arm_data[i] == 0x5b :
+ arm.extend(b'\x7d\x02')
+ elif arm_data[i] == 0x5d :
+ arm.extend(b'\x7d\x03')
+ elif arm_data[i] == 0x2c :
+ arm.extend(b'\x7d\x04')
+ elif arm_data[i] == 0x2a :
+ arm.extend(b'\x7d\x05')
+ else :
+ arm.append(arm_data[i])
+
+ datalen = len(arm) + 4+len(str(arm_sec))+1
+ #print("len(str(arm_sec)):{}".format(len(str(arm_sec))+1))
+ send_data = bytearray("SZKW*%s*%04X*TKS,%d,"%(self.imei,datalen,arm_sec))
+ send_data.extend(arm)
+ MD5_SIGN = self.pack_MD5_head(send_data)
+ data = bytearray('[')
+ data.extend(MD5_SIGN)
+ data.extend(send_data)
+ data.extend(']')
+ EventMesh.publish(constants.EVENT.CHANNEL_SOCKET_SEND, data)
+
+ def recv(self, event, msg):
+ """
+
+
+ @param event: 微聊
+ @param msg: 接收到的下行数据
+ [SZKW*860132060004322*20BD*TK,#!AMR...]
+ """
+ #print("K_ProtoCol:recv:data:{}".format(msg))
+ msg_tmp = msg.decode('ascii')
+ str = msg_tmp.split('TK,')
+ print("TK_ProtoCol:recv:len:{} {} {}".format(len(msg),len(str),msg_tmp.find("#!AMR")))
+ if msg_tmp.find("#!AMR") != -1: #是否是服务器下发音频数据
+ # print("TK_ProtoCol:recv:datalen{}".format(len(msg)))
+ arm_data = bytearray(str[1])#获取amr输出
+ get_wechat_data = EventMesh.publish("get_wechat_data")
+ wechat_num = get_wechat_data[1]
+ MXA_MSG = get_wechat_data[0]
+ wechat_recode_list = get_wechat_data[2]
+ if wechat_num >= MXA_MSG:
+ wechat_num = 0
+ wechat_num += 1
+ #写记录列表
+ wechat_recode_list["%02d"%(wechat_num)] = "R:{}".format(3)
+ EventMesh.publish("set_wechat_data",[MXA_MSG,wechat_num,wechat_recode_list])
+ #写语音文件数据
+ path = "/ext/static/audio_amr/amr/{}.amr".format(wechat_num)
+ with open(path,"w") as fd:
+ arm = bytearray()
+ j = 0
+ for i in range(len(arm_data)):
+ if arm_data[j] == 0x7d and arm_data[j+1] == 0x01:
+ arm.extend(b'\x7d')
+ j+=1
+ elif arm_data[j] == 0x7d and arm_data[j+1] == 0x02:
+ arm.extend(b'\x5b')
+ j+=1
+ elif arm_data[j] == 0x7d and arm_data[j+1] == 0x03:
+ arm.extend(b'\x5d')
+ j+=1
+ elif arm_data[j] == 0x7d and arm_data[j+1] == 0x04:
+ arm.extend(b'\x2c')
+ j+=1
+ elif arm_data[j] == 0x7d and arm_data[j+1] == 0x05:
+ arm.extend(b'\x2a')
+ j+=1
+ else :
+ arm.append(arm_data[j])
+ j+=1
+ if j >= len(arm_data):
+ break
+ fd.write(arm)
+
+ #print("TK_ProtoCol end:wechat_num :{} wechat_recode_list:{} self.MXA_MSG:{}".format(wechat_num,wechat_recode_list,MXA_MSG))
+
+ #EventMesh.publish("set_wechat_data",[MXA_MSG,wechat_num,wechat_recode_list])
+ EventMesh.publish("wechat_updata_list_show")
+
+
+
+
+
+
PHL_SEND = "PHL_SEND"
PHL_RECV = "PHL_RECV"
+ TK_SEND = "TK_SEND"
+ TK_RECV = "TK_RECV"
class EVENT:
from ext.common import Abstract
from ext.lcd import gpio_backlight,tp_cst816
from ext.btn_device_ec800m import BtnDevice
- from usr.protocol import LK_ProtoCol,PING_ProtoCol, CR_ProtoCol,UD_ProtoCol,KA_ProtoCol,FIND_ProtoCol,POWEROFF_ProtoCol,ProtoColResolver,PHL_ProtoCol
+ from ext.protocol import LK_ProtoCol,PING_ProtoCol, CR_ProtoCol,UD_ProtoCol,KA_ProtoCol,FIND_ProtoCol,POWEROFF_ProtoCol,ProtoColResolver,PHL_ProtoCol
import ext.mgr as mgr
import ext.ui as _ui
from ext.mgr import ConfigStoreManager, DeviceInfoManager, LocationManager, SockManager, \
- NetManager, BatteryManager,AddrBookManager,MsgManager,MsgdetailManager,CallLogManager,PhoneCallingManager
+ NetManager, BatteryManager,AddrBookManager,MsgdetailManager,CallLogManager,PhoneCallingManager
from ext.appAlipay import Alipay ,AlipayOpenScreen,Alipay_1_1,Alipay_invite,Alipay_inviting,\
Alipay_success,Alipay_paycode,Alipay_pay_success,Alipay_collect,Alipay_parent
from ext.ui_WatchFaceScreen import WatchFaceScreen
from ext.ui_main_menu import MainMenuScreen
- # from usr.test import ContactsScreen
+ from usr.appWechat import WechatScreen,TK_ProtoCol
import ext.ui_setting as _ui_setting
+ from usr.test_sms import PopupScreen,MsgManager
+
+ #from usr.ui_wechat import WechatScreen,TK_ProtoCol
btn_device = BtnDevice(tp_cst816)
btn_device.start()
ui = _ui.UI(gpio_backlight)
ui.add_screen(WatchFaceScreen())
- ui.add_screen(_ui.PopupScreen())
+ ui.add_screen(PopupScreen())
ui.add_screen(_ui.PhoneScreen())
ui.add_screen(MainMenuScreen())
ui.add_screen(_ui.HeartrateScreen())
ui.add_screen(_ui.Spo2Screen())
ui.add_screen(_ui.TemperatureScreen())
ui.add_screen(_ui.ContactsScreen())
- ui.add_screen(_ui.WechatScreen())
+ ui.add_screen(WechatScreen())
# ui.add_screen(_ui_setting.LanguageScreen())
ui.add_screen(_ui_setting.DialswitchScreen())
pcr.add_support(FIND_ProtoCol())
pcr.add_support(POWEROFF_ProtoCol())
pcr.add_support(PHL_ProtoCol())
+ pcr.add_support(TK_ProtoCol())
sm = SockManager()
sm.add_support_resolver(pcr)
app.append_manager(sm)
.add_screen(_ui.Spo2Screen()) \
.add_screen(_ui.TemperatureScreen()) \
.add_screen(_ui.ContactsScreen()) \
- .add_screen(_ui.WechatScreen()) \
.add_screen(_ui.CountdownScreen()) \
.add_screen(_ui.LanguageScreen()) \
.add_screen(_ui.DialswitchScreen()) \
_thread.start_new_thread(self.reconnect, ())
break
data = data + r
- if len(data) < 3:
+ if data[-1] != 0x5d and len(data)<10*1024: #']':
continue
self.connect_tmp = 1 #有数据,就认为是连接状态
+ print("TCP:recv:len:{} type:{}".format(len(data),type(data)))
EventMesh.publish(constants.EVENT.SET_CONNECT, 1)
- self.resolver.handler(data.decode('ascii'))
+ self.resolver.handler(data)
data = b''
+
class NetManager(Abstract):
THRESHOLD = 10
}
def done_return(self):
EventMesh.publish("load_screen", {"screen": "main_menu"})
-
+import sms
class MsgManager(Abstract):
# 短信
def __init__(self):
EventMesh.subscribe("get_msg_detail", self.get_msg_detail)
def get_msg_nums(self, event, msg):
+
self.msg_nums = sms.getMsgNums()
+ print("self.msg_nums {}:".format(self.msg_nums))
return self.msg_nums
def get_msg_detail(self, event, msg):
- #self.msg_detail = sms.searchTextMsg(msg)
+
+ self.msg_detail = sms.searchTextMsg(self.msg_nums)
+ print("self.msg_detai {}:".format(self.msg_detai))
return{
"小明":"有内鬼,停止交易",
"小红":"今晚十点一起吃饭"
@param event: PING
@param msg: 接收到的下行数据
"""
- #print("PING_ProtoCol:recv:%s"%(msg))
- data_tmp = msg.split(']')[0] #去掉]
+ #print("PING_ProtoCol:recv:%s"%(msg))
+ data_tmp = msg.decode('ascii')
+ data_tmp = data_tmp.split(']')[0] #去掉]
EventMesh.publish(constants.EVENT.SET_PING, data_tmp.split(',')[1])
class KA_ProtoCol(ProtoCol):
"""
msg = msg[1:-1]
# print("phonebook:msg:%s\r\n"%msg)
- msg_tmp = msg.split(',')
+ msg_tmp = msg.decode('ascii')
+ msg_tmp = msg_tmp.split(',')
print("phonebook:len:{}\r\n data:{}".format(len(msg_tmp),msg_tmp))
#check_json = ql_fs.path_exists("/usr/phonebook.json")
EventMesh.publish(constants.PROTOCOL.PHL_SEND)
-
-class REMIND_ProtoCol(ProtoCol):
- """闹钟同步"""
- TYPE = "REMIND"
-
+#协议
+class TK_ProtoCol(ProtoCol):
+ """微聊"""
+ TYPE = "TK"
+ global wechat_num
def send(self, event, msg):
- # [SZKW*867387060319491*0008*PHL]
-
- send_data = "SZKW*%s*0003*REMIND"%(self.imei)
+ # [SZKW*YYYYYYYYYYYYYYY*LEN*TK,AMR 格式音频数据]
+ #[XT*YYYYYYYYYYYYYYY*LEN*TKS,秒数(十进制),AMR 格式音频数据]
+ arm_data = msg[1]
+ arm_sec = msg[0]
+ print("TK_ProtoCol:msgtype:",type(msg))
+
+ arm = bytearray()
+ for i in range(len(arm_data)):
+ if arm_data[i] == 0x7d:
+ arm.extend(b'\x7d\x01')
+ elif arm_data[i] == 0x5b :
+ arm.extend(b'\x7d\x02')
+ elif arm_data[i] == 0x5d :
+ arm.extend(b'\x7d\x03')
+ elif arm_data[i] == 0x2c :
+ arm.extend(b'\x7d\x04')
+ elif arm_data[i] == 0x2a :
+ arm.extend(b'\x7d\x05')
+ else :
+ arm.append(arm_data[i])
+
+ datalen = len(arm) + 4+len(str(arm_sec))+1
+ print("len(str(arm_sec)):{}".format(len(str(arm_sec))+1))
+ send_data = bytearray("SZKW*%s*%04X*TKS,%d,"%(self.imei,datalen,arm_sec))
+ send_data.extend(arm)
MD5_SIGN = self.pack_MD5_head(send_data)
- data = "[%s%s]"%(str(MD5_SIGN),send_data)
- #print("POWEROFF_ProtoCol:send:%s"%(data))
- # 通过socket发送到服务器端
+ data = bytearray('[')
+ data.extend(MD5_SIGN)
+ data.extend(send_data)
+ data.extend(']')
EventMesh.publish(constants.EVENT.CHANNEL_SOCKET_SEND, data)
def recv(self, event, msg):
"""
- @param event: 电话本同步
+
+ @param event: 微聊
@param msg: 接收到的下行数据
+ [SZKW*860132060004322*20BD*TK,#!AMR...]
"""
- msg = msg[1:-1]
- # print("phonebook:msg:%s\r\n"%msg)
- msg_tmp = msg.split(',')
- print("phonebook:len:{}\r\n data:{}".format(len(msg_tmp),msg_tmp))
-
- #check_json = ql_fs.path_exists("/usr/phonebook.json")
- #self.phonebook = EventMesh.publish("get_addr_book_list")
- #print("check_json %d"%check_json)
- phonebook = {}
- msg_tmp = msg_tmp[1:]
- # print("msg_tmp1:{}".format(msg_tmp))
- j = 0
- phonebook_oldtmp = {}
- # 0 1 2 3
- for phonebook_tmp in msg_tmp:
- j+=1
- # print("phonebook_tmp:{}".format(phonebook_tmp))
- if (j%2) == 0:
- phonebook[UnicodeHexStr_To_Utf8Str(phonebook_tmp)] = phonebook_oldtmp
- phonebook_oldtmp = phonebook_tmp
- print("phonebook!!!:{}".format(str(phonebook)))
- with open("usr/phonebook.json","w",encoding="utf-8") as fd:
- ujson.dump(phonebook,fd)
- print("创建电话簿")
+ #print("K_ProtoCol:recv:data:{}".format(msg))
- EventMesh.publish(constants.PROTOCOL.PHL_SEND)
-
-
-
+ print("TK_ProtoCol:wechat_num :{} wechat_recode_list:{} MXA_MSG:{}".format(wechat_num,wechat_recode_list,MXA_MSG))
+ msg_tmp = msg.decode('ascii')
+ str = msg_tmp.split('TK,')
+ print("TK_ProtoCol:recv:len:{} {} {}".format(len(msg),len(str),msg_tmp.find("#!AMR")))
+ if msg_tmp.find("#!AMR") != -1: #是否是服务器下发音频数据
+ # print("TK_ProtoCol:recv:datalen{}".format(len(msg)))
+ arm_data = bytearray(str[1])#获取amr输出
+
+ if wechat_num >= MXA_MSG:
+ wechat_num = 0
+ wechat_num += 1
+ #写语音文件数据
+ path = "/ext/static/audio_amr/amr/{}.amr".format(wechat_num)
+ with open(path,"w") as fd:
+ arm = bytearray()
+ j = 0
+ for i in range(len(arm_data)):
+ if arm_data[j] == 0x7d and arm_data[j+1] == 0x01:
+ arm.extend(b'\x7d')
+ j+=1
+ elif arm_data[j] == 0x7d and arm_data[j+1] == 0x02:
+ arm.extend(b'\x5b')
+ j+=1
+ elif arm_data[j] == 0x7d and arm_data[j+1] == 0x03:
+ arm.extend(b'\x5d')
+ j+=1
+ elif arm_data[j] == 0x7d and arm_data[j+1] == 0x04:
+ arm.extend(b'\x2c')
+ j+=1
+ elif arm_data[j] == 0x7d and arm_data[j+1] == 0x05:
+ arm.extend(b'\x2a')
+ j+=1
+ else :
+ arm.append(arm_data[j])
+ j+=1
+ if j >= len(arm_data):
+ break
+ fd.write(arm)
+ #写记录列表
+ wechat_recode_list["%02d"%(wechat_num)] = "R:{}".format(3)
+ print("TK_ProtoCol end:wechat_num :{} wechat_recode_list:{} MXA_MSG:{}".format(wechat_num,wechat_recode_list,MXA_MSG))
+ with open("ext/static/audio_amr/record.json","w",encoding="utf-8") as fd:
+ ujson.dump(wechat_recode_list,fd)
+ #写编号
+ with open("/ext/static/audio_amr/num.txt","w") as fd:
+ fd.write("{}".format(wechat_num))
+ EventMesh.publish("wechat_updata_list_show")
+
class ProtoColResolver(object):
def __init__(self):
# elif data.startswith("Update;"):
# data = data[7:]
# EventMesh.publish(constants.PROTOCOL.H04_RECV, data)
- data_tmp = data.split(']')[0] #去掉]
+ print("handler:{}".format(type(data)))
+ data_tmp = data.decode('ascii')
+ data_tmp = data_tmp.split(']')[0] #去掉]
ProtoCol_type = data_tmp.split('*')[3] #拿到协议标识
ProtoCol_type = ProtoCol_type.split(',')[0]
ProtoCol_type = "%s_RECV"%(ProtoCol_type)
- print("ProtoColResolver:ProtoCol_type:%s\r\ndata:%s"%(ProtoCol_type,data))
+ #print("ProtoColResolver:ProtoCol_type:%s\r\ndata:%s"%(ProtoCol_type,data))
EventMesh.publish(ProtoCol_type, data) #返回协议read
+++ /dev/null
-import utime
-import osTimer
-import lvgl as lv
-from ext import EventMesh
-from machine import Timer
-import voiceCall
-import osTimer
-from ext import constants
-from misc import Power
-import pm
-import ujson
-import ql_fs
-import audio
-from machine import Pin
-from ext.lcd import gpio_backlight,lcd,lcd_ctrl,tp_cst816
-from ext.ui import style_btn,ContStyle ,style_font_youyuan_20,style_screen,Screen,style_font_youyuan_20_black
-# -------------------------------------------contacts screen----------------------------------------------------------
-style_bar = lv.style_t()
-style_bar.init()
-style_bar.set_radius(10)
-style_bar.set_bg_color(lv.color_make(0xA0, 0xA0, 0xA0))
-style_bar.set_bg_grad_color(lv.color_make(0xA0, 0xA0, 0xA0))
-style_bar.set_bg_grad_dir(lv.GRAD_DIR.VER)
-style_bar.set_bg_opa(60)
-style_bar.set_pad_left(0)
-style_bar.set_pad_right(0)
-style_bar.set_pad_top(0)
-style_bar.set_pad_bottom(0)
-
-style_volume_btn = lv.style_t()
-style_volume_btn.init()
-style_volume_btn.set_shadow_opa(0)
-style_volume_btn.set_border_width(0)
-style_volume_btn.set_bg_color(lv.color_make(0x80, 0x80, 0x80))
-
-style_bar_indic = lv.style_t()
-style_bar_indic.init()
-style_bar_indic.set_radius(10)
-style_bar_indic.set_bg_color(lv.color_make(0xff, 0x61, 0x3a))
-style_bar_indic.set_bg_grad_color(lv.color_make(0xff, 0x61, 0x3a))
-style_bar_indic.set_bg_grad_dir(lv.GRAD_DIR.VER)
-style_bar_indic.set_bg_opa(255)
-
-
-
-
-
-
-
-
-
-contacts_screen = lv.obj()
-contacts = lv.obj(contacts_screen)
-contacts.center()
-contacts.set_size(240, 320)
-contacts.add_style(style_screen, lv.PART.MAIN | lv.STATE.DEFAULT)
-
-
-contact_none_label = lv.label(contacts)
-contact_none_label.set_pos(0, 120)
-contact_none_label.set_size(240, 60)
-contact_none_label.set_text(" ")
-contact_none_label.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0)
-contact_none_label.add_style(style_font_youyuan_20, lv.PART.MAIN | lv.STATE.DEFAULT)
-
-
-
-
-
-contacts_cont = lv.obj(contacts)
-contacts_cont.set_pos(0, 0)
-contacts_cont.set_size(240, 320)
-contacts_cont_style = ContStyle()
-contacts_cont.add_style(
- contacts_cont_style.style_cont(0, lv.color_make(0x00, 0x00, 0x00), lv.color_make(0x00, 0x00, 0x00), 255),
- lv.PART.MAIN | lv.STATE.DEFAULT)
-# # create style style_btn
-# style_btn = lv.style_t()
-# style_btn.init()
-# style_btn.set_bg_opa(0)
-# style_btn.set_shadow_opa(0)
-# style_btn.set_border_width(0)
-
-# style_contact_btn = lv.style_t()
-# style_contact_btn.init()
-# style_contact_btn.set_bg_color(lv.color_make(0x1E, 0x26, 0xff))
-# style_contact_btn.set_border_width(0)
-# style_contact_btn.set_shadow_opa(0)
-
-# style_contact_btn_pressed = lv.style_t()
-# style_contact_btn_pressed.init()
-# style_contact_btn_pressed.set_bg_opa(lv.OPA.TRANSP)
-# style_contact_btn_pressed.set_shadow_opa(0)
-# style_contact_btn_pressed.set_border_width(0)
-
-CONTACT_FLAG = 0
-
-class ContactsScreen(Screen):
- NAME = "contacts"
-
- def __init__(self):
- super().__init__()
- self.meta = contacts_screen
- self.phonebook = {}
- self.count = 0
- self.phone_num_count = 0
- self.phone_num = {}
- self.name = []
- self.check_json = 0
-
- def post_processor_before_initialization(self):
- self.check_json = ql_fs.path_exists("/usr/phonebook.json")
- self.phonebook = EventMesh.publish("get_addr_book_list")
- print("check_json %d"%(self.check_json))
- self.count = 0
- if self.check_json == True:
- with open("usr/phonebook.json","r",encoding="utf-8") as fd:
- self.phonebook = ujson.load(fd)
- print("读取电话簿")
-
-
- # if check_json == False:
- # # with open("usr/phonebook.json","w",encoding="utf-8") as fd:
- # # ujson.dump(self.phonebook,fd)
- # # print("创建电话簿")
- # else:
- # with open("usr/phonebook.json","r",encoding="utf-8") as fd:
- # self.phonebook = ujson.load(fd)
- # print("读取电话簿")
-
- def initialization(self):
- #读取json文件中的字典放到self.phonebook中
- #创建btn
- self.btn_create()
-
- def btn_create(self):
- #读取json文件中的键作为label文本;
- if self.check_json == 1:
- contact_none_label.set_text(" ")
- for key,value in dict.items(self.phonebook): #字典 key value
-
- contact_btn = lv.btn(contacts_cont)
- contact_btn.set_pos(0, 82*self.count)
- contact_btn.set_size(230,80)
- contact_btn_label = lv.label(contact_btn)
- contact_btn_label.set_text(key+'\r\n'+ value)
- contact_btn.set_style_pad_all(0, lv.STATE.DEFAULT)
- contact_btn.set_style_text_align(lv.TEXT_ALIGN.LEFT ,0)
- # contact_btn_label.align(lv.ALIGN.LEFT_MID, 10, 0)
- contact_btn_label.set_style_text_color(lv.color_make(0x00, 0x00, 0x00), lv.STATE.DEFAULT)
- contact_btn_label.add_style(style_font_youyuan_20, lv.PART.MAIN | lv.STATE.DEFAULT)
- contact_btn.add_style(style_btn, lv.PART.MAIN | lv.STATE.DEFAULT)
- contact_btn.add_event_cb(lambda e: self.calling(e),
- lv.EVENT.CLICKED, None)
-
- # contact_btn = lv.btn(contacts_cont)
- # contact_btn.set_size(230,80)
- # contact_btn.set_pos(0,82*self.count )
- # contact_btn_label = lv.label(contact_btn)
- # contact_btn_label.set_text(key+'\r\n'+ value)
- # contact_btn.set_style_pad_all(0, lv.STATE.DEFAULT)
-
- # contact_btn.add_style(style_contact_btn, lv.PART.MAIN | lv.STATE.DEFAULT)
- # contact_btn.add_style(style_contact_btn_pressed, lv.PART.MAIN | lv.STATE.PRESSED)
- # contact_btn.add_event_cb(lambda e: self.calling(e),
- # lv.EVENT.PRESSED, None)
-
-
- # contact_btn_label.set_text(key+'\r\n'+ value)
- # contact_btn_label.align(lv.ALIGN.LEFT_MID, 10, 0)
- # contact_btn_label.add_style(style_font_youyuan_20_black, lv.PART.MAIN | lv.STATE.DEFAULT)
-
- # contact_btn_labe2 = lv.label(contacts)
- # contact_btn_labe2.set_text(value)
- # contact_btn_labe2.set_pos(10,(82*self.count) + 45)
- # contact_btn_labe2.set_style_text_align(lv.TEXT_ALIGN.LEFT, 30)
- # # contact_btn_labe2.align(lv.ALIGN.LEFT_MID, 10, 20)
- # contact_btn_labe2.add_style(style_font_youyuan_20_black, lv.PART.MAIN | lv.STATE.DEFAULT)
- self.count += 1
- else:
- contact_none_label.set_text("空")
- def calling(self,e):
- _msg = e.get_target().get_child(0).get_text()
- _msg = _msg.split('\r\n')
- EventMesh.publish("save_phonenum", _msg[0])
- self.phone_num = self.phonebook[_msg[0]]
- # print(_msg,self.phone_num,_msg)
- voiceCall.callStart(self.phone_num)
- EventMesh.publish("load_screen", {"screen": "dialing"})
-
- def done_return(self):
- EventMesh.publish("load_screen", {"screen": "main_menu"})
-
- def btn1_release(self):
- EventMesh.publish("load_screen", {"screen": "watchface"})
-
- def btn8_press(self):
- EventMesh.publish("load_screen", {"screen": "watchface"})
\ No newline at end of file
--- /dev/null
+
+
+import utime
+import osTimer
+import lvgl as lv
+from ext import EventMesh
+from machine import Timer
+import voiceCall
+import osTimer
+from ext import constants
+from misc import Power
+import pm
+import ujson
+import audio
+import ql_fs
+import sms
+import audio
+from machine import Pin
+from ext.lcd import gpio_backlight,lcd,lcd_ctrl,tp_cst816
+from ext.ui import style_screen,style_font_youyuan_20,style_contact_btn,style_common_bg_rect_btn_pressed,Screen,style_wechat_btn
+from ext.common import Abstract
+MSG_FLAG = 0
+MSG_MAX = 10 #最大显示短信内容条数
+
+msg_list_screen = lv.obj()
+msg_screen = lv.obj(msg_list_screen)
+msg_screen.center()
+msg_screen.set_size(240, 320)
+msg_screen.add_style(style_screen, lv.PART.MAIN | lv.STATE.DEFAULT)
+
+msg_top_title = lv.label(msg_screen)
+msg_top_title.set_pos(0, 10)
+msg_top_title.set_size(240, 40)
+msg_top_title.set_text("信息")
+msg_top_title.set_long_mode(lv.label.LONG.WRAP)
+msg_top_title.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0)
+msg_top_title.add_style(style_font_youyuan_20, lv.PART.MAIN | lv.STATE.DEFAULT)
+
+msg_cont_detail = lv.obj(msg_screen)
+msg_cont_detail.set_pos(0, 50)
+msg_cont_detail.set_size(240, 270)
+msg_cont_detail.add_style(style_font_youyuan_20, lv.PART.MAIN | lv.STATE.DEFAULT)
+
+
+msg_list_t= lv.obj(msg_list_screen)
+msg_list_t.set_pos(0, 50)
+msg_list_t.set_size(240, 270)
+msg_list_t.set_scrollbar_mode(lv.SCROLLBAR_MODE.OFF)
+msg_list_t.add_style(style_screen, lv.PART.MAIN | lv.STATE.DEFAULT)
+
+
+no_msg_text = lv.label(msg_list_t)
+no_msg_text.set_pos(0, 120)
+no_msg_text.set_size(240, 40)
+no_msg_text.set_text("暂无信息")
+no_msg_text.set_long_mode(lv.label.LONG.WRAP)
+no_msg_text.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0)
+no_msg_text.add_style(style_font_youyuan_20, lv.PART.MAIN | lv.STATE.DEFAULT)
+
+
+
+
+
+
+
+
+
+def msg_cb(args):
+ index = args[1]
+ storage = args[2]
+ print('New message! storage:{},index:{}'.format(storage, index))
+
+sms.setCallback(msg_cb)
+
+
+
+class PopupScreen(Screen):
+ NAME = "popup"
+
+ def __init__(self):
+ super().__init__()
+ # -------------------------------------------popup_menu screen----------------------------------------------------------
+ self.meta = msg_list_screen
+ self.msg_detail = {}
+ self.msg_nums = 0
+
+ def post_processor_before_initialization(self):
+ # self.msg_nums = EventMesh.publish("get_msg_nums")
+ self.msg_nums = sms.getMsgNums()
+ print("self.msg_nums:{} type:{}".format(self.msg_nums,type(sms.getMsgNums())))
+
+
+ def initialization(self):
+ global MSG_FLAG
+ if MSG_FLAG == 0 :
+ self.btn_create()
+
+ def btn_create(self):
+ global MSG_FLAG
+ MSG_FLAG = 1
+ i = 0
+ j = 0
+ if self.msg_nums > 0:
+ no_msg_text.add_flag(lv.obj.FLAG.HIDDEN)
+ if self.msg_nums > 10:
+ j = self.msg_nums-10
+ for i in range(self.msg_nums):
+ if i > MSG_MAX:
+ break
+ #print("sms.searchTextMsg(i):{} type:{}".format(sms.searchTextMsg(i),type(sms.searchTextMsg(i))))
+ tmp = sms.searchTextMsg(j)
+ self.msg_detail[0] = tmp[0]
+ self.msg_detail[1] = tmp[1]
+ msg_btn = lv.btn(msg_list_t)
+ msg_btn.set_size(240,80)
+ msg_btn.set_pos(0,82*i)
+ msg_btn.add_style(style_contact_btn, lv.PART.MAIN | lv.STATE.DEFAULT)
+ msg_btn.add_style(style_common_bg_rect_btn_pressed, lv.PART.MAIN | lv.STATE.PRESSED)
+ msg_btn.add_event_cb(lambda e: self.calling(e),
+ lv.EVENT.CLICKED, None)
+
+
+
+
+
+ _btn_label2 = lv.label(msg_btn)
+ _btn_label2.set_pos(0, 5)
+ _btn_label2.set_size(180, 25)
+ _btn_label2.set_text(str(self.msg_detail[0]))
+ _btn_label2.set_long_mode(lv.label.LONG.DOT)
+ _btn_label2.add_style(style_font_youyuan_20, lv.PART.MAIN | lv.STATE.DEFAULT)
+ #
+
+ _btn_label1 = lv.label(msg_btn)
+ _btn_label1.set_pos(0, 0)
+ _btn_label1.set_long_mode(lv.label.LONG.DOT)
+ _btn_label1.set_size(0, 0)
+ _btn_label1.set_text(str(i))
+
+ detail = self.msg_detail[1]
+ _btn_label3 = lv.label(msg_btn)
+ _btn_label3.set_pos(0, 25)
+ _btn_label3.set_size(220, 30)
+ _btn_label3.set_text(str(detail))
+ _btn_label3.set_long_mode(lv.label.LONG.DOT)
+ _btn_label3.add_style(style_font_youyuan_20, lv.PART.MAIN | lv.STATE.DEFAULT)
+
+
+ i = i + 1
+ j += 1
+ else:
+ no_msg_text.clear_flag(lv.obj.FLAG.HIDDEN)
+
+ def calling(self,e):
+ #上传标题和内容
+ _name = e.get_target().get_child(0).get_text()
+ EventMesh.publish("save_msg_name", _name)
+ #_content = e.get_target().get_child(1).get_text()
+ conten = e.get_target().get_child(2).get_text()
+ EventMesh.publish("save_msg_content", conten)
+
+ #显示详细页面
+ EventMesh.publish("load_screen", {"screen": "msg_detail"})
+
+ def done_return(self):
+ EventMesh.publish("load_screen", {"screen": "watchface"})
+ def btn1_release(self):
+ EventMesh.publish("load_screen", {"screen": "watchface"})
+ def btn8_press(self):
+ EventMesh.publish("load_screen", {"screen": "watchface"})
+
+
+
+
+
+
+
+class MsgManager(Abstract):
+ # 短信
+ def __init__(self):
+ self.msg_nums = 0
+ self.msg_detail = ""
+
+ def post_processor_after_instantiation(self):
+ EventMesh.subscribe("get_msg_nums", self.get_msg_nums)
+ # 可通过此push_addr_book_list主动推送
+ EventMesh.subscribe("get_msg_detail", self.get_msg_detail)
+
+ def get_msg_nums(self, event, msg):
+
+ self.msg_nums = sms.getMsgNums()
+ print("self.msg_nums {}:".format(self.msg_nums))
+ return self.msg_nums
+
+ def get_msg_detail(self, event, msg):
+
+ # self.msg_detail = sms.searchTextMsg(self.msg_nums)
+ # print("self.msg_detai {}:".format(self.msg_detai))
+ return{
+ "小明":"有内鬼,停止交易",
+ "小红":"今晚十点一起吃饭"
+ }
+
+
+
+
+
msg_detail_cont.set_pos(0, 50)
msg_detail_cont.set_size(240, 200)
msg_detail_cont.set_long_mode(lv.label.LONG.WRAP)
-msg_detail_cont.set_style_text_align(lv.TEXT_ALIGN.LEFT, 20)
+msg_detail_cont.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0)
msg_detail_cont.add_style(style_font_youyuan_20, lv.PART.MAIN | lv.STATE.DEFAULT)
# -------------------------------------------call_log screen----------------------------------------------------------
call_log.set_size(240, 320)
call_log.add_style(style_screen, lv.PART.MAIN | lv.STATE.DEFAULT)
+call_log_screen = lv.obj()
+call_log = lv.obj(call_log_screen)
+call_log.center()
+call_log.set_size(240, 320)
+call_log.add_style(style_screen, lv.PART.MAIN | lv.STATE.DEFAULT)
+
call_log_title = lv.label(call_log)
call_log_title.set_pos(0, 10)
call_log_title.set_size(240, 40)
self.msg_title.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0)
self.msg_title.add_style(style_font_youyuan_20, lv.PART.MAIN | lv.STATE.DEFAULT)
- # def post_processor_before_initialization(self):
- # EventMesh.publish("get_msg_count")
- # self.msg_detail = EventMesh.publish("get_msg_detail")
def post_processor_before_initialization(self):
check_json = ql_fs.path_exists("/usr/msg.json")
contact_content_label.set_text(detail[:15])
contact_content_label.align(lv.ALIGN.LEFT_MID, 80, 0)
contact_content_label.add_style(style_font_youyuan_20, lv.PART.MAIN | lv.STATE.DEFAULT)
-
i = i + 1
- # self.name.append(str(key))
-
- # print(self.name)
+
def calling(self,e):
#上传标题和内容
_name = e.get_target().get_child(0).get_text()
msg_detail_cont.set_text(self.content)
def done_return(self):
- EventMesh.publish("load_screen", {"screen": "watchface"})
+ EventMesh.publish("load_screen", {"screen": "popup"})
def hangup(self,e):
voiceCall.callEnd()
def btn1_release(self):
EventMesh.publish("load_screen", {"screen": "watchface"})
def btn8_press(self):
- EventMesh.publish("load_screen", {"screen": "watchface"})
+ EventMesh.publish("load_screen", {"screen": "popup"})
class HeartrateScreen(Screen):
import audio
from machine import Pin
-# from functools import reduce
-# DIGITS = {'0':0,'1':1,'2':2,'3':3,'4':4,'5':5,'6':6,'7':7,'8':8,'9':9}
-# def str2int(str):
-# def char2num(s):
-# return DIGITS[s]
-# return reduce(lambda x,y:x*10+y,map(char2num,str))
-
-class WechatScreen(Screen):
- NAME = "wechat"
-
- def __init__(self):
- super().__init__()
-
- self.record_test = audio.Record()
-
- self.aud = audio.Audio(0)
- self.aud.set_pa(Pin.GPIO29)
- self.aud.setVolume(10)
- self.meta = wechat_screen
- self.count = 0
- wechat_press_btn.add_event_cb(lambda e: self.talking(e),
- lv.EVENT.PRESSING, None)
- wechat_press_btn.add_event_cb(lambda e: self.sending(e),
- lv.EVENT.RELEASED, None)
- wechat_press_play_btn.add_event_cb(lambda e: self.play_label(e),
- lv.EVENT.CLICKED, None)
- self.timer = osTimer()
- wechat_label.set_text(" ")
- self.num = 0
- def initialization(self):
- wechat_label.add_flag(lv.obj.FLAG.HIDDEN)
- # self.check_json = ql_fs.path_exists("/ext/static/audio_amr/num.txt")
- # print("self.check_json %d"%self.check_json)
- # if self.check_json == True:
- # with open("/ext/static/audio_amr/num.txt","r") as fd:
- # num_str = fd.read()
- # print("fd.read %s"%(num_str))
- # self.num = len(num_str)
- # if self.num >= 10:
- # self.num = 0
- # self.num+=1
- # else:
- # self.num = 0
- # self.record_test.start("E:/static/audio_amr/{}.amr".format(self.num),15)
-
- def talking(self,e):
- self.check_json = ql_fs.path_exists("/ext/static/audio_amr/num.txt")
- print("self.check_json %d"%self.check_json)
- if self.check_json == True:
- with open("/ext/static/audio_amr/num.txt","r") as fd:
- num_str = fd.read()
- print("num_str %s \r\n"%(num_str))
- self.num = int(str(num_str))
- print("self.num %d .......\r\n"%self.num)
- if self.num >= 10:
- self.num = 0
- self.num += 1
- print("fd.read %s \r\n"%(fd.read()))
- print("self.num %d \r\n"%self.num)
- # else:
- # self.num = 0
- self.record_test.start("E:/static/audio_amr/{}.amr".format(self.num),15)
- wechat_label.clear_flag(lv.obj.FLAG.HIDDEN)
- wechat_label.set_text("松开发送")
-
- def sending(self,e):
- self.record_test.stop()
- with open("/ext/static/audio_amr/num.txt","w") as fd:
- print("write data txt.........%s.....\r\n"%(str(self.num)))
- fd.write(str(self.num))
- self.timer.start(2 * 1000, 0, self.hide_label)
- def play_label(self,e):
- a = audio.Audio(0)
- a.play(1, 0, 'E:/static/audio_amr/{}.amr'.format(self.num)) #文件名前面要加上路径
-
- def hide_label(self,*args):
- wechat_label.clear_flag(lv.obj.FLAG.HIDDEN)
- wechat_label.set_text("发送中")
- # self.make_btn()
- def done_return(self):
- EventMesh.publish("load_screen", {"screen": "main_menu"})
-
- def btn1_release(self):
- EventMesh.publish("load_screen", {"screen": "watchface"})
-
- def btn8_press(self):
- EventMesh.publish("load_screen", {"screen": "watchface"})
class StepScreen(Screen):