Add basic MP3 player

* Fix KNX PA exception. Regression from 6.2.1 buffer overflow caused by subStr() (#3700, #3710)
 * Add basic support for MP3 player using DFRobot RB-DFR-562 (#3723)
This commit is contained in:
Theo Arends 2018-09-07 10:54:24 +02:00
parent f760525e51
commit b659444c3a
3 changed files with 24 additions and 19 deletions

View File

@ -1,7 +1,8 @@
/* 6.2.1.2 20180906 /* 6.2.1.2 20180906
* Fix KNX PA exception. Regression from 6.2.1 buffer overflow (#3700, #3710) * Fix KNX PA exception. Regression from 6.2.1 buffer overflow caused by subStr() (#3700, #3710)
* Add command SetOption52 to control display of optional time offset from UTC in JSON messages (#3629, #3711) * Add command SetOption52 to control display of optional time offset from UTC in JSON messages (#3629, #3711)
* Add experimental support for PZEM-003,014,016,017 Energy monitoring (#3694) * Add experimental support for PZEM-003,014,016,017 Energy monitoring (#3694)
* Add basic support for MP3 player using DFRobot RB-DFR-562 (#3723)
* *
* 6.2.1.1 20180905 * 6.2.1.1 20180905
* Rewrite energy monitoring using energy sensor driver modules * Rewrite energy monitoring using energy sensor driver modules

View File

@ -268,9 +268,6 @@
// -- Internal Analog input ----------------------- // -- Internal Analog input -----------------------
#define USE_ADC_VCC // Display Vcc in Power status. Disable for use as Analog input on selected devices #define USE_ADC_VCC // Display Vcc in Power status. Disable for use as Analog input on selected devices
// -- MP3 player ----------------------------------
//#define USE_MP3_PLAYER // Use of the DFPlayer Mini MP3 Player RB-DFR-562 commands: play, volume and stop
// -- One wire sensors ---------------------------- // -- One wire sensors ----------------------------
// WARNING: Select none for default one DS18B20 sensor or enable one of the following two options for multiple sensors // WARNING: Select none for default one DS18B20 sensor or enable one of the following two options for multiple sensors
#define USE_DS18x20 // Optional for more than one DS18x20 sensors with id sort, single scan and read retry (+1k3 code) #define USE_DS18x20 // Optional for more than one DS18x20 sensors with id sort, single scan and read retry (+1k3 code)
@ -343,6 +340,7 @@
#define SDM120_SPEED 9600 // SDM120-Modbus RS485 serial speed (default: 2400 baud) #define SDM120_SPEED 9600 // SDM120-Modbus RS485 serial speed (default: 2400 baud)
//#define USE_SDM630 // Add support for Eastron SDM630-Modbus energy meter (+2k code) //#define USE_SDM630 // Add support for Eastron SDM630-Modbus energy meter (+2k code)
#define SDM630_SPEED 9600 // SDM630-Modbus RS485 serial speed (default: 9600 baud) #define SDM630_SPEED 9600 // SDM630-Modbus RS485 serial speed (default: 9600 baud)
//#define USE_MP3_PLAYER // Use of the DFPlayer Mini MP3 Player RB-DFR-562 commands: play, volume and stop
// Power monitoring sensors ----------------------- // Power monitoring sensors -----------------------
#define USE_PZEM004T // Add support for PZEM004T Energy monitor (+2k code) #define USE_PZEM004T // Add support for PZEM004T Energy monitor (+2k code)

View File

@ -1,32 +1,39 @@
/* /*
xdrv_91_mp3.ino - MP3 Player support for Sonoff-Tasmota xdrv_14_mp3.ino - MP3 support for Sonoff-Tasmota
Player type: RB-DFR-562, DFPlayer Mini MP3 Player
Copyright (C) 2018 Theo Arends Copyright (C) 2018 gemu2015, mike2nl and Theo Arends
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifdef USE_MP3_PLAYER #ifdef USE_MP3_PLAYER
/*********************************************************************************************\
* MP3 control for RB-DFR-562 DFRobot mini MP3 player
* https://www.dfrobot.com/wiki/index.php/DFPlayer_Mini_SKU:DFR0299
\*********************************************************************************************/
#include <TasmotaSerial.h> #include <TasmotaSerial.h>
TasmotaSerial *MP3Player; TasmotaSerial *MP3Player;
#define D_CMND_MP3 "MP3" #define D_CMND_MP3 "MP3"
const char S_JSON_MP3_COMMAND_NVALUE[] PROGMEM = "{\"" D_CMND_MP3 "%s\":%d}"; const char S_JSON_MP3_COMMAND_NVALUE[] PROGMEM = "{\"" D_CMND_MP3 "%s\":%d}";
const char S_JSON_MP3_COMMAND[] PROGMEM = "{\"" D_CMND_MP3 "%s\"}"; const char S_JSON_MP3_COMMAND[] PROGMEM = "{\"" D_CMND_MP3 "%s\"}";
enum MP3_Commands { CMND_MP3_PLAY, CMND_MP3_STOP, CMND_MP3_VOLUME}; enum MP3_Commands { CMND_MP3_PLAY, CMND_MP3_STOP, CMND_MP3_VOLUME};
const char kMP3_Commands[] PROGMEM = "Play" "|" "Stop" "|" "Volume"; const char kMP3_Commands[] PROGMEM = "Play|Stop|Volume";
#define MP3_CMD_PLAY 3 #define MP3_CMD_PLAY 3
#define MP3_CMD_VOLUME 6 #define MP3_CMD_VOLUME 6
@ -43,11 +50,10 @@ uint16_t MP3_Checksum(uint8_t *array)
} }
// init player define serial tx port // init player define serial tx port
void InitMP3Player() { void MP3PlayerInit() {
MP3Player = new TasmotaSerial(-1, pin[GPIO_MP3PLAYER]); MP3Player = new TasmotaSerial(-1, pin[GPIO_MP3_DFR562]);
if (MP3Player->begin(9600)) { if (MP3Player->begin(9600)) {
//serial_bridge_active = 1;
MP3Player->flush(); MP3Player->flush();
} }
} }
@ -67,7 +73,7 @@ boolean MP3PlayerCmd() {
char command[CMDSZ]; char command[CMDSZ];
boolean serviced = true; boolean serviced = true;
uint8_t disp_len = strlen(D_CMND_MP3); uint8_t disp_len = strlen(D_CMND_MP3);
if (!strncasecmp_P(XdrvMailbox.topic, PSTR(D_CMND_MP3), disp_len)) { // Prefix if (!strncasecmp_P(XdrvMailbox.topic, PSTR(D_CMND_MP3), disp_len)) { // Prefix
int command_code = GetCommandCode(command, sizeof(command), XdrvMailbox.topic + disp_len, kMP3_Commands); int command_code = GetCommandCode(command, sizeof(command), XdrvMailbox.topic + disp_len, kMP3_Commands);
@ -82,7 +88,7 @@ boolean MP3PlayerCmd() {
MP3_CMD(MP3_CMD_VOLUME, XdrvMailbox.payload * 30 / 100); MP3_CMD(MP3_CMD_VOLUME, XdrvMailbox.payload * 30 / 100);
} }
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_MP3_COMMAND_NVALUE, command, XdrvMailbox.payload); snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_MP3_COMMAND_NVALUE, command, XdrvMailbox.payload);
} }
else if (CMND_MP3_STOP == command_code) { // stop else if (CMND_MP3_STOP == command_code) { // stop
MP3_CMD(MP3_CMD_STOP, 0); MP3_CMD(MP3_CMD_STOP, 0);
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_MP3_COMMAND, command, XdrvMailbox.payload); snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_MP3_COMMAND, command, XdrvMailbox.payload);
@ -97,15 +103,15 @@ boolean MP3PlayerCmd() {
* Interface * Interface
\*********************************************************************************************/ \*********************************************************************************************/
#define XDRV_91 #define XDRV_14
boolean Xdrv91(byte function) boolean Xdrv14(byte function)
{ {
boolean result = false; boolean result = false;
switch (function) { switch (function) {
case FUNC_PRE_INIT: case FUNC_PRE_INIT:
InitMP3Player(); MP3PlayerInit();
break; break;
case FUNC_COMMAND: case FUNC_COMMAND:
result = MP3PlayerCmd(); result = MP3PlayerCmd();
@ -114,4 +120,4 @@ boolean Xdrv91(byte function)
return result; return result;
} }
#endif // USE_MP3_PLAYER #endif // USE_MP3_PLAYER