Skip to content

Commit

Permalink
added sleep mode
Browse files Browse the repository at this point in the history
  • Loading branch information
d03n3rfr1tz3 committed Jun 22, 2024
1 parent 8d66cf4 commit e79487a
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. <br/> `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.

Expand Down
76 changes: 76 additions & 0 deletions src/divoom/divoom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
*/
Expand Down
1 change: 1 addition & 0 deletions src/divoom/divoom.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit e79487a

Please sign in to comment.