Battery status improvement.

This commit is contained in:
Vojtěch Pour 2022-12-13 19:12:39 +01:00
parent b2b34f2710
commit e76f6f8c68
3 changed files with 1313 additions and 14 deletions

View file

@ -43,7 +43,7 @@ void drawGui(screenMode COLOR_MODE) {
M5.Lcd.drawString("100", 60, 20, 4);
if (COLOR_MODE == DARK) {
M5.lcd.drawBitmap(280, 5, 30, 50, (uint16_t *) bluetooth_dark);
M5.lcd.drawBitmap(240, 5, 30, 50, (uint16_t *) bluetooth_dark);
} else {
M5.lcd.drawBitmap(240, 5, 30, 50, (uint16_t *) bluetooth_light);
}

File diff suppressed because it is too large Load diff

View file

@ -19,8 +19,7 @@ Button restartButton(200, 191, 45, 50, false, "", noDraw);
Button powerOffButton(260, 186, 55, 55, false, "", noDraw);
boolean buttonPressed = false;
enum screenMode { DARK,
LIGHT };
enum screenMode { DARK, LIGHT };
screenMode COLOR_MODE = LIGHT;
uint16_t COLORS[2] = { WHITE, BLACK };
@ -47,6 +46,11 @@ uint32_t eegPower[8];
// system variables
long lastReceivedPacket = 0;
boolean bigPacket = false;
float batVoltage;
float batPercentage;
boolean lock = false;
// Multi threading
TaskHandle_t TaskHandle_1;
TaskHandle_t TaskHandle_2;
@ -249,7 +253,12 @@ void task1(void *pvParameters) {
void task2(void *pvParameters) {
bluetoothLoading();
vTaskDelete(TaskHandle_2);
while (1) {
if (!lock) {
drawBattery();
}
delay(500);
}
}
void drawGui(screenMode COLOR_MODE) {
@ -261,17 +270,19 @@ void drawGui(screenMode COLOR_MODE) {
updatePoorQuality();
if (COLOR_MODE == DARK) {
M5.lcd.drawBitmap(280, 5, 30, 50, (uint16_t *)bluetoothDark);
M5.lcd.drawBitmap(240, 5, 30, 50, (uint16_t *)bluetoothDark);
} else {
M5.lcd.drawBitmap(280, 5, 30, 50, (uint16_t *)bluetoothLight);
M5.lcd.drawBitmap(240, 5, 30, 50, (uint16_t *)bluetoothLight);
}
if (isConnected == false && !connecting) { // IF BLUETOOTH DISCONNECTED
for (int i = 0; i < 4; i++) { // thicker line
M5.lcd.drawLine(280 + i, 55, 310 + i, 5, RED);
M5.lcd.drawLine(240 + i, 55, 270 + i, 5, RED);
}
}
drawBattery();
M5.Lcd.drawLine(0, 60, 320, 60, COLORS[COLOR_MODE]);
// BODY
@ -329,35 +340,39 @@ void screenModeHandler(Event &e) {
buttonPressed = true;
if (!connecting) {
lock = true;
drawGui(COLOR_MODE);
lock = false;
}
}
void bluetoothLoading() {
while (connecting) {
if (buttonPressed) {
drawGui(COLOR_MODE);
drawGui(COLOR_MODE);
buttonPressed = false;
}
if (COLOR_MODE == DARK) {
M5.lcd.fillRect(280, 5, 35, 51, BLACK);
M5.lcd.fillRect(240, 5, 35, 51, BLACK);
delay(500);
drawBattery();
if (!buttonPressed) {
M5.lcd.drawBitmap(280, 5, 30, 50, (uint16_t *)bluetoothDark);
M5.lcd.drawBitmap(240, 5, 30, 50, (uint16_t *)bluetoothDark);
delay(500);
}
} else {
M5.lcd.fillRect(280, 5, 35, 51, WHITE);
M5.lcd.fillRect(240, 5, 35, 51, WHITE);
delay(500);
drawBattery();
if (!buttonPressed) {
M5.lcd.drawBitmap(280, 5, 30, 50, (uint16_t *)bluetoothLight);
delay(500);
M5.lcd.drawBitmap(240, 5, 30, 50, (uint16_t *)bluetoothLight);
delay(500);
}
}
}
if (!connecting) {
for (int i = 0; i < 4; i++) { // thicker line
M5.lcd.drawLine(280 + i, 55, 310 + i, 5, RED);
M5.lcd.drawLine(240 + i, 55, 270 + i, 5, RED);
}
}
}
@ -420,6 +435,45 @@ void updateMeditation() {
}
}
void drawBattery() {
batVoltage = M5.Axp.GetBatVoltage();
batPercentage = (batVoltage < 3.2) ? 0 : (batVoltage - 3.2) * 100;
if (COLOR_MODE == DARK) {
if (M5.Axp.isCharging()) {
M5.lcd.drawBitmap(280, 5, 32, 50, (uint16_t *) batteryCharging_white);
} else {
if (batPercentage > 90) {
M5.lcd.drawBitmap(280, 5, 32, 50, (uint16_t *) batteryStatus4_white);
} else if ((90 > batPercentage) && (batPercentage > 60)) {
M5.lcd.drawBitmap(280, 5, 32, 50, (uint16_t *) batteryStatus3_white);
} else if ((60 > batPercentage) && (batPercentage > 20)) {
M5.lcd.drawBitmap(280, 5, 32, 50, (uint16_t *) batteryStatus2_white);
} else if ((20 > batPercentage) && (batPercentage > 10)) {
M5.lcd.drawBitmap(280, 5, 32, 50, (uint16_t *) batteryStatus1_white);
} else {
M5.lcd.drawBitmap(280, 5, 32, 50, (uint16_t *) batteryStatus0_white);
}
}
} else {
if (M5.Axp.isCharging()) {
M5.lcd.drawBitmap(280, 5, 32, 50, (uint16_t *) batteryCharging);
} else {
if (batPercentage > 90) {
M5.lcd.drawBitmap(280, 5, 32, 50, (uint16_t *) batteryStatus4);
} else if ((90 > batPercentage) && (batPercentage > 60)) {
M5.lcd.drawBitmap(280, 5, 32, 50, (uint16_t *) batteryStatus3);
} else if ((60 > batPercentage) && (batPercentage > 20)) {
M5.lcd.drawBitmap(280, 5, 32, 50, (uint16_t *) batteryStatus2);
} else if ((20 > batPercentage) && (batPercentage > 10)) {
M5.lcd.drawBitmap(280, 5, 32, 50, (uint16_t *) batteryStatus1);
} else {
M5.lcd.drawBitmap(280, 5, 32, 50, (uint16_t *) batteryStatus0);
}
}
}
}
int countDigit(int n) {
if (n == 0)
return 1;