本期為大家推送迪文開發(fā)者論壇獲獎開源案例——迪文屏與安卓手機雙向聯(lián)動控制音樂播放。工程師通過藍牙模塊實現(xiàn)了迪文智能屏與安卓手機的數(shù)據(jù)交互,用戶可以輕松控制安卓手機、U盤中的歌曲播放、暫停、換曲及音效設(shè)置,體驗智能屏與安卓手機的雙向便捷操控。
UI開發(fā)示例
C51工程設(shè)計
T5L 串口與藍牙模塊進行數(shù)據(jù)交互,修改播放狀態(tài)、設(shè)置音量、讀取藍牙狀態(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();//讀取藍牙狀態(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://藍牙 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)與智能屏進行藍牙連接、通信控制,部分參考代碼如下:
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("開始檢測連接藍牙"); 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文章
3402瀏覽量
42711 -
安卓手機
+關(guān)注
關(guān)注
2文章
122瀏覽量
14839 -
迪文屏
+關(guān)注
關(guān)注
3文章
78瀏覽量
5464
發(fā)布評論請先 登錄
相關(guān)推薦
【開源獲獎案例】基于T5L芯片的調(diào)音臺麥克風(fēng)混響回聲控制
![【<b class='flag-5'>開源</b><b class='flag-5'>獲獎</b>案例】基于T5L芯片的調(diào)音臺麥克風(fēng)混響回聲<b class='flag-5'>控制</b>](https://file.elecfans.com/web2/M00/2A/81/poYBAGHKtJGANsQ1AAT-FWnPlz8451.jpg)
迪文串口屏如何與電腦連接
迪文串口屏ModBus開發(fā)流程
![<b class='flag-5'>迪</b><b class='flag-5'>文</b>串口<b class='flag-5'>屏</b>ModBus開發(fā)流程](https://file.elecfans.com/web2/M00/3E/6A/pYYBAGJhBGGAGyDYAACBPQuBZQI711.png)
ESP32 IDF 4.3藍牙音樂demo手機打開絕對音量后無法調(diào)整音量大小怎么解決?
ESP32藍牙功能安卓手機可以搜索到連接,蘋果手機搜不到藍牙信息,為什么呢?
使用I2S播放音樂時,BLE不能被手機掃描到怎么解決?
串口音樂播放IC:音樂播放的新革命
迪文科技2024年首展丨湖南醫(yī)療器械展完美收官
![<b class='flag-5'>迪</b>文科技2024年首展丨湖南醫(yī)療器械展完美收官](https://file.elecfans.com/web2/M00/2A/81/poYBAGHKtJGANsQ1AAT-FWnPlz8451.jpg)
評論