mirror of
https://github.com/justcallmekoko/ESP32Marauder.git
synced 2026-03-12 21:22:59 -07:00
Merge pull request #1147 from justcallmekoko/develop
No brightness for mini...for now
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
#include "CommandLine.h"
|
||||
|
||||
// Brightness functions defined in esp32_marauder.ino
|
||||
extern void brightnessCycle();
|
||||
extern uint8_t getBrightnessLevel();
|
||||
#ifndef HAS_MINI_SCREEN
|
||||
extern void brightnessCycle();
|
||||
extern uint8_t getBrightnessLevel();
|
||||
#endif
|
||||
|
||||
void CommandLine::RunSetup() {
|
||||
Serial.println(this->ascii_art);
|
||||
@@ -1367,24 +1369,26 @@ void CommandLine::runCommand(String input) {
|
||||
|
||||
// Brightness command
|
||||
else if (cmd_args.get(0) == BRIGHTNESS_CMD) {
|
||||
int c_arg = this->argSearch(&cmd_args, "-c");
|
||||
int s_arg = this->argSearch(&cmd_args, "-s");
|
||||
if (c_arg != -1) {
|
||||
brightnessCycle();
|
||||
} else if (s_arg != -1) {
|
||||
uint8_t lvl = cmd_args.get(s_arg + 1).toInt();
|
||||
if (lvl < 10) {
|
||||
extern void brightnessSave(uint8_t level);
|
||||
brightnessSave(lvl);
|
||||
Serial.print(F("[Brightness] Set to level "));
|
||||
Serial.println(lvl);
|
||||
#ifndef HAS_MINI_SCREEN
|
||||
int c_arg = this->argSearch(&cmd_args, "-c");
|
||||
int s_arg = this->argSearch(&cmd_args, "-s");
|
||||
if (c_arg != -1) {
|
||||
brightnessCycle();
|
||||
} else if (s_arg != -1) {
|
||||
uint8_t lvl = cmd_args.get(s_arg + 1).toInt();
|
||||
if (lvl < 10) {
|
||||
extern void brightnessSave(uint8_t level);
|
||||
brightnessSave(lvl);
|
||||
Serial.print(F("[Brightness] Set to level "));
|
||||
Serial.println(lvl);
|
||||
} else {
|
||||
Serial.println(F("Level must be 0-9"));
|
||||
}
|
||||
} else {
|
||||
Serial.println(F("Level must be 0-9"));
|
||||
Serial.print(F("[Brightness] Current level: "));
|
||||
Serial.println(getBrightnessLevel());
|
||||
}
|
||||
} else {
|
||||
Serial.print(F("[Brightness] Current level: "));
|
||||
Serial.println(getBrightnessLevel());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// Update command
|
||||
|
||||
@@ -2705,9 +2705,11 @@ void MenuFunctions::RunSetup()
|
||||
this->changeMenu(&saveFileMenu, true);
|
||||
});
|
||||
|
||||
this->addNodes(&deviceMenu, "Brightness", TFTYELLOW, NULL, KEYBOARD_ICO, [this]() {
|
||||
this->brightnessMode();
|
||||
});
|
||||
#ifndef HAS_MINI_SCREEN
|
||||
this->addNodes(&deviceMenu, "Brightness", TFTYELLOW, NULL, KEYBOARD_ICO, [this]() {
|
||||
this->brightnessMode();
|
||||
});
|
||||
#endif
|
||||
|
||||
this->addNodes(&deviceMenu, text_table1[17], TFTWHITE, NULL, DEVICE_INFO, [this]() {
|
||||
wifi_scan_obj.currentScanMode = SHOW_INFO;
|
||||
@@ -3723,86 +3725,88 @@ void MenuFunctions::displayCurrentMenu(int start_index)
|
||||
// Hold top/bottom zone 1.5s to enter. TAP TOP = brighter, TAP BOTTOM = dimmer.
|
||||
// TAP MIDDLE or wait 3s = save & exit.
|
||||
// ============================================================
|
||||
void MenuFunctions::brightnessMode() {
|
||||
extern void brightnessSave(uint8_t level);
|
||||
extern uint8_t getBrightnessLevel();
|
||||
#ifndef HAS_MINI_SCREEN
|
||||
void MenuFunctions::brightnessMode() {
|
||||
extern void brightnessSave(uint8_t level);
|
||||
extern uint8_t getBrightnessLevel();
|
||||
|
||||
const uint8_t levels[] = {26, 51, 77, 102, 128, 153, 179, 204, 230, 255};
|
||||
const uint8_t numLevels = 10;
|
||||
uint8_t level = getBrightnessLevel();
|
||||
const uint8_t levels[] = {26, 51, 77, 102, 128, 153, 179, 204, 230, 255};
|
||||
const uint8_t numLevels = 10;
|
||||
uint8_t level = getBrightnessLevel();
|
||||
|
||||
// LEDC write compatibility (2.x vs 3.x board package)
|
||||
#if ESP_ARDUINO_VERSION_MAJOR >= 3
|
||||
#define BL_PREVIEW(duty) ledcWrite(TFT_BL, (duty))
|
||||
#else
|
||||
#define BL_PREVIEW(duty) ledcWrite(0, (duty))
|
||||
#endif
|
||||
// LEDC write compatibility (2.x vs 3.x board package)
|
||||
#if ESP_ARDUINO_VERSION_MAJOR >= 3
|
||||
#define BL_PREVIEW(duty) ledcWrite(TFT_BL, (duty))
|
||||
#else
|
||||
#define BL_PREVIEW(duty) ledcWrite(0, (duty))
|
||||
#endif
|
||||
|
||||
display_obj.tft.fillScreen(TFT_BLACK);
|
||||
display_obj.tft.setTextColor(TFT_CYAN, TFT_BLACK);
|
||||
display_obj.tft.drawCentreString("BRIGHTNESS", TFT_WIDTH/2, 30, 2);
|
||||
display_obj.tft.fillScreen(TFT_BLACK);
|
||||
display_obj.tft.setTextColor(TFT_CYAN, TFT_BLACK);
|
||||
display_obj.tft.drawCentreString("BRIGHTNESS", TFT_WIDTH/2, 30, 2);
|
||||
|
||||
display_obj.tft.setTextColor(TFT_DARKGREY, TFT_BLACK);
|
||||
display_obj.tft.drawCentreString("TAP TOP = BRIGHTER", TFT_WIDTH/2, 10, 1);
|
||||
display_obj.tft.drawCentreString("TAP BOTTOM = DIMMER", TFT_WIDTH/2, TFT_HEIGHT - 20, 1);
|
||||
display_obj.tft.setTextColor(TFT_RED, TFT_BLACK);
|
||||
display_obj.tft.drawCentreString("TAP MIDDLE or WAIT 3s = SAVE", TFT_WIDTH/2, TFT_HEIGHT/2 + 50, 1);
|
||||
display_obj.tft.setTextColor(TFT_DARKGREY, TFT_BLACK);
|
||||
display_obj.tft.drawCentreString("TAP TOP = BRIGHTER", TFT_WIDTH/2, 10, 1);
|
||||
display_obj.tft.drawCentreString("TAP BOTTOM = DIMMER", TFT_WIDTH/2, TFT_HEIGHT - 20, 1);
|
||||
display_obj.tft.setTextColor(TFT_RED, TFT_BLACK);
|
||||
display_obj.tft.drawCentreString("TAP MIDDLE or WAIT 3s = SAVE", TFT_WIDTH/2, TFT_HEIGHT/2 + 50, 1);
|
||||
|
||||
auto drawBar = [&]() {
|
||||
uint16_t barX = 30, barY = TFT_HEIGHT/2 - 25, barW = TFT_WIDTH - 60, barH = 30;
|
||||
display_obj.tft.drawRect(barX, barY, barW, barH, TFT_WHITE);
|
||||
uint16_t fillW = (barW - 4) * (level + 1) / numLevels;
|
||||
display_obj.tft.fillRect(barX + 2, barY + 2, barW - 4, barH - 4, TFT_BLACK);
|
||||
display_obj.tft.fillRect(barX + 2, barY + 2, fillW, barH - 4, TFT_CYAN);
|
||||
display_obj.tft.fillRect(0, barY + barH + 5, TFT_WIDTH, 20, TFT_BLACK);
|
||||
display_obj.tft.setTextColor(TFT_WHITE, TFT_BLACK);
|
||||
String pct = String(levels[level] * 100 / 255) + "%";
|
||||
display_obj.tft.drawCentreString(pct, TFT_WIDTH/2, barY + barH + 8, 2);
|
||||
};
|
||||
drawBar();
|
||||
auto drawBar = [&]() {
|
||||
uint16_t barX = 30, barY = TFT_HEIGHT/2 - 25, barW = TFT_WIDTH - 60, barH = 30;
|
||||
display_obj.tft.drawRect(barX, barY, barW, barH, TFT_WHITE);
|
||||
uint16_t fillW = (barW - 4) * (level + 1) / numLevels;
|
||||
display_obj.tft.fillRect(barX + 2, barY + 2, barW - 4, barH - 4, TFT_BLACK);
|
||||
display_obj.tft.fillRect(barX + 2, barY + 2, fillW, barH - 4, TFT_CYAN);
|
||||
display_obj.tft.fillRect(0, barY + barH + 5, TFT_WIDTH, 20, TFT_BLACK);
|
||||
display_obj.tft.setTextColor(TFT_WHITE, TFT_BLACK);
|
||||
String pct = String(levels[level] * 100 / 255) + "%";
|
||||
display_obj.tft.drawCentreString(pct, TFT_WIDTH/2, barY + barH + 8, 2);
|
||||
};
|
||||
drawBar();
|
||||
|
||||
uint16_t zoneUp = TFT_HEIGHT * 25 / 100;
|
||||
uint16_t zoneDown = TFT_HEIGHT * 75 / 100;
|
||||
uint32_t lastTouch = millis();
|
||||
uint16_t zoneUp = TFT_HEIGHT * 25 / 100;
|
||||
uint16_t zoneDown = TFT_HEIGHT * 75 / 100;
|
||||
uint32_t lastTouch = millis();
|
||||
|
||||
while (true) {
|
||||
// Auto-save after 3s of no touch
|
||||
if (millis() - lastTouch >= 3000) {
|
||||
brightnessSave(level);
|
||||
break;
|
||||
}
|
||||
|
||||
uint16_t tx, ty;
|
||||
if (display_obj.updateTouch(&tx, &ty)) {
|
||||
lastTouch = millis();
|
||||
// Wait for release
|
||||
while (display_obj.updateTouch(&tx, &ty)) delay(10);
|
||||
|
||||
if (ty < zoneUp) {
|
||||
if (level < numLevels - 1) {
|
||||
level++;
|
||||
BL_PREVIEW(levels[level]);
|
||||
drawBar();
|
||||
}
|
||||
} else if (ty >= zoneDown) {
|
||||
if (level > 0) {
|
||||
level--;
|
||||
BL_PREVIEW(levels[level]);
|
||||
drawBar();
|
||||
}
|
||||
} else {
|
||||
// Middle = save now
|
||||
while (true) {
|
||||
// Auto-save after 3s of no touch
|
||||
if (millis() - lastTouch >= 3000) {
|
||||
brightnessSave(level);
|
||||
break;
|
||||
}
|
||||
delay(150);
|
||||
}
|
||||
delay(30);
|
||||
}
|
||||
|
||||
#undef BL_PREVIEW
|
||||
this->changeMenu(current_menu, true);
|
||||
}
|
||||
uint16_t tx, ty;
|
||||
if (display_obj.updateTouch(&tx, &ty)) {
|
||||
lastTouch = millis();
|
||||
// Wait for release
|
||||
while (display_obj.updateTouch(&tx, &ty)) delay(10);
|
||||
|
||||
if (ty < zoneUp) {
|
||||
if (level < numLevels - 1) {
|
||||
level++;
|
||||
BL_PREVIEW(levels[level]);
|
||||
drawBar();
|
||||
}
|
||||
} else if (ty >= zoneDown) {
|
||||
if (level > 0) {
|
||||
level--;
|
||||
BL_PREVIEW(levels[level]);
|
||||
drawBar();
|
||||
}
|
||||
} else {
|
||||
// Middle = save now
|
||||
brightnessSave(level);
|
||||
break;
|
||||
}
|
||||
delay(150);
|
||||
}
|
||||
delay(30);
|
||||
}
|
||||
|
||||
#undef BL_PREVIEW
|
||||
this->changeMenu(current_menu, true);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -272,7 +272,9 @@ class MenuFunctions
|
||||
void changeMenu(Menu* menu, bool simple_change = false);
|
||||
void drawStatusBar();
|
||||
void displayCurrentMenu(int start_index = 0);
|
||||
void brightnessMode();
|
||||
#ifndef HAS_MINI_SCREEN
|
||||
void brightnessMode();
|
||||
#endif
|
||||
void main(uint32_t currentTime);
|
||||
void RunSetup();
|
||||
void orientDisplay();
|
||||
|
||||
@@ -779,9 +779,9 @@
|
||||
#ifdef MARAUDER_MINI_V3
|
||||
#define L_BTN 0
|
||||
#define C_BTN 1
|
||||
#define U_BTN 4
|
||||
#define R_BTN 8
|
||||
#define D_BTN 9
|
||||
#define U_BTN 8//4
|
||||
#define R_BTN 9//8
|
||||
#define D_BTN 4//9
|
||||
|
||||
#define HAS_L
|
||||
#define HAS_R
|
||||
|
||||
@@ -128,68 +128,96 @@ uint32_t currentTime = 0;
|
||||
|
||||
// Helper macros for LEDC API compatibility (2.x vs 3.x board package)
|
||||
#ifdef HAS_SCREEN
|
||||
#if ESP_ARDUINO_VERSION_MAJOR >= 3
|
||||
#define BL_SETUP() ledcAttach(TFT_BL, BL_FREQ, BL_RESOLUTION)
|
||||
#define BL_SET(duty) ledcWrite(TFT_BL, (duty))
|
||||
#else
|
||||
#define BL_SETUP() do { ledcSetup(BL_CHANNEL, BL_FREQ, BL_RESOLUTION); ledcAttachPin(TFT_BL, BL_CHANNEL); } while(0)
|
||||
#define BL_SET(duty) ledcWrite(BL_CHANNEL, (duty))
|
||||
#ifndef HAS_MINI_SCREEN
|
||||
#if ESP_ARDUINO_VERSION_MAJOR >= 3
|
||||
#define BL_SETUP() ledcAttach(TFT_BL, BL_FREQ, BL_RESOLUTION)
|
||||
#define BL_SET(duty) ledcWrite(TFT_BL, (duty))
|
||||
#else
|
||||
#define BL_SETUP() do { ledcSetup(BL_CHANNEL, BL_FREQ, BL_RESOLUTION); ledcAttachPin(TFT_BL, BL_CHANNEL); } while(0)
|
||||
#define BL_SET(duty) ledcWrite(BL_CHANNEL, (duty))
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void brightnessInit() {
|
||||
#ifdef HAS_SCREEN
|
||||
BL_SETUP();
|
||||
bl_prefs.begin("backlight", false);
|
||||
bl_level_idx = bl_prefs.getUChar("level", 9);
|
||||
if (bl_level_idx >= BL_NUM_LEVELS) bl_level_idx = 9;
|
||||
BL_SET(BL_LEVELS[bl_level_idx]);
|
||||
#endif
|
||||
}
|
||||
#ifndef HAS_MINI_SCREEN
|
||||
void brightnessInit() {
|
||||
#ifdef HAS_SCREEN
|
||||
BL_SETUP();
|
||||
bl_prefs.begin("backlight", false);
|
||||
bl_level_idx = bl_prefs.getUChar("level", 9);
|
||||
if (bl_level_idx >= BL_NUM_LEVELS) bl_level_idx = 9;
|
||||
BL_SET(BL_LEVELS[bl_level_idx]);
|
||||
#endif
|
||||
}
|
||||
|
||||
void brightnessCycle() {
|
||||
#ifdef HAS_SCREEN
|
||||
bl_level_idx = (bl_level_idx + 1) % BL_NUM_LEVELS;
|
||||
BL_SET(BL_LEVELS[bl_level_idx]);
|
||||
bl_prefs.putUChar("level", bl_level_idx);
|
||||
Serial.print(F("[Brightness] Level "));
|
||||
Serial.print(bl_level_idx + 1);
|
||||
Serial.print(F("/"));
|
||||
Serial.print(BL_NUM_LEVELS);
|
||||
Serial.print(F(" ("));
|
||||
Serial.print(BL_LEVELS[bl_level_idx] * 100 / 255);
|
||||
Serial.println(F("%)"));
|
||||
#endif
|
||||
}
|
||||
void brightnessCycle() {
|
||||
#ifdef HAS_SCREEN
|
||||
bl_level_idx = (bl_level_idx + 1) % BL_NUM_LEVELS;
|
||||
BL_SET(BL_LEVELS[bl_level_idx]);
|
||||
bl_prefs.putUChar("level", bl_level_idx);
|
||||
Serial.print(F("[Brightness] Level "));
|
||||
Serial.print(bl_level_idx + 1);
|
||||
Serial.print(F("/"));
|
||||
Serial.print(BL_NUM_LEVELS);
|
||||
Serial.print(F(" ("));
|
||||
Serial.print(BL_LEVELS[bl_level_idx] * 100 / 255);
|
||||
Serial.println(F("%)"));
|
||||
#endif
|
||||
}
|
||||
|
||||
uint8_t getBrightnessLevel() {
|
||||
#ifdef HAS_SCREEN
|
||||
return bl_level_idx;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
uint8_t getBrightnessLevel() {
|
||||
#ifdef HAS_SCREEN
|
||||
return bl_level_idx;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void brightnessSave(uint8_t level) {
|
||||
#ifdef HAS_SCREEN
|
||||
if (level >= BL_NUM_LEVELS) level = BL_NUM_LEVELS - 1;
|
||||
bl_level_idx = level;
|
||||
BL_SET(BL_LEVELS[bl_level_idx]);
|
||||
bl_prefs.putUChar("level", bl_level_idx);
|
||||
#endif
|
||||
}
|
||||
void brightnessSave(uint8_t level) {
|
||||
#ifdef HAS_SCREEN
|
||||
if (level >= BL_NUM_LEVELS) level = BL_NUM_LEVELS - 1;
|
||||
bl_level_idx = level;
|
||||
BL_SET(BL_LEVELS[bl_level_idx]);
|
||||
bl_prefs.putUChar("level", bl_level_idx);
|
||||
#endif
|
||||
}
|
||||
|
||||
void backlightOn() {
|
||||
#ifdef HAS_SCREEN
|
||||
BL_SET(BL_LEVELS[bl_level_idx]);
|
||||
#endif
|
||||
}
|
||||
void backlightOn() {
|
||||
#ifdef HAS_SCREEN
|
||||
BL_SET(BL_LEVELS[bl_level_idx]);
|
||||
#endif
|
||||
}
|
||||
|
||||
void backlightOff() {
|
||||
#ifdef HAS_SCREEN
|
||||
BL_SET(0);
|
||||
#endif
|
||||
}
|
||||
void backlightOff() {
|
||||
#ifdef HAS_SCREEN
|
||||
BL_SET(0);
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
void backlightOn() {
|
||||
#ifdef HAS_SCREEN
|
||||
#if defined(MARAUDER_MINI) || defined(MARAUDER_MINI_V3)
|
||||
digitalWrite(TFT_BL, LOW);
|
||||
#endif
|
||||
|
||||
#if !defined(MARAUDER_MINI) && !defined(MARAUDER_MINI_V3)
|
||||
digitalWrite(TFT_BL, HIGH);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void backlightOff() {
|
||||
#ifdef HAS_SCREEN
|
||||
#if defined(MARAUDER_MINI) || defined(MARAUDER_MINI_V3)
|
||||
digitalWrite(TFT_BL, HIGH);
|
||||
#endif
|
||||
|
||||
#if !defined(MARAUDER_MINI) && !defined(MARAUDER_MINI_V3)
|
||||
digitalWrite(TFT_BL, LOW);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAS_C5_SD
|
||||
SPIClass sharedSPI(SPI);
|
||||
@@ -280,8 +308,10 @@ void setup()
|
||||
#endif
|
||||
|
||||
// Init PWM brightness AFTER display init (so ledcAttach overrides TFT_eSPI's pinMode)
|
||||
brightnessInit();
|
||||
backlightOff();
|
||||
#ifndef HAS_MINI_SCREEN
|
||||
brightnessInit();
|
||||
backlightOff();
|
||||
#endif
|
||||
|
||||
#ifdef HAS_SCREEN
|
||||
#ifndef MARAUDER_CARDPUTER
|
||||
|
||||
Reference in New Issue
Block a user