This commit is contained in:
j3d1 2023-01-19 07:07:24 +01:00
parent be01d6b985
commit 9de089083c
8 changed files with 191 additions and 144 deletions

View file

@ -23,7 +23,7 @@ void user_init(void) {
wifi_available_semaphore = xSemaphoreCreateBinary(); wifi_available_semaphore = xSemaphoreCreateBinary();
xTaskCreate(mqtt_task, "mqtt_task", 1024, NULL, 1, NULL); //xTaskCreate(mqtt_task, "mqtt_task", 1024, NULL, 1, NULL);
xTaskCreate(wifi_task, "wifi_task", 1024, NULL, 1, NULL); xTaskCreate(wifi_task, "wifi_task", 1024, NULL, 1, NULL);
@ -34,7 +34,7 @@ void user_init(void) {
wifi_alive = xSemaphoreCreateBinary(); wifi_alive = xSemaphoreCreateBinary();
publish_queue = xQueueCreate(3, PUB_MSG_LEN); publish_queue = xQueueCreate(3, PUB_MSG_LEN);
xTaskCreate(&beat_task, "beat_task", 256, NULL, 3, NULL); //xTaskCreate(&beat_task, "beat_task", 256, NULL, 3, NULL);
} }

View file

@ -17,14 +17,14 @@ char str_i32[] = "00000000";
extern "C" void syslog_i32(const uint32_t val) { extern "C" void syslog_i32(const uint32_t val) {
str_i32[1] = hex_lookup[val & 0xF]; str_i32[7] = hex_lookup[val & 0xF];
str_i32[0] = hex_lookup[(val >> 4) & 0xF]; str_i32[6] = hex_lookup[(val >> 4) & 0xF];
str_i32[3] = hex_lookup[(val >> 8) & 0xF]; str_i32[5] = hex_lookup[(val >> 8) & 0xF];
str_i32[2] = hex_lookup[(val >> 12) & 0xF]; str_i32[4] = hex_lookup[(val >> 12) & 0xF];
str_i32[5] = hex_lookup[(val >> 16) & 0xF]; str_i32[3] = hex_lookup[(val >> 16) & 0xF];
str_i32[4] = hex_lookup[(val >> 20) & 0xF]; str_i32[2] = hex_lookup[(val >> 20) & 0xF];
str_i32[7] = hex_lookup[(val >> 24) & 0xF]; str_i32[1] = hex_lookup[(val >> 24) & 0xF];
str_i32[6] = hex_lookup[(val >> 28) & 0xF]; str_i32[0] = hex_lookup[(val >> 28) & 0xF];
// //
syslog(str_i32); syslog(str_i32);
} }

View file

