【Open Source】 DWIN Screen and Android Phone Two-way Linkage Control Music Playback

–From DWIN Developer Forum

This issue for you to push the award-winning open-source case of DWIN developer forum – DWIN screen and Android phone two-way linkage control music playback. Engineers through the Bluetooth module to achieve the DWIN intelligent screen and Android phone data interaction, users can easily control the Android phone, USB flash drive in the song play, pause, change the song and sound settings, experience intelligent screen and Android phone two-way convenient control.

1.C51 Design
(1) The T5L serial port interacts with the Bluetooth module to modify the playback status, set the volume, and read the Bluetooth status, part of the reference code is as follows:
int main(void)
{
INIT_CPU();
T2_Init();
UART4_Init();
EA=1;
//UART4_SendStr(“hello”,sizeof(“hello”));
//WDT_ON();//Turn on the Watchdog.
while(1)
{
//WDT_RST();//Feet the dog
Process();
}
}
void UART4_Init(void)
{
// UART4 Baud rate setting:
//BODE2_DIV_H=CPU Mains frequency/(8*Baud rate) .
//206438400/8/115200=224=0xe0
//206438400/8/921600=28=0x1C
//206438400/8=25804800/230400=112=0×70
SCON2T=0×80;
SCON2R=0×80;
BODE2_DIV_H=0×00;//FCLK/(8*DIV)
BODE2_DIV_L=0xe0;// 921600 Baud rate
//BODE2_DIV_H=0×00;
//FCLK/(8*DIV)
//BODE2_DIV_L=0×70;
//ES3T=1;
ES2R=1;
EA=1;
}
void TenMsHandle(void)
{
if(!TenmsFlag)
return;
TenmsFlag=0;
SourcePress();//Tone generator
PlayCtrPress();//Playback state change
VolCtrSlider();//Volume change
VolLogSlider();//Volume change
ReadBtState();//Read Bluetooth status
}
void SourcePress(void)
{
charTouchKey[2]={0,0};
u8Sdata[2];
read_dgusii_vp(0×3000,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:// External LineIn Input
Sdata[0]=2;
SendDataToBT(Write_Run_Mode,Sdata,1);
break;
case3://蓝牙
Sdata[0]=3;
SendDataToBT(Write_Run_Mode,Sdata,1);
break;
}
write_dgusii_vp(0×3003,TouchKey,1);
memset(TouchKey,0,sizeof(TouchKey));
write_dgusii_vp(0×3000,TouchKey,1);
ReadBtStatecount=0;
}
void PlayCtrPress(void)
{
charTouchKey[2]={0,0};
u8Sdata[2];
read_dgusii_vp(0×3001,TouchKey,1);
if(TouchKey[1]==0)
return;
Sdata[1]=0;
switch(TouchKey[1])
{
case1:// Previous song
Sdata[0]=1;
SendDataToBT(Write_Next_Pre_PT,Sdata,1);
break;
case2:// Playback Pause
Sdata[0]=2;
SendDataToBT(Write_Next_Pre_PT,Sdata,1);
break;
case3:// Next song
Sdata[0]=3;
SendDataToBT(Write_Next_Pre_PT,Sdata,1);
break;
}
memset(TouchKey,0,sizeof(TouchKey));
write_dgusii_vp(0×3001,TouchKey,1);
ReadBtStatecount=0;
}

(2)The Android software package is written through QT, mainly realizing Bluetooth connection and communication control with the smart screen, part of the reference code is as follows:
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);// Write mode change issued
connect(mwin,&mainwin:layCtrPreNextSt,
devicecommHandle,&DeviceComm:layCtrPreNextSt);// lit. write down the upper and lower parts of a song
connect(mwin,&mainwin:layMusicVolChange,
devicecommHandle,&DeviceComm:layMusicVolChange);// Write volume change down
connect(devicecommHandle,&DeviceComm::ReadPlayMode,
this,[=](int mode){// Setting the current mode
qDebug()<<”mode:”<<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){// Setting the Volume Display
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(“Searching “);
connect(bluetooth_ble_Tool,&Bluetooth_ble_Tool::BlueBLE_FindDevicefinished,
this,[=](bool ok){
ui->pushButton->setEnabled(true);
ui->pushButton->setText(“Start detecting connected Bluetooth “);
if(ok==false) {
QMessageBox::information(this,tr(“Search Status “),” The device cannot be searched, please check if the device is already turned on, or if another cell phone is already connected to it?”);} });}
void BLE_PairPage::BlueSearchConnectState(Bluetooth_ble_Tool::startStateprogressBar_em Linkst, int progress){
ui->progressBar->setValue(progress);
if(Linkst>=Bluetooth_ble_Tool::Ble_OtherError){
QMessageBox::information(this,tr(“connection prompt “),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(“connection prompt “),” buggy “);
ui->label_tips->setText(“buggy “);}
else if(Linkst==Bluetooth_ble_Tool::Ble_Connect_characterOk){// QMessageBox::information(
this,tr(“successfully connected “),bluetooth_ble_Tool->getErrorinfo());
ui->label_tips->setText(“successfully connected “);
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(“Searching for connections “); }


Post time: May-23-2024