/* ================================================================== * * Function: web_index * Description: Static callback function to display the homepage of the web server * Parameters: See Webduino documentation * obj is a pointer to the instance of Server that added the callback * ================================================================== */ void web_index(WebServer &server, WebServer::ConnectionType type, char * c, bool b, void * obj) { server.httpSuccess(); if (type != WebServer::HEAD) { server.printP(control_panel); } }
/* ================================================================== * * Function: web_input * Description: Static callback function to handle input to the server * Parameters: See Webduino documentation * obj is a pointer to the instance of Server that added the callback * ================================================================== */ void web_input(WebServer &server, WebServer::ConnectionType type, char * c, bool b, void * obj) { if (type == WebServer::POST) { Server * s = (Server *) obj; bool repeat; char name[16], value[16]; do { // Read all POST params, returns false when no more params repeat = server.readPOSTparam(name, 16, value, 16); if (strcmp(name, "visualizer") == 0) { int type = strtol(value, NULL, 10); // Ensure type is valid, default to VISUALIZER_BARS switch (type) { case VISUALIZER_BARS: case VISUALIZER_BARS_MIDDLE: case VISUALIZER_PULSE: case VISUALIZER_PLASMA: case VISUALIZER_RAINBOW: case VISUALIZER_WHEEL: s->set_visualizer(type); break; default: s->set_visualizer(VISUALIZER_BARS); break; } } else if (strcmp(name, "other") == 0) { int type = strtol(value, NULL, 10); // Ensure type is valid, default to BOUNCING_LINES switch (type) { case BOUNCING_LINES: case BAR_TEST: case PIXEL_TEST: case AMBIENT_LIGHTING: s->set_visualizer(type); break; default: s->set_visualizer(BOUNCING_LINES); break; } } else if (strcmp(name, "power") == 0) { s->set_power(strtol(value, NULL, 10)); } } while (repeat); // after procesing the POST data, tell the web browser to reload // the page using a GET method. server.httpSeeOther("/web_input"); return; } /* for a GET or HEAD, send the standard "it's all OK headers" */ server.httpSuccess(); /* we don't output the body for a HEAD request */ if (type == WebServer::GET) { server.printP(control_panel); } }