Merge pull request #36 from n0xa/dimmer-millis
Decouple screen dim timer from RTC
This commit is contained in:
commit
d5575819fe
|
@ -8,7 +8,7 @@
|
||||||
//#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.1.0";
|
String buildver="2.1.1";
|
||||||
#define BGCOLOR BLACK
|
#define BGCOLOR BLACK
|
||||||
#define FGCOLOR GREEN
|
#define FGCOLOR GREEN
|
||||||
|
|
||||||
|
@ -52,6 +52,7 @@ String buildver="2.1.0";
|
||||||
#define M5_BUTTON_HOME 37
|
#define M5_BUTTON_HOME 37
|
||||||
#define M5_BUTTON_RST 39
|
#define M5_BUTTON_RST 39
|
||||||
//TODO: Figure out screen brightness on PLUS2 (if possible at all?) without AXP.
|
//TODO: Figure out screen brightness on PLUS2 (if possible at all?) without AXP.
|
||||||
|
#define BACKLIGHT 27 // best I can tell from the schematics?
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(STICK_C)
|
#if defined(STICK_C)
|
||||||
|
@ -71,7 +72,6 @@ String buildver="2.1.0";
|
||||||
// -=-=- ALIASES -=-=-
|
// -=-=- ALIASES -=-=-
|
||||||
#define DISP M5.Lcd
|
#define DISP M5.Lcd
|
||||||
#define IRLED 9
|
#define IRLED 9
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(CARDPUTER)
|
#if defined(CARDPUTER)
|
||||||
|
@ -90,6 +90,7 @@ String buildver="2.1.0";
|
||||||
// -=-=- ALIASES -=-=-
|
// -=-=- ALIASES -=-=-
|
||||||
#define DISP M5Cardputer.Display
|
#define DISP M5Cardputer.Display
|
||||||
#define IRLED 44
|
#define IRLED 44
|
||||||
|
#define BACKLIGHT 38
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// -=-=-=-=-=- LIST OF CURRENTLY DEFINED FEATURES -=-=-=-=-=-
|
// -=-=-=-=-=- LIST OF CURRENTLY DEFINED FEATURES -=-=-=-=-=-
|
||||||
|
@ -191,6 +192,7 @@ void check_menu_press() {
|
||||||
#if defined(M5_BUTTON_MENU)
|
#if defined(M5_BUTTON_MENU)
|
||||||
if (digitalRead(M5_BUTTON_MENU) == LOW){
|
if (digitalRead(M5_BUTTON_MENU) == LOW){
|
||||||
#endif
|
#endif
|
||||||
|
dimtimer();
|
||||||
isSwitching = true;
|
isSwitching = true;
|
||||||
rstOverride = false;
|
rstOverride = false;
|
||||||
current_proc = 1;
|
current_proc = 1;
|
||||||
|
@ -204,14 +206,17 @@ bool check_next_press(){
|
||||||
if (M5Cardputer.Keyboard.isKeyPressed(';')){
|
if (M5Cardputer.Keyboard.isKeyPressed(';')){
|
||||||
// hack to handle the up arrow
|
// hack to handle the up arrow
|
||||||
cursor = cursor - 2;
|
cursor = cursor - 2;
|
||||||
|
dimtimer();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
M5Cardputer.update();
|
M5Cardputer.update();
|
||||||
if (M5Cardputer.Keyboard.isKeyPressed(KEY_TAB) || M5Cardputer.Keyboard.isKeyPressed('.')){
|
if (M5Cardputer.Keyboard.isKeyPressed(KEY_TAB) || M5Cardputer.Keyboard.isKeyPressed('.')){
|
||||||
|
dimtimer();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (digitalRead(M5_BUTTON_RST) == LOW){
|
if (digitalRead(M5_BUTTON_RST) == LOW){
|
||||||
|
dimtimer();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -222,11 +227,12 @@ bool check_select_press(){
|
||||||
#if defined(KB)
|
#if defined(KB)
|
||||||
M5Cardputer.update();
|
M5Cardputer.update();
|
||||||
if (M5Cardputer.Keyboard.isKeyPressed(KEY_ENTER) || M5Cardputer.Keyboard.isKeyPressed('/')){
|
if (M5Cardputer.Keyboard.isKeyPressed(KEY_ENTER) || M5Cardputer.Keyboard.isKeyPressed('/')){
|
||||||
|
dimtimer();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (digitalRead(M5_BUTTON_HOME) == LOW){
|
if (digitalRead(M5_BUTTON_HOME) == LOW){
|
||||||
|
dimtimer();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -285,34 +291,33 @@ void screenBrightness(int bright){
|
||||||
#if defined(AXP)
|
#if defined(AXP)
|
||||||
M5.Axp.ScreenBreath(bright);
|
M5.Axp.ScreenBreath(bright);
|
||||||
#endif
|
#endif
|
||||||
#if defined(CARDPUTER)
|
#if defined(BACKLIGHT)
|
||||||
analogWrite(38, 155 + (bright));
|
analogWrite(BACKLIGHT, 155 + (bright));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void screen_dim_proc() {
|
int uptime(){
|
||||||
#if defined(AXP) && defined(RTC)
|
return(int(millis() / 1000));
|
||||||
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) {
|
void dimtimer(){
|
||||||
newtime = newtime - 60;
|
if(screen_dim_dimmed){
|
||||||
}
|
screenBrightness(brightness);
|
||||||
screen_dim_current = newtime;
|
screen_dim_dimmed = false;
|
||||||
}
|
}
|
||||||
|
screen_dim_current = uptime() + screen_dim_time + 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
void screen_dim_proc() {
|
||||||
|
check_menu_press();
|
||||||
|
check_next_press();
|
||||||
|
check_select_press();
|
||||||
if (screen_dim_dimmed == false) {
|
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) {
|
if (uptime() == screen_dim_current || (uptime() + 1) == screen_dim_current || (uptime() + 2) == screen_dim_current) {
|
||||||
M5.Axp.ScreenBreath(10);
|
screenBrightness(10);
|
||||||
screen_dim_dimmed = true;
|
screen_dim_dimmed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Dimmer MENU ///
|
/// Dimmer MENU ///
|
||||||
|
@ -339,18 +344,15 @@ void screen_dim_proc() {
|
||||||
void dmenu_setup() {
|
void dmenu_setup() {
|
||||||
DISP.fillScreen(BGCOLOR);
|
DISP.fillScreen(BGCOLOR);
|
||||||
DISP.setCursor(0, 5, 1);
|
DISP.setCursor(0, 5, 1);
|
||||||
#if defined(RTC)
|
DISP.println("SET AUTO DIM TIME");
|
||||||
DISP.println("SET AUTO DIM TIME");
|
delay(1000);
|
||||||
delay(1000);
|
cursor = (screen_dim_time / 5) - 1;
|
||||||
cursor = (screen_dim_time / 5) - 1;
|
rstOverride = true;
|
||||||
rstOverride = true;
|
dmenu_drawmenu();
|
||||||
dmenu_drawmenu();
|
delay(500); // Prevent switching after menu loads up
|
||||||
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) );
|
||||||
|
@ -359,11 +361,10 @@ void screen_dim_proc() {
|
||||||
}
|
}
|
||||||
if (check_select_press()) {
|
if (check_select_press()) {
|
||||||
screen_dim_time = dmenu[cursor].command;
|
screen_dim_time = dmenu[cursor].command;
|
||||||
#if defined(USE_EEPROM) && defined(RTC)
|
#if defined(USE_EEPROM)
|
||||||
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");
|
||||||
|
@ -388,9 +389,7 @@ void screen_dim_proc() {
|
||||||
isSwitching = true;
|
isSwitching = true;
|
||||||
current_proc = 2;
|
current_proc = 2;
|
||||||
}
|
}
|
||||||
#if defined(RTC)
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
/// SETTINGS MENU ///
|
/// SETTINGS MENU ///
|
||||||
MENU smenu[] = {
|
MENU smenu[] = {
|
||||||
|
@ -1615,21 +1614,23 @@ void setup() {
|
||||||
if(EEPROM.read(0) > 3 || EEPROM.read(1) > 30 || EEPROM.read(2) > 100 || EEPROM.read(3) > 1) {
|
if(EEPROM.read(0) > 3 || EEPROM.read(1) > 30 || EEPROM.read(2) > 100 || EEPROM.read(3) > 1) {
|
||||||
// Assume out-of-bounds settings are a fresh/corrupt EEPROM and write defaults for everything
|
// Assume out-of-bounds settings are a fresh/corrupt EEPROM and write defaults for everything
|
||||||
Serial.println("EEPROM likely not properly configured. Writing defaults.");
|
Serial.println("EEPROM likely not properly configured. Writing defaults.");
|
||||||
|
#if defined(CARDPUTER)
|
||||||
|
EEPROM.write(0, 1); // Right rotation for cardputer
|
||||||
|
#else
|
||||||
EEPROM.write(0, 3); // Left rotation
|
EEPROM.write(0, 3); // Left rotation
|
||||||
|
#endif
|
||||||
EEPROM.write(1, 15); // 15 second auto dim time
|
EEPROM.write(1, 15); // 15 second auto dim time
|
||||||
EEPROM.write(2, 100); // 100% brightness
|
EEPROM.write(2, 100); // 100% brightness
|
||||||
EEPROM.write(3, 0); // TVBG NA Region
|
EEPROM.write(3, 0); // TVBG NA Region
|
||||||
EEPROM.commit();
|
EEPROM.commit();
|
||||||
}
|
}
|
||||||
rotation = EEPROM.read(0);
|
rotation = EEPROM.read(0);
|
||||||
#if defined(RTC)
|
screen_dim_time = EEPROM.read(1);
|
||||||
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
|
||||||
screenBrightness(brightness);
|
screenBrightness(brightness);
|
||||||
|
dimtimer();
|
||||||
DISP.setRotation(rotation);
|
DISP.setRotation(rotation);
|
||||||
DISP.setTextColor(FGCOLOR, BGCOLOR);
|
DISP.setTextColor(FGCOLOR, BGCOLOR);
|
||||||
bootScreen();
|
bootScreen();
|
||||||
|
@ -1662,11 +1663,7 @@ void loop() {
|
||||||
// This is the code to handle running the main loops
|
// This is the code to handle running the main loops
|
||||||
// Background processes
|
// Background processes
|
||||||
switcher_button_proc();
|
switcher_button_proc();
|
||||||
#if defined(AXP) && defined(RTC)
|
|
||||||
screen_dim_proc();
|
screen_dim_proc();
|
||||||
#endif
|
|
||||||
#if defined(CARDPUTER)
|
|
||||||
#endif
|
|
||||||
check_menu_press();
|
check_menu_press();
|
||||||
|
|
||||||
// Switcher
|
// Switcher
|
||||||
|
|
Loading…
Reference in New Issue