From 29d3e701465c61b2c26d9b83c0144242fe232c58 Mon Sep 17 00:00:00 2001 From: blakadder Date: Thu, 28 Jan 2021 01:14:37 +0100 Subject: [PATCH] add L1MusicSync mode --- tasmota/xlgt_05_sonoff_l1.ino | 58 +++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/tasmota/xlgt_05_sonoff_l1.ino b/tasmota/xlgt_05_sonoff_l1.ino index 368e1673d..908015d68 100644 --- a/tasmota/xlgt_05_sonoff_l1.ino +++ b/tasmota/xlgt_05_sonoff_l1.ino @@ -57,6 +57,12 @@ struct SNFL1 { uint8_t power; } Snfl1; +const char kL1Commands[] PROGMEM = "L1|" // prefix + "MusicSync"; + +void (* const L1Command[])(void) PROGMEM = { + &CmndMusicSync }; + /********************************************************************************************/ #ifdef SONOFF_L1_START_DELAY @@ -318,6 +324,55 @@ bool SnfL1ModuleSelected(void) return false; } +// SONOFF_L1_MODE_COLORFUL +void SnfL1ModeColorful() { + char buffer[SONOFF_L1_BUFFER_SIZE]; + snprintf_P(buffer, sizeof(buffer), PSTR("AT+UPDATE=\"sequence\":\"%d%03d\",\"switch\":\"%s\",\"colorR\":%d,\"colorG\":%d,\"colorB\":%d,\"bright\":%d,\"mode\":%d"), + LocalTime(), millis()%1000, + Snfl1.power ? "on" : "off", + Snfl1.color[0], Snfl1.color[1], Snfl1.color[2], + Snfl1.dimmer, + SONOFF_L1_MODE_COLORFUL); + + SnfL1Send(buffer); +} + +// SONOFF_L1_MODE_SYNC_TO_MUSIC +void SnfL1ModeMusic(uint32_t sensitive, uint32_t speed) { + char buffer[SONOFF_L1_BUFFER_SIZE]; + snprintf_P(buffer, sizeof(buffer), PSTR("AT+UPDATE=\"sequence\":\"%d%03d\",\"mode\":%d,\"sensitive\":%d,\"speed\":%d"), + LocalTime(), millis()%1000, + SONOFF_L1_MODE_SYNC_TO_MUSIC, + sensitive, + speed + ); + + SnfL1Send(buffer); +} + +void CmndMusicSync(void) +{ + // Format is L1MusicSync sensitivity,speed + // sensitivity 1..10, speed 1..100 + char *p; + strtok_r(XdrvMailbox.data, ",", &p); + if (0 == XdrvMailbox.payload) { + SnfL1SetChannels(); + + ResponseCmndDone(); + } + else if (p != nullptr) { + uint32_t sen = strtol(XdrvMailbox.data, nullptr, 0); + uint32_t spd = strtol(p, nullptr, 0); + if ( (sen >= 0) && (sen <= 10) && (spd >= 0) && (spd <= 100) ) { + SnfL1ModeMusic(sen, spd); + ResponseCmndDone(); + } + else { + return; // error + } + } +} /*********************************************************************************************\ * Interface \*********************************************************************************************/ @@ -336,6 +391,9 @@ bool Xlgt05(uint8_t function) case FUNC_MODULE_INIT: result = SnfL1ModuleSelected(); break; + case FUNC_COMMAND: + result = DecodeCommand(kL1Commands, L1Command); + break; } return result; }