From cf4701f8ed108d9f5f5674ebeb6761eecb4ba5ab Mon Sep 17 00:00:00 2001 From: Christian Herzog Date: Tue, 3 Sep 2019 22:21:11 +0200 Subject: [PATCH 1/4] build command line from website form --- components/wifi-manager/code.js | 74 +++++++++++++++++++-------- components/wifi-manager/http_server.c | 2 +- components/wifi-manager/index.html | 23 +++++++++ components/wifi-manager/style.css | 25 +++++++++ 4 files changed, 101 insertions(+), 23 deletions(-) diff --git a/components/wifi-manager/code.js b/components/wifi-manager/code.js index 0f438865..f50a994b 100644 --- a/components/wifi-manager/code.js +++ b/components/wifi-manager/code.js @@ -1,3 +1,5 @@ +var commandHeader = 'squeezelite -b 500:2000 -d all=info '; + // First, checks if it isn't implemented yet. if (!String.prototype.format) { String.prototype.format = function() { @@ -173,10 +175,18 @@ $(document).ready(function(){ $( "#wifi" ).slideDown( "fast", function() {}) }); - $("#update-command").on("click", function() { + $("#update-command").click(function() { updateAutoexec(); }); + $("#generate-command").click(function() { + generateCommand(); + }); + + $('[name=audio]').click(function(){ + selectOutput(this); + }); + //first time the page loads: attempt get the connection status and start the wifi scan refreshAP(); startCheckStatusInterval(); @@ -184,27 +194,6 @@ $(document).ready(function(){ getConfig(); }); - -function performFactory(){ - -// $( "#ok-connect" ).prop("disabled",true); -// $( "#ssid-wait" ).text(selectedSSID); -// $( "#connect" ).slideUp( "fast", function() {}); -// $( "#connect_manual" ).slideUp( "fast", function() {}); -// $( "#connect-wait" ).slideDown( "fast", function() {}); -// // todo: should we update the UI here? - - $.ajax({ - url: '/factory.json', - dataType: 'json', - method: 'POST', - cache: false, - data: { 'timestamp': Date.now()} - }); - - -} - function performConnect(conntype){ //stop the status refresh. This prevents a race condition where a status @@ -407,3 +396,44 @@ function updateAutoexec(){ console.log('sent config JSON with headers:', autoexec, autoexec1); } +function performFactory(){ +// $( "#ok-connect" ).prop("disabled",true); +// $( "#ssid-wait" ).text(selectedSSID); +// $( "#connect" ).slideUp( "fast", function() {}); +// $( "#connect_manual" ).slideUp( "fast", function() {}); +// $( "#connect-wait" ).slideDown( "fast", function() {}); +// // todo: should we update the UI here? + + $.ajax({ + url: '/factory.json', + dataType: 'json', + method: 'POST', + cache: false, + data: { 'timestamp': Date.now()} + }); +} + +var output = ''; +function selectOutput(el) { + if ($(el).attr('id') == 'bt') { + $("#btsinkdiv").show(200); + output = 'bt'; + } else { + $("#btsinkdiv").hide(200); + output = 'i2s'; + } +} + +function generateCommand() { + var commandLine = commandHeader + '-n ' + $("#player").val(); + + if (output == 'bt') { + commandLine += ' -o "BT -n \'' + $("#btsink").val() + '\'" -R -u m -Z 192000 -r "44100-44100"'; + } else { + commandLine += ' -o I2S'; + } + if ($("#optional").val() != '') { + commandLine += ' ' + $("#optional").val(); + } + $("#autoexec1").val(commandLine); +} diff --git a/components/wifi-manager/http_server.c b/components/wifi-manager/http_server.c index 5b536940..0564b340 100644 --- a/components/wifi-manager/http_server.c +++ b/components/wifi-manager/http_server.c @@ -308,7 +308,7 @@ void http_server_netconn_serve(struct netconn *conn) { if(autoexec_value ){ // todo: replace line below, as it causes an error during compile. - // snprintf(autoexec_value, lenS+1, autoexec_value); + snprintf(autoexec_value, lenS+1, autoexec_value); if(lenS < MAX_COMMAND_LINE_SIZE ){ ESP_LOGD(TAG, "http_server_netconn_serve: config.json/ call, with %s: %s, length %i", autoexec_key, autoexec_value, lenS); wifi_manager_save_autoexec_config(autoexec_value,autoexec_key,lenS); diff --git a/components/wifi-manager/index.html b/components/wifi-manager/index.html index 0f2157d5..e7cea9f3 100644 --- a/components/wifi-manager/index.html +++ b/components/wifi-manager/index.html @@ -182,6 +182,29 @@ function handleClick(cb) {
+
+

