Skip to content

Commit

Permalink
Fixed menu to html code to handle nested menu if/else/endif blocks. I…
Browse files Browse the repository at this point in the history
…mproved the display of checkboxes so they show the choices text.
  • Loading branch information
MartinNohr committed Oct 20, 2022
1 parent e2417c1 commit a9f40d7
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 49 deletions.
Binary file modified MagicImageWand.docx
Binary file not shown.
14 changes: 8 additions & 6 deletions MagicImageWand.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

const char* MIW_Version = "2.79";
const char* MIW_Version = "2.80";

const char* StartFileName = "START.MIW";
#include "MIWconfig.h"
Expand Down Expand Up @@ -786,16 +786,16 @@ MenuItem LedLightBarMenu[] = {
{eBool,"Allow rollover: %s",ToggleBool,&BuiltinInfo.bAllowRollover,0,0,0,"Yes","No"},
{eTextInt,"Change Delay: %d mS",GetIntegerValue,&BuiltinInfo.nDisplayAllChangeTime,0,1000},
{eList,"Color Mode: %s",GetSelectChoice,&BuiltinInfo.nLightBarMode,0,sizeof(LightBarModeText) / sizeof(*LightBarModeText) - 1,0,NULL,NULL,NULL,LightBarModeText},
{eIfIntEqual,"",NULL,&BuiltinInfo.nLightBarMode,LBMODE_RGB},
{eTextInt,"Red: %d",GetIntegerValue,&BuiltinInfo.nDisplayAllRed,0,255},
{eTextInt,"Green: %d",GetIntegerValue,&BuiltinInfo.nDisplayAllGreen,0,255},
{eTextInt,"Blue: %d",GetIntegerValue,&BuiltinInfo.nDisplayAllBlue,0,255},
{eEndif},
{eIfIntEqual,"",NULL,&BuiltinInfo.nLightBarMode,LBMODE_HSV},
{eTextInt,"Hue: %d",GetIntegerValueHue,&BuiltinInfo.nDisplayAllHue,0,255,0,NULL,NULL,UpdateStripHue},
{eTextInt,"Saturation: %d",GetIntegerValue,&BuiltinInfo.nDisplayAllSaturation,0,255},
{eTextInt,"Brightness: %d",GetIntegerValue,&BuiltinInfo.nDisplayAllBrightness,0,255,0,NULL,NULL,UpdateStripBrightness},
{eEndif},
{eIfIntEqual,"",NULL,&BuiltinInfo.nLightBarMode,LBMODE_RGB},
{eTextInt,"Red: %d",GetIntegerValue,&BuiltinInfo.nDisplayAllRed,0,255},
{eTextInt,"Green: %d",GetIntegerValue,&BuiltinInfo.nDisplayAllGreen,0,255},
{eTextInt,"Blue: %d",GetIntegerValue,&BuiltinInfo.nDisplayAllBlue,0,255},
{eEndif},
{eIfIntEqual,"",NULL,&BuiltinInfo.nLightBarMode,LBMODE_KELVIN},
{eList,"Temp: %s",GetSelectChoice,&BuiltinInfo.nColorTemperature,0,sizeof(LightBarColorKelvinText) / sizeof(*LightBarColorKelvinText) - 1,0,NULL,NULL,NULL,LightBarColorKelvinText},
{eEndif},
Expand Down Expand Up @@ -1298,3 +1298,5 @@ OnServerItem OnServerList[] = {
{"/verifyrebootsystem", VerifyRebootSystem},
{"/rebootsystem", RebootSystem},
};

String MenuToHtml(MenuItem* menu, bool bActive = true, int nLevel = 0);
80 changes: 39 additions & 41 deletions MagicImageWand.ino
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,6 @@ void ShowMenu(struct MenuItem* menu)
MenuStack.top()->menucount = 0;
int y = 0;
int x = 0;
char line[50]{};
// load with a false to start with
std::stack<bool> skipStack;
skipStack.push(false);
Expand Down Expand Up @@ -5354,57 +5353,40 @@ void HomePage() {
// handle the builtin settings changes
void WebChangeBuiltinSettings()
{
bool bSkipping = false;
MenuItem* menu = BuiltInFiles[currentFileIndex.nFileIndex].menu;
Serial.println("builtin settings change");
//Serial.println("builtin settings change");
String str, line, name, stmp;
double sfloat;
for (int ix = 0; menu->op != eTerminate; ++ix, ++menu) {
if (bSkipping) {
switch (menu->op) {
case eIfEqual:
case eIfIntEqual:
case eElse:
case eEndif:
break;
default:
continue;
break;
}
}
name = "bi_" + String(ix);
//Serial.println("id:" + name);
switch (menu->op) {
case eText:
Serial.println("eText");
//Serial.println("eText");
break;
case eTextInt:
*(int*)(menu->value) = server.arg(name).toInt();
//Serial.println("eTextInt:" + name);
if (server.hasArg(name))
*(int*)(menu->value) = server.arg(name).toInt();
break;
case eBool:
*(bool*)(menu->value) = server.arg(name).length() ? true : false;
break;
case eList: // a dropdown list
// figure out which one
for (int ix = 0; ix <= menu->max; ++ix) {
if (server.arg(name) == String(menu->nameList[ix])) {
*(int*)menu->value = ix;
if (server.hasArg(name)) {
for (int ix = 0; ix <= menu->max; ++ix) {
if (server.arg(name) == String(menu->nameList[ix])) {
*(int*)menu->value = ix;
}
}
}
Serial.println("eList: " + String(server.arg(name)));
//Serial.println("eList: " + String(server.arg(name)));
break;
case eIfEqual:
bSkipping = *(bool*)(menu->value) != (menu->min ? true : false);
break;
case eIfIntEqual:
bSkipping = *(int*)(menu->value) != (menu->min);
break;
case eElse:
bSkipping = !bSkipping;
break;
case eEndif:
bSkipping = false;
break;
case eExit: // do nothing
case eTextCurrentFile:
case eMenu:
Expand Down Expand Up @@ -5900,13 +5882,25 @@ void WebCancel()
}

// map a menuitem list to html
String MenuToHtml(MenuItem* menu)
// recurses for each eIf
String MenuToHtml(MenuItem* pMenu, bool bActive, int nLevel)
{
bool bSkipping = false;
String str, line, name, stmp;
static String str;
static int ix;
static MenuItem* menu, *StartMenu;
static String line, name, stmp;
double sfloat;
for (int ix = 0; menu->op != eTerminate; ++ix, ++menu) {
if (bSkipping) {
if (nLevel == 0) {
StartMenu = pMenu;
str = "";
ix = 0;
}
else {
++ix;
}
for (menu = &StartMenu[ix]; menu->op != eTerminate; ++ix, ++menu) {
if (!bActive) {
// skip if not one of the if else parts when not active
switch (menu->op) {
case eIfEqual:
case eIfIntEqual:
Expand All @@ -5919,6 +5913,7 @@ String MenuToHtml(MenuItem* menu)
}
}
name = "bi_" + String(ix);
//Serial.println("name: " + name);
// keep the line without %x's
line = menu->text;
if (line.indexOf("%d.%d") >= 0) {
Expand All @@ -5939,8 +5934,8 @@ String MenuToHtml(MenuItem* menu)
str += "<input type='text' name='" + name + "' size='" + String(5) + "' value='" + stmp + "'>";
str += "</label>";
break;
case eBool:
str += "<label>" + line;
case eBool: // show the two text choices in (...)
str += "<label>" + line + " (" + menu->on + "&#x2611; | " + menu->off + "&#9633;)";
str += "<input type='checkbox' name='" + name + "' value='" + name + "'";
if (*(bool*)(menu->value))
str += " checked='checked'";
Expand All @@ -5962,16 +5957,18 @@ String MenuToHtml(MenuItem* menu)
case eExit:
break;
case eIfEqual:
bSkipping = *(bool*)(menu->value) != (menu->min ? true : false);
MenuToHtml(NULL, *(bool*)(menu->value) == (menu->min ? true : false), nLevel + 1);
continue;
break;
case eIfIntEqual:
bSkipping = *(int*)(menu->value) != (menu->min);
MenuToHtml(NULL, *(int*)(menu->value) == (menu->min), nLevel + 1);
continue;
break;
case eElse:
bSkipping = !bSkipping;
bActive = !bActive;
break;
case eEndif:
bSkipping = false;
return str;
break;
case eTextCurrentFile:
case eMenu:
Expand All @@ -5984,8 +5981,9 @@ String MenuToHtml(MenuItem* menu)
default:
break;
}
if (!bSkipping)
if (bActive) {
str += "<br>";
}
}
return str;
}
Expand Down
Binary file modified Release/MagicImageWand.bin
Binary file not shown.
2 changes: 1 addition & 1 deletion __vm/Compile.vmps.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion __vm/Upload.vmps.xml

Large diffs are not rendered by default.

0 comments on commit a9f40d7

Please sign in to comment.