Skip to content
This repository has been archived by the owner on Aug 22, 2024. It is now read-only.

Support for battery info and M5LED fix for M5Stickc plus2 #63

Merged
merged 6 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 67 additions & 18 deletions m5stick-nemo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//#define CARDPUTER
// -=-=- Uncommenting more than one at a time will result in errors -=-=-

String buildver="2.3.4";
String buildver="2.3.5";
#define BGCOLOR BLACK
#define FGCOLOR GREEN

Expand Down Expand Up @@ -40,6 +40,8 @@ String buildver="2.3.4";
#define SD_CLK_PIN 0
#define SD_MISO_PIN 36
#define SD_MOSI_PIN 26
#define M5LED_ON LOW
#define M5LED_OFF HIGH
#endif

#if defined(STICK_C_PLUS2)
Expand All @@ -52,10 +54,12 @@ String buildver="2.3.4";
#define TINY_TEXT 1
// -=-=- FEATURES -=-=-
//#define ACTIVE_LOW_IR
#define M5LED
#define ROTATION
#define USE_EEPROM
//#define RTC //TODO: plus2 has a BM8563 RTC but the class isn't the same, needs work.
//#define SDCARD //Requires a custom-built adapter
#define PWRMGMT
// -=-=- ALIASES -=-=-
#define DISP M5.Lcd
#define IRLED 19
Expand All @@ -68,6 +72,8 @@ String buildver="2.3.4";
#define SD_CLK_PIN 0
#define SD_MISO_PIN 36
#define SD_MOSI_PIN 26
#define M5LED_ON HIGH
#define M5LED_OFF LOW
#endif

#if defined(STICK_C)
Expand All @@ -92,6 +98,8 @@ String buildver="2.3.4";
#define SD_CLK_PIN 0
#define SD_MISO_PIN 36
#define SD_MOSI_PIN 26
#define M5LED_ON LOW
#define M5LED_OFF HIGH
#endif

#if defined(CARDPUTER)
Expand Down Expand Up @@ -122,9 +130,10 @@ String buildver="2.3.4";
#endif

