From 15fb96bb02b8f50ada82946e10765aebc0f29c66 Mon Sep 17 00:00:00 2001 From: jedi Date: Mon, 19 Jul 2021 23:58:00 +0200 Subject: [PATCH] stash --- firmware/constcat.h | 65 ++++++++++++++ firmware/web.cpp | 85 ++++++++++++++++++ firmware/webdir/index.html | 171 +++++++++++++++++++++++++++++++++++++ 3 files changed, 321 insertions(+) create mode 100644 firmware/constcat.h diff --git a/firmware/constcat.h b/firmware/constcat.h new file mode 100644 index 0000000..b111512 --- /dev/null +++ b/firmware/constcat.h @@ -0,0 +1,65 @@ +// +// Created by jedi on 23.07.21. +// + +#ifdef __cplusplus + +template +using size=std::integral_constant; + +template +constexpr size length( T const(&)[N] ) { return {}; } +template +constexpr size length( std::array const& ) { return {}; } + +template +using length_t = decltype(length(std::declval())); + +constexpr size_t string_size() { return 0; } +template +constexpr size_t string_size( size_t i, Ts... ts ) { +return (i?i-1:0) + string_size(ts...); +} +template +using string_length=size< string_size( length_t{}... )>; + +template +using combined_string = std::array{}+1>; + +template +constexpr const combined_string +concat_impl( Lhs const& lhs, Rhs const& rhs, seq, seq) +{ +// the '\0' adds to symmetry: +return {{ lhs[I1]..., rhs[I2]..., '\0' }}; +} + +template +constexpr const combined_string +concat(Lhs const& lhs, Rhs const& rhs) +{ +return concat_impl( + lhs, rhs, + gen_seq{}>{}, +gen_seq{}>{} +); +} + +template +constexpr const combined_string +concat(T0 const&t0, T1 const&t1, Ts const&...ts) +{ +return concat(t0, concat(t1, ts...)); +} + +template +constexpr const combined_string +concat(T const&t) { +return concat(t, ""); +} +constexpr const combined_string<> +concat() { + return concat(""); +} + +#endif \ No newline at end of file diff --git a/firmware/web.cpp b/firmware/web.cpp index ed55e2d..b42a32a 100644 --- a/firmware/web.cpp +++ b/firmware/web.cpp @@ -204,7 +204,21 @@ void websocket_task(void *pvParameter) { } + vTaskDelayMs(250); + { + uint8_t response[3]; + uint16_t val; + val = sdk_system_adc_read(); + response[2] = (uint8_t) val; + response[1] = val >> 8; + response[0] = 'V'; + LOCK_TCPIP_CORE(); + websocket_write(pcb, response, 3, WS_BIN_MODE); + UNLOCK_TCPIP_CORE(); + } vTaskDelayMs(500); + //printf("9: %d\n",gpio_read(9)); + //printf("10: %d\n",gpio_read(10)); } syslog_detach(); @@ -247,7 +261,18 @@ void websocket_cb(struct tcp_pcb *pcb, char *data, u16_t data_len, bool togl = false; + int8_t en = 0; + /*uint8_t ap_disable_if_sta = 0; + uint8_t ssid_hidden = 0; + uint8_t dns_enable = 0; + uint8_t mdns_enable = 0;*/ + switch (data[0]) { + case 'V': // ADC + /* This should be done on a separate thread in 'real' applications */ + val = sdk_system_adc_read(); + cmd = 'V'; + break; case 'R': // Restart cmd = 'R'; ret = OK; @@ -292,6 +317,41 @@ void websocket_cb(struct tcp_pcb *pcb, char *data, u16_t data_len, } cmd = 'C'; break; + case 'S': { + if(data[1] == 'E') + en = 1; + char *ssid = &data[2]; + size_t ssid_len = strlen(ssid); + char *password = &data[3 + ssid_len]; + size_t password_len = strlen(password); + (void) password_len; + + sysparam_set_int8("wifi_sta_enable", en); + sysparam_set_string("wifi_sta_ssid", ssid); + sysparam_set_string("wifi_sta_password", password); + } + cmd = 'S'; + break; + case 'A': { + if(data[1] == 'E') + en = 1; + char *ssid = &data[2]; + size_t ssid_len = strlen(ssid); + char *password = &data[3 + ssid_len]; + size_t password_len = strlen(password); + (void) password_len; + + sysparam_set_int8("wifi_ap_enable", en); + sysparam_set_string("wifi_ap_ssid", ssid); + sysparam_set_string("wifi_ap_password", password); + + //sysparam_set_int8("wifi_ap_disable_if_sta", ap_disable_if_sta); + //sysparam_set_int8("wifi_ap_ssid_hidden", ssid_hidden); + //sysparam_set_int8("wifi_ap_dns", dns_enable); + //sysparam_set_int8("wifi_ap_mdns", mdns_enable); + } + cmd = 'A'; + break; default: printf("[websocket_callback]:\n%.*s\n", (int) data_len, (char *) data); printf("Unknown command %c\n", data[0]); @@ -327,11 +387,36 @@ void websocket_open_cb(struct tcp_pcb *pcb, const char *uri) { } } +/*const char *gpio_cgi_handler(int iIndex, int iNumParams, char *pcParam[], char *pcValue[]) { + for (int i = 0; i < iNumParams; i++) { + if(strcmp(pcParam[i], "on") == 0) { + uint8_t gpio_num = atoi(pcValue[i]); + gpio_enable(gpio_num, GPIO_OUTPUT); + gpio_write(gpio_num, true); + } else if(strcmp(pcParam[i], "off") == 0) { + uint8_t gpio_num = atoi(pcValue[i]); + gpio_enable(gpio_num, GPIO_OUTPUT); + gpio_write(gpio_num, false); + } else if(strcmp(pcParam[i], "toggle") == 0) { + uint8_t gpio_num = atoi(pcValue[i]); + gpio_enable(gpio_num, GPIO_OUTPUT); + gpio_toggle(gpio_num); + } + } + return "/index.html"; +}*/ + extern "C" void httpd_task(void *pvParameters) { (void) pvParameters; while (!uxSemaphoreGetCount(wifi_available_semaphore)) vTaskDelay(500 / portTICK_PERIOD_MS); + /*tCGI pCGIs[] = { + {"/gpio", (tCGIHandler) gpio_cgi_handler}, + }; + + // register handlers and start the server + http_set_cgi_handlers(pCGIs, sizeof(pCGIs) / sizeof(pCGIs[0]));*/ websocket_register_callbacks((tWsOpenHandler) websocket_open_cb, (tWsHandler) websocket_cb); httpd_init(); diff --git a/firmware/webdir/index.html b/firmware/webdir/index.html index 317dc10..dfad951 100644 --- a/firmware/webdir/index.html +++ b/firmware/webdir/index.html @@ -17,6 +17,8 @@ @@ -75,6 +77,125 @@ +
+

I/O

+
+
+

Protocols

+
+
+
+ + +
+
+ + +
+
+
+
+
+

Station Mode current connection

+
+
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + +
+
+
+
+
+

Wifi Settings

+
+
+

AP Mode

+
+
+
+ + +
+
+ + +
+
+ + +
+
+ AP IP + N/A +
+
+ AP MAC + N/A +
+
+ + +
+
+
+
+
+

Station Mode current connection

+
+
+
+ + +
+
+ + +
+
+ + +
+
+ Sation IP + N/A +
+
+ Station MAC + N/A +
+
+ + +
+
+
+

Status

@@ -175,6 +296,16 @@

I/O

+
+
+ Channel 1-6 + SPI Dimmer +
+
+ Channel 7-127 + WS2812 via I2S +
+