diff --git a/Other Examples/ProgrammableHub2/ProgrammableHub2.ino b/Other Examples/ProgrammableHub2/ProgrammableHub2.ino index 5d383fb..b5d0e37 100644 --- a/Other Examples/ProgrammableHub2/ProgrammableHub2.ino +++ b/Other Examples/ProgrammableHub2/ProgrammableHub2.ino @@ -103,17 +103,16 @@ void setup() { new SpanUserCommand('R'," - add dimmable light accessory with full RGB color control using name=",[](const char *c){addLight(c+1,true,FULL_RGB);}); new SpanUserCommand('l'," - list all light accessories",listAccessories); - new SpanUserCommand('d'," - delete a light accessory with index=",deleteAccessory); + new SpanUserCommand('d'," - delete a light accessory with index=",[](const char *buf){deleteAccessory(atoi(buf+1));}); new SpanUserCommand('D'," - delete ALL light accessories",deleteAllAccessories); new SpanUserCommand('u',"- update accessories database",updateAccessories); - - homeSpan.autoPoll(); - + } // end of setup() /////////////////////////// void loop(){ + homeSpan.poll(); webServer.handleClient(); // handle incoming web server traffic } @@ -147,21 +146,21 @@ void addLight(int index){ /////////////////////////// -void addLight(const char *name, boolean isDimmable, colorType_t colorType){ +int addLight(const char *name, boolean isDimmable, colorType_t colorType){ int index=0; for(index=0;indexsizeof(lightData[index].name)) @@ -176,6 +175,7 @@ void addLight(const char *name, boolean isDimmable, colorType_t colorType){ nvs_commit(savedData); addLight(index); + return(index); } /////////////////////////// @@ -199,9 +199,7 @@ size_t strncpy_trim(char *dest, const char *src, size_t dSize){ /////////////////////////// -void deleteAccessory(const char *buf){ - - int index=atoi(buf+1); +void deleteAccessory(int index){ if(index<0 || index>=MAX_LIGHTS){ Serial.printf("Invalid Light Accessory index - must be between 0 and %d.\n",MAX_LIGHTS-1); @@ -266,31 +264,96 @@ void listAccessories(const char *buf){ /////////////////////////// void setupWeb(){ + Serial.printf("Starting Light Server Hub at %s.local\n\n",HUB_NAME); webServer.begin(); webServer.on("/", []() { String response = "HomeSpan Programmable Light Hub"; - response += "\n"; + response += "\n"; response += "

HomeSpan Lights

"; - response += ""; + response += ""; + response += "
AccessoryDim?Color Control
"; + + int openSlots=MAX_LIGHTS; for(int i=0;i"; - response += ""; + response += ""; + response += ""; + response += ""; + response += ""; + response += ""; + openSlots--; } } + response += ""; + response += ""; + response += ""; + response += ""; + response += ""; + response += "
AccessoryDim?Color ControlAction
":">") + "
" + String(lightData[i].name) + "":">") + "":">") + " NONE "; + response += "":">") + " TEMP ONLY "; + response += "":">") + " FULL COLOR
"; + response += ""; + response += "
"; - + response += ""; + + if(!openSlots) + response += "

Can't add any more Light Accessories. Max="+ String(MAX_LIGHTS) + "

"; response += ""; webServer.send(200, "text/html", response); }); + webServer.on("/deleteLight", []() { + + int index=atoi(webServer.arg(0).c_str()); + + String response = "HomeSpan Programmable Light Hub"; + response += "Deleted Light Accessory '" + String(lightData[index].name) + "'..."; + + deleteAccessory(index); + + webServer.send(200, "text/html", response); + + }); + + webServer.on("/addLight", []() { + + colorType_t colorType=NO_COLOR; + boolean isDimmable=false; + int iName=-1; + + for(int i=0;i