// -=-=-=-=-=- LIST OF CURRENTLY DEFINED FEATURES -=-=-=-=-=-
// M5LED - An LED exposed as M5_LED
// M5LED - An LED exposed as IRLED
// RTC - Real-time clock exposed as M5.Rtc
// AXP - AXP192 Power Management exposed as M5.Axp
// PWRMGMT - StickC+2 Power Management exposed as M5.Power
// KB - Keyboard exposed as M5Cardputer.Keyboard
// HID - HID exposed as USBHIDKeyboard
// USE_EEPROM - Store settings in EEPROM
Expand Down Expand Up @@ -466,7 +475,7 @@ void dmenu_loop() {
/// SETTINGS MENU ///
MENU smenu[] = {
{ TXT_BACK, 1},
#if defined(AXP)
#if defined(AXP) || defined(PWRMGMT)
{ TXT_BATT_INFO, 6},
#endif
#if defined(CARDPUTER)
Expand All @@ -477,7 +486,7 @@ MENU smenu[] = {
{ TXT_SET_CLOCK, 3},
#endif
#if defined(ROTATION)
{ XT_ROTATION, 7},
{ TXT_ROTATION, 7},
#endif
{ TXT_ABOUT, 10},
{ TXT_REBOOT, 98},
Expand Down Expand Up @@ -572,9 +581,48 @@ int rotation = 1;
}
#endif //ROTATION

#if defined(AXP)
/// BATTERY INFO ///
int oldbattery=0;
/// BATTERY INFO ///

#if defined(PWRMGMT)
int old_battery = 0;

void battery_drawmenu(int battery) {
DISP.setTextSize(SMALL_TEXT);
DISP.fillScreen(BGCOLOR);
DISP.setCursor(0, 8, 1);
DISP.print(TXT_BATT);
DISP.print(battery);
DISP.println("%");
DISP.println(TXT_EXIT);
}

int get_battery_voltage() {
return M5.Power.getBatteryLevel();
}

void battery_setup() {
int battery = get_battery_voltage();
battery_drawmenu(battery);
delay(500); // Prevent switching after menu loads up
}

void battery_loop() {
delay(300);
int battery = get_battery_voltage();

if (battery != old_battery){
battery_drawmenu(battery);
}
if (check_select_press()) {
isSwitching = true;
current_proc = 1;
}
old_battery = battery;
}
#endif

#ifdef AXP
int old_battery=0;
void battery_drawmenu(int battery, int b, int c) {
DISP.setTextSize(SMALL_TEXT);
DISP.fillScreen(BGCOLOR);
Expand All @@ -589,6 +637,7 @@ int rotation = 1;
DISP.println("");
DISP.println(TXT_EXIT);
}

void battery_setup() {
rstOverride = false;
float c = M5.Axp.GetVapsData() * 1.4 / 1000;
Expand All @@ -603,15 +652,15 @@ int rotation = 1;
float c = M5.Axp.GetVapsData() * 1.4 / 1000;
float b = M5.Axp.GetVbatData() * 1.1 / 1000;
int battery = ((b - 3.0) / 1.2) * 100;
if (battery != oldbattery){
if (battery != old_battery){
battery_drawmenu(battery, b, c);
}
if (check_select_press()) {
rstOverride = false;
isSwitching = true;
current_proc = 1;
current_proc = 1;
}
oldbattery = battery;
old_battery = battery;
}
#endif // AXP

Expand Down Expand Up @@ -1259,9 +1308,9 @@ void aj_adv(){
pAdvertising->setAdvertisementData(oAdvertisementData);
pAdvertising->start();
#if defined(M5LED)
digitalWrite(M5_LED, LOW); //LED ON on Stick C Plus
digitalWrite(IRLED, M5LED_ON); //LED ON on Stick C Plus
delay(10);
digitalWrite(M5_LED, HIGH); //LED OFF on Stick C Plus
digitalWrite(IRLED, M5LED_OFF); //LED OFF on Stick C Plus
#endif
}
if (check_next_press()) {
Expand Down Expand Up @@ -1368,9 +1417,9 @@ void wifispam_loop() {
int i = 0;
int len = 0;
#if defined(M5LED)
digitalWrite(M5_LED, LOW); //LED ON on Stick C Plus
digitalWrite(IRLED, M5LED_ON); //LED ON on Stick C Plus
delay(1);
digitalWrite(M5_LED, HIGH); //LED OFF on Stick C Plus
digitalWrite(IRLED, M5LED_OFF); //LED OFF on Stick C Plus
#endif
currentTime = millis();
if (currentTime - attackTime > 100) {
Expand Down Expand Up @@ -1753,8 +1802,8 @@ void setup() {

// Pin setup
#if defined(M5LED)
pinMode(M5_LED, OUTPUT);
digitalWrite(M5_LED, HIGH); //LEDOFF
pinMode(IRLED, OUTPUT);
digitalWrite(IRLED, M5LED_OFF); //LEDOFF
#endif
#if !defined(KB)
pinMode(M5_BUTTON_HOME, INPUT);
Expand Down Expand Up @@ -1817,7 +1866,7 @@ void loop() {
case 5:
tvbgone_setup();
break;
#if defined(AXP)
#if defined(AXP) || defined(PWRMGMT)
case 6:
battery_setup();
break;
Expand Down Expand Up @@ -1894,7 +1943,7 @@ void loop() {
case 5:
tvbgone_loop();
break;
#if defined(AXP)
#if defined(AXP) || defined(PWRMGMT)
case 6:
battery_loop();
break;
Expand Down
4 changes: 2 additions & 2 deletions portal.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,9 @@ String clear_GET() {
void blinkLed() {
int count = 0;
while (count < 5) {
digitalWrite(M5_LED, LOW);
digitalWrite(IRLED, M5LED_ON);
delay(500);
digitalWrite(M5_LED, HIGH);
digitalWrite(IRLED, M5LED_OFF);
delay(500);
count = count + 1;
}
Expand Down
2 changes: 1 addition & 1 deletion songs.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void setupSongs() {
#if defined(STICK_C_PLUS)
SPEAKER.tone(4000);
delay(noteDuration * 0.9);
delay(noteDuration)
delay(noteDuration);
SPEAKER.mute();
#elif defined(CARDPUTER)
// we only play the note for 90% of the duration, leaving 10% as a pause
Expand Down
4 changes: 2 additions & 2 deletions tvbg.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ void delay_ten_us(uint16_t us) {

void quickflashLED( void ) {
#if defined(M5LED)
digitalWrite(M5_LED, LOW);
digitalWrite(IRLED, M5LED_ON);
delay_ten_us(3000); // 30 ms ON-time delay
digitalWrite(M5_LED, HIGH);
digitalWrite(IRLED, M5LED_OFF);
#endif
}

Expand Down