From a64e4f17cf302a2aa036c0f1d625a48d942ed6a9 Mon Sep 17 00:00:00 2001 From: Kai Lauterbach Date: Mon, 1 May 2023 19:23:31 +0200 Subject: [PATCH] Added a script which converts html pages into arduino strings. Added beta state code for html page generation. --- firmware/config_html.h | 67 +++++ firmware/firmware.ino | 511 ++++++---------------------------- firmware/index_html.h | 280 +++++++++++++++++++ firmware/light_control_html.h | 35 +++ tools/html2string.sh | 5 + 5 files changed, 473 insertions(+), 425 deletions(-) create mode 100644 tools/html2string.sh diff --git a/firmware/config_html.h b/firmware/config_html.h index e69de29..b58691c 100644 --- a/firmware/config_html.h +++ b/firmware/config_html.h @@ -0,0 +1,67 @@ + +String getConfigHTML() +{ + String config_html = "" +"
" +"

Config

" +"
" +"" +"" +"
" +"
" +"" +"" +"
" +"
" +"

Wifi

" +"
" +"" +"" +"
" +"
" +"" +"" +"
" +"
" +"

Network

" +"
" +"" +"ON" +"OFF" +"
" +"
" +"" +"" +"
" +"
" +"" +"" +"
" +"
" +"" +"" +"
" +"
" +"" +"" +"
" +"
" +"" +"
" +"
"; + return config_html; +} diff --git a/firmware/firmware.ino b/firmware/firmware.ino index ac1600b..ad31c52 100644 --- a/firmware/firmware.ino +++ b/firmware/firmware.ino @@ -610,457 +610,118 @@ void init_webserver() } // Generate HTML page - String http_content = ""; - http_content += ""; - http_content += ""; - http_content += ""; - http_content += ""; - http_content += ""; - //http_content += ""; // Reload the page every 15 seconds automatically - http_content += "Light Setup"; - http_content += ""; - http_content += ""; - http_content += ""; - http_content += ""; - http_content += ""; - http_content += ""; - http_content += "
"; - http_content += "

" + (String)light_name + "

"; + String http_content = getIndexHTML(); - http_content += "
"; + http_content.replace("{{LIGHT_NAME}}", (String)light_name); - http_content += "
"; - http_content += "alert   reset   reset timing control data   update"; - http_content += ""; - http_content += "
"; - - // timing control button - http_content += "
"; - http_content += "
"; - http_content += ""; int tc_val = EEPROM.read(EEPROM_TIMING_CONTROL_ENABLED_ADDRESS); - http_content += "ON"; - http_content += "OFF"; - http_content += "
"; - http_content += ""; - http_content += "
"; + if (tc_val == TIMING_CONTROL_ENABLED) + { + http_content.replace("{{TC_LINK_PRIMARY_ON}}", "pure-button-primary"); + } else { + http_content.replace("{{TC_LINK_PRIMARY_ON}}", ""); + } + if (tc_val == TIMING_CONTROL_DISABLED) + { + http_content.replace("{{TC_LINK_PRIMARY_OFF}}", "pure-button-primary"); + } else { + http_content.replace("{{TC_LINK_PRIMARY_OFF}}", ""); + } - http_content += "
"; - http_content += ""; - http_content += ""; - http_content += "
"; - http_content += "
"; + http_content.replace("{{TRANSITION_TIME}}", (String)default_transitiontime); - http_content += ""; - - http_content += "
"; + String light_content = ""; // Light control for (uint8 light_num = 0; light_num < LIGHTS_COUNT; light_num++) { - // on/off buttons - http_content += "

Light " + (String)(light_num + 1) + "

"; - http_content += "
"; - http_content += ""; - http_content += "ON"; - http_content += "OFF"; - http_content += "
"; + // Generate lights part of the HTML page + String tmp_light_content = getLightControlHTML(); - // slider for brightness - http_content += "
"; - http_content += ""; - http_content += ""; - http_content += " " + (String)(int)(bri[light_num] * 100.0 / 255.0) + "%"; - http_content += "
"; - http_content += ""; - http_content += " %"; - http_content += ""; - - http_content += "
"; + // on/off buttons and slider + tmp_light_content.replace("{{LIGHT_NUMBER}}", (String)(light_num + 1)); + tmp_light_content.replace("{{LIGHT_NUMBER_DEC}}", (String)light_num); + // add the lights code to the html output string + light_content += tmp_light_content; } - http_content += ""; - http_content += "
"; + // add the created lights control code to the html output + http_content.replace("{{LIGHTS_CONTROL}}", light_content); - // startup state and scene for all of the lights - http_content += "
"; - http_content += "
"; - http_content += "

"; - http_content += "

Config

"; - http_content += "
"; - http_content += ""; - http_content += ""; - http_content += "
"; + if (ls_val == LAST_STATE_STARTUP_LIGHT_LAST_STATE) + { + http_content.replace("{{STARTUP_SELECTED_LS_0}}", "selected=\"selected\""); + } else { + http_content.replace("{{STARTUP_SELECTED_LS_0}}", ""); + } + + if (ls_val == LAST_STATE_STARTUP_LIGHT_ON_STATE) + { + http_content.replace("{{STARTUP_SELECTED_ON_1}}", "selected=\"selected\""); + } else { + http_content.replace("{{STARTUP_SELECTED_ON_1}}", ""); + } + + if (ls_val == LAST_STATE_STARTUP_LIGHT_OFF_STATE) + { + http_content.replace("{{STARTUP_SELECTED_OFF_2}}", "selected=\"selected\""); + } else { + http_content.replace("{{STARTUP_SELECTED_OFF_2}}", ""); + } // scene - http_content += "
"; - http_content += ""; - http_content += ""; - http_content += "
"; + if (sc_val == SCENE_RELEAX) + { + http_content.replace("{{SCENE_SELECTED_RELAX_0}}", "selected=\"selected\""); + } else { + http_content.replace("{{SCENE_SELECTED_RELAX_0}}", ""); + } + if (sc_val == SCENE_BRIGHT) + { + http_content.replace("{{SCENE_SELECTED_BRIGHT_1}}", "selected=\"selected\""); + } else { + http_content.replace("{{SCENE_SELECTED_BRIGHT_1}}", ""); + } + if (sc_val == SCENE_NIGHTLY) + { + http_content.replace("{{SCENE_SELECTED_NIGHT_2}}", "selected=\"selected\""); + } else { + http_content.replace("{{SCENE_SELECTED_NIGHT_2}}", ""); + } + + // Generate lights part of the HTML page + String config_content = getConfigHTML(); // Wifi settings - http_content += "
"; - http_content += "

