Support brightness control and EEPROM on Cardputer

This commit is contained in:
Noah Axon 2023-12-28 10:56:27 -06:00
parent d17a180e0a
commit da8b7b2c34
1 changed files with 78 additions and 80 deletions

View File

@ -2,13 +2,13 @@
// github.com/n0xa | IG: @4x0nn // github.com/n0xa | IG: @4x0nn
// -=-=-=-=-=-=- Uncomment the platform you're building for -=-=-=-=-=-=- // -=-=-=-=-=-=- Uncomment the platform you're building for -=-=-=-=-=-=-
#define STICK_C_PLUS //#define STICK_C_PLUS
//#define STICK_C_PLUS2 //#define STICK_C_PLUS2
//#define STICK_C //#define STICK_C
//#define CARDPUTER #define CARDPUTER
// -=-=- Uncommenting more than one at a time will result in errors -=-=- // -=-=- Uncommenting more than one at a time will result in errors -=-=-
String buildver="2.0.3"; String buildver="2.0.5";
#define BGCOLOR BLACK #define BGCOLOR BLACK
#define FGCOLOR GREEN #define FGCOLOR GREEN
@ -86,6 +86,7 @@ String buildver="2.0.3";
#define KB #define KB
#define HID #define HID
#define ACTIVE_LOW_IR #define ACTIVE_LOW_IR
#define USE_EEPROM
// -=-=- ALIASES -=-=- // -=-=- ALIASES -=-=-
#define DISP M5Cardputer.Display #define DISP M5Cardputer.Display
#define IRLED 44 #define IRLED 44
@ -122,6 +123,7 @@ bool maelstrom = false; // Internal flag to place AppleJuice into Bluetooth Ma
#include <EEPROM.h> #include <EEPROM.h>
#define EEPROM_SIZE 4 #define EEPROM_SIZE 4
#endif #endif
struct MENU { struct MENU {
char name[19]; char name[19];
int command; int command;
@ -273,42 +275,44 @@ void mmenu_loop() {
} }
} }
//Screen dimming needs both AXP and RTC features
bool screen_dim_dimmed = false;
int screen_dim_time = 30;
int screen_dim_current = 0;
void screenBrightness(int bright){
#if defined(AXP)
M5.Axp.ScreenBreath(bright);
#endif
#if defined(CARDPUTER)
analogWrite(38, 155 + (bright));
#endif
}
void screen_dim_proc() {
#if defined(AXP) && defined(RTC) #if defined(AXP) && defined(RTC)
//Screen dimming needs both AXP and RTC features M5.Rtc.GetBm8563Time();
bool pct_brightness = true; /* set to false if the screen goes // if one of the buttons is pressed, take the current time and add screen_dim_time on to it and roll over when necessary
to full brightness over level 2. if (check_next_press() || check_select_press()) {
Useful range is about 7-15. if (screen_dim_dimmed) {
Set to true if the screen is too screen_dim_dimmed = false;
dim no matter what level is set. M5.Axp.ScreenBreath(brightness);
Some versions of the M5Stack lib
have a percentage range 0-100. */
bool screen_dim_dimmed = false;
int screen_dim_time = 30;
int screen_dim_current = 0;
void screen_dim_proc() {
M5.Rtc.GetBm8563Time();
// if one of the buttons is pressed, take the current time and add screen_dim_time on to it and roll over when necessary
if (check_next_press() || check_select_press()) {
if (screen_dim_dimmed) {
screen_dim_dimmed = false;
M5.Axp.ScreenBreath(brightness);
}
int newtime = M5.Rtc.Second + screen_dim_time + 2; // hacky but needs a couple extra seconds added
if (newtime >= 60) {
newtime = newtime - 60;
}
screen_dim_current = newtime;
} }
if (screen_dim_dimmed == false) { int newtime = M5.Rtc.Second + screen_dim_time + 2; // hacky but needs a couple extra seconds added
if (M5.Rtc.Second == screen_dim_current || (M5.Rtc.Second + 1) == screen_dim_current || (M5.Rtc.Second + 2) == screen_dim_current) {
M5.Axp.ScreenBreath(10); if (newtime >= 60) {
screen_dim_dimmed = true; newtime = newtime - 60;
} }
screen_dim_current = newtime;
}
if (screen_dim_dimmed == false) {
if (M5.Rtc.Second == screen_dim_current || (M5.Rtc.Second + 1) == screen_dim_current || (M5.Rtc.Second + 2) == screen_dim_current) {
M5.Axp.ScreenBreath(10);
screen_dim_dimmed = true;
} }
} }
#endif
}
/// Dimmer MENU /// /// Dimmer MENU ///
MENU dmenu[] = { MENU dmenu[] = {
@ -334,15 +338,18 @@ void mmenu_loop() {
void dmenu_setup() { void dmenu_setup() {
DISP.fillScreen(BGCOLOR); DISP.fillScreen(BGCOLOR);
DISP.setCursor(0, 5, 1); DISP.setCursor(0, 5, 1);
DISP.println("SET AUTO DIM TIME"); #if defined(RTC)
delay(1000); DISP.println("SET AUTO DIM TIME");
cursor = (screen_dim_time / 5) - 1; delay(1000);
rstOverride = true; cursor = (screen_dim_time / 5) - 1;
dmenu_drawmenu(); rstOverride = true;
delay(500); // Prevent switching after menu loads up dmenu_drawmenu();
delay(500); // Prevent switching after menu loads up
#endif
} }
void dmenu_loop() { void dmenu_loop() {
#if defined(RTC)
if (check_next_press()) { if (check_next_press()) {
cursor++; cursor++;
cursor = cursor % ( sizeof(dmenu) / sizeof(MENU) ); cursor = cursor % ( sizeof(dmenu) / sizeof(MENU) );
@ -351,57 +358,46 @@ void mmenu_loop() {
} }
if (check_select_press()) { if (check_select_press()) {
screen_dim_time = dmenu[cursor].command; screen_dim_time = dmenu[cursor].command;
#if defined(USE_EEPROM) #if defined(USE_EEPROM) && defined(RTC)
EEPROM.write(1, screen_dim_time); EEPROM.write(1, screen_dim_time);
EEPROM.commit(); EEPROM.commit();
#endif #endif
#endif
DISP.fillScreen(BGCOLOR); DISP.fillScreen(BGCOLOR);
DISP.setCursor(0, 5, 1); DISP.setCursor(0, 5, 1);
DISP.println("SET BRIGHTNESS"); DISP.println("SET BRIGHTNESS");
delay(1000); delay(1000);
if(pct_brightness){ cursor = brightness / 10;
cursor = brightness / 10;
} else {
cursor = brightness + 5;
}
timeset_drawmenu(11); timeset_drawmenu(11);
while( !check_select_press()) { while( !check_select_press()) {
if (check_next_press()) { if (check_next_press()) {
cursor++; cursor++;
cursor = cursor % 11 ; cursor = cursor % 11 ;
timeset_drawmenu(11); timeset_drawmenu(11);
if(pct_brightness){ screenBrightness(10 * cursor);
M5.Axp.ScreenBreath(10 * cursor);
} else {
M5.Axp.ScreenBreath(5 + cursor);
}
delay(250); delay(250);
} }
} }
if(pct_brightness){ screenBrightness(10 * cursor);
brightness = cursor * 10;
} else {
brightness = cursor + 5;
}
M5.Axp.ScreenBreath(brightness);
#if defined(USE_EEPROM) #if defined(USE_EEPROM)
EEPROM.write(2, brightness); EEPROM.write(2, 10 * cursor);
EEPROM.commit(); EEPROM.commit();
#endif #endif
rstOverride = false; rstOverride = false;
isSwitching = true; isSwitching = true;
current_proc = 2; current_proc = 2;
} }
#if defined(RTC)
} }
#endif //AXP / RTC Dimmer #endif
/// SETTINGS MENU /// /// SETTINGS MENU ///
MENU smenu[] = { MENU smenu[] = {
{ "Back", 1}, { "Back", 1},
#if defined(AXP) #if defined(AXP)
{ "Battery Info", 6}, { "Battery Info", 6},
{ "Brightness", 4},
#endif #endif
{ "Brightness", 4},
#if defined(RTC) #if defined(RTC)
{ "Set Clock", 3}, { "Set Clock", 3},
#endif #endif
@ -712,19 +708,6 @@ void sendAllCodes() {
} }
/// CLOCK /// /// CLOCK ///
#if defined(RTC)
void clock_setup() {
DISP.fillScreen(BGCOLOR);
DISP.setTextSize(MEDIUM_TEXT);
}
void clock_loop() {
M5.Rtc.GetBm8563Time();
DISP.setCursor(40, 40, 2);
DISP.printf("%02d:%02d:%02d\n", M5.Rtc.Hour, M5.Rtc.Minute, M5.Rtc.Second);
delay(250);
}
/// TIMESET /// /// TIMESET ///
void timeset_drawmenu(int nums) { void timeset_drawmenu(int nums) {
DISP.setTextSize(SMALL_TEXT); DISP.setTextSize(SMALL_TEXT);
@ -745,6 +728,19 @@ void sendAllCodes() {
} }
} }
#if defined(RTC)
void clock_setup() {
DISP.fillScreen(BGCOLOR);
DISP.setTextSize(MEDIUM_TEXT);
}
void clock_loop() {
M5.Rtc.GetBm8563Time();
DISP.setCursor(40, 40, 2);
DISP.printf("%02d:%02d:%02d\n", M5.Rtc.Hour, M5.Rtc.Minute, M5.Rtc.Second);
delay(250);
}
/// TIME SETTING /// /// TIME SETTING ///
void timeset_setup() { void timeset_setup() {
rstOverride = true; rstOverride = true;
@ -1561,6 +1557,7 @@ void setup() {
#if defined(CARDPUTER) #if defined(CARDPUTER)
auto cfg = M5.config(); auto cfg = M5.config();
M5Cardputer.begin(cfg, true); M5Cardputer.begin(cfg, true);
pinMode(38, OUTPUT); // Backlight analogWrite range ~150 - 255
#else #else
M5.begin(); M5.begin();
#endif #endif
@ -1580,13 +1577,14 @@ void setup() {
EEPROM.commit(); EEPROM.commit();
} }
rotation = EEPROM.read(0); rotation = EEPROM.read(0);
screen_dim_time = EEPROM.read(1); #if defined(RTC)
screen_dim_time = EEPROM.read(1);
#endif
brightness = EEPROM.read(2); brightness = EEPROM.read(2);
region = EEPROM.read(3); region = EEPROM.read(3);
#endif #endif
#if defined(AXP) screenBrightness(brightness);
M5.Axp.ScreenBreath(brightness);
#endif
DISP.setRotation(rotation); DISP.setRotation(rotation);
DISP.setTextColor(FGCOLOR, BGCOLOR); DISP.setTextColor(FGCOLOR, BGCOLOR);
bootScreen(); bootScreen();
@ -1645,10 +1643,10 @@ void loop() {
case 3: case 3:
timeset_setup(); timeset_setup();
break; break;
#endif
case 4: case 4:
dmenu_setup(); dmenu_setup();
break; break;
#endif
case 5: case 5:
tvbgone_setup(); tvbgone_setup();
break; break;
@ -1715,10 +1713,10 @@ void loop() {
case 3: case 3:
timeset_loop(); timeset_loop();
break; break;
#endif
case 4: case 4:
dmenu_loop(); dmenu_loop();
break; break;
#endif
case 5: case 5:
tvbgone_loop(); tvbgone_loop();
break; break;