Audio output

+ + + + +
+
+ +
+
+

Player name

+ +
+
+

Optional setting (e.g. for LMS IP address)

+ +
+ +
+ +
+

Command to run

diff --git a/components/wifi-manager/style.css b/components/wifi-manager/style.css index 66e70a7e..260fa7bd 100644 --- a/components/wifi-manager/style.css +++ b/components/wifi-manager/style.css @@ -347,7 +347,32 @@ input#ota { margin-bottom: 15px; } +#btsink, #player, #optional { + margin-left: 13px; +} + +#btsinkdiv { + display: none; + margin-top: 20px; +} + textarea#autoexec1 { width: 100%; } +.toggle-buttons input[type="radio"] { + visibility: hidden; + width: 3px; + margin-top: 10px; +} + +.toggle-buttons label { + border: 1px solid #000; + border-radius: 0.5em; + padding: 0.5em; +} + +.toggle-buttons input:checked + label { + background: #5a9900; + box-shadow: none; +} From e62616c232ef511a8194bb2b2e36e72e20a92c85 Mon Sep 17 00:00:00 2001 From: Christian Herzog Date: Wed, 4 Sep 2019 21:32:39 +0200 Subject: [PATCH 2/4] fix autoexec1 length problem --- components/wifi-manager/http_server.c | 5 ----- components/wifi-manager/wifi_manager.c | 8 +++++--- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/components/wifi-manager/http_server.c b/components/wifi-manager/http_server.c index 34152dd9..74cd7cdd 100644 --- a/components/wifi-manager/http_server.c +++ b/components/wifi-manager/http_server.c @@ -35,9 +35,6 @@ function to process requests, decode URLs, serve files, etc. etc. #include "cmd_system.h" -// todo: resolve the restrict error below -#pragma GCC diagnostic warning "-Wrestrict" - /* @brief tag used for ESP serial console messages */ static const char TAG[] = "http_server"; static const char json_start[] = "{ \"autoexec\": %u, \"list\": ["; @@ -309,8 +306,6 @@ void http_server_netconn_serve(struct netconn *conn) { if(autoexec_value ){ - // todo: replace line below, as it causes an error during compile. - snprintf(autoexec_value, lenS+1, autoexec_value); if(lenS < MAX_COMMAND_LINE_SIZE ){ ESP_LOGD(TAG, "http_server_netconn_serve: config.json/ call, with %s: %s, length %i", autoexec_key, autoexec_value, lenS); wifi_manager_save_autoexec_config(autoexec_value,autoexec_key,lenS); diff --git a/components/wifi-manager/wifi_manager.c b/components/wifi-manager/wifi_manager.c index 7d997700..9fde0f95 100644 --- a/components/wifi-manager/wifi_manager.c +++ b/components/wifi-manager/wifi_manager.c @@ -242,7 +242,9 @@ esp_err_t wifi_manager_save_autoexec_flag(uint8_t flag){ } esp_err_t wifi_manager_save_autoexec_config(char * value, char * name, int len){ nvs_handle handle; + char val[len+1]; esp_err_t esp_err; + if (len) { *val = '\0'; strncat(val, value, len); } ESP_LOGI(TAG, "About to save config to flash"); esp_err = nvs_open(wifi_manager_nvs_namespace, NVS_READWRITE, &handle); if (esp_err != ESP_OK) { @@ -250,9 +252,9 @@ esp_err_t wifi_manager_save_autoexec_config(char * value, char * name, int len){ return esp_err; } - esp_err = nvs_set_str(handle, name, value); + esp_err = nvs_set_str(handle, name, val); if (esp_err != ESP_OK){ - ESP_LOGE(TAG,"Unable to save value %s=%s",name,value); + ESP_LOGE(TAG,"Unable to save value %s=%s",name,val); nvs_close(handle); return esp_err; } @@ -265,7 +267,7 @@ esp_err_t wifi_manager_save_autoexec_config(char * value, char * name, int len){ nvs_close(handle); - ESP_LOGD(TAG, "wifi_manager_wrote %s=%s with length %i", name, value, len); + ESP_LOGD(TAG, "wifi_manager_wrote %s=%s with length %i", name, val, len); return ESP_OK; From 78f18a672f28727865cdb948290613c85554e1f3 Mon Sep 17 00:00:00 2001 From: Christian Herzog Date: Tue, 10 Sep 2019 15:46:05 +0200 Subject: [PATCH 3/4] add SPDIF config --- components/wifi-manager/code.js | 6 ++++++ components/wifi-manager/index.html | 2 ++ 2 files changed, 8 insertions(+) diff --git a/components/wifi-manager/code.js b/components/wifi-manager/code.js index f50a994b..0ba261d0 100644 --- a/components/wifi-manager/code.js +++ b/components/wifi-manager/code.js @@ -304,6 +304,7 @@ function checkStatus(){ //update wait screen $( "#loading" ).hide(); + $( "#connect-success" ).append("

