70 lines
1.9 KiB
C++
70 lines
1.9 KiB
C++
/**
|
|
* @file menuAkku.cpp
|
|
* @author Alexander Klein (alex@kleiax.de)
|
|
* @brief Contains a implementation of the class MenuAkku
|
|
* @version 0.1
|
|
* @date 2022-02-05
|
|
*
|
|
* @copyright Copyright (c) 2022
|
|
*
|
|
*/
|
|
|
|
#include "menuAkku.h"
|
|
|
|
MenuAkku::MenuAkku(Battery* mainBattery) {
|
|
this->mainBattery = mainBattery;
|
|
}
|
|
|
|
void MenuAkku::right() {
|
|
this->printMenu();
|
|
}
|
|
|
|
void MenuAkku::left() {
|
|
if (this->parentMenu)
|
|
this->parentMenu->printMenu();
|
|
}
|
|
|
|
void MenuAkku::no() {
|
|
this->left();
|
|
}
|
|
|
|
void MenuAkku::yes() {
|
|
this->right();
|
|
}
|
|
|
|
void MenuAkku::printMenu() {
|
|
char buf[17];
|
|
uint8_t controllerBattery = -1;
|
|
uint8_t mainBattery = this->mainBattery->getBatteryPercent();
|
|
double mainBatteryVolt = this->mainBattery->getBatteryVoltage();
|
|
|
|
if( controllerBattery != Ps3.data.status.battery ){
|
|
controllerBattery = Ps3.data.status.battery;
|
|
}
|
|
|
|
if( controllerBattery == ps3_status_battery_charging ) sprintf(buf, "LOAD");
|
|
else if( controllerBattery == ps3_status_battery_full ) sprintf(buf, "FULL");
|
|
else if( controllerBattery == ps3_status_battery_high ) sprintf(buf, "HIGH");
|
|
else if( controllerBattery == ps3_status_battery_low) sprintf(buf, "LOW");
|
|
else if( controllerBattery == ps3_status_battery_dying ) sprintf(buf, "BAD");
|
|
else if( controllerBattery == ps3_status_battery_shutdown ) sprintf(buf, "OFF");
|
|
else sprintf(buf, "UNDEF");
|
|
|
|
if (this->lcd) {
|
|
lcd->clear();
|
|
lcd->setCursor(0, 0);
|
|
lcd->printf("Controller: %s", buf);
|
|
lcd->setCursor(0, 1);
|
|
lcd->printf("Main: %u%% %4.2fV", mainBattery, mainBatteryVolt);
|
|
}
|
|
std::cout << "Controller: " << buf << " Main: " << (int) mainBattery << "% " << mainBatteryVolt << "V" << std::endl;
|
|
}
|
|
|
|
void MenuAkku::update() {
|
|
if (millis() - this->last_millis < this->delay) {
|
|
return;
|
|
}
|
|
this->printMenu();
|
|
this->last_millis = millis();
|
|
}
|