From 32e40e2cb7a49059ddd78fa1f0458ca130ec4cda Mon Sep 17 00:00:00 2001 From: Djuri Baars Date: Fri, 7 Jun 2024 15:18:34 +0200 Subject: [PATCH] Fix frontlight --- dependencies.lock | 4 ++-- src/lib/config.cpp | 26 +++++++++++++------------- src/lib/led_handler.cpp | 8 +++++--- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/dependencies.lock b/dependencies.lock index 27f0397..6400884 100644 --- a/dependencies.lock +++ b/dependencies.lock @@ -3,7 +3,7 @@ dependencies: component_hash: null source: type: idf - version: 4.4.6 -manifest_hash: c799a313787fb26f19e5716786e23d7a9f10f1cd0bbd7bc379c518bb5e67be3e + version: 4.4.7 +manifest_hash: 615d994fdba8799111cf7825a85adb23ca6a2ae02b2335b53fde1188ff862f23 target: esp32s3 version: 1.0.0 diff --git a/src/lib/config.cpp b/src/lib/config.cpp index 214297f..fd2ae09 100644 --- a/src/lib/config.cpp +++ b/src/lib/config.cpp @@ -18,9 +18,9 @@ uint lastTimeSync; void setup() { + setupPreferences(); setupHardware(); - setupPreferences(); setupDisplays(); if (preferences.getBool("ledTestOnPower", true)) { @@ -701,26 +701,26 @@ uint getLastTimeSync() #ifdef HAS_FRONTLIGHT void setupFrontlight() { - if (!flArray.begin(PCA9685_MODE1_AUTOINCR, PCA9685_MODE2_INVERT)) + if (!flArray.begin(PCA9685_MODE1_AUTOINCR | PCA9685_MODE1_ALLCALL, PCA9685_MODE2_TOTEMPOLE)) { Serial.println(F("FL driver error")); return; } Serial.println(F("FL driver active")); - flArray.setFrequency(1000); - flArray.setOutputEnablePin(PCA_OE_PIN); - flArray.setOutputEnable(true); - delay(1000); - flArray.setOutputEnable(false); + if (!preferences.isKey("flMaxBrightness")) { - preferences.putUInt("flMaxBrightness", 4095); + preferences.putUInt("flMaxBrightness", 2048); + } + + if (preferences.getBool("flAlwaysOn", false)) { + Serial.println(F("FL Always on")); + + frontlightFadeInAll(); + } else { + Serial.println(F("FL all off")); + flArray.allOFF(); } - // Initialize all LEDs to off - // for (int ledPin = 0; ledPin < NUM_SCREENS; ledPin++) { - // flArray.setPWM(ledPin, 0, 0); // Turn off LED - // } - flArray.allOFF(); } #endif diff --git a/src/lib/led_handler.cpp b/src/lib/led_handler.cpp index 2c31e4f..5d37924 100644 --- a/src/lib/led_handler.cpp +++ b/src/lib/led_handler.cpp @@ -338,11 +338,11 @@ void ledTheaterChaseRainbow(int wait) { Adafruit_NeoPixel getPixels() { return pixels; } #ifdef HAS_FRONTLIGHT -int flDelayTime = 10; +int flDelayTime = 5; void frontlightFadeInAll() { for (int dutyCycle = 0; dutyCycle <= preferences.getUInt("flMaxBrightness"); dutyCycle += 5) { - for (int ledPin = 0; ledPin < NUM_SCREENS; ledPin++) { + for (int ledPin = 0; ledPin <= NUM_SCREENS; ledPin++) { flArray.setPWM(ledPin, 0, dutyCycle); } vTaskDelay(pdMS_TO_TICKS(flDelayTime)); @@ -351,11 +351,13 @@ void frontlightFadeInAll() { void frontlightFadeOutAll() { for (int dutyCycle = preferences.getUInt("flMaxBrightness"); dutyCycle >= 0; dutyCycle -= 5) { - for (int ledPin = 0; ledPin < NUM_SCREENS; ledPin++) { + for (int ledPin = 0; ledPin <= NUM_SCREENS; ledPin++) { flArray.setPWM(ledPin, 0, dutyCycle); } vTaskDelay(pdMS_TO_TICKS(flDelayTime)); } + + flArray.allOFF(); } void frontlightFadeIn(uint num) {