forked from j3d1/fiatlux
Compare commits
2 commits
stable
...
jedi/dev/h
Author | SHA1 | Date | |
---|---|---|---|
e791c5aac0 | |||
9eb69ac329 |
3 changed files with 336 additions and 0 deletions
65
firmware/constcat.h
Normal file
65
firmware/constcat.h
Normal file
|
@ -0,0 +1,65 @@
|
|||
//
|
||||
// Created by jedi on 23.07.21.
|
||||
//
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
template<size_t S>
|
||||
using size=std::integral_constant<size_t, S>;
|
||||
|
||||
template<class T, size_t N>
|
||||
constexpr size<N> length( T const(&)[N] ) { return {}; }
|
||||
template<class T, size_t N>
|
||||
constexpr size<N> length( std::array<T, N> const& ) { return {}; }
|
||||
|
||||
template<class T>
|
||||
using length_t = decltype(length(std::declval<T>()));
|
||||
|
||||
constexpr size_t string_size() { return 0; }
|
||||
template<class...Ts>
|
||||
constexpr size_t string_size( size_t i, Ts... ts ) {
|
||||
return (i?i-1:0) + string_size(ts...);
|
||||
}
|
||||
template<class...Ts>
|
||||
using string_length=size< string_size( length_t<Ts>{}... )>;
|
||||
|
||||
template<class...Ts>
|
||||
using combined_string = std::array<char, string_length<Ts...>{}+1>;
|
||||
|
||||
template<class Lhs, class Rhs, unsigned...I1, unsigned...I2>
|
||||
constexpr const combined_string<Lhs,Rhs>
|
||||
concat_impl( Lhs const& lhs, Rhs const& rhs, seq<I1...>, seq<I2...>)
|
||||
{
|
||||
// the '\0' adds to symmetry:
|
||||
return {{ lhs[I1]..., rhs[I2]..., '\0' }};
|
||||
}
|
||||
|
||||
template<class Lhs, class Rhs>
|
||||
constexpr const combined_string<Lhs,Rhs>
|
||||
concat(Lhs const& lhs, Rhs const& rhs)
|
||||
{
|
||||
return concat_impl(
|
||||
lhs, rhs,
|
||||
gen_seq<string_length<Lhs>{}>{},
|
||||
gen_seq<string_length<Rhs>{}>{}
|
||||
);
|
||||
}
|
||||
|
||||
template<class T0, class T1, class... Ts>
|
||||
constexpr const combined_string<T0, T1, Ts...>
|
||||
concat(T0 const&t0, T1 const&t1, Ts const&...ts)
|
||||
{
|
||||
return concat(t0, concat(t1, ts...));
|
||||
}
|
||||
|
||||
template<class T>
|
||||
constexpr const combined_string<T>
|
||||
concat(T const&t) {
|
||||
return concat(t, "");
|
||||
}
|
||||
constexpr const combined_string<>
|
||||
concat() {
|
||||
return concat("");
|
||||
}
|
||||
|
||||
#endif
|
|
@ -16,6 +16,8 @@
|
|||
<label for="bmenub" class="burger pseudo button">☰</label>
|
||||
<div class="menu">
|
||||
<a href="/#" class="button icon-picture">Dashboard</a>
|
||||
<a href="/#io" class="button icon-puzzle">I/O</a>
|
||||
<a href="/#wifi" class="button icon-puzzle">Wifi Settings</a>
|
||||
<a href="/#ota" class="button icon-picture">System</a>
|
||||
</div>
|
||||
</nav>
|
||||
|
@ -58,6 +60,125 @@
|
|||
</article>
|
||||
|
||||
</section>
|
||||
<section id="io">
|
||||
<h2>I/O</h2>
|
||||
<article class="card">
|
||||
<header>
|
||||
<h3>Protocols</h3>
|
||||
</header>
|
||||
<div class="table">
|
||||
<div class="row">
|
||||
<label>MQTT</label>
|
||||
<span><input type="checkbox" class="plain"/></span>
|
||||
</div>
|
||||
<div class="row">
|
||||
<span><input type="reset" class="button"/></span>
|
||||
<span><input type="submit" value="Save"></span>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
<article class="card">
|
||||
<header>
|
||||
<h3>Station Mode <span class="label success">current connection</span></h3>
|
||||
</header>
|
||||
<div class="table">
|
||||
<div class="row">
|
||||
<label>WS2812 via I2S</label>
|
||||
<span><input type="checkbox" class="plain"/></span>
|
||||
<span><input type="color"/></span>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label>APA102C via SPI</label>
|
||||
<span><input type="checkbox" class="plain"/></span>
|
||||
<span><input type="color"/></span>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label>6 Channel SPI Dimmer</label>
|
||||
<span><input type="checkbox" class="plain"/></span>
|
||||
<span><input type="color"/></span>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label>Binary Output on GPIO4</label>
|
||||
<span><input type="checkbox" class="plain"/></span>
|
||||
<span><button class="toggle button">Toggle</button></span>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label>Binary Output on GPIO5</label>
|
||||
<span><input type="checkbox" class="plain"/></span>
|
||||
<span><button class="toggle button">Toggle</button></span>
|
||||
</div>
|
||||
<div class="row">
|
||||
<span><input type="reset" class="button"/></span>
|
||||
<span><input type="submit" value="Save"></span>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
</section>
|
||||
<section id="wifi">
|
||||
<h2>Wifi Settings</h2>
|
||||
<article class="card">
|
||||
<header>
|
||||
<h3>AP Mode</h3>
|
||||
</header>
|
||||
<div class="table">
|
||||
<div class="row">
|
||||
<label>Enable</label>
|
||||
<span><input id="ap_toggle" type="checkbox" class="plain"/></span>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label>SSID</label>
|
||||
<span><input id="ap_ssid" type="text" placeholder="SSID"/></span>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label>Password</label>
|
||||
<span><input id="ap_pw" type="password" placeholder="Password"/></span>
|
||||
</div>
|
||||
<div class="row">
|
||||
<span>AP IP</span>
|
||||
<span><span class="postfill_apip">N/A</span></span>
|
||||
</div>
|
||||
<div class="row">
|
||||
<span>AP MAC</span>
|
||||
<span><span class="postfill_apmac">N/A</span></span>
|
||||
</div>
|
||||
<div class="row">
|
||||
<span><input type="reset" class="button"/></span>
|
||||
<span><input onclick="ap_update();" type="submit" value="Save"></span>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
<article class="card">
|
||||
<header>
|
||||
<h3>Station Mode <span class="label success">current connection</span></h3>
|
||||
</header>
|
||||
<div class="table">
|
||||
<div class="row">
|
||||
<label>Eanable</label>
|
||||
<span><input id="sta_toggle" type="checkbox" class="plain"/></span>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label>SSID</label>
|
||||
<span><input id="sta_ssid" type="text" placeholder="SSID"/></span>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label>Password</label>
|
||||
<span><input id="sta_pw" type="password" placeholder="Password"/></span>
|
||||
</div>
|
||||
<div class="row">
|
||||
<span>Sation IP</span>
|
||||
<span><span class="postfill_staip">N/A</span></span>
|
||||
</div>
|
||||
<div class="row">
|
||||
<span>Station MAC</span>
|
||||
<span><span class="postfill_stamac">N/A</span></span>
|
||||
</div>
|
||||
<div class="row">
|
||||
<span><input type="reset" class="button"/></span>
|
||||
<span><input onclick="sta_update();" type="submit" value="Save"></span>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
</section>
|
||||
<section id="dashboard">
|
||||
<h2>Status</h2>
|
||||
<div class="flex">
|
||||
|
@ -158,11 +279,22 @@
|
|||
<header>
|
||||
<h3>I/O</h3>
|
||||
</header>
|
||||
<div class="table">
|
||||
<div class="row">
|
||||
<span>Channel 1-6</span>
|
||||
<span>SPI Dimmer</span>
|
||||
</div>
|
||||
<div class="row">
|
||||
<span>Channel 7-127</span>
|
||||
<span>WS2812 via I2S</span>
|
||||
</div>
|
||||
</div>
|
||||
<footer>
|
||||
<label>
|
||||
<input type="checkbox" name="onoffswitch" id="led-switch" onclick="gpio()">
|
||||
<span class="toggle button">toggle signal led</span>
|
||||
</label>
|
||||
<span><input type="color" onchange="console.log(colorStringToVec(event.target.value))"/></span>
|
||||
</footer>
|
||||
</article>
|
||||
</div>
|
||||
|
@ -190,6 +322,18 @@
|
|||
return pos;
|
||||
};
|
||||
|
||||
DataView.prototype.setInt8Vec = function (pos, vec) {
|
||||
for (var i = 0; i < vec.length; i++) {
|
||||
this.setInt8(pos++, vec[i]);
|
||||
}
|
||||
return pos;
|
||||
};
|
||||
|
||||
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();
|
||||
|
@ -394,6 +538,48 @@
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
var sta_toggle = document.getElementById("sta_toggle");
|
||||
var sta_ssid = document.getElementById("sta_ssid");
|
||||
var sta_pw = document.getElementById("sta_pw");
|
||||
|
||||
function sta_update() {
|
||||
var en = sta_toggle.checked;
|
||||
|
||||
const ssid = sta_ssid.value;
|
||||
const password = sta_pw.value;
|
||||
|
||||
const buffer = new ArrayBuffer(ssid.length + password.length + 4);
|
||||
const view1 = new DataView(buffer);
|
||||
var tx_len = 0;
|
||||
view1.setChar(tx_len++, 'S');
|
||||
view1.setChar(tx_len++, (en ? "E" : "D"));
|
||||
tx_len = view1.setString(tx_len, ssid);
|
||||
tx_len = view1.setString(tx_len, password);
|
||||
wsWrite(buffer);
|
||||
}
|
||||
|
||||
var ap_toggle = document.getElementById("ap_toggle");
|
||||
var ap_ssid = document.getElementById("ap_ssid");
|
||||
var ap_pw = document.getElementById("ap_pw");
|
||||
|
||||
function ap_update() {
|
||||
var en = ap_toggle.checked;
|
||||
|
||||
const ssid = ap_ssid.value;
|
||||
const password = ap_pw.value;
|
||||
|
||||
const buffer = new ArrayBuffer(ssid.length + password.length + 4 + 8);
|
||||
const view1 = new DataView(buffer);
|
||||
var tx_len = 0;
|
||||
view1.setChar(tx_len++, 'A');
|
||||
view1.setChar(tx_len++, (en ? "E" : "D"));
|
||||
tx_len = view1.setString(tx_len, ssid);
|
||||
tx_len = view1.setString(tx_len, password);
|
||||
tx_len = view1.setInt8Vec(tx_len, [192, 168, 111, 1]);
|
||||
tx_len = view1.setInt8Vec(tx_len, [255, 255, 255, 0]);
|
||||
wsWrite(buffer);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -184,7 +184,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));
|
||||
}
|
||||
|
||||
vTaskDelete(nullptr);
|
||||
|
@ -221,7 +235,18 @@ void websocket_cb(struct tcp_pcb *pcb, char *data, u16_t data_len,
|
|||
|
||||
bool togl = 0;
|
||||
|
||||
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';
|
||||
break;
|
||||
|
@ -258,6 +283,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]);
|
||||
|
@ -294,11 +354,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();
|
||||
|
||||
|
|
Loading…
Reference in a new issue