mirror of
https://github.com/BitMaker-hub/NerdMiner_v2.git
synced 2025-04-25 16:00:39 +02:00
CYD ESP32_2432S028 Brightness option in config
This commit is contained in:
parent
8b82bd139f
commit
d68516607c
@ -76,6 +76,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);
|
||||
//render.setDrawer(background); // Link drawing object to background instance (so font will be rendered on background)
|
||||
@ -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)
|
||||
@ -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) {
|
||||
|
@ -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;
|
||||
|
@ -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");
|
||||
@ -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
|
||||
|
@ -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"
|
||||
@ -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"
|
||||
@ -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
|
||||
@ -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_
|
@ -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: ");
|
||||
@ -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
|
||||
@ -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);
|
||||
}
|
||||
@ -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
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user