Skip to content

Commit

Permalink
Merge pull request #530 from Xundi007/cyd-brightness-option
Browse files Browse the repository at this point in the history
CYD ESP32_2432S028 Brightness option in config
  • Loading branch information
BitMaker-hub authored Dec 16, 2024
2 parents 8b82bd1 + d685166 commit 9b07356
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/drivers/displays/esp23_2432s028r.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ void esp32_2432S028R_Init(void)

TFT_eTouchBase::Calibation calibation = { 233, 3785, 3731, 120, 2 };
touch.setCalibration(calibation);

// Configuring screen backlight brightness using ledcontrol channel 0.
// Using 5000Hz in 8bit resolution, which gives 0-255 possible duty cycle setting.
ledcSetup(0, 5000, 8);
ledcAttachPin(TFT_BL, 0);
ledcWrite(0, Settings.Brightness);

//background.createSprite(WIDTH, HEIGHT); // Background Sprite
//background.setSwapBytes(true);
Expand Down Expand Up @@ -103,9 +109,14 @@ void esp32_2432S028R_Init(void)

void esp32_2432S028R_AlternateScreenState(void)
{
int screen_state = digitalRead(TFT_BL);
Serial.println("Switching display state");
digitalWrite(TFT_BL, !screen_state);
int screen_state_duty = ledcRead(0);
// Switching the duty cycle for the ledc channel, where the TFT_BL pin is attached.
if (screen_state_duty > 0) {
ledcWrite(0, 0);
} else {
ledcWrite(0, Settings.Brightness);
}
}

void esp32_2432S028R_AlternateRotation(void)
Expand Down Expand Up @@ -533,6 +544,10 @@ void esp32_2432S028R_DoLedStuff(unsigned long frame)
if (((t_x > 109)&&(t_x < 211)) && ((t_y > 185)&&(t_y < 241))) {
bottomScreenBlue ^= true;
hasChangedScreen = true;
} else if((t_x > 235) && ((t_y > 0)&&(t_y < 16))) {
// Touching the top right corner of the screen, roughly in the gray status label.
// Disabling the screen backlight.
esp32_2432S028R_AlternateScreenState();
}
else
if (t_x > 160) {
Expand Down
5 changes: 5 additions & 0 deletions src/drivers/storage/SDCard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ bool SDCard::loadConfigFile(TSettings* Settings)
} else {
Settings->invertColors = false;
}
if (json.containsKey(JSON_KEY_BRIGHTNESS)) {
Settings->Brightness = json[JSON_KEY_BRIGHTNESS].as<int>();
} else {
Settings->Brightness = 250;
}
// Serial.printf("Carteira Lida SD:%s\n", Settings.BtcWallet);
Serial.printf("Carteira Lida SDs:%s\n", Settings->BtcWallet);
return true;
Expand Down
6 changes: 6 additions & 0 deletions src/drivers/storage/nvMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ bool nvMemory::saveConfig(TSettings* Settings)
json[JSON_SPIFFS_KEY_TIMEZONE] = Settings->Timezone;
json[JSON_SPIFFS_KEY_STATS2NV] = Settings->saveStats;
json[JSON_SPIFFS_KEY_INVCOLOR] = Settings->invertColors;
json[JSON_SPIFFS_KEY_BRIGHTNESS] = Settings->Brightness;

// Open config file
File configFile = SPIFFS.open(JSON_CONFIG_FILE, "w");
Expand Down Expand Up @@ -103,6 +104,11 @@ bool nvMemory::loadConfig(TSettings* Settings)
} else {
Settings->invertColors = false;
}
if (json.containsKey(JSON_SPIFFS_KEY_BRIGHTNESS)) {
Settings->Brightness = json[JSON_SPIFFS_KEY_BRIGHTNESS].as<int>();
} else {
Settings->Brightness = 250;
}
return true;
}
else
Expand Down
4 changes: 4 additions & 0 deletions src/drivers/storage/storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#define DEFAULT_TIMEZONE 2
#define DEFAULT_SAVESTATS false
#define DEFAULT_INVERTCOLORS false
#define DEFAULT_BRIGHTNESS 250