@ -36,32 +36,9 @@ struct apa10xx_pixel_t {
uint8_t r = 0; uint8_t r = 0;
}; };
static ws2812_pixel_t next_colour(int i) {
ws2812_pixel_t colour = {{0, 0, 0, 0}};
if(i == 8) {
colour.white = 32;
} else {
colour.red = i & 1 ? 32 : 0;
colour.green = i & 2 ? 32 : 0;
colour.blue = i & 4 ? 32 : 0;
}
return colour;
}
static apa10xx_pixel_t next_color(int i) {
apa10xx_pixel_t colour;
colour.global.mod = 8;
colour.r = i & 1 ? 32 : 0;
colour.g = i & 2 ? 32 : 0;
colour.b = i & 4 ? 32 : 0;
return colour;
}
rgba_t top_color; rgba_t top_color;
rgba_t bottom_color; rgba_t bottom_color;
uint16_t dimmer_value; volatile uint16_t light_value;
namespace fiatlux { namespace fiatlux {
@ -246,6 +223,20 @@ extern "C" void signal_led(bool state) {
fiatlux::signal::write_data(state); fiatlux::signal::write_data(state);
} }
uint32_t spi_transfer_32_duplex(uint8_t bus, uint32_t val) {
uint32_t out = val;
uint32_t in;
spi_transfer(bus, &out, &in, 1, SPI_32BIT);
return in;
};
uint16_t spi_transfer_16_duplex(uint8_t bus, uint32_t val) {
uint16_t out = val;
uint16_t in;
spi_transfer(bus, &out, &in, 1, SPI_16BIT);
return in;
};
/* 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.
* *
@ -266,7 +257,7 @@ extern "C" [[noreturn]] void lux_task(void *pvParameters) {
ws2812_i2s_init(lux_ws2812_number, PIXEL_RGBW); ws2812_i2s_init(lux_ws2812_number, PIXEL_RGBW);
memset(pixels, 0, sizeof(ws2812_pixel_t) * lux_ws2812_number); memset(pixels, 0, sizeof(ws2812_pixel_t) * lux_ws2812_number);
apa10xx_pixel_t leds[lux_apa10xx_number]; //apa10xx_pixel_t leds[lux_apa10xx_number]; // TODO
//lux_apa102c_number //lux_apa102c_number
@ -279,7 +270,7 @@ extern "C" [[noreturn]] void lux_task(void *pvParameters) {
fiatlux::relais::setup(); fiatlux::relais::setup();
//fiatlux::apa10x::setup(); //fiatlux::apa10x::setup();
spi_init(1, SPI_MODE0, SPI_FREQ_DIV_500K, true, SPI_BIG_ENDIAN, false); spi_init(1, SPI_MODE0, SPI_FREQ_DIV_2M, true, SPI_BIG_ENDIAN, false);
/* /*
CC48 API: CC48 API:
@ -288,83 +279,70 @@ extern "C" [[noreturn]] void lux_task(void *pvParameters) {
- [2*n+1] = 8bit PWM value - [2*n+1] = 8bit PWM value
*/ */
uint32_t dummy = 0;
union { union {
struct { struct {
unsigned dat: 16; unsigned dat: 12;
unsigned addr: 12; unsigned addr: 4;
unsigned op: 4;
} __attribute__((packed)); } __attribute__((packed));
uint32_t _; uint16_t _;
} frame = {._=0}; } frame = {._=0};
dimmer_value = 255; light_value = 0xFFF;
uint16_t last_dimmer_value = 0; uint16_t last_light_value = 0xFFFF;
while (true) { while (true) {
/*for (int j = 0; j < 64; j++) {
for (int i = 0; i < 8; i++)
spi_dac(i, 64 * j);
//printf("> %d\n", 64*j);
vTaskDelay(100 / portTICK_PERIOD_MS);
}*/
/*gpio_write(gpio4, 1);
vTaskDelay(200 / portTICK_PERIOD_MS);
gpio_write(gpio4, 0);
for (int i = 0; i < 8; i++)
spi_dac(i, 0);
gpio_write(gpio5, 1);
vTaskDelay(200 / portTICK_PERIOD_MS);
gpio_write(gpio5, 0);*/
fiatlux::signal::write_data(false); fiatlux::signal::write_data(false);
for (int c = 8; c >= 0; c--) {
/*for (auto &pixel: pixels) { if(last_light_value != light_value) {
pixel = next_colour(c);
}*/
if(last_dimmer_value != dimmer_value) { syslog("# ");
for (int i = 0; i < 6; ++i) { syslog_i32(light_value);
syslog("\n");
frame.op = 0xA; for (int i = 0; i < 6; ++i) {
frame.addr = i * 2 + 1;
frame.dat = 255;
spi_transfer_32(1, frame._);
vTaskDelay(13 / portTICK_PERIOD_MS); frame.addr = i;
//for (volatile int i = 0; i < 512 * 32; ++i); frame.dat = light_value;
uint16_t reply = spi_transfer_16_duplex(1, frame._);
frame.op = 0xA; /*if(!i) {
frame.addr = i * 2; syslog(" > ");
frame.dat = dimmer_value << 4; syslog_i32(frame._);
spi_transfer_32(1, frame._);
vTaskDelay(13 / portTICK_PERIOD_MS); if(reply) {
//for (volatile int i = 0; i < 512 * 32; ++i); syslog(" < ");
} syslog_i32(reply);
//last_dimmer_value = dimmer_value; }
syslog("\n");
}*/
for (volatile int k = 0; k < 512; ++k);
} }
for (int i = 0; i < 120; i++) last_light_value = light_value;
pixels[i] = {{top_color.r, top_color.g, top_color.b, top_color.a}};
for (int i = 120; i < 240; i++)
pixels[i] = {{bottom_color.r, bottom_color.g, bottom_color.b, bottom_color.a}};
ws2812_i2s_update(pixels, PIXEL_RGBW);
//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);
for (int i = 0; i < 120; i++)
pixels[i] = {{top_color.r, top_color.g, top_color.b, top_color.a}};
for (int i = 120; i < 240; i++)
pixels[i] = {{bottom_color.r, bottom_color.g, bottom_color.b, bottom_color.a}};
ws2812_i2s_update(pixels, PIXEL_RGBW);
/*//fiatlux::write_channel((uint8_t *) &leds[0], lux_apa10xx_number, 4, fiatlux::hal_module_t::APA10X);
vTaskDelay(200 / portTICK_PERIOD_MS);
fiatlux::relais::write_data(true, false); fiatlux::relais::write_data(true, false);
vTaskDelay(200 / portTICK_PERIOD_MS); vTaskDelay(200 / portTICK_PERIOD_MS);
fiatlux::relais::write_data(false, true); fiatlux::relais::write_data(false, true);
vTaskDelay(200 / portTICK_PERIOD_MS); vTaskDelay(200 / portTICK_PERIOD_MS);
fiatlux::relais::write_data(false, false); fiatlux::relais::write_data(false, false);
fiatlux::signal::write_data(true); fiatlux::signal::write_data(true);
vTaskDelay(200 / portTICK_PERIOD_MS); vTaskDelay(200 / portTICK_PERIOD_MS);*/
} }

View file

@ -24,7 +24,7 @@ typedef struct {
extern rgba_t top_color; extern rgba_t top_color;
extern rgba_t bottom_color; extern rgba_t bottom_color;
extern uint16_t dimmer_value; extern volatile uint16_t light_value;
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -55,9 +55,9 @@ namespace fiatlux {
} __attribute__((packed)); } __attribute__((packed));
struct system_info { struct system_info {
unsigned walltime; uint32_t walltime;
unsigned uptime; uint32_t uptime;
int heap; int32_t heap;
uint32_t chipid; uint32_t chipid;
uint32_t flashid; uint32_t flashid;
uint32_t flashsize; uint32_t flashsize;

View file

@ -78,12 +78,14 @@ for file in httpFiles:
else: else:
response = b'HTTP/1.0 200 OK\r\n' response = b'HTTP/1.0 200 OK\r\n'
response += b"lwIP/1.4.1 (http://savannah.nongnu.org/projects/lwip)\r\n" response += b"lwIP/1.4.1 (http://savannah.nongnu.org/projects/lwip)\r\n"
#fext = file.split('.')[-1]
response += b'Content-type: ' + mimeType.encode() + b'\r\n' response += b'Content-type: ' + mimeType.encode() + b'\r\n'
binFile = open(file, 'rb') binFile = open(file, 'rb')
binData = binFile.read() binData = binFile.read()
compEff = False compEff = False
if args.minify: if args.minify:
# shell: binData | minify --html-keep-document-tags --mime text/html | minData
p = subprocess.Popen(["minify", "--html-keep-document-tags", "--mime", mimeType], stdin=subprocess.PIPE, p = subprocess.Popen(["minify", "--html-keep-document-tags", "--mime", mimeType], stdin=subprocess.PIPE,
stdout=subprocess.PIPE) stdout=subprocess.PIPE)
minData = p.communicate(binData)[0] minData = p.communicate(binData)[0]

View file

@ -30,7 +30,6 @@ using namespace fiatlux;
#define vTaskDelayMs(ms) vTaskDelay((ms) / portTICK_PERIOD_MS) #define vTaskDelayMs(ms) vTaskDelay((ms) / portTICK_PERIOD_MS)
uint16_t voltage_val; uint16_t voltage_val;
struct { struct {
@ -44,7 +43,7 @@ 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}; has_changed = {true, true, true, true};
syslog_attach(); syslog_attach();
unsigned local_log_tail = syslog_current_tail(); unsigned local_log_tail = syslog_current_tail();
@ -73,7 +72,7 @@ void websocket_task(void *pvParameter) {
} }
//Global Info //Global Info
if(false && has_changed.global) { if(has_changed.global) {
timeval tv{}; timeval tv{};
gettimeofday(&tv, nullptr); gettimeofday(&tv, nullptr);
size_t uptime = xTaskGetTickCount() * portTICK_PERIOD_MS / 1000; size_t uptime = xTaskGetTickCount() * portTICK_PERIOD_MS / 1000;
@ -95,6 +94,11 @@ void websocket_task(void *pvParameter) {
frame.msg.flashsize = flash_size; frame.msg.flashsize = flash_size;
//frame.msg. = ; // hostname //frame.msg. = ; // hostname
LOCK_TCPIP_CORE();
websocket_write(pcb, (unsigned char *) &frame, sizeof(frame), WS_BIN_MODE);
has_changed.global = false;
UNLOCK_TCPIP_CORE();
free(hostname); free(hostname);
/*LOCK_TCPIP_CORE(); /*LOCK_TCPIP_CORE();
websocket_write(pcb, (uint8_t * ) &frame, sizeof(frame), WS_BIN_MODE); websocket_write(pcb, (uint8_t * ) &frame, sizeof(frame), WS_BIN_MODE);
@ -107,13 +111,13 @@ void websocket_task(void *pvParameter) {
gettimeofday(&tv, nullptr); gettimeofday(&tv, nullptr);
size_t connuptime = (xTaskGetTickCount() - connstarttime) * portTICK_PERIOD_MS / 1000; size_t connuptime = (xTaskGetTickCount() - connstarttime) * portTICK_PERIOD_MS / 1000;
printf("conn %d: %d.%.%.%d <-> %d.%d.&d.%d \n", pcb->netif_idx, IP2STR(&pcb->local_ip), printf("conn %d: %d.%d.%d.%d <-> %d.%d.%d.%d \n", pcb->netif_idx, IP2STR(&pcb->local_ip),
IP2STR(&pcb->remote_ip)); IP2STR(&pcb->remote_ip));
char response[192]; char response[192];
size_t size_t
len = snprintf(response, sizeof(response), "{\"connage\" : \"%d\"," "\"clientip\" : \"" len = snprintf(response, sizeof(response), "{\"connage\" : \"%d\"," "\"clientip\" : \""
IPSTR IPSTR
"\"" "}", connuptime, IP2STR(&pcb->remote_ip)); "\"" "}", connuptime, IP2STR(&pcb->remote_ip));
if(len < sizeof(response)) { if(len < sizeof(response)) {
LOCK_TCPIP_CORE(); LOCK_TCPIP_CORE();
websocket_write(pcb, (unsigned char *) response, len, WS_TEXT_MODE); websocket_write(pcb, (unsigned char *) response, len, WS_TEXT_MODE);
@ -213,7 +217,7 @@ void websocket_task(void *pvParameter) {
res.ret = OK; res.ret = OK;
res.cmd = (messages::id) 'V'; res.cmd = (messages::id) 'V';
LOCK_TCPIP_CORE(); LOCK_TCPIP_CORE();
websocket_write(pcb, (uint8_t * ) & res, sizeof(res), WS_BIN_MODE); websocket_write(pcb, (uint8_t *) &res, sizeof(res), WS_BIN_MODE);
UNLOCK_TCPIP_CORE(); UNLOCK_TCPIP_CORE();
taskYIELD(); taskYIELD();
} else { } else {
@ -257,7 +261,7 @@ void websocket_cb(struct tcp_pcb *pcb, char *data, u16_t data_len,
res.ret = OK; res.ret = OK;
} else if(data[0] == 'B') { } else if(data[0] == 'B') {
// Disable LED // Disable LED
uint32_t val = data[4] | (data[5] << 8) | (data[6] << 16) | (data[7] << 24); uint32_t val = data[7] | (data[6] << 8) | (data[5] << 16) | (data[4] << 24);
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];
@ -270,17 +274,28 @@ void websocket_cb(struct tcp_pcb *pcb, char *data, u16_t data_len,
res.val = 1; res.val = 1;
} else if(data[0] == 'T') { } else if(data[0] == 'T') {
// Disable LED // Disable LED
uint32_t val = data[4] | (data[5] << 8) | (data[6] << 16) | (data[7] << 24); uint32_t val = data[7] | (data[6] << 8) | (data[5] << 16) | (data[4] << 24);
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];
syslog("B"); syslog("T");
syslog_i32(val); syslog_i32(val);
syslog("\n"); syslog("\n");
//signal_led(false); //signal_led(false);
res.cmd = (messages::id) 'T'; res.cmd = (messages::id) 'T';
res.ret = OK; res.ret = OK;
res.val = 1; res.val = 1;
} else if(data[0] == 'J') {
// Disable LED
uint32_t val = data[7] | (data[6] << 8) | (data[5] << 16) | (data[4] << 24);
light_value = data[7] | (data[6] << 8);
syslog("J");
syslog_i32(val);
syslog("\n");
//signal_led(false);
res.cmd = (messages::id) 'J';
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");
@ -358,7 +373,7 @@ void websocket_cb(struct tcp_pcb *pcb, char *data, u16_t data_len,
} }
LOCK_TCPIP_CORE(); LOCK_TCPIP_CORE();
websocket_write(pcb, (uint8_t * ) & res, sizeof(res), WS_BIN_MODE); websocket_write(pcb, (uint8_t *) &res, sizeof(res), WS_BIN_MODE);
UNLOCK_TCPIP_CORE(); UNLOCK_TCPIP_CORE();
if(res.ret == OK) { if(res.ret == OK) {
@ -418,9 +433,15 @@ extern "C" void httpd_task(void *pvParameters) {
websocket_register_callbacks((tWsOpenHandler) websocket_open_cb, (tWsHandler) websocket_cb); websocket_register_callbacks((tWsOpenHandler) websocket_open_cb, (tWsHandler) websocket_cb);
httpd_init(); httpd_init();
uint16_t last_voltage = 0;
while (1) { while (1) {
voltage_val = sdk_system_adc_read(); uint16_t voltage = sdk_system_adc_read();
has_changed.voltage = true; if(false && voltage != last_voltage) {
vTaskDelayMs(1000); last_voltage = voltage;
voltage_val = voltage;
has_changed.voltage = true;
}
//has_changed.global = true;
vTaskDelayMs(5000);
} }
} }

View file

@ -259,17 +259,23 @@
</header> </header>
<footer> <footer>
<label> <label>
<input type="checkbox" name="onoffswitch" id="led-switch" onclick="gpio(this.value)"> <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>
<label> <label>
<span>toggle signal led</span> <span>toggle signal led</span>
<input type="color" onchange="colorTop(this.value)"> <input type="color" oninput="colorTop(this.value)">
</label> </label>
<label> <label>
<span>toggle signal led</span> <span>toggle signal led</span>
<input type="color" onchange="colorBottom(this.value)"> <input type="color" oninput="colorBottom(this.value)">
</label> </label>
<label>
<span>toggle signal led</span>
<input type="range" min="0" max="4096" value="0" class="slider"
oninput="lightSlider(this.value)">
</label>
</footer> </footer>
</article> </article>
</div> </div>
@ -279,12 +285,18 @@
<div id="unused_values" style="display:none;"></div> <div id="unused_values" style="display:none;"></div>
<script type="text/javascript" src="js/smoothie_min.js"></script> <script type="text/javascript" src="js/smoothie_min.js"></script>
<script> <script>
var menu = document.getElementById("bmenub");
var voltage = document.getElementById("out_voltage"); var voltage = document.getElementById("out_voltage");
var syslog = document.getElementById("syslog"); var syslog = document.getElementById("syslog");
var menu = document.getElementById("bmenub");
var onoffswitch = document.getElementById("led-switch");
var sbox = document.getElementById('status_box');
var unused_values = {}; var unused_values = {};
var ws;
var retries;
var series = new TimeSeries();
DataView.prototype.setChar = function (pos, char) { DataView.prototype.setChar = function (pos, char) {
this.setInt8(pos++, char.charCodeAt(0)); this.setInt8(pos++, char.charCodeAt(0));
return pos; return pos;
@ -309,17 +321,20 @@
return pos; return pos;
}; };
function htons(n) {
return ((n & 0xFF) << 8) | ((n >> 8) & 0xFF);
}
function htonl(n) {
return ((n & 0xFF) << 24) | ((n & 0xFF00) << 8) | ((n >> 8) & 0xFF00) | ((n >> 24) & 0xFF);
}
function colorStringToVec(hex) { function colorStringToVec(hex) {
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result ? [parseInt(result[1], 16), parseInt(result[2], 16), parseInt(result[3], 16)] : null; return result ? [parseInt(result[1], 16), parseInt(result[2], 16), parseInt(result[3], 16)] : null;
} }
var ws;
var retries;
var series = new TimeSeries();
function setMsg(cls, text) { function setMsg(cls, text) {
sbox = document.getElementById('status_box');
sbox.className = "label " + cls; sbox.className = "label " + cls;
sbox.innerHTML = text; sbox.innerHTML = text;
console.info(text); console.info(text);
@ -344,30 +359,40 @@
retries = 0; retries = 0;
if (typeof evt.data == 'string') { if (typeof evt.data == 'string') {
var data = JSON.parse(evt.data); var data = JSON.parse(evt.data);
for (const [key, value] of Object.entries(data)) { console.log("deprecated json:", data);
const elements = document.querySelectorAll(".postfill_" + key);
if (!elements.length)
unused_values[key] = value;
else
for (i = 0; i < elements.length; ++i) {
elements[i].innerHTML = value;
}
}
document.getElementById("unused_values").innerHTML = JSON.stringify(unused_values);
} else { } else {
var data = {};
var dv = new DataView(evt.data); var dv = new DataView(evt.data);
console.log("[0]", dv.getUint8(0)); let cmds = ["NONE", "RESTART", "CLEAR_CONFIG", "FIRMWARE_FRAME", "FIRMWARE_CHECK", "VOLTAGE_INFO", "SYSTEM_INFO"];
var cmd = String.fromCharCode(dv.getUint8(0)); //console.log("[0]", dv.getUint8(0));
let fst = dv.getUint8(0);
var cmd;
if (fst < cmds.length) {
cmd = cmds[fst];
} else {
cmd = String.fromCharCode(fst);
}
var val = dv.getUint16(1); var val = dv.getUint16(1);
if (cmd === 'G') if (cmd === "SYSTEM_INFO") {
data.walltime = htonl(dv.getUint32(1));
data.uptime = htonl(dv.getUint32(5));
data.heap = htonl(dv.getInt32(9));
data.chipid = Number(htonl(dv.getUint32(13))).toString(16);
data.flashid = Number(htonl(dv.getUint32(17))).toString(16);
data.flashsize = htonl(dv.getUint32(21));
} else if (cmd === "VOLTAGE_INFO") {
console.log(cmd, buf2hex(evt.data));
} else if (cmd === "G") {
console.log("LED switched", val); console.log("LED switched", val);
else if ((cmd === 'F') || (cmd === "C")) { onoffswitch.checked = !!val;
console.log("LED ", onoffswitch);
} else if ((cmd === "F") || (cmd === "C")) {
receive_chunk_confirmation(dv); receive_chunk_confirmation(dv);
} else if (cmd === 'V') { } else if (cmd === "V") {
voltage.innerHTML = (val * 13 / 1024).toFixed(2); voltage.innerHTML = (val * 13 / 1024).toFixed(2);
series.append(new Date().getTime(), val); series.append(new Date().getTime(), val);
} else if (cmd === 'L') { } else if (cmd === "L") {
var len = dv.getUint8(1); var len = dv.getUint8(1);
var offset = dv.getUint16(2); var offset = dv.getUint16(2);
var str = ""; var str = "";
@ -376,9 +401,22 @@
syslog.innerHTML = syslog.innerHTML.slice(0, offset) + str; syslog.innerHTML = syslog.innerHTML.slice(0, offset) + str;
const scrollingElement = (document.scrollingElement || document.body); const scrollingElement = (document.scrollingElement || document.body);
scrollingElement.scrollTop = scrollingElement.scrollHeight; scrollingElement.scrollTop = scrollingElement.scrollHeight;
} else } else {
console.log("[0]", dv.getUint8(0));
console.log('unknown command', cmd, val); console.log('unknown command', cmd, val);
console.log(cmd);
}
} }
for (const [key, value] of Object.entries(data)) {
const elements = document.querySelectorAll(".postfill_" + key);
if (!elements.length)
unused_values[key] = value;
else
for (i = 0; i < elements.length; ++i) {
elements[i].innerHTML = value;
}
}
document.getElementById("unused_values").innerHTML = JSON.stringify(unused_values);
} }
function wsOpen() { function wsOpen() {
@ -448,11 +486,23 @@
wsWrite(header); wsWrite(header);
} }
function lightSlider(val) {
var header = new ArrayBuffer(8);
var headerview = new DataView(header);
headerview.setChar(0, 'J');
headerview.setInt32(4, val);
console.log(buf2hex(header));
wsWrite(header);
}
window.onload = function () { window.onload = function () {
wsOpen(); wsOpen();
startPolling(); startPolling();
} }
var firmware_file;
const chunk_size = 512;
var makeCRCTable = function () { var makeCRCTable = function () {
var c; var c;
var crcTable = []; var crcTable = [];
@ -478,8 +528,6 @@
return (crc ^ (-1)) >>> 0; return (crc ^ (-1)) >>> 0;
}; };
var firmware_file;
function load_firmware(evt) { function load_firmware(evt) {
var file = evt.target.files[0]; var file = evt.target.files[0];
if (!file) { if (!file) {
@ -493,8 +541,6 @@
reader.readAsArrayBuffer(file) reader.readAsArrayBuffer(file)
} }
const chunk_size = 512;
function transmit_firmware_chunk(buf, i) { function transmit_firmware_chunk(buf, i) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const begin = i * chunk_size; const begin = i * chunk_size;
@ -556,6 +602,13 @@
} }
} }
function update_progress(progressBar, progress) {
var iP = Math.floor(progress);
var dBar = document.getElementById("progress_bar_" + progressBar);
dBar.innerText = iP + "%";
dBar.style.width = progress + "%";
}
var sta_toggle = document.getElementById("sta_toggle"); var sta_toggle = document.getElementById("sta_toggle");
var sta_ssid = document.getElementById("sta_ssid"); var sta_ssid = document.getElementById("sta_ssid");
var sta_pw = document.getElementById("sta_pw"); var sta_pw = document.getElementById("sta_pw");
@ -597,13 +650,6 @@
tx_len = view1.setInt8Vec(tx_len, [255, 255, 255, 0]); tx_len = view1.setInt8Vec(tx_len, [255, 255, 255, 0]);
wsWrite(buffer); wsWrite(buffer);
} }
function update_progress(progressBar, progress) {
var iP = Math.floor(progress);
var dBar = document.getElementById("progress_bar_" + progressBar);
dBar.innerText = iP + "%";
dBar.style.width = progress + "%";
}
</script> </script>
</body> </body>
</html> </html>