diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index 49193dfbd..82d12f28e 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -1,7 +1,8 @@ /* 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 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 * Rewrite energy monitoring using energy sensor driver modules diff --git a/sonoff/user_config.h b/sonoff/user_config.h index b7a54408d..d46a295d7 100644 --- a/sonoff/user_config.h +++ b/sonoff/user_config.h @@ -268,9 +268,6 @@ // -- Internal Analog input ----------------------- #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 ---------------------------- // 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) @@ -343,6 +340,7 @@ #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 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 ----------------------- #define USE_PZEM004T // Add support for PZEM004T Energy monitor (+2k code) diff --git a/sonoff/xdrv_91_mp3.ino b/sonoff/xdrv_14_mp3.ino similarity index 83% rename from sonoff/xdrv_91_mp3.ino rename to sonoff/xdrv_14_mp3.ino index 82c778127..e4c72cb16 100644 --- a/sonoff/xdrv_91_mp3.ino +++ b/sonoff/xdrv_14_mp3.ino @@ -1,32 +1,39 @@ /* - xdrv_91_mp3.ino - MP3 Player support for Sonoff-Tasmota - Player type: RB-DFR-562, DFPlayer Mini MP3 Player - Copyright (C) 2018 Theo Arends + xdrv_14_mp3.ino - MP3 support for Sonoff-Tasmota + + Copyright (C) 2018 gemu2015, mike2nl and Theo Arends + 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 the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + You should have received a copy of the GNU General Public License along with this program. If not, see . - */ #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 *MP3Player; #define D_CMND_MP3 "MP3" + const char S_JSON_MP3_COMMAND_NVALUE[] PROGMEM = "{\"" D_CMND_MP3 "%s\":%d}"; const char S_JSON_MP3_COMMAND[] PROGMEM = "{\"" D_CMND_MP3 "%s\"}"; 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_VOLUME 6 @@ -43,11 +50,10 @@ uint16_t MP3_Checksum(uint8_t *array) } // init player define serial tx port -void InitMP3Player() { - MP3Player = new TasmotaSerial(-1, pin[GPIO_MP3PLAYER]); - +void MP3PlayerInit() { + MP3Player = new TasmotaSerial(-1, pin[GPIO_MP3_DFR562]); + if (MP3Player->begin(9600)) { - //serial_bridge_active = 1; MP3Player->flush(); } } @@ -67,7 +73,7 @@ boolean MP3PlayerCmd() { char command[CMDSZ]; boolean serviced = true; uint8_t disp_len = strlen(D_CMND_MP3); - + 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); @@ -82,7 +88,7 @@ boolean MP3PlayerCmd() { MP3_CMD(MP3_CMD_VOLUME, XdrvMailbox.payload * 30 / 100); } snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_MP3_COMMAND_NVALUE, command, XdrvMailbox.payload); - } + } else if (CMND_MP3_STOP == command_code) { // stop MP3_CMD(MP3_CMD_STOP, 0); snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_MP3_COMMAND, command, XdrvMailbox.payload); @@ -97,15 +103,15 @@ boolean MP3PlayerCmd() { * Interface \*********************************************************************************************/ -#define XDRV_91 +#define XDRV_14 -boolean Xdrv91(byte function) +boolean Xdrv14(byte function) { boolean result = false; switch (function) { case FUNC_PRE_INIT: - InitMP3Player(); + MP3PlayerInit(); break; case FUNC_COMMAND: result = MP3PlayerCmd(); @@ -114,4 +120,4 @@ boolean Xdrv91(byte function) return result; } -#endif // USE_MP3_PLAYER +#endif // USE_MP3_PLAYER