// JSON config files
#define JSON_CONFIG_FILE "/config.json"
Expand All @@ -33,6 +34,7 @@
#define JSON_KEY_TIMEZONE "Timezone"
#define JSON_KEY_STATS2NV "SaveStats"
#define JSON_KEY_INVCOLOR "invertColors"
#define JSON_KEY_BRIGHTNESS "Brightness"

// JSON config file SPIFFS (different for backward compatibility with existing devices)
#define JSON_SPIFFS_KEY_POOLURL "poolString"
Expand All @@ -42,6 +44,7 @@
#define JSON_SPIFFS_KEY_TIMEZONE "gmtZone"
#define JSON_SPIFFS_KEY_STATS2NV "saveStatsToNVS"
#define JSON_SPIFFS_KEY_INVCOLOR "invertColors"
#define JSON_SPIFFS_KEY_BRIGHTNESS "Brightness"

// settings
struct TSettings
Expand All @@ -55,6 +58,7 @@ struct TSettings
int Timezone{ DEFAULT_TIMEZONE };
bool saveStats{ DEFAULT_SAVESTATS };
bool invertColors{ DEFAULT_INVERTCOLORS };
int Brightness{ DEFAULT_BRIGHTNESS };
};

#endif // _STORAGE_H_
22 changes: 22 additions & 0 deletions src/wManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,13 @@ void init_WifiManager()
}
WiFiManagerParameter invertColors("inverColors", "Invert Display Colors (if the colors looks weird)", "T", 2, checkboxParams2, WFM_LABEL_AFTER);
wm.addParameter(&invertColors);
#endif
#if defined(ESP32_2432S028R) || defined(ESP32_2432S028_2USB)
char brightnessConvValue[2];
sprintf(brightnessConvValue, "%d", Settings.Brightness);
// Text box (Number) - 3 characters maximum
WiFiManagerParameter brightness_text_box_num("Brightness", "Screen backlight Duty Cycle (0-255)", brightnessConvValue, 3);
wm.addParameter(&brightness_text_box_num);
#endif

Serial.println("AllDone: ");
Expand All @@ -211,6 +218,9 @@ void init_WifiManager()
#ifdef ESP32_2432S028R
Settings.invertColors = (strncmp(invertColors.getValue(), "T", 1) == 0);
#endif
#if defined(ESP32_2432S028R) || defined(ESP32_2432S028_2USB)
Settings.Brightness = atoi(brightness_text_box_num.getValue());
#endif
nvMem.saveConfig(&Settings);
delay(3*SECOND_MS);
//reset and try again, or maybe put it to deep sleep
Expand Down Expand Up @@ -241,6 +251,9 @@ void init_WifiManager()
#ifdef ESP32_2432S028R
Settings.invertColors = (strncmp(invertColors.getValue(), "T", 1) == 0);
#endif
#if defined(ESP32_2432S028R) || defined(ESP32_2432S028_2USB)
Settings.Brightness = atoi(brightness_text_box_num.getValue());
#endif
nvMem.saveConfig(&Settings);
vTaskDelay(2000 / portTICK_PERIOD_MS);
}
Expand Down Expand Up @@ -290,6 +303,12 @@ void init_WifiManager()
Serial.println(Settings.invertColors);
#endif

#if defined(ESP32_2432S028R) || defined(ESP32_2432S028_2USB)
Settings.Brightness = atoi(brightness_text_box_num.getValue());
Serial.print("Brightness: ");
Serial.println(Settings.Brightness);
#endif

}

// Save the custom parameters to FS
Expand All @@ -299,6 +318,9 @@ void init_WifiManager()
#ifdef ESP32_2432S028R
if (Settings.invertColors) ESP.restart();
#endif
#if defined(ESP32_2432S028R) || defined(ESP32_2432S028_2USB)
if (Settings.Brightness != 250) ESP.restart();
#endif
}
}

Expand Down

0 comments on commit 9b07356

Please sign in to comment.