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();
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);
@ -34,7 +34,7 @@ void user_init(void) {
wifi_alive = xSemaphoreCreateBinary();
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) {
str_i32[1] = hex_lookup[val & 0xF];
str_i32[0] = hex_lookup[(val >> 4) & 0xF];
str_i32[3] = hex_lookup[(val >> 8) & 0xF];
str_i32[2] = hex_lookup[(val >> 12) & 0xF];
str_i32[5] = hex_lookup[(val >> 16) & 0xF];
str_i32[4] = hex_lookup[(val >> 20) & 0xF];
str_i32[7] = hex_lookup[(val >> 24) & 0xF];
str_i32[6] = hex_lookup[(val >> 28) & 0xF];
str_i32[7] = hex_lookup[val & 0xF];
str_i32[6] = hex_lookup[(val >> 4) & 0xF];
str_i32[5] = hex_lookup[(val >> 8) & 0xF];
str_i32[4] = hex_lookup[(val >> 12) & 0xF];
str_i32[3] = hex_lookup[(val >> 16) & 0xF];
str_i32[2] = hex_lookup[(val >> 20) & 0xF];
str_i32[1] = hex_lookup[(val >> 24) & 0xF];
str_i32[0] = hex_lookup[(val >> 28) & 0xF];
//
syslog(str_i32);
}

View file

