Tune GPIOViewer

This commit is contained in:
Theo Arends 2024-01-13 15:16:34 +01:00
parent 779fe14c60
commit 9fc47b7d90
4 changed files with 97 additions and 49 deletions

View File

@ -0,0 +1,31 @@
/////////////////////////////////////////////////////////////////////
// compressed by tools/unishox/compress-html-uncompressed.py
/////////////////////////////////////////////////////////////////////
const size_t HTTP_GV_PAGE_SIZE = 806;
const char HTTP_GV_PAGE_COMPRESSED[] PROGMEM = "\x3D\x0F\xE1\x10\x98\x1D\x19\x0C\x64\x88\x51\x51\x0D\x20\x8F\xC3\xD0\x55\x0D\x08"
"\xFC\x3D\x05\x3B\x10\xFC\x3D\x2B\x68\x26\x7E\x1F\x5E\x47\x5A\x21\xE2\x18\x5A\x58"
"\x88\xCF\x58\xFB\xF9\xE8\x76\x02\x0D\x43\xD0\x75\xF9\xA1\x5F\x66\x0F\x87\xD9\xF5"
"\xE3\xEC\xFC\x3D\x02\xDE\x34\x5A\x21\xF0\xFB\x11\x98\xB1\x61\x51\x7A\x8C\x82\x65"
"\xE1\x4D\xD1\xF6\xBE\xC2\x3E\x1F\x7E\xA3\x20\x9F\x81\x06\x68\x20\xE2\x80\x8F\x89"
"\x0E\xCB\xF8\x80\xC1\xB1\x0F\xB0\x8F\x87\xDE\x87\x9C\x08\x75\x4C\x59\x9E\x87\x9C"
"\x74\xD0\xF0\xFB\x54\x64\x31\x9F\x0F\xBD\x1B\x63\xCC\xEC\x36\x1D\x7A\x1E\x71\xF6"
"\x7E\x1E\x9E\x0F\xFA\x32\x97\xBE\x19\xF0\xFB\x04\x19\x07\x60\xFB\x1C\x5E\xC0\xCD"
"\x1D\x1D\x0D\x7E\x3E\xCF\xC3\xD0\xEC\x04\x1A\x60\xA1\x83\x82\x0E\xFA\x3F\xB4\x18"
"\xA7\xF0\x50\xC2\xCF\xC3\x3B\xFA\xF3\xF9\x9B\xF9\x0C\xCF\xD1\xF0\xFA\x10\xF0\x67"
"\x7F\x5A\x30\xF8\x7D\x9F\x5E\x3E\xCF\x06\x77\xF5\xEC\x17\xF0\xD9\xF3\x98\xFA\x26"
"\x66\xFA\x8B\xD8\x2F\xE1\xB3\xBA\x7D\x8A\xAA\x18\x79\x9D\x87\x61\xF5\xE3\xCC\xFA"
"\x10\xEC\x66\x6F\xAB\xC7\xD9\xDE\x04\x1C\x3A\xC6\x8C\x0B\x78\x78\xFD\xEF\x53\xF9"
"\x9D\x84\x7C\x3E\xCF\xA1\x01\x07\x29\x19\xEF\xD8\xD2\xF6\x9B\x59\xF0\xFB\x3E\x84"
"\x44\x68\x43\x81\x06\x91\x8F\xB6\x5E\x34\x74\x18\xA2\xF0\xCB\x0C\x11\x6C\x02\x2F"
"\x01\x47\x60\x20\xF2\x78\x3B\x04\x32\x3F\x0F\x41\x34\xCD\x06\x15\xFB\xC7\xC3\xEC"
"\x7B\xFA\x21\xD6\x1E\x75\x5E\xF3\xF9\xF6\x08\x36\x34\x43\xE1\xF6\x35\xFB\xD6\x3C"
"\xC8\x76\x1B\x0F\xB0\x43\xC2\x01\x0A\x79\xD6\x3B\x0D\x88\x56\x88\x23\xE3\xEC\xFC"
"\x3D\x0E\xC1\x34\xCC\x10\x79\x9A\x7F\x04\x3C\x14\x10\x65\x1F\x60\x85\xA9\x3F\x82"
"\x46\x9D\xA3\x6C\x79\x82\x86\x9F\xA3\x6C\x79\x90\xFF\xEC\x60\xC7\xF0\x44\xD4\x41"
"\x07\x0B\x1F\x04\x2A\x2B\x47\xE1\xE9\xA3\x47\x81\x17\x99\x82\xD1\xB6\x3C\xCF\xB0"
"\x41\xE4\x3C\xFB\x56\x15\x1F\x0F\xB2\x1D\x97\xF1\x10\x20\xD5\x04\x6C\xDF\x84\xD0"
"\xEE\xB3\xFE\x04\x4E\x03\xC1\x06\x10\x23\xC8\x3B\x01\x07\x87\xA3\xB0\x55\x0D\x08"
"\xFC";
#define HTTP_GV_PAGE Decompress(HTTP_GV_PAGE_COMPRESSED,HTTP_GV_PAGE_SIZE).c_str()

