Skip to content
Snippets Groups Projects
Fields.h 3.94 KiB
Newer Older
  • Learn to ignore specific revisions
  • /*
       ESP8266 + FastLED + IR Remote: https://github.com/jasoncoon/esp8266-fastled-webserver
       Copyright (C) 2016 Jason Coon
    
       This program is free software: you can redistribute it and/or modify
       it under the terms of the GNU General Public License as published by
       the Free Software Foundation, either version 3 of the License, or
       (at your option) any later version.
    
       This program is distributed in the hope that it will be useful,
       but WITHOUT ANY WARRANTY; without even the implied warranty of
       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       GNU General Public License for more details.
    
       You should have received a copy of the GNU General Public License
       along with this program.  If not, see <http://www.gnu.org/licenses/>.
    */
    
    uint8_t power = 1;
    uint8_t brightness = brightnessMap[brightnessIndex];
    
    //String setPower(String value) {
    //  power = value.toInt();
    //  if(power < 0) power = 0;
    //  else if (power > 1) power = 1;
    //  return String(power);
    //}
    
    String getPower() {
      return String(power);
    }
    
    //String setBrightness(String value) {
    //  brightness = value.toInt();
    //  if(brightness < 0) brightness = 0;
    //  else if (brightness > 255) brightness = 255;
    //  return String(brightness);
    //}
    
    String getBrightness() {
      return String(brightness);
    }
    
    String getPattern() {
      return String(currentPatternIndex);
    }
    
    String getPatterns() {
      String json = "";
    
      for (uint8_t i = 0; i < patternCount; i++) {
    
        json += "{ \"name\": \"" + patterns[i].name + "\",";
        json += "\"show_palette\": " + String(patterns[i].show_palette ? "true": "false") + ",";
        json += "\"show_speed\": " + String(patterns[i].show_speed ? "true": "false") + ",";
        json += "\"show_color_picker\": " + String(patterns[i].show_color_picker ? "true": "false") + ",";
        json += "\"show_cooling_sparking\": " + String(patterns[i].show_cooling_sparking ? "true": "false") + ",";
        json += "\"show_twinkle\": " + String(patterns[i].show_twinkle ? "true": "false");
        json += "}";
    
        if (i < patternCount - 1)
          json += ",";
      }
    
      return json;
    }
    
    
    Jason Coon's avatar
    Jason Coon committed
    String getPalette() {
      return String(currentPaletteIndex);
    }
    
    String getPalettes() {
      String json = "";
    
      for (uint8_t i = 0; i < paletteCount; i++) {
    
        json += "{ \"name\": \"" + paletteNames[i] + "\"}";
    
    Jason Coon's avatar
    Jason Coon committed
        if (i < paletteCount - 1)
          json += ",";
      }
    
      return json;
    }
    
    
    String getAutoplay() {
      return String(autoplay);
    }
    
    String getAutoplayDuration() {
      return String(autoplayDuration);
    }
    
    String getSolidColor() {
      return String(solidColor.r) + "," + String(solidColor.g) + "," + String(solidColor.b);
    }
    
    String getCooling() {
      return String(cooling);
    }
    
    String getSparking() {
      return String(sparking);
    }
    
    String getSpeed() {
      return String(speed);
    }
    
    String getTwinkleSpeed() {
      return String(twinkleSpeed);
    }
    
    String getTwinkleDensity() {
      return String(twinkleDensity);
    }
    
    FieldList fields = {
      { "power", "Power", BooleanFieldType, 0, 1, getPower },
      { "brightness", "Brightness", NumberFieldType, 1, 255, getBrightness },
      { "pattern", "Pattern", SelectFieldType, 0, patternCount, getPattern, getPatterns },
    
    Jason Coon's avatar
    Jason Coon committed
      { "palette", "Palette", SelectFieldType, 0, paletteCount, getPalette, getPalettes },
    
      { "speed", "Speed", NumberFieldType, 1, 255, getSpeed },
      { "autoplay", "Autoplay", SectionFieldType },
      { "autoplay", "Autoplay", BooleanFieldType, 0, 1, getAutoplay },
      { "autoplayDuration", "Autoplay Duration", NumberFieldType, 0, 255, getAutoplayDuration },
      { "solidColor", "Solid Color", SectionFieldType },
      { "solidColor", "Color", ColorFieldType, 0, 255, getSolidColor },
      { "fire", "Fire & Water", SectionFieldType },
      { "cooling", "Cooling", NumberFieldType, 0, 255, getCooling },
      { "sparking", "Sparking", NumberFieldType, 0, 255, getSparking },
      { "twinkles", "Twinkles", SectionFieldType },
      { "twinkleSpeed", "Twinkle Speed", NumberFieldType, 0, 8, getTwinkleSpeed },
      { "twinkleDensity", "Twinkle Density", NumberFieldType, 0, 8, getTwinkleDensity },
    };
    
    uint8_t fieldCount = ARRAY_SIZE(fields);