Skip to content

Commit

Permalink
finishing touch
Browse files Browse the repository at this point in the history
  • Loading branch information
d03n3rfr1tz3 committed Apr 28, 2024
1 parent aa06e4a commit bf62d97
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 22 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ Shows the clock channel.
| Parameter | Description |
| --- | --- |
| `clock` | The style of the clock. Accepts a number between 0 and 9. <br/> `0` = Fullscreen, `1` = Rainbow, `2` = Boxed, `3` = Analog square, <br/> `4` = Fullscreen negative, `5` = Analog round, `6` = Widescreen |
| `twentyfour` | Changes between 12h or 24h format. <br/> `0` = 12h, `1` = 24h. Defaults to 24h. |
| `twentyfour` | Changes between 12h or 24h format. <br/> `0` = 12h, `1` = 24h. Defaults to 24h. Doesn't actually change the current time. |
| `weather` | Actives or deactivates showing the weather with `0` or `1`. |
| `temp` | Actives or deactivates showing the temperature with `0` or `1`. |
| `calendar` | Actives or deactivates showing the calendar date with `0` or `1`. |
Expand Down Expand Up @@ -330,15 +330,15 @@ MODE keyboard 0
#### MODE light
Shows the light channel.

`MODE light [color] [brightness] [power]`
`MODE light [brightness] [color] [power]`
| Parameter | Description |
| --- | --- |
| `color` | The color of the clock in the typical RGB HEX format. Example: `FF0000` for red. |
| `brightness` | The brightness value between 0 and 100. |
| `color` | The color of the clock in the typical RGB HEX format. Example: `FF0000` for red. |
| `power` | Activates or deactivates powering the LED panel. |

```
MODE light FF0000 100 1
MODE light 100 FF0000 1
```

#### MODE lyrics
Expand Down
2 changes: 1 addition & 1 deletion src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

/* TCP Configuration */
#define TCP_PORT 7777
#define TCP_MAX 5
#define TCP_MAX 3

/* MQTT Configuration */
#define MQTT_CLIENT "ESP32-Divoom"
Expand Down
22 changes: 11 additions & 11 deletions src/divoom/divoom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,15 @@ data_commands_t* Divoom::parseMode(char *buffer, size_t size) {
char* content = buffer + offset;
size -= offset;

char* color = nullptr;
uint8_t brightness = 0;
bool power = 0;
char* color = nullptr;
bool power = 1;

char *token = strtok(content, " ");
if (token != NULL) color = token;
if (token != NULL) brightness = strtoul(token, NULL, 10);

token = strtok(NULL, " ");
if (token != NULL) brightness = strtoul(token, NULL, 10);
if (token != NULL) color = token;

token = strtok(NULL, " ");
if (token != NULL) power = strtoul(token, NULL, 10);
Expand Down Expand Up @@ -635,7 +635,7 @@ void Divoom::show_light(char* color, uint8_t brightness, bool power) {
}

buffer[index++] = brightness; // brightness
buffer[index++] = color != nullptr ? 0x01 : 0x00; // effect mode
buffer[index++] = color == nullptr ? 0x01 : 0x00; // effect mode
buffer[index++] = power ? 0x01 : 0x00; // power on/off

command(&(commands.command[commands.count++]), buffer, index);
Expand Down Expand Up @@ -707,12 +707,12 @@ void Divoom::show_scoreboard(uint8_t version, uint16_t player1, uint16_t player2
buffer[index++] = 0x06; // scoreboard view
buffer[index++] = 0x00;

buffer[index++] = (player1 & 0xff); // player1
buffer[index++] = (player1 >> 8); // player1

buffer[index++] = (player2 & 0xff); // player2
buffer[index++] = (player2 >> 8); // player2

buffer[index++] = (player1 & 0xff); // player1
buffer[index++] = (player1 >> 8); // player1

command(&(commands.command[commands.count++]), buffer, index);
}

Expand All @@ -724,12 +724,12 @@ void Divoom::show_scoreboard(uint8_t version, uint16_t player1, uint16_t player2
buffer[index++] = 0x01; // scoreboard tool
buffer[index++] = 0x01; // show it

buffer[index++] = (player1 & 0xff); // player1
buffer[index++] = (player1 >> 8); // player1

buffer[index++] = (player2 & 0xff); // player2
buffer[index++] = (player2 >> 8); // player2

buffer[index++] = (player1 & 0xff); // player1
buffer[index++] = (player1 >> 8); // player1

command(&(commands.command[commands.count++]), buffer, index);
}
}
Expand Down
4 changes: 0 additions & 4 deletions src/hardware/wifictl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,6 @@ void WifiHandler::connected(WiFiEvent_t event, WiFiEventInfo_t info) {

MDNS.begin(WIFI_NAME);
MDNS.addService("_divoom_esp32", "_tcp", TCP_PORT);

if (MqttInput::check()) {
MqttInput::update();
}
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/input/mqtt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ void MqttInput::setup() {
void MqttInput::loop() {
if (strlen(MQTT_HOST) == 0) return;

if (getElapsed(timer) > 10000) {
bool isWifiConnected = WifiHandler::check(true);
if (getElapsed(timer) > 15000 || (isWifiConnected && !wasWifiConnected)) {
wasWifiConnected = isWifiConnected;
timer = millis();

if (check()) {
Expand All @@ -49,6 +51,7 @@ void MqttInput::loop() {
*/
bool MqttInput::check(void) {
if (strlen(MQTT_HOST) == 0) return false;
if (!wasWifiConnected) return false;

if (mqttClient.connected())
{
Expand Down Expand Up @@ -81,6 +84,7 @@ bool MqttInput::check(void) {
*/
void MqttInput::update(void) {
if (strlen(MQTT_HOST) == 0) return;
if (!isConnected) return;

char topicState[strlen(MQTT_TOPIC) + strlen("proxy")];
snprintf(topicState, sizeof( topicState ), MQTT_TOPIC, "proxy");
Expand Down
1 change: 1 addition & 0 deletions src/input/mqtt.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

private:
inline static bool isConnected;
inline static bool wasWifiConnected;
inline static unsigned long timer;

static void parse(char* topic, uint8_t* payload, size_t size);
Expand Down
2 changes: 1 addition & 1 deletion src/input/tcp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void TcpInput::setup() {
tcpServer.onClient(connection, &tcpServer);
tcpServer.begin();

parsePacketQueue = xQueueCreate(10, sizeof(data_packet_t));
parsePacketQueue = xQueueCreate(5, sizeof(data_packet_t));
xTaskCreatePinnedToCore(queue, "ParsePacketTask", 4096, NULL, 1, &parsePacketHandle, 1);
}

Expand Down

0 comments on commit bf62d97

Please sign in to comment.