本期為大家推送迪文開發(fā)者論壇獲獎開源案例——迪文屏與安卓手機雙向聯(lián)動控制音樂播放。工程師通過藍(lán)牙模塊實現(xiàn)了迪文智能屏與安卓手機的數(shù)據(jù)交互,用戶可以輕松控制安卓手機、U盤中的歌曲播放、暫停、換曲及音效設(shè)置,體驗智能屏與安卓手機的雙向便捷操控。
UI開發(fā)示例
C51工程設(shè)計
T5L 串口與藍(lán)牙模塊進(jìn)行數(shù)據(jù)交互,修改播放狀態(tài)、設(shè)置音量、讀取藍(lán)牙狀態(tài),部分參考代碼如下:
int main(void){ INIT_CPU(); T2_Init(); UART4_Init();EA=1; //UART4_SendStr("hello",sizeof("hello")); //WDT_ON();//打開看門狗 while(1){ //WDT_RST();//喂狗 Process(); }}void UART4_Init(void){ //UART4波特率設(shè)置: //BODE2_DIV_H=CPU 主頻/(8*波特率) 。 //206438400/8/115200=224=0xe0 //206438400/8/921600=28=0x1C //206438400/8=25804800/230400=112=0x70 SCON2T=0x80; SCON2R=0x80; BODE2_DIV_H=0x00;//FCLK/(8*DIV) BODE2_DIV_L=0xe0;//921600 波特率 //BODE2_DIV_H=0x00; //FCLK/(8*DIV) //BODE2_DIV_L=0x70; //ES3T=1; ES2R=1; EA=1;}void TenMsHandle(void){ if(!TenmsFlag) return; TenmsFlag=0; SourcePress();//音源改變 PlayCtrPress();//播放狀態(tài)改變 VolCtrSlider();//音量改變 VolLogSlider();//音量改變 ReadBtState();//讀取藍(lán)牙狀態(tài)}void SourcePress(void){ charTouchKey[2]={0,0}; u8Sdata[2]; read_dgusii_vp(0x3000,TouchKey,1); if(TouchKey[1]==0) return;Sdata[1]=0; switch(TouchKey[1]) { case1://U盤 Sdata[0]=1; SendDataToBT(Write_Run_Mode,Sdata,1); break; case2://外部LineIn輸入 Sdata[0]=2; SendDataToBT(Write_Run_Mode,Sdata,1); break; case3://藍(lán)牙 Sdata[0]=3; SendDataToBT(Write_Run_Mode,Sdata,1); break; } write_dgusii_vp(0x3003,TouchKey,1); memset(TouchKey,0,sizeof(TouchKey)); write_dgusii_vp(0x3000,TouchKey,1); ReadBtStatecount=0;}void PlayCtrPress(void){ charTouchKey[2]={0,0}; u8Sdata[2]; read_dgusii_vp(0x3001,TouchKey,1); if(TouchKey[1]==0) return;Sdata[1]=0; switch(TouchKey[1]) { case1://上一曲 Sdata[0]=1; SendDataToBT(Write_Next_Pre_PT,Sdata,1); break; case2://播放暫停 Sdata[0]=2; SendDataToBT(Write_Next_Pre_PT,Sdata,1); break; case3://下一曲 Sdata[0]=3; SendDataToBT(Write_Next_Pre_PT,Sdata,1); break; } memset(TouchKey,0,sizeof(TouchKey)); write_dgusii_vp(0x3001,TouchKey,1); ReadBtStatecount=0;}
安卓軟件包通過QT編寫,主要實現(xiàn)與智能屏進(jìn)行藍(lán)牙連接、通信控制,部分參考代碼如下:
ui->setupUi(this); bluetooth_ble_Tool=new Bluetooth_ble_Tool("dwin_bt(BLE)"); ui->label_localBT_Name->setText(bluetooth_ble_Tool->getLocalName()); connect(bluetooth_ble_Tool,&Bluetooth_ble_Tool::BlueSearchConnectState, this,&BLE_PairPage::BlueSearchConnectState); //btchat=new BtChat(); //btchat->set_ble_Tool(bluetooth_ble_Tool); //btchat->init_Page(); //btchat->hide(); devicecommHandle=new DeviceComm(); devicecommHandle->set_ble_Tool(bluetooth_ble_Tool); devicecommHandle->InitDevice(); mwin=new mainwin(); mwin->hide(); connect(mwin,&mainwin:layChangeMode, devicecommHandle,&DeviceComm:layChangeMode);//寫模式改變下發(fā) connect(mwin,&mainwin:layCtrPreNextSt, devicecommHandle,&DeviceComm:layCtrPreNextSt);//寫上下曲 connect(mwin,&mainwin:layMusicVolChange, devicecommHandle,&DeviceComm:layMusicVolChange);//寫音量改變下發(fā) connect(devicecommHandle,&DeviceComm::ReadPlayMode, this,[=](int mode){//設(shè)置目前的模式 qDebug()<<"mode:"< mwin->B_Upan->setChecked(false); mwin->B_AUX->setChecked(false); mwin->B_BT->setChecked(false); if(mode==1) mwin->B_Upan->setChecked(true); else if(mode==2) mwin->B_AUX->setChecked(true); else if(mode==3) mwin->B_BT->setChecked(true); }); connect(devicecommHandle,&DeviceComm::ReadPlayMusicVol, this,[=](int vol){//設(shè)置音量顯示 mwin->QS_MainVol->setValue(vol); }); connect(bluetooth_ble_Tool,&Bluetooth_ble_Tool::BLE_Link_error, this,[=](){ this->show(); mwin->hide(); devicecommHandle->TimerStopReadDeviceST(); this->ui->progressBar->setValue(0); });void BLE_PairPage::on_pushButton_clicked(){ bluetooth_ble_Tool->SetOperUuidServer(QBluetoothUuid(serviceUuid)); //ui->label_localBT->clear(); //ui->label_localBT_Name->setText(bluetooth_ble_Tool->getLocalName()); bluetooth_ble_Tool->startFindConnectBle(); //bluetooth_ble_Tool->startStateprogressBar(); ui->pushButton->setEnabled(false); ui->pushButton->setText("正在搜索"); connect(bluetooth_ble_Tool,&Bluetooth_ble_Tool::BlueBLE_FindDevicefinished, this,[=](bool ok){ ui->pushButton->setEnabled(true); ui->pushButton->setText("開始檢測連接藍(lán)牙"); if(ok==false) { QMessageBox::information(this,tr("搜索狀態(tài)"),"搜索不到設(shè)備,請查看設(shè)備是否已經(jīng)開機,或者有其它手機已經(jīng)連接上?");} });} void BLE_PairPage::startStateprogressBar_em Linkst, int progress){ ui->progressBar->setValue(progress); if(Linkst>=Bluetooth_ble_Tool::Ble_OtherError){ QMessageBox::information(this,tr("連接提示"),bluetooth_ble_Tool->getErrorinfo()); ui->label_tips->setText(bluetooth_ble_Tool->getErrorinfo());} else if(Linkst>=Bluetooth_ble_Tool::Ble_Deconnect_device){ QMessageBox::information(this,tr("連接提示"),"有錯誤"); ui->label_tips->setText("有錯誤");} else if(Linkst==Bluetooth_ble_Tool::Ble_Connect_characterOk){// QMessageBox::information( this,tr("成功連接"),bluetooth_ble_Tool->getErrorinfo()); ui->label_tips->setText("已成功連接"); this->hide(); mwin->show(); devicecommHandle->TimerStartReadDeviceST(100); //btchat->show(); //disconnect(bluetooth_ble_Tool,&Bluetooth_ble_Tool::BlueSearchConnectState, //this,&BLE_PairPage::BlueSearchConnectState); } else{ ui->label_tips->setText("搜索連接中"); }}
-
開源
+關(guān)注
關(guān)注
3文章
3309瀏覽量
42471 -
安卓手機
+關(guān)注
關(guān)注
2文章
122瀏覽量
14733 -
迪文屏
+關(guān)注
關(guān)注
3文章
78瀏覽量
5382
發(fā)布評論請先 登錄
相關(guān)推薦
評論