add toogle button for signal led in http frontend

This commit is contained in:
j3d1 2021-07-19 23:31:20 +02:00
parent 006d281ad6
commit 8c775e9705
3 changed files with 24 additions and 1 deletions

View file

@ -109,6 +109,19 @@
<canvas id="chartCanvas" style="height:100px"></canvas> <canvas id="chartCanvas" style="height:100px"></canvas>
</article> </article>
</div> </div>
<div>
<article class="card">
<header>
<h3>I/O</h3>
</header>
<footer>
<label>
<input type="checkbox" name="onoffswitch" id="led-switch" onclick="gpio()">
<span class="toggle button">toggle signal led</span>
</label>
</footer>
</article>
</div>
</div> </div>
</section> </section>
</main> </main>

View file

@ -17,7 +17,7 @@ const int gpio4 = 4;
const int gpio5 = 5; const int gpio5 = 5;
extern "C" void signal_led(bool state) { extern "C" void signal_led(bool state) {
gpio_write(signal_led_pin, state); gpio_write(signal_led_pin, !state);
} }
extern "C" void lux_task(void *pvParameters) { extern "C" void lux_task(void *pvParameters) {

View file

@ -226,6 +226,16 @@ void websocket_cb(struct tcp_pcb *pcb, char *data, u16_t data_len, uint8_t mode)
char cmd = '0'; char cmd = '0';
switch (data[0]) { switch (data[0]) {
case 'D': // Disable LED
signal_led(false);
val = 1;
cmd = 'G';
break;
case 'E': // Enable LED
signal_led(true);
val = 0;
cmd = 'G';
break;
default: default:
printf("[websocket_callback]:\n%.*s\n", (int) data_len, (char *) data); printf("[websocket_callback]:\n%.*s\n", (int) data_len, (char *) data);
printf("Unknown command\n"); printf("Unknown command\n");