diff --git a/lib/MatrixUI/MatrixDisplayUi.cpp b/lib/MatrixUI/MatrixDisplayUi.cpp index ba6a9b0..549d58d 100644 --- a/lib/MatrixUI/MatrixDisplayUi.cpp +++ b/lib/MatrixUI/MatrixDisplayUi.cpp @@ -30,8 +30,8 @@ #include "MatrixDisplayUi.h" #include "Fonts/AwtrixFont.h" - GifPlayer gif1; - GifPlayer gif2; +GifPlayer gif1; +GifPlayer gif2; MatrixDisplayUi::MatrixDisplayUi(FastLED_NeoMatrix *matrix) { @@ -223,11 +223,28 @@ void MatrixDisplayUi::tick() } this->matrix->clear(); + if (this->AppCount > 0) this->drawApp(); this->drawOverlays(); + this->drawIndicators(); this->matrix->show(); } +void MatrixDisplayUi::drawIndicators() +{ + if (indicator1State) + { + matrix->drawPixel(31, 0, indicator1Color); + matrix->drawPixel(30, 0, indicator1Color); + matrix->drawPixel(31, 1, indicator1Color); + } + if (indicator2State) + { + matrix->drawPixel(31, 7, indicator2Color); + matrix->drawPixel(31, 6, indicator2Color); + matrix->drawPixel(30, 7, indicator2Color); + } +} void MatrixDisplayUi::drawApp() { @@ -293,3 +310,17 @@ uint8_t MatrixDisplayUi::getnextAppNumber() return this->nextAppNumber; return (this->state.currentApp + this->AppCount + this->state.appTransitionDirection) % this->AppCount; } + +void MatrixDisplayUi::setIndicator1(bool state, uint16_t color) +{ + this->indicator1State = state; + if (color > 0) + this->indicator1Color = color; +} + +void MatrixDisplayUi::setIndicator2(bool state, uint16_t color) +{ + this->indicator2State = state; + if (color > 0) + this->indicator2Color = color; +} \ No newline at end of file diff --git a/lib/MatrixUI/MatrixDisplayUi.h b/lib/MatrixUI/MatrixDisplayUi.h index 5ef0e4c..5430311 100644 --- a/lib/MatrixUI/MatrixDisplayUi.h +++ b/lib/MatrixUI/MatrixDisplayUi.h @@ -77,7 +77,6 @@ class MatrixDisplayUi private: FastLED_NeoMatrix *matrix; - // Values for the Apps AnimationDirection appAnimationDirection = SLIDE_DOWN; int8_t lastTransitionDirection = 1; @@ -102,6 +101,12 @@ private: // Bookeeping for update uint8_t updateInterval = 33; + uint16_t indicator1Color = 63488; + uint16_t indicator2Color = 31; + + bool indicator1State = false; + bool indicator2State = false; + uint8_t getnextAppNumber(); void drawApp(); void drawOverlays(); @@ -148,6 +153,10 @@ public: */ void setTimePerTransition(uint16_t time); + void setIndicator1(bool state, uint16_t color); + void setIndicator2(bool state, uint16_t color); + + void drawIndicators(); // Customize indicator position and style // App settings diff --git a/src/Dictionary.cpp b/src/Dictionary.cpp index 721bca3..20d879e 100644 --- a/src/Dictionary.cpp +++ b/src/Dictionary.cpp @@ -17,6 +17,15 @@ const char HAmodel[] PROGMEM = {"AWTRIX Light"}; const char HAmatID[] PROGMEM = {"%s_mat"}; const char HAmatIcon[] PROGMEM = {"mdi:lightbulb"}; const char HAmatName[] PROGMEM = {"Matrix"}; + +const char HAi1ID[] PROGMEM = {"%s_ind1"}; +const char HAi1Icon[] PROGMEM = {"mdi:arrow-top-right-thick"}; +const char HAi1Name[] PROGMEM = {"Indicator 1"}; + +const char HAi2ID[] PROGMEM = {"%s_ind2"}; +const char HAi2Icon[] PROGMEM = {"mdi:arrow-bottom-right-thick"}; +const char HAi2Name[] PROGMEM = {"Indicator 2"}; + const char HAbriID[] PROGMEM = {"%s_bri"}; const char HAbriIcon[] PROGMEM = {"mdi:brightness-auto"}; const char HAbriName[] PROGMEM = {"Brightness mode"}; @@ -74,12 +83,10 @@ const char HAupdateName[] PROGMEM = {"Update"}; const char HAupdateClass[] PROGMEM = {"update"}; const char HAupdateIcon[] PROGMEM = {"mdi:update"}; - const char HAdoUpID[] PROGMEM = {"%s_doupd"}; const char HAdoUpName[] PROGMEM = {"Start Update"}; const char HAdoUpIcon[] PROGMEM = {"mdi:update"}; - const char HAsigID[] PROGMEM = {"%s_sig"}; const char HAsigIcon[] PROGMEM = {"mdi:sun-wireless"}; const char HAsigName[] PROGMEM = {"WiFi strength"}; diff --git a/src/Dictionary.h b/src/Dictionary.h index 1b44a63..39aca56 100644 --- a/src/Dictionary.h +++ b/src/Dictionary.h @@ -17,6 +17,15 @@ extern const char HAmodel[]; extern const char HAmatID[]; extern const char HAmatIcon[]; extern const char HAmatName[]; + +extern const char HAi1ID[]; +extern const char HAi1Icon[]; +extern const char HAi1Name[]; + +extern const char HAi2ID[]; +extern const char HAi2Icon[]; +extern const char HAi2Name[]; + extern const char HAbriID[]; extern const char HAbriIcon[]; extern const char HAbriName[]; diff --git a/src/DisplayManager.cpp b/src/DisplayManager.cpp index 2ce1518..834f7ed 100644 --- a/src/DisplayManager.cpp +++ b/src/DisplayManager.cpp @@ -54,6 +54,7 @@ void DisplayManager_::setBrightness(uint8_t bri) else { matrix->setBrightness(bri); + //napplyGamma_video(&leds[256], 256, 2.2); } } @@ -140,6 +141,7 @@ bool jpg_output(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t *bitmap) void DisplayManager_::printText(int16_t x, int16_t y, const char *text, bool centered, byte textCase) { + if (centered) { uint16_t textWidth = getTextWidth(text, textCase); @@ -533,9 +535,8 @@ void DisplayManager_::setup() TJpgDec.setCallback(jpg_output); TJpgDec.setJpgScale(1); - FastLED.addLeds(leds, MATRIX_WIDTH * MATRIX_HEIGHT).setTemperature(OvercastSky); + FastLED.addLeds(leds, MATRIX_WIDTH * MATRIX_HEIGHT).setCorrection(OvercastSky); setMatrixLayout(MATRIX_LAYOUT); - gif.setMatrix(matrix); ui->setAppAnimation(SLIDE_DOWN); ui->setTimePerApp(TIME_PER_APP); @@ -555,6 +556,7 @@ void DisplayManager_::tick() else { + ui->update(); if (ui->getUiState()->appState == IN_TRANSITION && !appIsSwitching) @@ -941,3 +943,13 @@ String DisplayManager_::getAppsAsJson() serializeJson(appsObject, json); return json; } + +void DisplayManager_::setIndicator1(bool state, uint16_t color) +{ + ui->setIndicator1(state, color); +} + +void DisplayManager_::setIndicator2(bool state, uint16_t color) +{ + ui->setIndicator2(state, color); +} diff --git a/src/DisplayManager.h b/src/DisplayManager.h index e7da06e..44caeeb 100644 --- a/src/DisplayManager.h +++ b/src/DisplayManager.h @@ -51,7 +51,7 @@ public: void MatrixState(bool); void generateNotification(const char *json); void generateCustomPage(const String &name, const char *json); - void printText(int16_t x, int16_t y, const char *text, bool centered, byte textCase); + void printText(int16_t x, int16_t y, const char *text, bool centered, byte textCase); bool setAutoTransition(bool active); void switchToApp(const char *json); void setNewSettings(const char *json); @@ -66,6 +66,8 @@ public: void setAppTime(uint16_t duration); String getAppsAsJson(); String getStat(); + void setIndicator1(bool state, uint16_t color); + void setIndicator2(bool state, uint16_t color); }; extern DisplayManager_ &DisplayManager; diff --git a/src/Functions.h b/src/Functions.h index d82df65..a0dfe6e 100644 --- a/src/Functions.h +++ b/src/Functions.h @@ -8,6 +8,38 @@ std::map CharMap = { {32, 2}, {33, 2}, {34, 4}, {35, 4}, {36, 4}, {37, 4}, {38, 4}, {39, 2}, {40, 3}, {41, 3}, {42, 4}, {43, 4}, {44, 3}, {45, 4}, {46, 2}, {47, 4}, {48, 4}, {49, 4}, {50, 4}, {51, 4}, {52, 4}, {53, 4}, {54, 4}, {55, 4}, {56, 4}, {57, 4}, {58, 2}, {59, 3}, {60, 4}, {61, 4}, {62, 4}, {63, 4}, {64, 4}, {65, 4}, {66, 4}, {67, 4}, {68, 4}, {69, 4}, {70, 4}, {71, 4}, {72, 4}, {73, 2}, {74, 4}, {75, 4}, {76, 4}, {77, 6}, {78, 5}, {79, 4}, {80, 4}, {81, 5}, {82, 4}, {83, 4}, {84, 4}, {85, 4}, {86, 4}, {87, 6}, {88, 4}, {89, 4}, {90, 4}, {91, 4}, {92, 4}, {93, 4}, {94, 4}, {95, 4}, {96, 3}, {97, 4}, {98, 4}, {99, 4}, {100, 4}, {101, 4}, {102, 4}, {103, 4}, {104, 4}, {105, 2}, {106, 4}, {107, 4}, {108, 4}, {109, 4}, {110, 4}, {111, 4}, {112, 4}, {113, 4}, {114, 4}, {115, 4}, {116, 4}, {117, 4}, {118, 4}, {119, 4}, {120, 4}, {121, 4}, {122, 4}, {123, 4}, {124, 2}, {125, 4}, {126, 4}, {161, 2}, {162, 4}, {163, 4}, {164, 4}, {165, 4}, {166, 2}, {167, 4}, {168, 4}, {169, 4}, {170, 4}, {171, 3}, {172, 4}, {173, 3}, {174, 4}, {175, 4}, {176, 4}, {177, 4}, {178, 4}, {179, 4}, {180, 3}, {181, 4}, {182, 4}, {183, 4}, {184, 4}, {185, 2}, {186, 4}, {187, 3}, {188, 4}, {189, 4}, {190, 4}, {191, 4}, {192, 4}, {193, 4}, {194, 4}, {195, 4}, {196, 4}, {197, 4}, {198, 4}, {199, 4}, {200, 4}, {201, 4}, {202, 4}, {203, 4}, {204, 4}, {205, 4}, {206, 4}, {207, 4}, {208, 4}, {209, 4}, {210, 4}, {211, 4}, {212, 4}, {213, 4}, {214, 4}, {215, 4}, {216, 4}, {217, 4}, {218, 4}, {219, 4}, {220, 4}, {221, 4}, {222, 4}, {223, 4}, {224, 4}, {225, 4}, {226, 4}, {227, 4}, {228, 4}, {229, 4}, {230, 4}, {231, 4}, {232, 4}, {233, 4}, {234, 4}, {235, 4}, {236, 3}, {237, 3}, {238, 4}, {239, 4}, {240, 4}, {241, 4}, {242, 4}, {243, 4}, {244, 4}, {245, 4}, {246, 4}, {247, 4}, {248, 4}, {249, 4}, {250, 4}, {251, 4}, {252, 4}, {253, 4}, {254, 4}, {255, 4}, {285, 2}, {338, 4}, {339, 4}, {352, 4}, {353, 4}, {376, 4}, {381, 4}, {382, 4}, {3748, 2}, {5024, 2}, {8226, 2}, {8230, 4}, {8364, 4}, {65533, 4}}; +//--------------------------------------------------------------- +// This is the gamma lookup for mapping 255 brightness levels +// The lookup table would be similar but have slightly shifted +// numbers for different gammas (gamma 2.0, 2.2, 2.5, etc.) +const uint8_t PROGMEM gamma8[] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, + 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, + 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, + 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16, + 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 24, 24, 25, + 25, 26, 27, 27, 28, 29, 29, 30, 31, 32, 32, 33, 34, 35, 35, 36, + 37, 38, 39, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 50, + 51, 52, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 66, 67, 68, + 69, 70, 72, 73, 74, 75, 77, 78, 79, 81, 82, 83, 85, 86, 87, 89, + 90, 92, 93, 95, 96, 98, 99,101,102,104,105,107,109,110,112,114, + 115,117,119,120,122,124,126,127,129,131,133,135,137,138,140,142, + 144,146,148,150,152,154,156,158,160,162,164,167,169,171,173,175, + 177,180,182,184,186,189,191,193,196,198,200,203,205,208,210,213, + 215,218,220,223,225,228,231,233,236,239,241,244,247,249,252,255 }; + + + +CRGB applyGammaCorrection(const CRGB& color) { + CRGB correctedColor; + correctedColor.r = pgm_read_byte(&gamma8[color.r]); + correctedColor.g = pgm_read_byte(&gamma8[color.g]); + correctedColor.b = pgm_read_byte(&gamma8[color.b]); + return correctedColor; +} + uint32_t hsvToRgb(uint8_t h, uint8_t s, uint8_t v) { CHSV hsv(h, s, v); diff --git a/src/MQTTManager.cpp b/src/MQTTManager.cpp index 1524508..281dd17 100644 --- a/src/MQTTManager.cpp +++ b/src/MQTTManager.cpp @@ -12,12 +12,14 @@ WiFiClient espClient; uint8_t lastBrightness; HADevice device; -HAMqtt mqtt(espClient, device, 22); +HAMqtt mqtt(espClient, device, 25); unsigned long reconnectTimer = 0; const unsigned long reconnectInterval = 30000; // 30 Sekunden HALight *Matrix = nullptr; +HALight *Indikator1 = nullptr; +HALight *Indikator2 = nullptr; HASelect *BriMode = nullptr; HAButton *dismiss = nullptr; HAButton *nextApp = nullptr; @@ -101,23 +103,45 @@ void onSelectCommand(int8_t index, HASelect *sender) void onRGBColorCommand(HALight::RGBColor color, HALight *sender) { - TEXTCOLOR_565 = ((color.red & 0x1F) << 11) | ((color.green & 0x3F) << 5) | (color.blue & 0x1F); - saveSettings(); + if (sender == Matrix) + { + TEXTCOLOR_565 = ((color.red & 0x1F) << 11) | ((color.green & 0x3F) << 5) | (color.blue & 0x1F); + saveSettings(); + } + else if (sender == Indikator1) + { + DisplayManager.setIndicator1(true, ((color.red & 0x1F) << 11) | ((color.green & 0x3F) << 5) | (color.blue & 0x1F)); + } + else if (sender == Indikator2) + { + DisplayManager.setIndicator2(true, ((color.red & 0x1F) << 11) | ((color.green & 0x3F) << 5) | (color.blue & 0x1F)); + } sender->setRGBColor(color); // report color back to the Home Assistant } void onStateCommand(bool state, HALight *sender) { - if (state) + if (sender == Matrix) { - MATRIX_OFF = false; - DisplayManager.setBrightness(lastBrightness); + if (state) + { + MATRIX_OFF = false; + DisplayManager.setBrightness(lastBrightness); + } + else + { + MATRIX_OFF = true; + lastBrightness = BRIGHTNESS; + DisplayManager.setBrightness(0); + } } - else + else if (sender == Indikator1) { - MATRIX_OFF = true; - lastBrightness = BRIGHTNESS; - DisplayManager.setBrightness(0); + DisplayManager.setIndicator1(state, 0); + } + else if (sender == Indikator2) + { + DisplayManager.setIndicator2(state, 0); } sender->setState(state); @@ -265,7 +289,7 @@ void connect() } } -char matID[40], briID[40]; +char matID[40], ind1ID[40], ind2ID[40], briID[40]; char btnAID[40], btnBID[40], btnCID[40], appID[40], tempID[40], humID[40], luxID[40], verID[40], ramID[40], upID[40], sigID[40], btnLID[40], btnMID[40], btnRID[40], transID[40], updateID[40], doUpdateID[40]; #ifdef ULANZI char batID[40]; @@ -304,6 +328,20 @@ void MQTTManager_::setup() Matrix->setCurrentState(true); Matrix->setBRIGHTNESS(BRIGHTNESS); + sprintf(ind1ID, HAi1ID, macStr); + Indikator1 = new HALight(ind1ID, HALight::RGBFeature); + Indikator1->setIcon(HAi1Icon); + Indikator1->setName(HAi1Name); + Indikator1->onStateCommand(onStateCommand); + Indikator1->onRGBColorCommand(onRGBColorCommand); + + sprintf(ind2ID, HAi2ID, macStr); + Indikator2 = new HALight(ind2ID, HALight::RGBFeature); + Indikator2->setIcon(HAi2Icon); + Indikator2->setName(HAi2Name); + Indikator2->onStateCommand(onStateCommand); + Indikator2->onRGBColorCommand(onRGBColorCommand); + HALight::RGBColor color; color.red = (TEXTCOLOR_565 >> 11) << 3; color.green = ((TEXTCOLOR_565 >> 5) & 0x3F) << 2;