@ -36,32 +36,9 @@ struct apa10xx_pixel_t {
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 bottom_color;
uint16_t dimmer_value;
volatile uint16_t light_value;
namespace fiatlux {
@ -246,6 +223,20 @@ extern "C" void signal_led(bool 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.
*
@ -266,7 +257,7 @@ extern "C" [[noreturn]] void lux_task(void *pvParameters) {
ws2812_i2s_init(lux_ws2812_number, PIXEL_RGBW);
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
@ -279,7 +270,7 @@ extern "C" [[noreturn]] void lux_task(void *pvParameters) {
fiatlux::relais::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:
@ -288,66 +279,53 @@ extern "C" [[noreturn]] void lux_task(void *pvParameters) {
- [2*n+1] = 8bit PWM value
*/
uint32_t dummy = 0;
union {
struct {
unsigned dat: 16;
unsigned addr: 12;
unsigned op: 4;
unsigned dat: 12;
unsigned addr: 4;
} __attribute__((packed));
uint32_t _;
uint16_t _;
} frame = {._=0};
dimmer_value = 255;
light_value = 0xFFF;
uint16_t last_dimmer_value = 0;
uint16_t last_light_value = 0xFFFF;
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);
for (int c = 8; c >= 0; c--) {
/*for (auto &pixel: pixels) {
pixel = next_colour(c);
}*/
if(last_light_value != light_value) {
syslog("# ");
syslog_i32(light_value);
syslog("\n");
if(last_dimmer_value != dimmer_value) {
for (int i = 0; i < 6; ++i) {
frame.op = 0xA;
frame.addr = i * 2 + 1;
frame.dat = 255;
spi_transfer_32(1, frame._);
frame.addr = i;
frame.dat = light_value;
uint16_t reply = spi_transfer_16_duplex(1, frame._);
vTaskDelay(13 / portTICK_PERIOD_MS);
//for (volatile int i = 0; i < 512 * 32; ++i);
/*if(!i) {
syslog(" > ");
syslog_i32(frame._);
frame.op = 0xA;
frame.addr = i * 2;
frame.dat = dimmer_value << 4;
spi_transfer_32(1, frame._);
vTaskDelay(13 / portTICK_PERIOD_MS);
//for (volatile int i = 0; i < 512 * 32; ++i);
if(reply) {
syslog(" < ");
syslog_i32(reply);
}
//last_dimmer_value = dimmer_value;
syslog("\n");
}*/
for (volatile int k = 0; k < 512; ++k);
}
last_light_value = light_value;
}
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}};
@ -355,16 +333,16 @@ extern "C" [[noreturn]] void lux_task(void *pvParameters) {
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);
/*//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);
vTaskDelay(200 / portTICK_PERIOD_MS);
fiatlux::relais::write_data(false, true);
vTaskDelay(200 / portTICK_PERIOD_MS);
fiatlux::relais::write_data(false, false);
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 bottom_color;
extern uint16_t dimmer_value;
extern volatile uint16_t light_value;
#ifdef __cplusplus
}

View file

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

View file

@ -78,12 +78,14 @@ for file in httpFiles:
else:
response = b'HTTP/1.0 200 OK\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'
binFile = open(file, 'rb')
binData = binFile.read()
compEff = False
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,
stdout=subprocess.PIPE)
minData = p.communicate(binData)[0]

View file

@ -30,7 +30,6 @@ using namespace fiatlux;
#define vTaskDelayMs(ms) vTaskDelay((ms) / portTICK_PERIOD_MS)
uint16_t voltage_val;
struct {
@ -44,7 +43,7 @@ void websocket_task(void *pvParameter) {
auto *pcb = (struct tcp_pcb *) pvParameter;
size_t connstarttime = xTaskGetTickCount();
has_changed = {true, true, true};
has_changed = {true, true, true, true};
syslog_attach();
unsigned local_log_tail = syslog_current_tail();
@ -73,7 +72,7 @@ void websocket_task(void *pvParameter) {
}
//Global Info
if(false && has_changed.global) {
if(has_changed.global) {
timeval tv{};
gettimeofday(&tv, nullptr);
size_t uptime = xTaskGetTickCount() * portTICK_PERIOD_MS / 1000;
@ -95,6 +94,11 @@ void websocket_task(void *pvParameter) {
frame.msg.flashsize = flash_size;
//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);
/*LOCK_TCPIP_CORE();
websocket_write(pcb, (uint8_t * ) &frame, sizeof(frame), WS_BIN_MODE);
@ -107,7 +111,7 @@ void websocket_task(void *pvParameter) {
gettimeofday(&tv, nullptr);
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));
char response[192];
size_t
@ -257,7 +261,7 @@ void websocket_cb(struct tcp_pcb *pcb, char *data, u16_t data_len,
res.ret = OK;
} else if(data[0] == 'B') {
// 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.g = data[6];
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;
} else if(data[0] == 'T') {
// 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.g = data[6];
top_color.b = data[5];
syslog("B");
syslog("T");
syslog_i32(val);
syslog("\n");
//signal_led(false);
res.cmd = (messages::id) 'T';
res.ret = OK;
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') {
// Disable LED
syslog("G\n");
@ -418,9 +433,15 @@ extern "C" void httpd_task(void *pvParameters) {
websocket_register_callbacks((tWsOpenHandler) websocket_open_cb, (tWsHandler) websocket_cb);
httpd_init();
uint16_t last_voltage = 0;
while (1) {
voltage_val = sdk_system_adc_read();
uint16_t voltage = sdk_system_adc_read();
if(false && voltage != last_voltage) {
last_voltage = voltage;
voltage_val = voltage;
has_changed.voltage = true;
vTaskDelayMs(1000);
}
//has_changed.global = true;
vTaskDelayMs(5000);
}
}

View file

@ -259,17 +259,23 @@
</header>
<footer>
<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>
</label>
<label>
<span>toggle signal led</span>
<input type="color" onchange="colorTop(this.value)">
<input type="color" oninput="colorTop(this.value)">
</label>
<label>
<span>toggle signal led</span>
<input type="color" onchange="colorBottom(this.value)">
<input type="color" oninput="colorBottom(this.value)">
</label>
<label>
<span>toggle signal led</span>
<input type="range" min="0" max="4096" value="0" class="slider"
oninput="lightSlider(this.value)">
</label>
</footer>
</article>
</div>
@ -279,12 +285,18 @@
<div id="unused_values" style="display:none;"></div>
<script type="text/javascript" src="js/smoothie_min.js"></script>
<script>
var menu = document.getElementById("bmenub");
var voltage = document.getElementById("out_voltage");
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 ws;
var retries;
var series = new TimeSeries();
DataView.prototype.setChar = function (pos, char) {
this.setInt8(pos++, char.charCodeAt(0));
return pos;
@ -309,17 +321,20 @@
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) {
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;
}
var ws;
var retries;
var series = new TimeSeries();
function setMsg(cls, text) {
sbox = document.getElementById('status_box');
sbox.className = "label " + cls;
sbox.innerHTML = text;
console.info(text);
@ -344,6 +359,54 @@
retries = 0;
if (typeof evt.data == 'string') {
var data = JSON.parse(evt.data);
console.log("deprecated json:", data);
} else {
var data = {};
var dv = new DataView(evt.data);
let cmds = ["NONE", "RESTART", "CLEAR_CONFIG", "FIRMWARE_FRAME", "FIRMWARE_CHECK", "VOLTAGE_INFO", "SYSTEM_INFO"];
//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);
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);
onoffswitch.checked = !!val;
console.log("LED ", onoffswitch);
} else if ((cmd === "F") || (cmd === "C")) {
receive_chunk_confirmation(dv);
} else if (cmd === "V") {
voltage.innerHTML = (val * 13 / 1024).toFixed(2);
series.append(new Date().getTime(), val);
} else if (cmd === "L") {
var len = dv.getUint8(1);
var offset = dv.getUint16(2);
var str = "";
for (var i = 0; i < len; i++)
str += dv.getChar(4 + i);
syslog.innerHTML = syslog.innerHTML.slice(0, offset) + str;
const scrollingElement = (document.scrollingElement || document.body);
scrollingElement.scrollTop = scrollingElement.scrollHeight;
} else {
console.log("[0]", dv.getUint8(0));
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)
@ -354,31 +417,6 @@
}
}
document.getElementById("unused_values").innerHTML = JSON.stringify(unused_values);
} else {
var dv = new DataView(evt.data);
console.log("[0]", dv.getUint8(0));
var cmd = String.fromCharCode(dv.getUint8(0));
var val = dv.getUint16(1);
if (cmd === 'G')
console.log("LED switched", val);
else if ((cmd === 'F') || (cmd === "C")) {
receive_chunk_confirmation(dv);
} else if (cmd === 'V') {
voltage.innerHTML = (val * 13 / 1024).toFixed(2);
series.append(new Date().getTime(), val);
} else if (cmd === 'L') {
var len = dv.getUint8(1);
var offset = dv.getUint16(2);
var str = "";
for (var i = 0; i < len; i++)
str += dv.getChar(4 + i);
syslog.innerHTML = syslog.innerHTML.slice(0, offset) + str;
const scrollingElement = (document.scrollingElement || document.body);
scrollingElement.scrollTop = scrollingElement.scrollHeight;
} else
console.log('unknown command', cmd, val);
}
}
function wsOpen() {
@ -448,11 +486,23 @@
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 () {
wsOpen();
startPolling();
}
var firmware_file;
const chunk_size = 512;
var makeCRCTable = function () {
var c;
var crcTable = [];
@ -478,8 +528,6 @@
return (crc ^ (-1)) >>> 0;
};
var firmware_file;
function load_firmware(evt) {
var file = evt.target.files[0];
if (!file) {
@ -493,8 +541,6 @@
reader.readAsArrayBuffer(file)
}
const chunk_size = 512;
function transmit_firmware_chunk(buf, i) {
return new Promise((resolve, reject) => {
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_ssid = document.getElementById("sta_ssid");
var sta_pw = document.getElementById("sta_pw");
@ -597,13 +650,6 @@
tx_len = view1.setInt8Vec(tx_len, [255, 255, 255, 0]);
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>
</body>
</html>