Optimized the code and especially string literals to get a smaller RAM footprint
This commit is contained in:
parent
86074fbc67
commit
781354a02f
@ -422,54 +422,55 @@ boolean ioGetModeApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc,
|
|||||||
boolean ioMode[8] = {0};
|
boolean ioMode[8] = {0};
|
||||||
char buffer[300] = "";
|
char buffer[300] = "";
|
||||||
char helperBuffer[20] = "";
|
char helperBuffer[20] = "";
|
||||||
|
const char * const IN = "IN", * const OUT = "OUT";
|
||||||
|
|
||||||
p->getIoManager().getPcf().getPinModeAll(ioMode);//We retrieve the IO modes aka INPUT or OUTPUT
|
p->getIoManager().getPcf().getPinModeAll(ioMode);//We retrieve the IO modes aka INPUT or OUTPUT
|
||||||
|
|
||||||
if(HRD.getParams.count() == 0)//We send every IO mode
|
if(HRD.getParams.count() == 0)//We send every IO mode
|
||||||
{
|
{
|
||||||
sprintf(buffer,"HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{ \"status\" : \"ok\", \"P0\" : \"%s\", \"P1\" : \"%s\", \"P2\" : \"%s\", \"P3\" : \"%s\", \"P4\" : \"%s\", \"P5\" : \"%s\", \"P6\" : \"%s\", \"P7\" : \"%s\" }",ioMode[0] ? "OUT":"IN",ioMode[1] ? "OUT":"IN",ioMode[2] ? "OUT":"IN",ioMode[3] ? "OUT":"IN",ioMode[4] ? "OUT":"IN",ioMode[5] ? "OUT":"IN",ioMode[6] ? "OUT":"IN",ioMode[7] ? "OUT":"IN");
|
sprintf(buffer,"HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{\"status\":\"ok\",\"P0\":\"%s\",\"P1\":\"%s\",\"P2\":\"%s\",\"P3\":\"%s\",\"P4\":\"%s\",\"P5\":\"%s\",\"P6\":\"%s\",\"P7\":\"%s\"}",ioMode[0] ? OUT:IN,ioMode[1] ? OUT:IN,ioMode[2] ? OUT:IN,ioMode[3] ? OUT:IN,ioMode[4] ? OUT:IN,ioMode[5] ? OUT:IN,ioMode[6] ? OUT:IN,ioMode[7] ? OUT:IN);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
strcpy(buffer,"HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{\"status\":\"ok\"");
|
strcpy(buffer,"HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{\"status\":\"ok\"");
|
||||||
if(HRD.getParams("P0") != NULL)
|
if(HRD.getParams("P0") != NULL)
|
||||||
{
|
{
|
||||||
sprintf(helperBuffer,", \"P0\" : \"%s\"",ioMode[0] ? "OUT":"IN");
|
sprintf(helperBuffer,",\"P0\":\"%s\"",ioMode[0] ? OUT:IN);
|
||||||
strcat(buffer,helperBuffer);
|
strcat(buffer,helperBuffer);
|
||||||
}
|
}
|
||||||
if(HRD.getParams("P1") != NULL)
|
if(HRD.getParams("P1") != NULL)
|
||||||
{
|
{
|
||||||
sprintf(helperBuffer,", \"P1\" : \"%s\"",ioMode[1] ? "OUT":"IN");
|
sprintf(helperBuffer,",\"P1\":\"%s\"",ioMode[1] ? OUT:IN);
|
||||||
strcat(buffer,helperBuffer);
|
strcat(buffer,helperBuffer);
|
||||||
}
|
}
|
||||||
if(HRD.getParams("P2") != NULL)
|
if(HRD.getParams("P2") != NULL)
|
||||||
{
|
{
|
||||||
sprintf(helperBuffer,", \"P2\" : \"%s\"",ioMode[2] ? "OUT":"IN");
|
sprintf(helperBuffer,",\"P2\":\"%s\"",ioMode[2] ? OUT:IN);
|
||||||
strcat(buffer,helperBuffer);
|
strcat(buffer,helperBuffer);
|
||||||
}
|
}
|
||||||
if(HRD.getParams("P3") != NULL)
|
if(HRD.getParams("P3") != NULL)
|
||||||
{
|
{
|
||||||
sprintf(helperBuffer,", \"P3\" : \"%s\"",ioMode[3] ? "OUT":"IN");
|
sprintf(helperBuffer,",\"P3\":\"%s\"",ioMode[3] ? OUT:IN);
|
||||||
strcat(buffer,helperBuffer);
|
strcat(buffer,helperBuffer);
|
||||||
}
|
}
|
||||||
if(HRD.getParams("P4") != NULL)
|
if(HRD.getParams("P4") != NULL)
|
||||||
{
|
{
|
||||||
sprintf(helperBuffer,", \"P4\" : \"%s\"",ioMode[4] ? "OUT":"IN");
|
sprintf(helperBuffer,",\"P4\":\"%s\"",ioMode[4] ? OUT:IN);
|
||||||
strcat(buffer,helperBuffer);
|
strcat(buffer,helperBuffer);
|
||||||
}
|
}
|
||||||
if(HRD.getParams("P5") != NULL)
|
if(HRD.getParams("P5") != NULL)
|
||||||
{
|
{
|
||||||
sprintf(helperBuffer,", \"P5\" : \"%s\"",ioMode[5] ? "OUT":"IN");
|
sprintf(helperBuffer,",\"P5\":\"%s\"",ioMode[5] ? OUT:IN);
|
||||||
strcat(buffer,helperBuffer);
|
strcat(buffer,helperBuffer);
|
||||||
}
|
}
|
||||||
if(HRD.getParams("P6") != NULL)
|
if(HRD.getParams("P6") != NULL)
|
||||||
{
|
{
|
||||||
sprintf(helperBuffer,", \"P6\" : \"%s\"",ioMode[6] ? "OUT":"IN");
|
sprintf(helperBuffer,",\"P6\":\"%s\"",ioMode[6] ? OUT:IN);
|
||||||
strcat(buffer,helperBuffer);
|
strcat(buffer,helperBuffer);
|
||||||
}
|
}
|
||||||
if(HRD.getParams("P7") != NULL)
|
if(HRD.getParams("P7") != NULL)
|
||||||
{
|
{
|
||||||
sprintf(helperBuffer,", \"P7\" : \"%s\"",ioMode[7] ? "OUT":"IN");
|
sprintf(helperBuffer,",\"P7\":\"%s\"",ioMode[7] ? OUT:IN);
|
||||||
strcat(buffer,helperBuffer);
|
strcat(buffer,helperBuffer);
|
||||||
}
|
}
|
||||||
strcat(buffer," }");
|
strcat(buffer," }");
|
||||||
@ -483,43 +484,44 @@ boolean ioSetModeApi(WEBServer<WEBClient>::HttpRequestData &HRD, WiFiClient *wc,
|
|||||||
{
|
{
|
||||||
SAB *p = (SAB *)pData;
|
SAB *p = (SAB *)pData;
|
||||||
char buffer[300] = "";
|
char buffer[300] = "";
|
||||||
|
const char * const IN = "IN", * const OUT = "OUT";
|
||||||
boolean ioMode[8] = {0};
|
boolean ioMode[8] = {0};
|
||||||
|
|
||||||
if(HRD.getParams("P0") != NULL)
|
if(HRD.getParams("P0") != NULL)
|
||||||
{
|
{
|
||||||
p->getIoManager().getPcf().pinMode(PCF8574::P0,strcmp(HRD.getParams("P0")->getString(), "IN") == 0 ? INPUT:OUTPUT);
|
p->getIoManager().getPcf().pinMode(PCF8574::P0,strcmp(HRD.getParams("P0")->getString(), IN) == 0 ? INPUT:OUTPUT);
|
||||||
}
|
}
|
||||||
if(HRD.getParams("P1") != NULL)
|
if(HRD.getParams("P1") != NULL)
|
||||||
{
|
{
|
||||||
p->getIoManager().getPcf().pinMode(PCF8574::P1,strcmp(HRD.getParams("P1")->getString(), "IN") == 0 ? INPUT:OUTPUT);
|
p->getIoManager().getPcf().pinMode(PCF8574::P1,strcmp(HRD.getParams("P1")->getString(), IN) == 0 ? INPUT:OUTPUT);
|
||||||
}
|
}
|
||||||
if(HRD.getParams("P2") != NULL)
|
if(HRD.getParams("P2") != NULL)
|
||||||
{
|
{
|
||||||
p->getIoManager().getPcf().pinMode(PCF8574::P2,strcmp(HRD.getParams("P2")->getString(), "IN") == 0 ? INPUT:OUTPUT);
|
p->getIoManager().getPcf().pinMode(PCF8574::P2,strcmp(HRD.getParams("P2")->getString(), IN) == 0 ? INPUT:OUTPUT);
|
||||||
}
|
}
|
||||||
if(HRD.getParams("P3") != NULL)
|
if(HRD.getParams("P3") != NULL)
|
||||||
{
|
{
|
||||||
p->getIoManager().getPcf().pinMode(PCF8574::P3,strcmp(HRD.getParams("P3")->getString(), "IN") == 0 ? INPUT:OUTPUT);
|
p->getIoManager().getPcf().pinMode(PCF8574::P3,strcmp(HRD.getParams("P3")->getString(), IN) == 0 ? INPUT:OUTPUT);
|
||||||
}
|
}
|
||||||
if(HRD.getParams("P4") != NULL)
|
if(HRD.getParams("P4") != NULL)
|
||||||
{
|
{
|
||||||
p->getIoManager().getPcf().pinMode(PCF8574::P4,strcmp(HRD.getParams("P4")->getString(), "IN") == 0 ? INPUT:OUTPUT);
|
p->getIoManager().getPcf().pinMode(PCF8574::P4,strcmp(HRD.getParams("P4")->getString(), IN) == 0 ? INPUT:OUTPUT);
|
||||||
}
|
}
|
||||||
if(HRD.getParams("P5") != NULL)
|
if(HRD.getParams("P5") != NULL)
|
||||||
{
|
{
|
||||||
p->getIoManager().getPcf().pinMode(PCF8574::P5,strcmp(HRD.getParams("P5")->getString(), "IN") == 0 ? INPUT:OUTPUT);
|
p->getIoManager().getPcf().pinMode(PCF8574::P5,strcmp(HRD.getParams("P5")->getString(), IN) == 0 ? INPUT:OUTPUT);
|
||||||
}
|
}
|
||||||
if(HRD.getParams("P6") != NULL)
|
if(HRD.getParams("P6") != NULL)
|
||||||
{
|
{
|
||||||
p->getIoManager().getPcf().pinMode(PCF8574::P6,strcmp(HRD.getParams("P6")->getString(), "IN") == 0 ? INPUT:OUTPUT);
|
p->getIoManager().getPcf().pinMode(PCF8574::P6,strcmp(HRD.getParams("P6")->getString(), IN) == 0 ? INPUT:OUTPUT);
|
||||||
}
|
}
|
||||||
if(HRD.getParams("P7") != NULL)
|
if(HRD.getParams("P7") != NULL)
|
||||||
{
|
{
|
||||||
p->getIoManager().getPcf().pinMode(PCF8574::P7,strcmp(HRD.getParams("P7")->getString(), "IN") == 0 ? INPUT:OUTPUT);
|
p->getIoManager().getPcf().pinMode(PCF8574::P7,strcmp(HRD.getParams("P7")->getString(), IN) == 0 ? INPUT:OUTPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
p->getIoManager().getPcf().getPinModeAll(ioMode);//We retrieve the IO modes aka INPUT or OUTPUT
|
p->getIoManager().getPcf().getPinModeAll(ioMode);//We retrieve the IO modes aka INPUT or OUTPUT
|
||||||
sprintf(buffer,"HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{ \"status\" : \"ok\", \"P0\" : \"%s\", \"P1\" : \"%s\", \"P2\" : \"%s\", \"P3\" : \"%s\", \"P4\" : \"%s\", \"P5\" : \"%s\", \"P6\" : \"%s\", \"P7\" : \"%s\" }",ioMode[0] ? "OUT":"IN",ioMode[1] ? "OUT":"IN",ioMode[2] ? "OUT":"IN",ioMode[3] ? "OUT":"IN",ioMode[4] ? "OUT":"IN",ioMode[5] ? "OUT":"IN",ioMode[6] ? "OUT":"IN",ioMode[7] ? "OUT":"IN");
|
sprintf(buffer,"HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{\"status\":\"ok\",\"P0\":\"%s\",\"P1\":\"%s\",\"P2\":\"%s\",\"P3\":\"%s\",\"P4\":\"%s\",\"P5\":\"%s\",\"P6\":\"%s\",\"P7\":\"%s\"}",ioMode[0] ? OUT:IN,ioMode[1] ? OUT:IN,ioMode[2] ? OUT:IN,ioMode[3] ? OUT:IN,ioMode[4] ? OUT:IN,ioMode[5] ? OUT:IN,ioMode[6] ? OUT:IN,ioMode[7] ? OUT:IN);
|
||||||
|
|
||||||
wc->print(buffer);
|
wc->print(buffer);
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user