diff --git a/README.md b/README.md index 406d7a2..aba4c1b 100644 --- a/README.md +++ b/README.md @@ -419,6 +419,23 @@ Shows the scoreboard channel or tool. MODE scoreboard 0 1 2 ``` +#### MODE sleep +Shows the sleep mode, which plays soothing sounds, optionally with a timer and light. + +| Parameter | Description | +| --- | --- | +| `value` | Controls the start/stop state.
`0` = stop, `1` = start | +| `time` | The time in minutes after which to stop the sleep mode. | +| `sleepmode` | The sound effect to play. Check in the app how many options are available. Accepts a number. | +| `frequency` | The radio frequency to set. | +| `volume` | The volume value between 0 and 100. | +| `color` | The color of the display in the typical RGB HEX format. Example: `FF0000` for red. | +| `brightness` | The brightness value between 0 and 100. | + +``` +MODE sleep 1 30 4 85.1 100 FF0000 100 +``` + #### MODE timer Shows the timer tool. diff --git a/src/divoom/divoom.cpp b/src/divoom/divoom.cpp index 20aeccb..f3ae44f 100644 --- a/src/divoom/divoom.cpp +++ b/src/divoom/divoom.cpp @@ -352,6 +352,43 @@ data_commands_t* Divoom::parseMode(char *buffer, size_t size) { show_radio(value, frequency); } + if (size > strlen("sleep") && strncmp("sleep ", (const char*)buffer, strlen("sleep ")) == 0) { + size_t offset = strlen("sleep ") * sizeof(uint8_t); + char* content = buffer + offset; + size -= offset; + + bool value = 0; + uint8_t sleeptime = 0; + uint8_t sleepmode = 0; + float frequency = 0; + uint8_t volume = 0; + char* color = nullptr; + uint8_t brightness = 0; + + char *token = strtok(content, " "); + if (token != NULL) value = strtoul(token, NULL, 10); + + token = strtok(NULL, " "); + if (token != NULL) sleeptime = strtoul(token, NULL, 10); + + token = strtok(NULL, " "); + if (token != NULL) sleepmode = strtoul(token, NULL, 10); + + token = strtok(NULL, " "); + if (token != NULL) frequency = strtof(token, NULL); + + token = strtok(NULL, " "); + if (token != NULL) volume = strtoul(token, NULL, 10); + + token = strtok(NULL, " "); + if (token != NULL) color = token; + + token = strtok(NULL, " "); + if (token != NULL) brightness = strtoul(token, NULL, 10); + + show_sleep(value, sleeptime, sleepmode, frequency, volume, color, brightness); + } + if (size > strlen("game") && strncmp("game ", (const char*)buffer, strlen("game ")) == 0) { size_t offset = strlen("game ") * sizeof(uint8_t); char* content = buffer + offset; @@ -935,6 +972,45 @@ void Divoom::show_radio(bool value, float frequency) { } } +/** + * shows the sleep mode +*/ +void Divoom::show_sleep(bool value, uint8_t sleeptime, uint8_t sleepmode, float frequency, uint8_t volume, char* color, uint8_t brightness) { + size_t index = 0; + uint8_t buffer[4]; + + buffer[index++] = 0x40; // set radio + buffer[index++] = sleeptime; // sleep time in minutes + buffer[index++] = sleepmode; // sleep mode + buffer[index++] = value ? 0x01 : 0x00; // on/off + + uint16_t freq = frequency * 10; + if (freq > 1000) { // frequency + buffer[index++] = (uint8_t)(freq - 1000); + buffer[index++] = (uint8_t)(freq / 100); + } else { + buffer[index++] = (uint8_t)(freq % 100); + buffer[index++] = (uint8_t)(freq / 100); + } + + buffer[index++] = volume; // volume + + if (color != nullptr) { // color + uint32_t colorLong = strtoul(color, NULL, 16); + buffer[index++] = (colorLong >> 16 & 0xFF); + buffer[index++] = (colorLong >> 8 & 0xFF); + buffer[index++] = (colorLong & 0xFF); + } else { + buffer[index++] = 0x00; + buffer[index++] = 0x00; + buffer[index++] = 0x00; + } + + buffer[index++] = brightness; // brightness + + command(&(commands.command[commands.count++]), buffer, index); +} + /** * shows a game */ diff --git a/src/divoom/divoom.h b/src/divoom/divoom.h index 1c28883..f98ac47 100644 --- a/src/divoom/divoom.h +++ b/src/divoom/divoom.h @@ -40,6 +40,7 @@ void show_alarm(uint8_t value, char* time, bool* weekdays, uint8_t alarm, uint8_t trigger, float frequency, uint8_t volume); void show_memorial(uint8_t value, char* date, char* time, char* text, bool animate); void show_radio(bool value, float frequency); + void show_sleep(bool value, uint8_t sleeptime, uint8_t sleepmode, float frequency, uint8_t volume, char* color, uint8_t brightness); void show_game(int8_t value); void send_gamecontrol(uint8_t value);