Skip to content

Commit

Permalink
added auto-sleep. changed button c press to wake, btn C long press to…
Browse files Browse the repository at this point in the history
… sleep.
  • Loading branch information
sboger committed Apr 7, 2019
1 parent 0b2b1bb commit f44fc33
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
45 changes: 27 additions & 18 deletions M5-BT-TFT_Terminal.ino
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ BluetoothSerial SerialBT;
#define BOT_FIXED_AREA 0 // Number of lines in bottom fixed area (lines counted from bottom of screen)
#define TOP_FIXED_AREA 16 // Number of lines in top fixed area (lines counted from top of screen)
#define YMAX 240 // Bottom of screen area
#define LCD_BRIGHTNESS 100 // 100 = 50%

#define LCD_BRIGHTNESS 50 // Save battery. 50%
#define SECS_TO_SLEEP 30 // Set display to auto sleep after 30 seconds
// Note: Will auto-awaken on input

// The initial y coordinate of the top of the scrolling area
uint16_t yStart = TOP_FIXED_AREA;
Expand All @@ -44,13 +47,15 @@ uint16_t yDraw = YMAX - BOT_FIXED_AREA - TEXT_HEIGHT;
// Keep track of the drawing x coordinate
uint16_t xPos = 0;

// For the byte we read from the serial port
// For the byte we read from the BT port
byte data = 0;

// A few test variables used during debugging
boolean change_colour = 1;
// Yes, we want to change color on each input line.
boolean change_color = 1;
boolean selected = 1;

long timeSinceLastUpdate = 0;

// We have to blank the top line each time the display is scrolled, but this takes up to 13 milliseconds
// for a full width line, meanwhile the serial buffer may be filling... and overflowing
// We can speed up scrolling of short text lines by just blanking the character we drew
Expand All @@ -75,7 +80,7 @@ void setup() {
M5.Lcd.fillRect(0,0,320,16, TFT_BLUE);
M5.Lcd.drawCentreString(" BLUETERM ",320/2,0,2);

// Change colour for scrolling zone text
// Change color for scrolling zone text
M5.Lcd.setTextColor(TFT_WHITE, TFT_BLACK);

// Setup scroll area
Expand All @@ -89,15 +94,16 @@ void setup() {
void loop(void) {

M5.update();

if (millis() - timeSinceLastUpdate > (1000L*SECS_TO_SLEEP)) {
M5.Lcd.setBrightness(0);
M5.Lcd.sleep();
timeSinceLastUpdate = millis();
}

// These lines change the text colour when the serial buffer is emptied
// These are test lines to see if we may be losing characters
// Also uncomment the change_colour line below to try them
//

if (change_colour) {
if (change_color) {
displayBatt();
change_colour = 0;
change_color = 0;
if (selected == 1) {
M5.Lcd.setTextColor(TFT_CYAN, TFT_BLACK); selected = 0;
} else {
Expand All @@ -109,9 +115,12 @@ void loop(void) {
// M5.Lcd.clear();
//}

if (M5.BtnC.isPressed()) {
if (M5.BtnC.wasReleased()) {
M5.Lcd.setBrightness(LCD_BRIGHTNESS);
M5.Lcd.wakeup();
} else if (M5.BtnC.wasReleasefor(400)) {
M5.Lcd.sleep();
M5.Lcd.setBrightness(0);
M5.Lcd.sleep();
}

while (SerialBT.available()) {
Expand All @@ -129,7 +138,7 @@ void loop(void) {
xPos += M5.Lcd.drawChar(data,xPos,yDraw,2);
blank[(18+(yStart-TOP_FIXED_AREA)/TEXT_HEIGHT)%19]=xPos; // Keep a record of line lengths
}
change_colour = 1; // Line to indicate buffer is being emptied
change_color = 1; // Line to indicate buffer is being emptied
}
}

Expand All @@ -140,16 +149,16 @@ void displayBatt() {

String battstat;

M5.Lcd.setTextColor(TFT_WHITE, TFT_BLUE);

if (M5.Power.isChargeFull()) {
battstat = "FULL";
} else if (M5.Power.isCharging()) {
battstat = "CHRG";
} else {
battstat = String(M5.Power.getBatteryLevel()) + " ";
}


M5.Lcd.setTextColor(TFT_WHITE, TFT_BLUE);

M5.Lcd.drawString(battstat.substring(0,4),280,0,2);

}
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ This MAIN m5stack branch is for work on integrating into M5Stack.

* LCD_BRIGHTNESS setting in sketch
* Battery status upper right
* Button C powers off display to save battery. Display will auto-awaken on data input.
* Display will autosleep after SECS_TO_SLEEP.
* Push Button C to wake display.
* Long-Push Button C to sleep display.
* *DISPLAY WILL AUTO-WAKE ON ANY INPUT.*

In Arduino, set Tool->Partition Scheme-> No OTA (Large APP)

Expand Down

0 comments on commit f44fc33

Please sign in to comment.