 /*
- * The Space Probe firmware is a very thin stub program, which speaks a
- * simple serial command/response protocol.
+ * The Space Probe firmware is a very thin stub program, implementing a simple web API
  *
- * All numbers <X> are transmitted as 4-digit decimal integers, regardless of scale.
- *
- * Commands:
- *
- * Cmd: L<R>,<G>,<B>,<O>,<F>\n
- * Rsp: OK\n
- *
- * Set LEDs R,G,B levels (0-255) with blink cylce <O>ms On then <F>ms off.
- *
- * ****
- *
- * Cmd: B<N>
- * Rsp: OK\n
- *
- * Beep for N milliseconds
- *
- * *****
- *
- * Cmd: D<N>\n
- * Rsp: OK\n
- *
- * Set dial gauge PWM output to <N> (0-255)
- *
- * *****
- *
- * Cmd: K\n
- * Rsp: <N>\n
- *
- * Read back knob position <N> (0-1023)
- *
- * *****
- *
- * Cmd: P\n
- * Rsp: OK\n
- *
- * Ping! Check the probe is still there. If the probe doesn't see any command (including ping)
- * for 5 seconds it'll start blinking the red LED quickly until it sees a response.
- */
+ * See the help_handler method below for the help text (also available if you GET HTTP address /)
+ * */
 
 #include <Ethernet.h>
 #include <Flash.h>

  return atoi(buf);
}

boolean set_gauge_handler(TinyWebServer& web_server)
{
  byte gauge = read_postdata_int(web_server);
  analogWrite(PANEL_PIN, gauge);
  web_server.send_error_code(200);
  web_server.end_headers();
  web_server << F("Setting gauge to ") << gauge << "\n";
}

boolean beep_handler(TinyWebServer& web_server)
{
  int length = read_postdata_int(web_server);
  stop_beep_ms = millis() + length;
  web_server.send_error_code(200);
  web_server.end_headers();
  web_server << F("Beeping for length ") << length << "\n";
  return true;
}


long last_ms = 0;

boolean knob_handler(TinyWebServer& web_server);
boolean set_leds_handler(TinyWebServer& web_server);
boolean set_dial_handler(TinyWebServer& web_server);
boolean buzz_handler(TinyWebServer& web_server);
boolean alive_handler(TinyWebServer& web_server);

TinyWebServer::PathHandler handlers[] = {
  // Register the index_handler for GET requests on /
  {"/", TinyWebServer::GET, &help_handler },
  {"/is_alive", TinyWebServer::GET, &alive_handler },
  {"/knob", TinyWebServer::GET, &knob_handler },
  {"/leds", TinyWebServer::POST, &set_leds_handler },
  {"/dial", TinyWebServer::POST, &set_dial_handler },
  {"/buzz", TinyWebServer::POST, &buzz_handler },
  {NULL}, // The array has to be NULL terminated this way
};

