#dev_type = "7PIN_BK_coze"#k扣子小瑞
#dev_type = "7PIN_BK_EU"#英文小瑞
#dev_type = "7PIN_coze"#柒牌扣子
-dev_type = "7PIN"#柒牌
+# dev_type = "7PIN"#柒牌
+dev_type = "7PIN_1_5"#柒牌1.5
#dev_type = 'momo'#食梦貘
#dev_type = 'sjgq'#四季甘泉
#dev_type = 'szbst'#深圳百事通
#self.led_green = Pin(Pin.GPIO21, Pin.OUT, Pin.PULL_PD, 1)
self.led_green = Pin(Pin.GPIO8, Pin.OUT, Pin.PULL_PD, 1)
self.led_blue = Pin(Pin.GPIO19, Pin.OUT, Pin.PULL_PD, 1)
- else:
+ elif dev_type == "7PIN_1_5":
self.led_red = Pin(Pin.GPIO28, Pin.OUT, Pin.PULL_PD, 0)
#self.led_green = Pin(Pin.GPIO21, Pin.OUT, Pin.PULL_PD, 1)
self.led_green = Pin(Pin.GPIO44, Pin.OUT, Pin.PULL_PD, 1)
self.led_blue = Pin(Pin.GPIO30, Pin.OUT, Pin.PULL_PD, 1)
+ else:
+ self.led_red = Pin(Pin.GPIO36, Pin.OUT, Pin.PULL_PD, 0)
+ self.led_green = Pin(Pin.GPIO21, Pin.OUT, Pin.PULL_PD, 1)
+ self.led_blue = Pin(Pin.GPIO19, Pin.OUT, Pin.PULL_PD, 1)
#=1 红灯闪,=2白灯闪,=3绿灯闪,=4全部灯闪
self.led_flicker_flag = 0
self.ping_json_str_tmp =""
self.read_uart_data = ""
self.bt_versions=""
-
- self.uart_send_queue = Queue(100)
- self.uart_send_queue_thread_id = _thread.start_new_thread(self.uart_send_queue_thread, ())
+ if dev_type == "7PIN_1_5":
+ self.uart_send_queue = Queue(100)
+ self.uart_send_queue_thread_id = _thread.start_new_thread(self.uart_send_queue_thread, ())
- self.uart_recv_queue = Queue(100)
- self.uart_recv_queue_thread_id = _thread.start_new_thread(self.uart_recv_queue_thread, ())
- self.send_get_versions()#获取蓝牙版本
+ self.uart_recv_queue = Queue(100)
+ self.uart_recv_queue_thread_id = _thread.start_new_thread(self.uart_recv_queue_thread, ())
+ self.send_get_versions()#获取蓝牙版本
def uart_send_queue_thread(self):
while True:
print("bt_send_end")
def send_data(self,str_data,need_resend = None,ACK_time =None):
+ if dev_type != "7PIN_1_5": #不是1.5代不能发串口数据
+ return
if self.bt_ota_flag == 1:
print("ota 中不需要上传")
return
# set_ipv4_datacall()
self.is_wdt = 0 #是否开启看门狗
#AT+QDAI=1,0,0,1,0,0,1,1PCM音频输出设置为主模式、短同步、16 kHz采样率和256 kHz时钟频率,采样位深为16bit,使用的时间间隙数量为1,并且使用第一个时间间隙。
- audio.set_qdai_cfg(1,0,0,2,0,1,1,1)
+ if dev_type == "7PIN_1_5" :
+ audio.set_qdai_cfg(1,0,0,2,0,1,1,1)
self.VBATT_tab = {"charge_full":4300,"100" :4250 , "90":4179 , "80":4070, "60": 3883, "40":3770, "20":3699, "10":3652,"5":3600,}
self.KeyAI_status = 0
self.KeyAI_timer_count = 0
self.wdt = WDT(30) #开启看门狗
# self.wdt_timer = osTimer()
# self.wdt_timer.start(5000, 1, self.wdt_timer_cb)
- #马达
- self.PIN_MOT=Pin(Pin.GPIO36, Pin.OUT, Pin.PULL_DISABLE, 0)
- #蓝牙电源
- self.PIN_BT_ON =Pin(Pin.GPIO31, Pin.OUT, Pin.PULL_DISABLE, 0)
+
count = 0
while True:
count += 1
elif dev_type == "7PIN_BK_EU":
self.pwk_key = ExtInt(ExtInt.GPIO41, ExtInt.IRQ_RISING_FALLING, ExtInt.PULL_PU, self.pwk_extint_cb)
self.extint_AI = ExtInt(ExtInt.GPIO5,ExtInt.IRQ_RISING_FALLING, ExtInt.PULL_PU, self.keyAI_extint_cb)
- else:
+ #蓝牙唤醒4G中断
+ elif dev_type == "7PIN_1_5":
self.pwk_key = ExtInt(ExtInt.GPIO41, ExtInt.IRQ_RISING_FALLING, ExtInt.PULL_PU, self.pwk_extint_cb)
self.extint_AI = ExtInt(ExtInt.GPIO43,ExtInt.IRQ_RISING_FALLING, ExtInt.PULL_PU, self.keyAI_extint_cb)
- #self.extint_AI = ExtInt(ExtInt.GPIO22,ExtInt.IRQ_RISING_FALLING, ExtInt.PULL_PU, self.keyAI_extint_cb)
- #蓝牙唤醒4G中断
- self.extint_wakeup_cta1 = ExtInt(ExtInt.GPIO22,ExtInt.IRQ_RISING, ExtInt.PULL_DISABLE, self.wakeup_extint_cb)
- #4G唤醒蓝牙中断
- self.PIN_wakeup_bt =Pin(Pin.GPIO21, Pin.OUT, Pin.PULL_DISABLE, 0)
-
- #马达
- self.PIN_MOT.write(1)
- utime.sleep_ms(200)
- self.PIN_MOT.write(0)
-
- self.PIN_BT_ON.write(1)
- self.extint_wakeup_cta1_timer = osTimer()
- self.extint_wakeup_cta1.enable()
+
+ self.extint_wakeup_cta1 = ExtInt(ExtInt.GPIO22,ExtInt.IRQ_RISING, ExtInt.PULL_DISABLE, self.wakeup_extint_cb)
+ #4G唤醒蓝牙中断
+ self.PIN_wakeup_bt =Pin(Pin.GPIO21, Pin.OUT, Pin.PULL_DISABLE, 0)
+ #马达
+ self.PIN_MOT=Pin(Pin.GPIO36, Pin.OUT, Pin.PULL_DISABLE, 0)
+ #蓝牙电源
+ self.PIN_BT_ON =Pin(Pin.GPIO31, Pin.OUT, Pin.PULL_DISABLE, 0)
+ #马达
+ self.PIN_MOT.write(1)
+ utime.sleep_ms(200)
+ self.PIN_MOT.write(0)
+
+ self.PIN_BT_ON.write(1)
+ self.extint_wakeup_cta1_timer = osTimer()
+ self.extint_wakeup_cta1.enable()
+ else:
+ self.pwk_key = ExtInt(ExtInt.GPIO41, ExtInt.IRQ_RISING_FALLING, ExtInt.PULL_PU, self.pwk_extint_cb)
+ #self.extint_AI = ExtInt(ExtInt.GPIO19,ExtInt.IRQ_RISING_FALLING, ExtInt.PULL_PU, self.keyAI_extint_cb)
+ self.extint_AI = ExtInt(ExtInt.GPIO22,ExtInt.IRQ_RISING_FALLING, ExtInt.PULL_PU, self.keyAI_extint_cb)
+
self.extint_AI.enable()
self.pwk_key_status = 0
self.pwk_key_timer_count = 0
#EventMesh.publish("audio_montage_play",["xianyikaiji.mp3"])
#EventMesh.publish("publish_AI_btnInfo",{"func":self.ntptime_cb})
self.check_rest_timer_count = 0
- self.ai_uart = AI_UART()
+ if dev_type == "7PIN_1_5": #不是1.5代不能发串口数据
+ self.ai_uart = AI_UART()
+
self.Keycall1_press_count = 0
self.ble_switch_flag_time = osTimer()
self.ble_switch_flag_time.start(10000, 0, self.ble_switch_flag_time_init)
#print("publish_AI_btnInfo 2")
def sys_sleep_cb(self,event=None,msg=None):#休眠前回调
+ if dev_type != "7PIN_1_5": #不是1.5代不能发串口数据
+ return
print("sys_sleep_cb!!!!!!!!!!!!!!!")
print("sys_sleep_cb!!!!!!!!!!!!!!!")
print("sys_sleep_cb!!!!!!!!!!!!!!!")
EventMesh.publish("sleep_BT")#休眠蓝牙
self.PIN_wakeup_bt.write(0)
def sys_up_cb(self,event=None,msg=None):#唤醒前回调
+ if dev_type != "7PIN_1_5": #不是1.5代不能发串口数据
+ return
print("sys_up_cb!!!!!!!!!!!!!!!")
print("sys_up_cb!!!!!!!!!!!!!!!")
print("sys_up_cb!!!!!!!!!!!!!!!")
utime.sleep_ms(100)
self.PIN_BT_ON.write(1)
def wakeup_BT(self,event=None,msg=None):#4G唤醒蓝牙
+ if dev_type != "7PIN_1_5": #不是1.5代不能发串口数据
+ return
print("wakeup_BT!!!!!!!!!!!!!!!")
print("wakeup_BT!!!!!!!!!!!!!!!")
wakeup_cta1_io = self.extint_wakeup_cta1.read_level()
def sleep_BT(self,event=None,msg=None):#使蓝牙休眠
+ if dev_type != "7PIN_1_5": #不是1.5代不能发串口数据
+ return
print("sleep_BT!!!!!")
print("sleep_BT!!!!!")
print("sleep_BT!!!!!")
def wakeup_extint_cb(self,args):#蓝牙唤醒4g
+ if dev_type != "7PIN_1_5": #不是1.5代不能发串口数据
+ return
print("wakeup_extint_cb:!!!!!!!!!")
EventMesh.publish(constants.EVENT.SYSTEM_UP)#唤醒休眠
self.PIN_wakeup_bt.write(1)
url =None
if dev_type == "7PIN_BK_EU":#英文小瑞
url = "http://dmp-global.raisound.com/bz-api/ota/result?deviceId={}¤tVersion={}".format(modem.getDevImei(),currentVersion)
- if dev_type == "7PIN" or dev_type == "7PIN_coze":#柒牌
+ if dev_type == "7PIN" or dev_type == "7PIN_1_5" or dev_type == "7PIN_coze":#柒牌
url = "http://ota.qipai.com/bz-cmp-api/api/result?deviceId={}¤tVersion={}".format(modem.getDevImei(),currentVersion)
else:
url = "http://dmp.raisound.com/bz-api/ota/result?deviceId={}¤tVersion={}".format(modem.getDevImei(),currentVersion)
if dev_type == 'jswm' or dev_type == 'jswm_BOX':#
#self.server_ip="115.190.94.208:22080"
self.server_ip="118.145.158.207:22086"
- elif dev_type == "7PIN" :
+ elif dev_type == "7PIN" or dev_type == "7PIN_1_5":
#self.server_ip="sevenpin.qipai.com.cn"
# self.server_ip="220.160.104.34"
# self.server_ip="118.145.158.207:22082"
#开机提示音
self.power_on_tone = EventMesh.publish("get_storage_config","power_on_tone")#
- if dev_type != "7PIN" and dev_type != "7PIN_coze"and dev_type != "jswm" and dev_type != 'jswm_BOX' and dev_type != "7PIN_BK":
+ if dev_type != "7PIN" and dev_type != "7PIN_1_5" and dev_type != "7PIN_coze"and dev_type != "jswm" and dev_type != 'jswm_BOX' and dev_type != "7PIN_BK":
self.power_on_tone = None
if self.power_on_tone == None:
if dev_type == "G10":
self.vad_silence = EventMesh.publish("get_storage_config","vad_silence")#语速配置
if self.vad_silence == None:
- if dev_type == "7PIN" or dev_type == "7PIN_coze":
+ if dev_type == "7PIN" or dev_type == "7PIN_1_5" or dev_type == "7PIN_coze":
self.vad_silence = 200
else:
self.vad_silence = 300
self.VC_stop_play_audio_flag = 0
self.VC_satrt_kws_flag = 0
self.session_id = ""
+ self.stop_voice_timer=osTimer()
EventMesh.subscribe("AI_key_press", self.AI_key_press)
EventMesh.subscribe("BT_AI_key_press", self.BT_AI_key_press)
EventMesh.subscribe("stop_AI_record", self.stop_AI_record)
EventMesh.subscribe("SET_TTS_VOLUME", self.set_tts_volume)
EventMesh.subscribe("set_VC_stop_play_audio_flag", self.set_VC_stop_play_audio_flag)
EventMesh.subscribe("set_yuyinaudio_flag",self.set_yuyinaudio_flag)
+ EventMesh.subscribe("get_yuyinaudio_flag",self.get_yuyinaudio_flag)
+ EventMesh.subscribe("exit_voice_message_mode",self.exit_voice_message_mode) #超时未退出语音留言模式
EventMesh.subscribe("get_audio_play_state",self.get_audio_play_state)
# EventMesh.subscribe("chenggong_tone",self.chenggong_tone)
self.outbound_attributess_provider = "volcengine"
self.inbound_attributess_provider = EventMesh.publish("get_storage_config","inbound_attributess_provider")#tts服务选择
if self.inbound_attributess_provider == None:
- if dev_type == "7PIN" or dev_type == "7PIN_coze" :
+ if dev_type == "7PIN" or dev_type == "7PIN_1_5" or dev_type == "7PIN_coze" :
self.inbound_attributess_provider = "xun-fei"
else:
self.inbound_attributess_provider = "volcengine"
except Exception as e:
usys.print_exception(e)
try:
- bt_ota_flag = self.ai_OTA.bt_ota()#先检查蓝牙是否要升级
+ bt_ota_flag=0
+ if dev_type == "7PIN_1_5":
+ bt_ota_flag = self.ai_OTA.bt_ota()#先检查蓝牙是否要升级
+
cat1_ota_flag = self.ai_OTA.min_sys_ota()
if bt_ota_flag==1 or cat1_ota_flag == 1:
#if 0:
url=None
if dev_type == "7PIN_BK_EU":#英文小瑞
url = "http://dmp-global.raisound.com/bz-api/dev/config/{}".format(modem.getDevImei())
- elif dev_type == "7PIN" or dev_type == "7PIN_coze":#柒牌
+ elif dev_type == "7PIN" or dev_type == "7PIN_1_5" or dev_type == "7PIN_coze":#柒牌
url = "http://ota.qipai.com/bz-cmp-api/api/config/{}".format(modem.getDevImei())
else:
url = "http://dmp.raisound.com/bz-api/dev/config/{}".format(modem.getDevImei())
else:
self.aud.setVolume(self.VC_TTS_volume //10)
pass
+ def get_yuyinaudio_flag(self, event=None, msg = None):
+ return self.voice_flag
+
def set_yuyinaudio_flag(self, event=None, msg = None):
self.voice_flag=0
def get_audio_play_state(self, event=None, msg = None):
return self.audio_play_state
-
+ def exit_voice_message_mode(self, event=None, msg = None):
+ if self.voice_flag == 1: #还是为1就提示已退出语音留言模式
+ self.voice_flag=0
+ exit_tts ="已退出语音留言模式"
+ EventMesh.publish("play_tts",[exit_tts,1])
+ pass
def AI_key_press(self, event=None, msg = None):#按键按下
EventMesh.publish(constants.EVENT.SYSTEM_UP)#唤醒休眠
if EventMesh.publish("get_sos_flag")== 1:
return
if self.voice_flag == 1: #语音留言模式
+ self.stop_voice_timer.stop() #关闭语音留言模式定时器
# EventMesh.publish("stop_AI_record")
self.Close()
EventMesh.publish("open_led_green")
self.get_config_timer_count = 0
self.key_state = 1
if PRESS_AUDIO_MODE == 1:
- if dev_type == "7PIN":
+ if dev_type == "7PIN" or dev_type == "7PIN_1_5":
self.aud.aud_tone_play(10,200)#播放按键音
self.Close()
if PRESS_AUDIO_MODE == 0:
- if dev_type == "7PIN":
+ if dev_type == "7PIN" or dev_type == "7PIN_1_5":
self.chenggong_tone()
# if dev_type == "7PIN":
# self.chenggong_tone()
return
if self.voice_flag == 1: #语音留言模式
# EventMesh.publish("stop_AI_record")
+ self.stop_voice_timer.stop() #关闭语音留言模式定时器
self.Close()
EventMesh.publish("open_led_green")
EventMesh.publish("start_voice_record",2)#停止静默录音
self.get_config_timer_count = 0
self.key_state = 1
if PRESS_AUDIO_MODE == 1:
- if dev_type == "7PIN":
+ if dev_type == "7PIN" or dev_type == "7PIN_1_5":
self.aud.aud_tone_play(10,200)#播放按键音
self.Close()
if PRESS_AUDIO_MODE == 0:
- if dev_type == "7PIN":
+ if dev_type == "7PIN" or dev_type == "7PIN_1_5":
self.chenggong_tone()
if self.VC_mode == 1: #长按对话模式 接收到蓝牙耳机按键事件
count+=1
utime.sleep_ms(500)
-
+ def exit_voice_message_timer(self,*argc):
+ EventMesh.publish("exit_voice_message_mode")
def AI_key_release(self, event=None, msg=None):#按键弹起
print("AI_key_release123")
self.key_state = 0
if self.voice_flag == 1:
+ self.stop_voice_timer.stop()
self.voice_flag=0
if EventMesh.publish("GET_USB_STATE") == 0:
EventMesh.publish("close_led")
self.AI_TTS_str = ""
else:
#开始上传语音
- if dev_type != "7PIN_coze" and dev_type != "7PIN" :
+ if dev_type != "7PIN_coze" and dev_type != "7PIN" and dev_type != "7PIN_1_5":
self.chenggong_tone()
if self.VC_mode == 0 :
self.VC_record_state_flag =2
self.voice_flag = 1
self.AI_TTS_str = "已进入语音留言模式,长按按钮开始录音,松开按钮结束"
self.Close_flag = 1
-
+ self.stop_voice_timer.stop() #关闭语音留言模式定时器
+ self.stop_voice_timer.start(30*1000,0,self.exit_voice_message_timer)
print("语音留言!!!!!!!!!!")
return 0
if text.find("开广播") != -1 or text.find("开蓝牙广播") != -1:
return 0
if len(text)<16 and (text.find("再见") != -1 or text.find("拜拜") != -1 or text.find("关闭对话") != -1):
#EventMesh.publish("publish_AI_btnInfo",{"func":self.Close})
- if dev_type != "7PIN" and dev_type != "7PIN_coze":#柒牌
+ if dev_type != "7PIN" and dev_type != "7PIN_coze" and dev_type != "7PIN_1_5":#柒牌
self.AI_TTS_str = "好嘞,再见,我们下次再聊"
self.Close_flag = 1
return 0
#EventMesh.publish("sleep_BT")#休眠蓝牙
return 1
if len(text)<12 and (text.find("关机") != -1 ):
- if dev_type == "7PIN" or dev_type == "7PIN_coze":#柒牌
+ if dev_type == "7PIN" or dev_type == "7PIN_coze" or dev_type == "7PIN_1_5":#柒牌
EventMesh.publish("publish_AI_btnInfo",{"func":self.Close})
#EventMesh.publish("sleep_BT")#休眠蓝牙
return 1
json_data["payload"]["dialog_attributes"]["cfg"]["bot_option"]["bot_id"]="7490852493640384538"#慈善会
json_data["payload"]["dialog_attributes"]["cfg"]["bot_option"]["use_workflow"]=False
json_data["payload"]["dialog_attributes"]["cfg"]["bot_option"]["workflow_id"]=""
- elif dev_type == "7PIN" :#柒牌
+ elif dev_type == "7PIN" or dev_type == "7PIN_1_5" :#柒牌
json_data["payload"]["dialog_attributes"]["cfg"]["bot_option"]["bot_id"]=""#
json_data["payload"]["dialog_attributes"]["cfg"]["bot_option"]["workflow_id"]=""
#json_data["payload"]["inbound_attributes"]["vad_silence"] = 1000
elif EventMesh.publish("get_voice_record_mode") == 1: #静默录音需要打断
EventMesh.publish("stop_voice_record")#停止静默录音
if PRESS_AUDIO_MODE == 1:
- if dev_type == "7PIN":
+ if dev_type == "7PIN" or dev_type == "7PIN_1_5" :
self.aud.aud_tone_play(10,200)
self.Close()
if PRESS_AUDIO_MODE == 0:
- if dev_type == "7PIN":
+ if dev_type == "7PIN" or dev_type == "7PIN_1_5":
self.chenggong_tone()
# if dev_type == "7PIN" :
# self.aud.aud_tone_play(10,400)#播放按键音
self.AI_ASR_str_tmp = ""
self.VC_state = VC_State_None
self.VC_Speech_End()
- self.VC_Speech_Start()
+ self.VC_Speech_Start()
self.AI_VC_start()
def set_vad_silence(self,event = None,msg= None):