diff --git a/transigione/src/main.cpp b/transigione/src/main.cpp index cb65e85..8804cc5 100644 --- a/transigione/src/main.cpp +++ b/transigione/src/main.cpp @@ -13,6 +13,7 @@ #include #include #include +#include // Information about this device. // All these keys will be added to a "device" key in the Home Assistant configuration for each entity. @@ -48,11 +49,7 @@ ezButton encoder2Button(22); MatrixPanel_I2S_DMA *dma_display = nullptr; -uint16_t myBLACK = dma_display->color565(0, 0, 0); -uint16_t myWHITE = dma_display->color565(255, 255, 255); -uint16_t myRED = dma_display->color565(255, 0, 0); -uint16_t myGREEN = dma_display->color565(0, 255, 0); -uint16_t myBLUE = dma_display->color565(0, 0, 255); +Preferences prefs; #define XMAX 64 #define YMAX 32 @@ -110,6 +107,8 @@ void setup() Serial.println("Moin"); + prefs.begin("transigione"); + encoder1Button.setDebounceTime(50); encoder2Button.setDebounceTime(50); @@ -119,8 +118,8 @@ void setup() encoder2.attachSingleEdge(32, 33); encoder1.setFilter(1023); encoder2.setFilter(1023); - encoder1.setCount(BRIGHTNESS << 1); - encoder2.setCount(program); + encoder1.setCount(prefs.getUChar("brightness", BRIGHTNESS) << 1); + encoder2.setCount(prefs.getUChar("program", 0)); SPIFFS.begin(true); // On first run, will format after failing to mount WiFiSettings.hostname = "transigione-"; @@ -260,6 +259,7 @@ void loop() { brightness = encoder1.getCount() >> 1; _ha_entity_light->publishBrightness(brightness << 1); + } dma_display->setBrightness8(power ? brightness : 0); @@ -281,6 +281,18 @@ void loop() _ha_entity_light->publishEffect(*it); } + if (minuteChanged()) { + Serial.println("Der checker"); + if(prefs.getUChar("brightness") != brightness) { + Serial.println("Storing brightness"); + prefs.putUChar("brightness", brightness); + } + if(prefs.getUChar("program") != program) { + Serial.println("Storing program"); + prefs.putUChar("program", program); + } + + } switch (program) { case 0: @@ -830,7 +842,7 @@ void transition4() {0x0000, 0x528A, 0xAD55, 0xFFFF}}; // Select the active palette here (index 0-7) - uint8_t currentPaletteIndex = (now_time / (1000 * 60 * 20)) % 8; + uint8_t currentPaletteIndex = (now_time / (1000 * 60 * 200)) % 8; const uint32_t TRANSITION_DURATION = 200000UL; uint32_t t = now_time; const uint16_t *currentPalette = palettes[currentPaletteIndex];