This commit is contained in:
parent
2b07102b69
commit
c7c19a8aa8
5 changed files with 91 additions and 59 deletions
102
firmware/lux.cpp
102
firmware/lux.cpp
|
@ -46,6 +46,8 @@ volatile rgba_t top_color;
|
||||||
volatile rgba_t bottom_color;
|
volatile rgba_t bottom_color;
|
||||||
volatile uint16_t light_value;
|
volatile uint16_t light_value;
|
||||||
|
|
||||||
|
volatile int32_t led_amount = 240;
|
||||||
|
|
||||||
volatile uint16_t peripheral_version;
|
volatile uint16_t peripheral_version;
|
||||||
|
|
||||||
|
|
||||||
|
@ -250,21 +252,23 @@ extern "C" [[noreturn]] void lux_task(void *pvParameters) {
|
||||||
fiatlux::signal::setup();
|
fiatlux::signal::setup();
|
||||||
fiatlux::relais::setup();
|
fiatlux::relais::setup();
|
||||||
|
|
||||||
bus_init();
|
//bus_init();
|
||||||
|
|
||||||
int32_t lux_ws2812_number = 240;
|
led_amount = 240;
|
||||||
auto ret = sysparam_get_int32("lux_ws2812_number", &lux_ws2812_number);
|
auto ret = sysparam_get_int32("led_amount", (int32_t*)&led_amount);
|
||||||
if(ret != SYSPARAM_OK)
|
if(ret != SYSPARAM_OK)
|
||||||
lux_ws2812_number = 240;
|
led_amount = 240;
|
||||||
|
|
||||||
int32_t lux_apa10xx_number = 40;
|
//int32_t lux_apa10xx_number = 40;
|
||||||
ret = sysparam_get_int32("lux_apa10xx_number", &lux_apa10xx_number);
|
//ret = sysparam_get_int32("lux_apa10xx_number", &lux_apa10xx_number);
|
||||||
if(ret != SYSPARAM_OK)
|
//if(ret != SYSPARAM_OK)
|
||||||
lux_apa10xx_number = 40;
|
// lux_apa10xx_number = 40;
|
||||||
|
|
||||||
ws2812_pixel_t pixels[lux_ws2812_number];
|
int32_t current_led_amount = led_amount;
|
||||||
ws2812_i2s_init(lux_ws2812_number, PIXEL_RGBW);
|
|
||||||
memset(pixels, 0, sizeof(ws2812_pixel_t) * lux_ws2812_number);
|
ws2812_pixel_t pixels[current_led_amount];
|
||||||
|
ws2812_i2s_init(current_led_amount, PIXEL_RGBW);
|
||||||
|
memset(pixels, 0, sizeof(ws2812_pixel_t) * current_led_amount);
|
||||||
|
|
||||||
//apa10xx_pixel_t leds[lux_apa10xx_number]; // TODO
|
//apa10xx_pixel_t leds[lux_apa10xx_number]; // TODO
|
||||||
|
|
||||||
|
@ -285,52 +289,52 @@ extern "C" [[noreturn]] void lux_task(void *pvParameters) {
|
||||||
- [2*n+1] = 8bit PWM value
|
- [2*n+1] = 8bit PWM value
|
||||||
*/
|
*/
|
||||||
|
|
||||||
{
|
//{
|
||||||
peripheral_version = bus_get_version();
|
// peripheral_version = bus_get_version();
|
||||||
syslog("peripheral_version: ");
|
// syslog("peripheral_version: ");
|
||||||
syslog_i32(peripheral_version);
|
// syslog_i32(peripheral_version);
|
||||||
syslog("\n");
|
// syslog("\n");
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
light_value = 0xFFF;
|
//light_value = 0xFFF;
|
||||||
uint16_t last_light_value = 0xFFFF;
|
//uint16_t last_light_value = 0xFFFF;
|
||||||
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|
||||||
fiatlux::signal::write_data(false);
|
//fiatlux::signal::write_data(false);
|
||||||
|
|
||||||
if(last_light_value != light_value) {
|
//if(last_light_value != light_value) {
|
||||||
|
//
|
||||||
|
// syslog("# ");
|
||||||
|
// syslog_i32(light_value);
|
||||||
|
// syslog("\n");
|
||||||
|
//
|
||||||
|
// bool ok = set_cc48(light_value);
|
||||||
|
//
|
||||||
|
// if(ok) {
|
||||||
|
// last_light_value = light_value;
|
||||||
|
// vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||||
|
// } else {
|
||||||
|
// syslog("reset_bus\n");
|
||||||
|
// reset_bus();
|
||||||
|
// vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//} else {
|
||||||
|
// bool ping = bus_ping();
|
||||||
|
// if(!ping) {
|
||||||
|
// syslog("ping: reset_bus\n");
|
||||||
|
// reset_bus();
|
||||||
|
// vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
syslog("# ");
|
for (int i = 0; i < current_led_amount; i++)
|
||||||
syslog_i32(light_value);
|
|
||||||
syslog("\n");
|
|
||||||
|
|
||||||
bool ok = set_cc48(light_value);
|
|
||||||
|
|
||||||
if(ok) {
|
|
||||||
last_light_value = light_value;
|
|
||||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
|
||||||
} else {
|
|
||||||
syslog("reset_bus\n");
|
|
||||||
reset_bus();
|
|
||||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
bool ping = bus_ping();
|
|
||||||
if(!ping) {
|
|
||||||
syslog("ping: reset_bus\n");
|
|
||||||
reset_bus();
|
|
||||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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}};
|
||||||
|
|
||||||
for (int i = 120; i < 240; i++)
|
//for (int i = 120; i < 240; i++)
|
||||||
pixels[i] = {{bottom_color.r, bottom_color.g, bottom_color.b, bottom_color.a}};
|
// pixels[i] = {{bottom_color.r, bottom_color.g, bottom_color.b, bottom_color.a}};
|
||||||
|
|
||||||
ws2812_i2s_update(pixels, PIXEL_RGBW);
|
ws2812_i2s_update(pixels, PIXEL_RGBW);
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,8 @@ extern volatile rgba_t top_color;
|
||||||
extern volatile rgba_t bottom_color;
|
extern volatile rgba_t bottom_color;
|
||||||
extern volatile uint16_t light_value;
|
extern volatile uint16_t light_value;
|
||||||
|
|
||||||
|
extern volatile int32_t led_amount;
|
||||||
|
|
||||||
extern volatile uint16_t peripheral_version;
|
extern volatile uint16_t peripheral_version;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -13,6 +13,7 @@ namespace fiatlux {
|
||||||
VOLTAGE_INFO,
|
VOLTAGE_INFO,
|
||||||
SYSTEM_INFO,
|
SYSTEM_INFO,
|
||||||
LIGHTS,
|
LIGHTS,
|
||||||
|
LIGHT_CONFIG,
|
||||||
count
|
count
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -26,6 +27,7 @@ namespace fiatlux {
|
||||||
"VOLTAGE_INFO",
|
"VOLTAGE_INFO",
|
||||||
"SYSTEM_INFO",
|
"SYSTEM_INFO",
|
||||||
"LIGHTS",
|
"LIGHTS",
|
||||||
|
"LIGHT_CONFIG",
|
||||||
"out of range"
|
"out of range"
|
||||||
};
|
};
|
||||||
if(val < id::count)
|
if(val < id::count)
|
||||||
|
@ -83,5 +85,9 @@ namespace fiatlux {
|
||||||
uint32_t bottom_color;
|
uint32_t bottom_color;
|
||||||
uint16_t white_brightness;
|
uint16_t white_brightness;
|
||||||
} __attribute__((packed));
|
} __attribute__((packed));
|
||||||
|
|
||||||
|
struct light_config {
|
||||||
|
int32_t led_amount;
|
||||||
|
} __attribute__((packed));
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -42,13 +42,14 @@ struct {
|
||||||
bool wifi;
|
bool wifi;
|
||||||
bool voltage;
|
bool voltage;
|
||||||
bool lights;
|
bool lights;
|
||||||
|
bool light_config;
|
||||||
} 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, true};
|
has_changed = {true, true, true, true, true, true};
|
||||||
syslog_attach();
|
syslog_attach();
|
||||||
unsigned local_log_tail = syslog_current_tail();
|
unsigned local_log_tail = syslog_current_tail();
|
||||||
|
|
||||||
|
@ -124,6 +125,16 @@ void websocket_task(void *pvParameter) {
|
||||||
has_changed.lights = false;
|
has_changed.lights = false;
|
||||||
UNLOCK_TCPIP_CORE();
|
UNLOCK_TCPIP_CORE();
|
||||||
|
|
||||||
|
taskYIELD();
|
||||||
|
} else if(has_changed.light_config) {
|
||||||
|
messages::frame<messages::light_config> frame;
|
||||||
|
frame.cmd = messages::LIGHT_CONFIG;
|
||||||
|
frame.msg.led_amount = led_amount;
|
||||||
|
LOCK_TCPIP_CORE();
|
||||||
|
websocket_write(pcb, (unsigned char *) &frame, sizeof(frame), WS_BIN_MODE);
|
||||||
|
has_changed.light_config = false;
|
||||||
|
UNLOCK_TCPIP_CORE();
|
||||||
|
|
||||||
taskYIELD();
|
taskYIELD();
|
||||||
} else if(has_changed.connection) {
|
} else if(has_changed.connection) {
|
||||||
timeval tv{};
|
timeval tv{};
|
||||||
|
@ -323,6 +334,18 @@ void websocket_cb(struct tcp_pcb *pcb, char *data, u16_t data_len,
|
||||||
res.cmd = (messages::id) 'J';
|
res.cmd = (messages::id) 'J';
|
||||||
res.ret = OK;
|
res.ret = OK;
|
||||||
res.val = 1;
|
res.val = 1;
|
||||||
|
} else if(data[0] == 'K') {
|
||||||
|
uint32_t val = data[7] | (data[6] << 8) | (data[5] << 16) | (data[4] << 24);
|
||||||
|
led_amount = data[7] | (data[6] << 8);
|
||||||
|
sysparam_set_int32("led_amount", led_amount);
|
||||||
|
has_changed.light_config = true;
|
||||||
|
syslog("K");
|
||||||
|
syslog_i32(val);
|
||||||
|
syslog("\n");
|
||||||
|
//signal_led(false);
|
||||||
|
res.cmd = (messages::id) 'K';
|
||||||
|
res.ret = OK;
|
||||||
|
res.val = 1;
|
||||||
} else if(data[0] == 'D') {
|
} else if(data[0] == 'D') {
|
||||||
// Disable LED
|
// Disable LED
|
||||||
syslog("G\n");
|
syslog("G\n");
|
||||||
|
|
|
@ -272,12 +272,7 @@
|
||||||
</label><br>
|
</label><br>
|
||||||
<label>
|
<label>
|
||||||
<span>change bottom color</span>
|
<span>change bottom color</span>
|
||||||
<input type="color" oninput="colorBottom(this.value)" class="postfill_bottom_color">
|
<input type="number" oninput="ledAmount(this.value)" class="postfill_led_amount">
|
||||||
</label><br>
|
|
||||||
<label>
|
|
||||||
<span>set white brightness</span>
|
|
||||||
<input type="range" min="0" max="4095" value="0" onchange="lightSlider(this.value)"
|
|
||||||
class="slider postfill_white_brightness">
|
|
||||||
</label>
|
</label>
|
||||||
</footer>
|
</footer>
|
||||||
</article>
|
</article>
|
||||||
|
@ -366,7 +361,7 @@
|
||||||
} 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", "LIGHTS"];
|
let cmds = ["NONE", "RESTART", "CLEAR_CONFIG", "FIRMWARE_FRAME", "FIRMWARE_CHECK", "VOLTAGE_INFO", "SYSTEM_INFO", "LIGHTS", "LIGHT_CONFIG"];
|
||||||
//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;
|
||||||
|
@ -390,6 +385,8 @@
|
||||||
data.top_color = htonl(dv.getUint32(1));
|
data.top_color = htonl(dv.getUint32(1));
|
||||||
data.bottom_color = htonl(dv.getUint32(5));
|
data.bottom_color = htonl(dv.getUint32(5));
|
||||||
data.white_brightness = htons(dv.getInt16(9));
|
data.white_brightness = htons(dv.getInt16(9));
|
||||||
|
} else if (cmd === "LIGHT_CONFIG") {
|
||||||
|
data.led_amount = htonl(dv.getUint32(1));
|
||||||
} 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") {
|
||||||
|
@ -511,10 +508,10 @@
|
||||||
wsWrite(header);
|
wsWrite(header);
|
||||||
}
|
}
|
||||||
|
|
||||||
function lightSlider(val) {
|
function ledAmount(val) {
|
||||||
var header = new ArrayBuffer(8);
|
var header = new ArrayBuffer(8);
|
||||||
var headerview = new DataView(header);
|
var headerview = new DataView(header);
|
||||||
headerview.setChar(0, 'J');
|
headerview.setChar(0, 'K');
|
||||||
headerview.setInt32(4, val);
|
headerview.setInt32(4, val);
|
||||||
console.log(buf2hex(header));
|
console.log(buf2hex(header));
|
||||||
wsWrite(header);
|
wsWrite(header);
|
||||||
|
|
Loading…
Reference in a new issue