RestService.cpp
/**
 * API GET, POST method to set a static color on the LED controller.
 */
API GET, POST method to set a static color on the LED controller.
API GET POST method to set a static color on the LED controller .
static void _handle_colors(void){
  String message = "";
  bool set = false;
  int cmd = 0;
  if(server.method() == HTTP_POST){ 
    String color = server.arg("color");
    if(color != ""){
      if(color == "white"){
        state.color = color;
        set = true;
        cmd = LED_COLOR_WHITE;
      }else if(color == "red"){
        state.color = color;
        set = true;
        cmd = LED_COLOR_RED;
      }else if(color == "orange"){
        state.color = color;
        set = true;
        cmd = LED_COLOR_ORANGE;
      }else if(color == "dark-yellow"){
        state.color = color;
        set = true;
        cmd = LED_COLOR_DARK_YELLOW;
      }else if(color == "yellow"){
        state.color = color;
        set = true;
        cmd = LED_COLOR_YELLOW;
      }else if(color == "light-yellow"){
        state.color = color;
        set = true;
        cmd = LED_COLOR_LIGHT_YELLOW;
      }else if(color == "green"){
        state.color = color;
        set = true;
        cmd = LED_COLOR_GREEN;
      }else if(color == "pea-green"){
        state.color = color;
        set = true;
        cmd = LED_COLOR_PEA_GREEN;
      }else if(color == "cyan"){
        state.color = color;
        set = true;
        cmd = LED_COLOR_CYAN;
      }else if(color == "light-blue"){
        state.color = color;
        set = true;
        cmd = LED_COLOR_LIGHT_BLUE;
      }else if(color == "sky-blue"){
        state.color = color;
        set = true;
        cmd = LED_COLOR_SKY_BLUE;
      }else if(color == "blue"){
        state.color = color;
        set = true;
        cmd = LED_COLOR_BLUE;
      }else if(color == "dark-orchid"){
        state.color = color;
        set = true;
        cmd = LED_COLOR_DARK_ORCHID;
      }else if(color == "purple"){
        state.color = color;
        set = true;
        cmd = LED_COLOR_PURPLE;
      }else if(color == "magenta"){
        state.color = color;
        set = true;
        cmd = LED_COLOR_MAGENTA;
      }else if(color == "pink"){
        state.color = color;
        set = true;
        cmd = LED_COLOR_PINK;
      }else{
        message += "error: argument does not match expected";
      }
    }else{
      message += "error: argument expected";
    }
    if(set){
      message += "success";
    }
  }else{ 
    if(server.arg("documentation") == "true"){
      message += "IR Controlled LED Strip Web Service\n\n"
          "Color command expects POST request with a single arguement. "
          "The contents of this argument will be a string enumeration from "
          "list below.\n\n"
          "   - white\n"
          "   - red\n"
          "   - orange\n"
          "   - dark-yellow\n"
          "   - yellow\n"
          "   - light-yellow\n"
          "   - green\n"
          "   - pea-green\n"
          "   - cyan\n"
          "   - light-blue\n"
          "   - sky-blue\n"
          "   - blue\n"
          "   - dark-orchid\n"
          "   - purple\n"
          "   - magenta\n"
          "   - pink\n";
    }else{
      message += "color: " + state.color;
    }
  }
  server.send(200, "text/plain", message);
  state.uri = server.uri();
  if(set){
    led_send_value(cmd);
    state.raw = cmd;
  }
}
static void _handle_colors ( void ) { String message = " " ; bool set = false ; int cmd = 0 ; if ( server . method ( ) == HTTP_POST ) { String color = server . arg ( " " ) ; if ( color != " " ) { if ( color == " " ) { state . color = color ; set = true ; cmd = LED_COLOR_WHITE ; } else if ( color == " " ) { state . color = color ; set = true ; cmd = LED_COLOR_RED ; } else if ( color == " " ) { state . color = color ; set = true ; cmd = LED_COLOR_ORANGE ; } else if ( color == " " ) { state . color = color ; set = true ; cmd = LED_COLOR_DARK_YELLOW ; } else if ( color == " " ) { state . color = color ; set = true ; cmd = LED_COLOR_YELLOW ; } else if ( color == " " ) { state . color = color ; set = true ; cmd = LED_COLOR_LIGHT_YELLOW ; } else if ( color == " " ) { state . color = color ; set = true ; cmd = LED_COLOR_GREEN ; } else if ( color == " " ) { state . color = color ; set = true ; cmd = LED_COLOR_PEA_GREEN ; } else if ( color == " " ) { state . color = color ; set = true ; cmd = LED_COLOR_CYAN ; } else if ( color == " " ) { state . color = color ; set = true ; cmd = LED_COLOR_LIGHT_BLUE ; } else if ( color == " " ) { state . color = color ; set = true ; cmd = LED_COLOR_SKY_BLUE ; } else if ( color == " " ) { state . color = color ; set = true ; cmd = LED_COLOR_BLUE ; } else if ( color == " " ) { state . color = color ; set = true ; cmd = LED_COLOR_DARK_ORCHID ; } else if ( color == " " ) { state . color = color ; set = true ; cmd = LED_COLOR_PURPLE ; } else if ( color == " " ) { state . color = color ; set = true ; cmd = LED_COLOR_MAGENTA ; } else if ( color == " " ) { state . color = color ; set = true ; cmd = LED_COLOR_PINK ; } else { message += " " ; } } else { message += " " ; } if ( set ) { message += " " ; } } else { if ( server . arg ( " " ) == " " ) { message += " \n \n " " " " " " \n \n " " \n " " \n " " \n " " \n " " \n " " \n " " \n " " \n " " \n " " \n " " \n " " \n " " \n " " \n " " \n " " \n " ; } else { message += " " + state . color ; } } server . send ( 200 , " " , message ) ; state . uri = server . uri ( ) ; if ( set ) { led_send_value ( cmd ) ; state . raw = cmd ; } }
API GET, POST method to set a static color on the LED controller.
API GET POST method to set a static color on the LED controller .
// update color state // report color information // Transmit over IR LED