466 lines
12 KiB
C++
466 lines
12 KiB
C++
/**************************************************************************
|
||
Copyright (C), 2014- , ʢ˼<CAA2>ƽ<EFBFBD>
|
||
File name: kt540b.cpp
|
||
Author: jiangzhaohui Version: v1.0 Date: 2016.12.15
|
||
Description: <20><><EFBFBD><EFBFBD>kt540b<30><62>mp3<70><33><EFBFBD><EFBFBD>
|
||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>ã<EFBFBD>
|
||
1<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>rx tx<74><78><EFBFBD><EFBFBD>
|
||
2<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>begin()<29><>ʼ<EFBFBD><CABC>
|
||
3<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ø<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܺ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɸ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ü<EFBFBD><EFBFBD><EFBFBD><EFBFBD>š<EFBFBD>
|
||
|
||
Others:
|
||
Function List:
|
||
1.
|
||
2.
|
||
History:
|
||
|
||
1. Date: 2014.10.8 Author:
|
||
Modification: <20><><EFBFBD>봴<EFBFBD><EBB4B4>
|
||
2. ...
|
||
****************************************************************************/
|
||
|
||
#include "BluebitKt540b.h"
|
||
|
||
Kt540bClass::Kt540bClass(int rxPin, int txPin) : Sserial(rxPin, txPin)
|
||
{
|
||
pinRx = rxPin;
|
||
pinTx = txPin;
|
||
}
|
||
|
||
void Kt540bClass::begin()
|
||
{
|
||
Sserial.begin(9600);
|
||
delay(1500); //<2F>ϵ<EFBFBD><CFB5><EFBFBD>ʱ
|
||
}
|
||
|
||
/***************************************************************************
|
||
Function: play()
|
||
Description: <20>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>
|
||
Calls:
|
||
Called By:
|
||
Input:
|
||
Output:
|
||
Return:
|
||
Others:
|
||
***************************************************************************/
|
||
void Kt540bClass::play(void) //<2F><><EFBFBD>ţ<EFBFBD><C5A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD>лָ<D0BB><D6B8><EFBFBD>
|
||
{
|
||
sendCmd(CMD_PLAY, 0, 0);
|
||
}
|
||
|
||
/***************************************************************************
|
||
Function: play()
|
||
Description: <20><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>Ÿ<EFBFBD><C5B8><EFBFBD>
|
||
Calls:
|
||
Called By:
|
||
Input:
|
||
1<EFBFBD><EFBFBD>uint8_t songNum<75><6D><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
Output:
|
||
Return:
|
||
Others:
|
||
***************************************************************************/
|
||
void Kt540bClass::play(uint8_t songNum) //<2F><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>Ÿ<EFBFBD><C5B8><EFBFBD>
|
||
{
|
||
sendCmd(CMD_PLAY_SONG, 0x00, songNum);
|
||
}
|
||
|
||
/***************************************************************************
|
||
Function: play()
|
||
Description: <20><>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>кŸ<D0BA><C5B8><EFBFBD>
|
||
Calls:
|
||
Called By:
|
||
Input:
|
||
1<EFBFBD><EFBFBD>uint8_t songNum<75><6D><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
2<EFBFBD><EFBFBD>uint8_t volume<6D><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
Output:
|
||
Return:
|
||
Others:
|
||
***************************************************************************/
|
||
//void Kt540bClass::play(uint8_t songNum, uint8_t volume)
|
||
//{
|
||
// sendCmd(CMD_PLAY_WITH_VOLUME, volume, songNum);
|
||
//}
|
||
|
||
/***************************************************************************
|
||
Function: playDir()
|
||
Description: <20><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
Calls:
|
||
Called By:
|
||
Input:
|
||
1<EFBFBD><EFBFBD>uint8_t songNum<75><6D><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
2<EFBFBD><EFBFBD>uint8_t volume<6D><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
Output:
|
||
Return:
|
||
Others:
|
||
***************************************************************************/
|
||
void Kt540bClass::playDir(uint8_t dir, uint8_t songNum)
|
||
{
|
||
sendCmd(CMD_DIR_PLAY, dir, songNum);
|
||
}
|
||
|
||
/***************************************************************************
|
||
Function: play()
|
||
Description: <20><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>Ÿ<EFBFBD><C5B8><EFBFBD>
|
||
Calls:
|
||
Called By:
|
||
Input:
|
||
1<EFBFBD><EFBFBD>uint8_t songNum<75><6D><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
Output:
|
||
Return:
|
||
Others:
|
||
***************************************************************************/
|
||
void Kt540bClass::playNext(void) //<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
|
||
{
|
||
sendCmd(CMD_NEXT, 0, 0);
|
||
}
|
||
|
||
/***************************************************************************
|
||
Function: play()
|
||
Description: <20><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>Ÿ<EFBFBD><C5B8><EFBFBD>
|
||
Calls:
|
||
Called By:
|
||
Input:
|
||
1<EFBFBD><EFBFBD>uint8_t songNum<75><6D><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
Output:
|
||
Return:
|
||
Others:
|
||
***************************************************************************/
|
||
void Kt540bClass::playPrev(void) //<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
|
||
{
|
||
sendCmd(CMD_PREV, 0, 0);
|
||
}
|
||
|
||
/***************************************************************************
|
||
Function: setVolume()
|
||
Description: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
Calls:
|
||
Called By:
|
||
Input:
|
||
1<><31>uint8_t volume<6D><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ <20><>Χ 0-30
|
||
Output:
|
||
Return:
|
||
Others:
|
||
***************************************************************************/
|
||
void Kt540bClass::setVolume(uint8_t volume) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
{
|
||
sendCmd(CMD_VOLUME, 0x00, volume);
|
||
}
|
||
|
||
/***************************************************************************
|
||
Function: volumeInc()
|
||
Description: <20><><EFBFBD><EFBFBD>+
|
||
Calls:
|
||
Called By:
|
||
Input:
|
||
Output:
|
||
Return:
|
||
Others:
|
||
***************************************************************************/
|
||
void Kt540bClass::volumeInc() //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
{
|
||
sendCmd(CMD_VOLUME_INC, 0, 0);
|
||
}
|
||
|
||
/***************************************************************************
|
||
Function: volumeDec()
|
||
Description: <20><><EFBFBD><EFBFBD>-
|
||
Calls:
|
||
Called By:
|
||
Input:
|
||
Output:
|
||
Return:
|
||
Others:
|
||
***************************************************************************/
|
||
void Kt540bClass::volumeDec() //<2F><><EFBFBD><EFBFBD>+
|
||
{
|
||
sendCmd(CMD_VOLUME_DEC, 0, 0);
|
||
}
|
||
|
||
/***************************************************************************
|
||
Function: setEQ()
|
||
Description: <20><><EFBFBD><EFBFBD>EQ
|
||
Calls:
|
||
Called By:
|
||
Input:
|
||
1<EFBFBD><EFBFBD>uint8_t eq <20><>eqֵ
|
||
Output:
|
||
Return:
|
||
Others:
|
||
***************************************************************************/
|
||
void Kt540bClass::setEQ(uint8_t eq) //<2F><><EFBFBD><EFBFBD>EQֵ
|
||
{
|
||
sendCmd(CMD_SET_EQ, 0, eq);
|
||
}
|
||
|
||
/***************************************************************************
|
||
Function: loop()
|
||
Description: ָ<><D6B8><EFBFBD><EFBFBD>Ŀѭ<C4BF><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
Calls:
|
||
Called By:
|
||
Input:
|
||
1<EFBFBD><EFBFBD>uint8_t songNo <20><>Ҫѭ<D2AA><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD>
|
||
Output:
|
||
Return:
|
||
Others:
|
||
***************************************************************************/
|
||
void Kt540bClass::loop(uint8_t songNo)
|
||
{
|
||
sendCmd(CMD_LOOP, 0, songNo);
|
||
}
|
||
|
||
/***************************************************************************
|
||
Function: loop()
|
||
Description: ָ<><D6B8>Ŀ¼<C4BF><C2BC>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>Ÿ<EFBFBD><C5B8><EFBFBD>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
Calls:
|
||
Called By:
|
||
Input:
|
||
1<EFBFBD><EFBFBD>uint8_t dir<69><72>Ŀ¼<C4BF>ţ<EFBFBD>Ŀ¼<C4BF><C2BC><EFBFBD><EFBFBD>Ϊ01<30><31>02<30><32>03<30><33><EFBFBD><EFBFBD><EFBFBD>ĸ<EFBFBD>ʽ<EFBFBD><CABD>
|
||
2<EFBFBD><EFBFBD>uint8_t songNo <20><>Ҫѭ<D2AA><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD>
|
||
Output:
|
||
Return:
|
||
Others:
|
||
***************************************************************************/
|
||
void Kt540bClass::loop(uint8_t dir, uint8_t songNo)
|
||
{
|
||
sendCmd(CMD_LOOP, dir, songNo);
|
||
}
|
||
|
||
/***************************************************************************
|
||
Function: loopDir()
|
||
Description: ָ<><D6B8>Ŀ¼ѭ<C2BC><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
Calls:
|
||
Called By:
|
||
Input:
|
||
1<EFBFBD><EFBFBD>uint8_t dir<69><72>Ŀ¼<C4BF>ţ<EFBFBD>Ŀ¼<C4BF><C2BC><EFBFBD><EFBFBD>Ϊ01<30><31>02<30><32>03<30><33><EFBFBD><EFBFBD><EFBFBD>ĸ<EFBFBD>ʽ<EFBFBD><CABD>
|
||
Output:
|
||
Return:
|
||
Others:
|
||
***************************************************************************/
|
||
void Kt540bClass::loopDir(uint8_t dir)
|
||
{
|
||
sendCmd(CMD_DIR_LOOP, 0, dir);
|
||
}
|
||
|
||
/***************************************************************************
|
||
Function: singleLoop()
|
||
Description: <20><><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD><EFBFBD>أ<EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD>ڷ<EFBFBD>һ<EFBFBD><D2BB>ָ<EFBFBD><EFBFBD><EEB2A5>һ<EFBFBD><EFBFBD><EFBFBD><F3A3ACB7><EFBFBD>ָ<EFBFBD><D6B8>ָ<EFBFBD><D6B8><EFBFBD>Ƿ<EFBFBD>ѭ<EFBFBD><D1AD>
|
||
ʾ<><CABE><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD><EFBFBD>ŵ<EFBFBD>3<EFBFBD>裩<D7B8><E8A3A9>
|
||
...
|
||
mp3Play.play(3);
|
||
mp3Play.singleLoop(0);
|
||
...
|
||
Calls:
|
||
Called By:
|
||
Input:
|
||
1<EFBFBD><EFBFBD>boolean onOff: 0:ѭ<><D1AD> 1<><31><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD>
|
||
Output:
|
||
Return:
|
||
Others:
|
||
test state: pass
|
||
***************************************************************************/
|
||
void Kt540bClass::singleLoop(boolean onOff)
|
||
{
|
||
sendCmd(CMD_LOOP_ONE, 0, onOff);
|
||
}
|
||
|
||
/***************************************************************************
|
||
Function: radomPlay()
|
||
Description: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C>Կ<EFBFBD><D4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ţ<EFBFBD><C5A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>еĸ<D0B5>
|
||
Calls:
|
||
Called By:
|
||
Input:
|
||
Output:
|
||
Return:
|
||
Others:
|
||
test state: pass
|
||
***************************************************************************/
|
||
void Kt540bClass::radomPlay(void) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
{
|
||
sendCmd(CMD_RADOM_PLAY, 0, 0);
|
||
}
|
||
|
||
/***************************************************************************
|
||
Function: pause()
|
||
Description: <20><>ͣ
|
||
Calls:
|
||
Called By:
|
||
Input:
|
||
Output:
|
||
Return:
|
||
Others:
|
||
***************************************************************************/
|
||
void Kt540bClass::pause(void) //<2F><>ͣ
|
||
{
|
||
sendCmd(CMD_PAUSE, 0, 0);
|
||
}
|
||
|
||
/***************************************************************************
|
||
Function: stop()
|
||
Description: ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD>
|
||
Calls:
|
||
Called By:
|
||
Input:
|
||
Output:
|
||
Return:
|
||
Others:
|
||
***************************************************************************/
|
||
void Kt540bClass::stop(void) //ֹͣ
|
||
{
|
||
sendCmd(CMD_STOP, 0, 0);
|
||
}
|
||
|
||
/***************************************************************************
|
||
Function: setDac()
|
||
Description: <20><><EFBFBD>û<EFBFBD>ֹͣDAC
|
||
Calls:
|
||
Called By:
|
||
Input:
|
||
bool onOff<66><66>0<EFBFBD><30>ֹͣ 1<><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
Output:
|
||
Return:
|
||
Others:
|
||
***************************************************************************/
|
||
void Kt540bClass::setDac(bool onOff) //DAC<41><43><EFBFBD><EFBFBD>
|
||
{
|
||
sendCmd(CMD_DAC_ON_OFF, 0, 0);
|
||
}
|
||
|
||
/***************************************************************************
|
||
Function: enterSleep()
|
||
Description: <20><><EFBFBD><EFBFBD>˯<EFBFBD><CBAF>ģʽ
|
||
Calls:
|
||
Called By:
|
||
Input:
|
||
Output:
|
||
Return:
|
||
Others:
|
||
***************************************************************************/
|
||
void Kt540bClass::enterSleep(void)
|
||
{
|
||
sendCmd(CMD_ENTER_SLEEP_MODE, 0, 0);
|
||
}
|
||
|
||
/***************************************************************************
|
||
Function: exitSleep()
|
||
Description: <20>˳<EFBFBD>˯<EFBFBD><CBAF>ģʽ
|
||
Calls:
|
||
Called By:
|
||
Input:
|
||
Output:
|
||
Return:
|
||
Others:
|
||
***************************************************************************/
|
||
void Kt540bClass::exitSleep(void)
|
||
{
|
||
sendCmd(CMD_EXIT_SLEEP_MODE, 0, 0);
|
||
}
|
||
|
||
/***************************************************************************
|
||
Function: resetDevice()
|
||
Description: <20>豸<EFBFBD><E8B1B8>λ
|
||
Calls:
|
||
Called By:
|
||
Input:
|
||
Output:
|
||
Return:
|
||
Others:
|
||
***************************************************************************/
|
||
void Kt540bClass::resetDevice(void)
|
||
{
|
||
sendCmd(CMD_RESET, 0, 0);
|
||
}
|
||
|
||
/***************************************************************************
|
||
Function: setPlayMedia()
|
||
Description: ѡ<><EFBFBD>ý<EFBFBD><C3BD>
|
||
Calls:
|
||
Called By:
|
||
Input:
|
||
MEDIA playMedia<69><61> UDISK<53><4B>U<EFBFBD><55> TFCARD<52><44>TF<54><46> FLASH<53><48>FLASHоƬ
|
||
Output:
|
||
Return:
|
||
Others:
|
||
***************************************************************************/
|
||
void Kt540bClass::setPlayMedia(MEDIA playMedia)
|
||
{
|
||
sendCmd(CMD_MEDIA_SELECT, 0, 0);
|
||
}
|
||
|
||
/***************************************************************************
|
||
Function: getPlayState()
|
||
Description: <20><>ȡ<EFBFBD>豸<EFBFBD><E8B1B8>ǰ״̬
|
||
Calls:
|
||
Called By:
|
||
Input:
|
||
Output: <20>豸״̬ 0:<3A><><EFBFBD><EFBFBD>ֹͣ 1<><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2<><32><EFBFBD><EFBFBD>ͣ
|
||
Return:
|
||
Others:
|
||
***************************************************************************/
|
||
uint8_t Kt540bClass::getPlayState(void)
|
||
{
|
||
uint8_t Buff[10];
|
||
uint8_t i;
|
||
|
||
sendCmd(0x42, 0, 0);
|
||
while (!Sserial.available());
|
||
while (Sserial.available())
|
||
{
|
||
if(0x7e == Sserial.read())
|
||
{
|
||
while (!Sserial.available());
|
||
if (0xff == Sserial.read())
|
||
{
|
||
Sserial.readBytes(Buff, 8);
|
||
}
|
||
return Buff[4];
|
||
}
|
||
}
|
||
return 0xff;
|
||
}
|
||
|
||
/***************************************************************************
|
||
Function: sendCmd()
|
||
Description: <20><>ģ<EFBFBD>鷢<EFBFBD><E9B7A2>ָ<EFBFBD><D6B8>
|
||
Calls:
|
||
Called By:
|
||
Input:
|
||
1<EFBFBD><EFBFBD>uint8_t cmd<6D><64> ָ<><D6B8>
|
||
2<EFBFBD><EFBFBD>uint8_t data1<61><31> <20><><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>1
|
||
3<EFBFBD><EFBFBD>uint8_t data2<61><32> <20><><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>2
|
||
Output:
|
||
Return:
|
||
Others:
|
||
***************************************************************************/
|
||
void Kt540bClass::sendCmd(uint8_t cmd, uint8_t data1, uint8_t data2)
|
||
{
|
||
uint8_t sendBuff[10];
|
||
uint8_t i;
|
||
uint16_t temp;
|
||
uint8_t tempH, tempL;
|
||
|
||
sendBuff[0] = 0x7e; //<2F><>ʼλ
|
||
sendBuff[1] = 0xff; //<2F>汾
|
||
sendBuff[2] = 0x06; //<2F><><EFBFBD><EFBFBD>
|
||
sendBuff[3] = cmd; //<2F><><EFBFBD><EFBFBD>
|
||
sendBuff[4] = 0x00; //<2F>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>0<EFBFBD><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
sendBuff[5] = data1; //<2F><><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>1
|
||
sendBuff[6] = data2; //<2F><><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>2
|
||
|
||
temp = 0xff + 0x06 + cmd + 0x00 + data1 + data2;
|
||
temp = (0xFFFF - temp) + 1;
|
||
tempH = (uint8_t)(temp >> 8);
|
||
tempL = (uint8_t)(temp & 0xff);
|
||
sendBuff[7] = tempH; //У<><D0A3><EFBFBD><EFBFBD>ֽ<EFBFBD>
|
||
sendBuff[8] = tempL; //У<><D0A3><EFBFBD><EFBFBD>ֽ<EFBFBD>
|
||
sendBuff[9] = 0xef; //<2F><><EFBFBD><EFBFBD>
|
||
|
||
for (i = 0; i < 10; i++)
|
||
Sserial.write(sendBuff[i]);
|
||
delay(20); //datasheetҪ<74><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EEB7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>20ms<6D><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ſ<EFBFBD>һ<EFBFBD><D2BB>
|
||
}
|
||
|
||
|
||
|
||
//Kt540bClass Kt540b;
|
||
|