This commit is contained in:
j3d1 2023-01-19 18:11:13 +01:00
parent 9de089083c
commit 1acaf657f0
6 changed files with 160 additions and 50 deletions

View file

@ -28,6 +28,9 @@ extern "C" {
using namespace fiatlux;
int version = 23;
#define vTaskDelayMs(ms) vTaskDelay((ms) / portTICK_PERIOD_MS)
uint16_t voltage_val;
@ -37,13 +40,14 @@ struct {
bool connection;
bool wifi;
bool voltage;
bool lights;
} has_changed;
void websocket_task(void *pvParameter) {
auto *pcb = (struct tcp_pcb *) pvParameter;
size_t connstarttime = xTaskGetTickCount();
has_changed = {true, true, true, true};
has_changed = {true, true, true, true, true};
syslog_attach();
unsigned local_log_tail = syslog_current_tail();
@ -92,6 +96,8 @@ void websocket_task(void *pvParameter) {
frame.msg.chipid = chip_id;
frame.msg.flashid = flash_id;
frame.msg.flashsize = flash_size;
frame.msg.version = version;
frame.msg.peripheral_version = peripheral_version;
//frame.msg. = ; // hostname
LOCK_TCPIP_CORE();
@ -105,6 +111,18 @@ void websocket_task(void *pvParameter) {
has_changed.global = false;
UNLOCK_TCPIP_CORE();*/
taskYIELD();
} else if(has_changed.lights) {
messages::frame<messages::lights> frame;
frame.cmd = messages::LIGHTS;
frame.msg.top_color = *(uint32_t*)&top_color;
frame.msg.bottom_color = *(uint32_t*)&bottom_color;
frame.msg.white_brightness = light_value;
LOCK_TCPIP_CORE();
websocket_write(pcb, (unsigned char *) &frame, sizeof(frame), WS_BIN_MODE);
has_changed.lights = false;
UNLOCK_TCPIP_CORE();
taskYIELD();
} else if(has_changed.connection) {
timeval tv{};
@ -265,6 +283,7 @@ void websocket_cb(struct tcp_pcb *pcb, char *data, u16_t data_len,
bottom_color.r = data[7];
bottom_color.g = data[6];
bottom_color.b = data[5];
has_changed.lights = true;
syslog("B");
syslog_i32(val);
syslog("\n");
@ -278,6 +297,7 @@ void websocket_cb(struct tcp_pcb *pcb, char *data, u16_t data_len,
top_color.r = data[7];
top_color.g = data[6];
top_color.b = data[5];
has_changed.lights = true;
syslog("T");
syslog_i32(val);
syslog("\n");
@ -289,6 +309,7 @@ void websocket_cb(struct tcp_pcb *pcb, char *data, u16_t data_len,
// Disable LED
uint32_t val = data[7] | (data[6] << 8) | (data[5] << 16) | (data[4] << 24);
light_value = data[7] | (data[6] << 8);
has_changed.lights = true;
syslog("J");
syslog_i32(val);
syslog("\n");