Wifi

"; - http_content += "
"; - http_content += ""; - http_content += ""; - http_content += "
"; - http_content += "
"; - http_content += ""; - http_content += ""; - http_content += "
"; + config_content.replace("{{WIFI_SSIF}}", WiFi.SSID()); // Network settings uint8_t dip = EEPROM.read(EEPROM_DYNAMIC_IP_ADDRESS); - http_content += "
"; - http_content += "

Network

"; - http_content += "
"; - http_content += ""; - http_content += "ON"; - http_content += "OFF"; - http_content += "
"; - - // ip config - if (dip == 0) { - http_content += "
"; - http_content += ""; - http_content += ""; - http_content += "
"; - http_content += "
"; - http_content += ""; - http_content += ""; - http_content += "
"; - http_content += "
"; - http_content += ""; - http_content += ""; - http_content += "
"; + if (dip) + { + config_content.replace("{{DIP_LINK_ON_PRIMARY}}", "pure-button-primary"); + config_content.replace("{{DIP_LINK_OFF_PRIMARY}}", ""); + } else { + config_content.replace("{{DIP_LINK_OFF_PRIMARY}}", "pure-button-primary"); + config_content.replace("{{DIP_LINK_ON_PRIMARY}}", ""); } - // The save button - http_content += "
"; - http_content += ""; - http_content += "
"; + // ip config + if (dip == 0) + { + config_content.replace("{{WIFI_IP}}", WiFi.localIP().toString()); + config_content.replace("{{WIFI_GW}}", WiFi.gatewayIP().toString()); + config_content.replace("{{WIFI_NM}}", WiFi.subnetMask().toString()); + config_content.replace("{{WIFI_DNS}}", WiFi.dnsIP().toString()); + } - http_content += ""; - - http_content += ""; - http_content += "
"; - http_content += "
"; - http_content += ""; - http_content += ""; + // set the pwm values + http_content.replace("{{PWM_MIN}}", (String)PWM_MIN); + http_content.replace("{{PWM_MAX}}", (String)PWM_MAX); server.send(200, "text/html", http_content); }); diff --git a/firmware/index_html.h b/firmware/index_html.h index e69de29..13769b5 100644 --- a/firmware/index_html.h +++ b/firmware/index_html.h @@ -0,0 +1,280 @@ + +String getIndexHTML() +{ + String index_html = "" +"" +"" +"" +"" +"" +"" +"Light setup" +"" +"" +"" +"" +"" +"" +"
" +"

{{LIGHT_NAME}}

" +"
" +"
" +"" +"alert" +"  " +"reset" +"  " +"reset timing control data" +"  " +"update" +"" +"" +"
" +"
" +"
" +"" +"ON" +"OFF" +"
" +"" +"
" +"
" +"" +"" +"
" +"
" +"" +"
" +"" +"" +"" +"" +"" +"
" +"{{LIGHTS_CONTROL}}" +"" +"" +"
" +"
" +"{{CONFIG_PAGE}}" +"" +"
" +"
" +"" +""; + return index_html; +} diff --git a/firmware/light_control_html.h b/firmware/light_control_html.h index e69de29..fac8b22 100644 --- a/firmware/light_control_html.h +++ b/firmware/light_control_html.h @@ -0,0 +1,35 @@ + +String getLightControlHTML() +{ + String light_control_html = "" +"

Light {{LIGHT_NUMBER}}

" +"
" +"" +"ON" +"OFF" +"
" +"
" +"" +"" +" " +"9" +"%" +"
" +"" +"" +" " +"" +"%" +"" +"
"; + return light_control_html; +} diff --git a/tools/html2string.sh b/tools/html2string.sh new file mode 100644 index 0000000..a339e62 --- /dev/null +++ b/tools/html2string.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +cat $1 | sed -e"s/^ *//ig" | sed -e 's/"/\\"/ig' | sed -e "s/^/\"/ig" | sed -e "s/$/\"/ig" +echo ";" +