Your IP address now is: " + text(data["ip"]) + "

"); $( "#connect-success" ).show(); $( "#connect-fail" ).hide(); } @@ -418,6 +419,9 @@ function selectOutput(el) { if ($(el).attr('id') == 'bt') { $("#btsinkdiv").show(200); output = 'bt'; + } else if ($(el).attr('id') == 'spdif') { + $("#btsinkdiv").hide(200); + output = 'spdif'; } else { $("#btsinkdiv").hide(200); output = 'i2s'; @@ -429,6 +433,8 @@ function generateCommand() { if (output == 'bt') { commandLine += ' -o "BT -n \'' + $("#btsink").val() + '\'" -R -u m -Z 192000 -r "44100-44100"'; + } else if (output == 'spdif') { + commandLine += ' -o SPDIF'; } else { commandLine += ' -o I2S'; } diff --git a/components/wifi-manager/index.html b/components/wifi-manager/index.html index e7cea9f3..ecd25c21 100644 --- a/components/wifi-manager/index.html +++ b/components/wifi-manager/index.html @@ -186,6 +186,8 @@ function handleClick(cb) {

Audio output

+ +
From f33fb6fb45c3cca01af4ea5beb5823fe15fcf695 Mon Sep 17 00:00:00 2001 From: Christian Herzog Date: Tue, 10 Sep 2019 16:33:42 +0200 Subject: [PATCH 4/4] UI cleanup --- components/wifi-manager/code.js | 11 ++++++++++ components/wifi-manager/index.html | 32 ++++++++++++++++++++++-------- components/wifi-manager/style.css | 5 ++++- 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/components/wifi-manager/code.js b/components/wifi-manager/code.js index 0ba261d0..6c903dbf 100644 --- a/components/wifi-manager/code.js +++ b/components/wifi-manager/code.js @@ -1,3 +1,4 @@ +var recovery = 0; var commandHeader = 'squeezelite -b 500:2000 -d all=info '; // First, checks if it isn't implemented yet. @@ -187,6 +188,16 @@ $(document).ready(function(){ selectOutput(this); }); + if (recovery) { + $("#recoverydiv").hide(); + $("#otadiv").show(); + $("#command_line").hide(); + $("#wifi").hide(); + } else { + $("#recoverydiv").show(); + $("#otadiv").hide(); + } + //first time the page loads: attempt get the connection status and start the wifi scan refreshAP(); startCheckStatusInterval(); diff --git a/components/wifi-manager/index.html b/components/wifi-manager/index.html index ecd25c21..0aa9f092 100644 --- a/components/wifi-manager/index.html +++ b/components/wifi-manager/index.html @@ -158,10 +158,14 @@ function heartbeat() } function handleClick(cb) { - if (cb.checked) { - $("#autoexec-command").show(200); - } else { - $("#autoexec-command").hide(200); + console.log(cb); + if (cb.id == 'autoexec-cb') { + if (cb.checked) { + $("#autoexec-command").show(200); + } else { + $("#autoexec-command").hide(200); + } + } else if (cb.id == 'autoexec-cb') { } } @@ -175,7 +179,7 @@ function handleClick(cb) {

-
@@ -184,7 +188,7 @@ function handleClick(cb) {

Audio output

- + @@ -207,14 +211,26 @@ function handleClick(cb) {
-

Command to run

+

Squeezelite command to run

- + +
+ +
+

System management

+

Check for firmware upgrade

+
+ +

Currently running: 0.1 - latest available version: 0.2

+
+

Reboot to recovery system to perform firmware upgrade

+
+
diff --git a/components/wifi-manager/style.css b/components/wifi-manager/style.css index 260fa7bd..39d1414f 100644 --- a/components/wifi-manager/style.css +++ b/components/wifi-manager/style.css @@ -22,7 +22,6 @@ button:focus { outline: none; } input[type="button"] { - width: 100px; padding: 5px; text-align: center; display: block; @@ -376,3 +375,7 @@ textarea#autoexec1 { background: #5a9900; box-shadow: none; } + +#otadiv { + display: none; +}