View File

@ -0,0 +1,33 @@
const char HTTP_GV_PAGE[] PROGMEM =
"<!DOCTYPE HTML>"
"<html>"
"<head>"
"<title>%s - GPIO Viewer</title>" // SettingsTextEscaped(SET_DEVICENAME).c_str()
"<base href='%s'>" // GV_BASE_URL
"<link id='defaultStyleSheet' rel='stylesheet' href=''>"
"<link id='boardStyleSheet' rel='stylesheet' href=''>"
"<link rel='icon' href='favicon.ico' type='image/x-icon'>"
"<script src='script/webSocket.js'></script>"
"<script src='script/boardSwitcher.js'></script>"
"<script>"
"var serverPort=%d;" // GV_PORT
"var ip='%s';" // WiFi.localIP().toString().c_str()
"var source=new EventSource('http://%s:%d/events');" // WiFi.localIP().toString().c_str(), GV_PORT
"var sampling_interval='%d';" // Gv.sampling
"var psramSize='%d KB';" // ESP.getPsramSize() / 1024
"var freeSketchSpace='%d KB';" // ESP_getFreeSketchSpace() / 1024
"</script>"
"</head>"
"<body>"
"<div class='grid-container'>"
"<div id='messageBox' class='message-box hidden'></div>"
"<header class='header'></header>"
"<div class='image-container'>"
"<div id='imageWrapper' class='image-wrapper'>"
"<img id='boardImage' src='' alt='Board Image'>"
"<div id='indicators'></div>"
"</div>"
"</div>"
"</div>"
"</body>"
"</html>";

View File

