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

@ -36,10 +36,12 @@ struct apa10xx_pixel_t {
uint8_t r = 0; uint8_t r = 0;
}; };
rgba_t top_color; volatile rgba_t top_color;
rgba_t bottom_color; volatile rgba_t bottom_color;
volatile uint16_t light_value; volatile uint16_t light_value;
volatile uint16_t peripheral_version;
namespace fiatlux { namespace fiatlux {
struct hal_error_t { struct hal_error_t {
@ -237,12 +239,28 @@ uint16_t spi_transfer_16_duplex(uint8_t bus, uint32_t val) {
return in; return in;
}; };
void reset_bus() {
gpio_write(4, false);
for (volatile int k = 0; k < 128; ++k);
gpio_write(4, true);
}
/* This task uses the high level GPIO API (esp_gpio.h) to blink an LED. /* This task uses the high level GPIO API (esp_gpio.h) to blink an LED.
* *
*/ */
extern "C" [[noreturn]] void lux_task(void *pvParameters) { extern "C" [[noreturn]] void lux_task(void *pvParameters) {
fiatlux::signal::setup();
fiatlux::relais::setup();
gpio_write(4, false);
for (volatile int k = 0; k < 512 * 2; ++k);
gpio_write(4, true);
gpio_enable(4, GPIO_OUT_OPEN_DRAIN);
gpio_write(4, true);
for (volatile int k = 0; k < 512 * 4; ++k);
int32_t lux_ws2812_number = 240; int32_t lux_ws2812_number = 240;
auto ret = sysparam_get_int32("lux_ws2812_number", &lux_ws2812_number); auto ret = sysparam_get_int32("lux_ws2812_number", &lux_ws2812_number);
if(ret != SYSPARAM_OK) if(ret != SYSPARAM_OK)
@ -266,9 +284,6 @@ extern "C" [[noreturn]] void lux_task(void *pvParameters) {
//fiatlux::spi_dimmer::setup(); //fiatlux::spi_dimmer::setup();
fiatlux::signal::setup();
fiatlux::relais::setup();
//fiatlux::apa10x::setup(); //fiatlux::apa10x::setup();
spi_init(1, SPI_MODE0, SPI_FREQ_DIV_2M, true, SPI_BIG_ENDIAN, false); spi_init(1, SPI_MODE0, SPI_FREQ_DIV_2M, true, SPI_BIG_ENDIAN, false);
@ -287,8 +302,20 @@ extern "C" [[noreturn]] void lux_task(void *pvParameters) {
uint16_t _; uint16_t _;
} frame = {._=0}; } frame = {._=0};
light_value = 0xFFF; {
frame.addr = 15;
frame.dat = 0;
spi_transfer_16_duplex(1, frame._);
for (volatile int k = 0; k < 512 * 2; ++k);
uint16_t reply = spi_transfer_16_duplex(1, 0x0000);
peripheral_version = reply;
for (volatile int k = 0; k < 512 * 2; ++k);
syslog("peripheral_version: ");
syslog_i32(peripheral_version);
syslog("\n");
}
light_value = 0xFFF;
uint16_t last_light_value = 0xFFFF; uint16_t last_light_value = 0xFFFF;
while (true) { while (true) {
@ -301,30 +328,57 @@ extern "C" [[noreturn]] void lux_task(void *pvParameters) {
syslog_i32(light_value); syslog_i32(light_value);
syslog("\n"); syslog("\n");
uint16_t last_frame = 0x0000;
uint16_t reply = 0x0000;
uint8_t error_count = 0;
for (int i = 0; i < 6; ++i) { for (int i = 0; i < 6; ++i) {
frame.addr = i; frame.addr = i + 1;
frame.dat = light_value; frame.dat = light_value;
uint16_t reply = spi_transfer_16_duplex(1, frame._); reply = spi_transfer_16_duplex(1, frame._);
/*if(!i) { if(reply != last_frame)
error_count++;
{
syslog(" > "); syslog(" > ");
syslog_i32(frame._); syslog_i32(frame._);
if(reply) {
syslog(" < "); syslog(" < ");
syslog_i32(reply); syslog_i32(reply);
} syslog(" -- ");
syslog_i32(last_frame);
syslog("\n"); syslog("\n");
}*/
for (volatile int k = 0; k < 512; ++k);
} }
last_frame = frame._;
for (volatile int k = 0; k < 512 * 2; ++k);
}
reply = spi_transfer_16_duplex(1, 0x0000);
if(reply != last_frame)
error_count++;
{
syslog(" > ");
syslog_i32(frame._);
syslog(" < ");
syslog_i32(reply);
syslog(" -- ");
syslog_i32(last_frame);
syslog("\n");
}
if(!error_count) {
last_light_value = light_value; last_light_value = light_value;
} else {
syslog("reset_bus\n");
reset_bus();
} }
vTaskDelay(200 / portTICK_PERIOD_MS); vTaskDelay(5000 / portTICK_PERIOD_MS);
}
for (int i = 0; i < 120; i++) for (int i = 0; i < 120; i++)
pixels[i] = {{top_color.r, top_color.g, top_color.b, top_color.a}}; pixels[i] = {{top_color.r, top_color.g, top_color.b, top_color.a}};
@ -334,6 +388,8 @@ extern "C" [[noreturn]] void lux_task(void *pvParameters) {
ws2812_i2s_update(pixels, PIXEL_RGBW); ws2812_i2s_update(pixels, PIXEL_RGBW);
vTaskDelay(200 / portTICK_PERIOD_MS);
/*//fiatlux::write_channel((uint8_t *) &leds[0], lux_apa10xx_number, 4, fiatlux::hal_module_t::APA10X); /*//fiatlux::write_channel((uint8_t *) &leds[0], lux_apa10xx_number, 4, fiatlux::hal_module_t::APA10X);
vTaskDelay(200 / portTICK_PERIOD_MS); vTaskDelay(200 / portTICK_PERIOD_MS);
fiatlux::relais::write_data(true, false); fiatlux::relais::write_data(true, false);

View file

@ -22,10 +22,12 @@ typedef struct {
uint8_t a; uint8_t a;
} rgba_t; } rgba_t;
extern rgba_t top_color; extern volatile rgba_t top_color;
extern rgba_t bottom_color; extern volatile rgba_t bottom_color;
extern volatile uint16_t light_value; extern volatile uint16_t light_value;
extern volatile uint16_t peripheral_version;
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View file

@ -12,6 +12,7 @@ namespace fiatlux {
FIRMWARE_CHECK, FIRMWARE_CHECK,
VOLTAGE_INFO, VOLTAGE_INFO,
SYSTEM_INFO, SYSTEM_INFO,
LIGHTS,
count count
}; };
@ -24,6 +25,7 @@ namespace fiatlux {
"FIRMWARE_CHECK", "FIRMWARE_CHECK",
"VOLTAGE_INFO", "VOLTAGE_INFO",
"SYSTEM_INFO", "SYSTEM_INFO",
"LIGHTS",
"out of range" "out of range"
}; };
if(val < id::count) if(val < id::count)
@ -61,6 +63,9 @@ namespace fiatlux {
uint32_t chipid; uint32_t chipid;
uint32_t flashid; uint32_t flashid;
uint32_t flashsize; uint32_t flashsize;
uint16_t version;
uint16_t peripheral_version;
/* /*
" \"hostname\" : \"%s\"" " \"hostname\" : \"%s\""
"}" "}"
@ -72,5 +77,11 @@ namespace fiatlux {
uint8_t ret; uint8_t ret;
uint16_t val; uint16_t val;
} __attribute__((packed)); } __attribute__((packed));
struct lights {
uint32_t top_color;
uint32_t bottom_color;
uint16_t white_brightness;
} __attribute__((packed));
} }
} }

View file

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

View file

@ -176,7 +176,11 @@
</div> </div>
<div class="row"> <div class="row">
<span>Firmware Version</span> <span>Firmware Version</span>
<span>N/A</span> <span><span class="postfill_firmware_version">N/A</span></span>
</div>
<div class="row">
<span>Peripheral Version</span>
<span><span class="postfill_peripheral_version">N/A</span></span>
</div> </div>
<div class="row"> <div class="row">
<span>Flash ID</span> <span>Flash ID</span>
@ -261,19 +265,19 @@
<label> <label>
<input type="checkbox" name="onoffswitch" id="led-switch" onclick="gpio(this.checked)"> <input type="checkbox" name="onoffswitch" id="led-switch" onclick="gpio(this.checked)">
<span class="toggle button">toggle signal led</span> <span class="toggle button">toggle signal led</span>
</label> </label><br>
<label> <label>
<span>toggle signal led</span> <span>change top color</span>
<input type="color" oninput="colorTop(this.value)"> <input type="color" oninput="colorTop(this.value)" class="postfill_top_color">
</label> </label><br>
<label> <label>
<span>toggle signal led</span> <span>change bottom color</span>
<input type="color" oninput="colorBottom(this.value)"> <input type="color" oninput="colorBottom(this.value)" class="postfill_bottom_color">
</label> </label><br>
<label> <label>
<span>toggle signal led</span> <span>set white brightness</span>
<input type="range" min="0" max="4096" value="0" class="slider" <input type="range" min="0" max="4095" value="0" onchange="lightSlider(this.value)"
oninput="lightSlider(this.value)"> class="slider postfill_white_brightness">
</label> </label>
</footer> </footer>
@ -358,12 +362,12 @@
function onMessage(evt) { function onMessage(evt) {
retries = 0; retries = 0;
if (typeof evt.data == 'string') { if (typeof evt.data == 'string') {
var cmd = "JSON";
var data = JSON.parse(evt.data); var data = JSON.parse(evt.data);
console.log("deprecated json:", data);
} else { } else {
var data = {}; var data = {};
var dv = new DataView(evt.data); var dv = new DataView(evt.data);
let cmds = ["NONE", "RESTART", "CLEAR_CONFIG", "FIRMWARE_FRAME", "FIRMWARE_CHECK", "VOLTAGE_INFO", "SYSTEM_INFO"]; let cmds = ["NONE", "RESTART", "CLEAR_CONFIG", "FIRMWARE_FRAME", "FIRMWARE_CHECK", "VOLTAGE_INFO", "SYSTEM_INFO", "LIGHTS"];
//console.log("[0]", dv.getUint8(0)); //console.log("[0]", dv.getUint8(0));
let fst = dv.getUint8(0); let fst = dv.getUint8(0);
var cmd; var cmd;
@ -381,6 +385,12 @@
data.chipid = Number(htonl(dv.getUint32(13))).toString(16); data.chipid = Number(htonl(dv.getUint32(13))).toString(16);
data.flashid = Number(htonl(dv.getUint32(17))).toString(16); data.flashid = Number(htonl(dv.getUint32(17))).toString(16);
data.flashsize = htonl(dv.getUint32(21)); data.flashsize = htonl(dv.getUint32(21));
data.firmware_version = htons(dv.getUint16(25));
data.peripheral_version = htons(dv.getUint16(27));
} else if (cmd === "LIGHTS") {
data.top_color = htonl(dv.getUint32(1));
data.bottom_color = htonl(dv.getUint32(5));
data.white_brightness = htons(dv.getInt16(9));
} else if (cmd === "VOLTAGE_INFO") { } else if (cmd === "VOLTAGE_INFO") {
console.log(cmd, buf2hex(evt.data)); console.log(cmd, buf2hex(evt.data));
} else if (cmd === "G") { } else if (cmd === "G") {
@ -404,18 +414,25 @@
} else { } else {
console.log("[0]", dv.getUint8(0)); console.log("[0]", dv.getUint8(0));
console.log('unknown command', cmd, val); console.log('unknown command', cmd, val);
console.log(cmd); console.log(fst, cmd);
} }
} }
console.log(cmd, data);
for (const [key, value] of Object.entries(data)) { for (const [key, value] of Object.entries(data)) {
const elements = document.querySelectorAll(".postfill_" + key); const elements = document.querySelectorAll(".postfill_" + key);
if (!elements.length) if (!elements.length)
unused_values[key] = value; unused_values[key] = value;
else else
for (i = 0; i < elements.length; ++i) { for (i = 0; i < elements.length; ++i) {
if (elements[i].type === "color") {
elements[i].value = "#" + (value).toString(16).padStart(6, '0');
} else if (elements[i].type === "range") {
elements[i].value = value;
} else {
elements[i].innerHTML = value; elements[i].innerHTML = value;
} }
} }
}
document.getElementById("unused_values").innerHTML = JSON.stringify(unused_values); document.getElementById("unused_values").innerHTML = JSON.stringify(unused_values);
} }

View file

@ -144,6 +144,7 @@ extern "C" void wifi_task(void *pvParameters) {
int8_t wifi_ap_enable = 1; int8_t wifi_ap_enable = 1;
sysparam_get_int8("wifi_sta_enable", &wifi_sta_enable); sysparam_get_int8("wifi_sta_enable", &wifi_sta_enable);
sysparam_get_int8("wifi_ap_enable", &wifi_ap_enable); sysparam_get_int8("wifi_ap_enable", &wifi_ap_enable);
wifi_ap_enable = 0;
if(!wifi_sta_enable) if(!wifi_sta_enable)
wifi_ap_enable = 1; wifi_ap_enable = 1;
@ -352,9 +353,11 @@ extern "C" void wifi_task(void *pvParameters) {
uint8_t retries = 30; uint8_t retries = 30;
while (1) { while (1) {
retries = 30;
while ((status != STATION_GOT_IP) && (retries)) { while ((status != STATION_GOT_IP) && (retries)) {
status = sdk_wifi_station_get_connect_status(); status = sdk_wifi_station_get_connect_status();
printf("%s: status = %d\n\r", __func__, status); printf("%s: status = %d [%d retries left]\n\r", __func__, status, retries);
if(status == STATION_WRONG_PASSWORD) { if(status == STATION_WRONG_PASSWORD) {
printf("WiFi: wrong password\n\r"); printf("WiFi: wrong password\n\r");
break; break;
@ -380,6 +383,6 @@ extern "C" void wifi_task(void *pvParameters) {
} }
printf("WiFi: disconnected\n\r"); printf("WiFi: disconnected\n\r");
sdk_wifi_station_disconnect(); sdk_wifi_station_disconnect();
vTaskDelay(1000 / portTICK_PERIOD_MS); vTaskDelay(10000 / portTICK_PERIOD_MS);
} }
} }