Added check if brightness even needs to be changed.

This commit is contained in:
carl committed 2026-11-03 15:57:45 +01:00
1 parent 1e8fa43794
commit 538a7fce2f
1 file changed
+10 -5
+10 -5
View File
@@ -42,6 +42,7 @@ float lux = 1.00f;
const int potPin = GPIO_NUM_6; const int potPin = GPIO_NUM_6;
int adcResult = 0; int adcResult = 0;
uint8_t targetBrightness = 255; uint8_t targetBrightness = 255;
uint8_t currentBrightness = 255;
#define NUM_SAMPLES 64 #define NUM_SAMPLES 64
// Gang i don't know // Gang i don't know
JPEGDEC jpeg; JPEGDEC jpeg;
@@ -392,6 +393,12 @@ void refreshToken() {
http.end(); http.end();
} }
void adjustBrightness(){
if(targetBrightness != currentBrightness){
dma_display->setPanelBrightness(targetBrightness);
currentBrightness = targetBrightness;
}
}
String getTrack() { String getTrack() {
HTTPClient http; HTTPClient http;
@@ -460,7 +467,6 @@ void spotifyTask(void *parameter) {
} }
void panelTask(void *parameter) { void panelTask(void *parameter) {
const TickType_t framePeriod = pdMS_TO_TICKS(33); const TickType_t framePeriod = pdMS_TO_TICKS(33);
;
String time = ntp.formattedTime("%m%e"); String time = ntp.formattedTime("%m%e");
if (time == String("11 1")) { if (time == String("11 1")) {
Serial.println("HAPPY BIRTHDAY"); Serial.println("HAPPY BIRTHDAY");
@@ -468,7 +474,6 @@ void panelTask(void *parameter) {
int start = millis(); int start = millis();
Serial.printf("Successfully opened GIF; Canvas size = %d x %d\n", gif.getCanvasWidth(), gif.getCanvasHeight()); Serial.printf("Successfully opened GIF; Canvas size = %d x %d\n", gif.getCanvasWidth(), gif.getCanvasHeight());
while (millis() - start < 5000) { while (millis() - start < 5000) {
dma_display->setBrightness(targetBrightness);
while (gif.playFrame(true, NULL)) { while (gif.playFrame(true, NULL)) {
dma_display->clearScreen(); dma_display->clearScreen();
for (int y = 0; y < 64; y++) { for (int y = 0; y < 64; y++) {
@@ -489,7 +494,7 @@ void panelTask(void *parameter) {
float deltaTime = (now - previousFrame) * portTICK_PERIOD_MS / 1000.0f; float deltaTime = (now - previousFrame) * portTICK_PERIOD_MS / 1000.0f;
previousFrame = now; previousFrame = now;
if (lux > 0.00 || switchState) { if (lux > 0.00 || switchState) {
dma_display->setBrightness(targetBrightness); adjustBrightness();
if (!playing) { if (!playing) {
Serial.println("Entering Idle."); Serial.println("Entering Idle.");
if (gif.open((uint8_t *)idle_gif, sizeof(idle_gif), GIFDraw)) { if (gif.open((uint8_t *)idle_gif, sizeof(idle_gif), GIFDraw)) {
@@ -498,7 +503,7 @@ void panelTask(void *parameter) {
if (lux == 0.00 && !switchState) { if (lux == 0.00 && !switchState) {
break; break;
} }
dma_display->setBrightness(targetBrightness); adjustBrightness();
while (gif.playFrame(true, NULL)) { while (gif.playFrame(true, NULL)) {
dma_display->clearScreen(); dma_display->clearScreen();
for (int y = 0; y < 64; y++) { for (int y = 0; y < 64; y++) {
@@ -588,7 +593,7 @@ void setup() {
xTaskCreatePinnedToCore( xTaskCreatePinnedToCore(
panelTask, panelTask,
"panelTask", "panelTask",
2048, 2560,
NULL, NULL,
1, 1,
&taskPanelHandle, &taskPanelHandle,