@ -42,44 +42,14 @@
const char *GVRelease = "1.0.7";
const char HTTP_GV_PAGE[] PROGMEM =
"<!DOCTYPE HTML>"
"<html>"
"<head>"
"<title>%s - GPIO Viewer</title>"
"<base href='" GV_BASE_URL "'>"
"<link id='defaultStyleSheet' rel='stylesheet' href=''>"
"<link id='boardStyleSheet' rel='stylesheet' href=''>"
"<link rel='icon' href='favicon.ico' type='image/x-icon'>"
"<script src='script/webSocket.js'></script>"
"<script src='script/boardSwitcher.js'></script>"
"<script>"
"var serverPort=" STR(GV_PORT) ";"
"var ip='%s';" // WiFi.localIP().toString().c_str()
"var source=new EventSource('http://%s:" STR(GV_PORT) "/events');" // WiFi.localIP().toString().c_str()
"var sampling_interval='%d';" // Gv.sampling
#ifdef ESP32
"var psramSize='%d KB';" // ESP.getPsramSize() / 1024
#endif // ESP32
"var freeSketchSpace='%d KB';" // ESP_getFreeSketchSpace() / 1024
"</script>"
"</head>"
"<body>"
"<div class='grid-container'>"
"<div id='messageBox' class='message-box hidden'></div>"
"<header class='header'></header>"
// Image
"<div class='image-container'>"
"<div id='imageWrapper' class='image-wrapper'>"
"<img id='boardImage' src='' alt='Board Image'>"
"<div id='indicators'></div>"
"</div>"
"</div>"
"</div>"
"</body>"
"</html>";
#ifdef USE_UNISHOX_COMPRESSION
#include "./html_compressed/HTTP_GV_PAGE.h"
#else
#include "./html_uncompressed/HTTP_GV_PAGE.h"
#endif
const char HTTP_GV_EVENT[] PROGMEM =
// Set CORS headers for global responses
"HTTP/1.1 200 OK\n"
"Content-Type: text/event-stream;\n"
"Connection: keep-alive\n"
@ -121,9 +91,9 @@ void GVBegin(void) {
GV.WebServer = new ESP8266WebServer(GV_PORT);
// Set CORS headers for global responses
GV.WebServer->sendHeader("Access-Control-Allow-Origin", "*");
GV.WebServer->sendHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
GV.WebServer->sendHeader("Access-Control-Allow-Headers", "Content-Type");
// GV.WebServer->sendHeader(F("Access-Control-Allow-Origin"), F("*"));
// GV.WebServer->sendHeader(F("Access-Control-Allow-Methods"), F("GET, POST, OPTIONS"));
// GV.WebServer->sendHeader(F("Access-Control-Allow-Headers"), F("Content-Type"));
GV.WebServer->on("/", GVHandleRoot);
GV.WebServer->on("/release", GVHandleRelease);
GV.WebServer->on("/free_psram", GVHandleFreePSRam);
@ -138,11 +108,15 @@ void GVHandleRoot(void) {
char* content = ext_snprintf_malloc_P(HTTP_GV_PAGE,
SettingsTextEscaped(SET_DEVICENAME).c_str(),
GV_BASE_URL,
GV_PORT,
WiFi.localIP().toString().c_str(),
WiFi.localIP().toString().c_str(),
WiFi.localIP().toString().c_str(), GV_PORT,
GV.sampling,
#ifdef ESP32
ESP.getPsramSize() / 1024,
#else
0,
#endif // ESP32
ESP_getFreeSketchSpace() / 1024);
if (content == nullptr) { return; } // Avoid crash
@ -190,7 +164,7 @@ void GVEventDisconnected(void) {
}
void GVCloseEvent(void) {
GVEventSend("{}", "close", millis()); // Closes window
GVEventSend("{}", "close", millis()); // Closes web page
GVEventDisconnected();
}
@ -229,7 +203,7 @@ void GVMonitorTask(void) {
if (pwm_resolution > 0) {
pintype = GV_PWMPin;
originalValue = ledcRead2(pin);
currentState = changeUIntScale(originalValue, 0, pwm_resolution, 0, 255); // bring back to 0..255
currentState = changeUIntScale(originalValue, 0, pwm_resolution, 0, 255); // Bring back to 0..255
}
#endif // ESP32
@ -239,7 +213,7 @@ void GVMonitorTask(void) {
if (pwm_value > -1) {
pintype = GV_PWMPin;
originalValue = pwm_value;
currentState = changeUIntScale(originalValue, 0, Settings->pwm_range, 0, 255); // bring back to 0..255
currentState = changeUIntScale(originalValue, 0, Settings->pwm_range, 0, 255); // Bring back to 0..255
}
#endif // ESP8266
@ -251,12 +225,12 @@ void GVMonitorTask(void) {
originalValue = AdcRead(pin, 2);
#endif // ESP32
#ifdef ESP8266
// Fix exception 9 if using ticker - GV.sampling != 100 (CallChain: (phy)pm_wakeup_init, (adc)test_tout, ets_timer_arm_new, delay, AdcRead, String6concat, MonitorTask)
// Fix exception 9 if using ticker - GV.sampling != 100 caused by delay(1) in AdcRead() (CallChain: (phy)pm_wakeup_init, (adc)test_tout, ets_timer_arm_new, delay, AdcRead, String6concat, MonitorTask)
originalValue = (GV.sampling != 100) ? analogRead(pin) : AdcRead(pin, 1);
#endif // ESP8266
*/
originalValue = AdcRead1(pin);
currentState = changeUIntScale(originalValue, 0, AdcRange(), 0, 255); // bring back to 0..255
currentState = changeUIntScale(originalValue, 0, AdcRange(), 0, 255); // Bring back to 0..255
}
else {
// Read digital GPIO
@ -284,6 +258,7 @@ void GVMonitorTask(void) {
uint32_t heap = ESP_getFreeHeap();
if (heap != GV.freeHeap) {
// Send freeHeap
GV.freeHeap = heap;
char temp[20];
snprintf_P(temp, sizeof(temp), PSTR("%d KB"), heap / 1024);
@ -293,6 +268,7 @@ void GVMonitorTask(void) {
#ifdef ESP32
if (UsePSRAM()) {
// Send freePsram
uint32_t psram = ESP.getFreePsram();
if (psram != GV.freePSRAM) {
GV.freePSRAM = psram;
@ -305,6 +281,7 @@ void GVMonitorTask(void) {
#endif // ESP32
if (!hasChanges) {
// Send freeHeap as keepAlive
uint32_t last_sent = millis() - GV.lastSentWithNoActivity;
if (last_sent > GV_KEEP_ALIVE) {
// No activity, resending for pulse

View File

@ -356,10 +356,17 @@ uint16_t AdcRead(uint32_t pin, uint32_t factor) {
uint32_t samples = 1 << factor;
uint32_t analog = 0;
for (uint32_t i = 0; i < samples; i++) {
analog += AdcRead1(pin);
#ifdef ESP32
analog += analogReadMilliVolts(pin); // get the value corrected by calibrated values from the eFuses
#else
analog += analogRead(pin);
#endif
delay(1);
}
analog >>= factor;
#ifdef ESP32
analog = analog/(ANALOG_V33*1000) * ANALOG_RANGE; // go back from mV to ADC
#endif
return analog;
}