moved battery information in systeminformation

This commit is contained in:
2022-12-28 14:57:31 +01:00
parent 7f1ffc874f
commit 35f1059562
5 changed files with 39 additions and 143 deletions
-70
View File
@@ -1,70 +0,0 @@
/**
* @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, Ps3Controller* gamepad) {
this->mainBattery = mainBattery;
this->gamepad = gamepad;
}
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 != this->gamepad->data.status.battery ){
controllerBattery = this->gamepad->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->lastMillis < this->delay) {
return;
}
this->printMenu();
this->lastMillis = millis();
}
-65
View File
@@ -1,65 +0,0 @@
/**
* @file menuAkku.h
* @author Alexander Klein (alex@kleiax.de)
* @brief Contains a Menu class to show battery pack informations
* @version 0.1
* @date 2022-02-05
*
* @copyright Copyright (c) 2022
*
*/
#ifndef MENU_AKKU_H
#define MENU_AKKU_H
#include <Ps3Controller.h>
#include "menuControl.h"
#include "battery.h"
/**
* @brief This class shows battery informations
*
* Provide information for main battery pack and
* PS3-Controller battery pack
*
*/
class MenuAkku : public MenuControl {
public:
/**
* @brief Construct a new Menu Akku object
*
*/
MenuAkku(Battery* mainBattery, Ps3Controller* gamepad);
void down() override {}
void up() override {}
void right() override;
void left() override;
void no() override;
void yes() override;
/**
* @brief Prints the Information to display and console
*
* The informations are only printed to the display if it
* set.
*/
void printMenu() override;
/**
* @brief Renew the informations and print them
*
*/
void update() override;
private:
const uint16_t delay = 15000;
uint32_t lastMillis = 0;
Battery* mainBattery;
Ps3Controller* gamepad;
};
#endif // MENU_AKKU_H
@@ -11,6 +11,12 @@
#include "menuSysteminformation.h"
MenuSysteminformation::MenuSysteminformation(Battery* mainBattery, Ps3Controller* gamepad)
: MenuInformationSites(5) {
this->mainBattery = mainBattery;
this->gamepad = gamepad;
}
void MenuSysteminformation::printPage() const {
String lineOne = "";
String lineTwo = "";
@@ -25,10 +31,34 @@ void MenuSysteminformation::printPage() const {
lineTwo.concat((millis() / 1000));
break;
case 2:
lineOne = "Main battery:";
lineTwo = "";
lineTwo.concat(this->mainBattery->getBatteryPercent());
lineTwo.concat("% V=");
lineTwo.concat(this->mainBattery->getBatteryVoltage());
break;
case 3:
lineOne = "PS3 battery";
lineTwo = "is ";
MenuSysteminformation::ps3ToString(this->gamepad->data.status.battery);
break;
default:
this->printDefault();
return;
}
this->print(lineOne, lineTwo);
}
}
String MenuSysteminformation::ps3ToString(uint8_t battery) {
if( battery == ps3_status_battery_charging ) return "LOAD";
else if( battery == ps3_status_battery_full ) return "FULL";
else if( battery == ps3_status_battery_high ) return "HIGH";
else if( battery == ps3_status_battery_low) return "LOW";
else if( battery == ps3_status_battery_dying ) return "BAD";
else if( battery == ps3_status_battery_shutdown ) return "OFF";
else return "UNDEF";
}
@@ -13,15 +13,21 @@
#define MENU_SYSTEMINFORMATION_H
#include <Arduino.h>
#include <Ps3Controller.h>
#include "menuInformationSites.h"
#include "battery.h"
class MenuSysteminformation : public MenuInformationSites {
public:
MenuSysteminformation() : MenuInformationSites(5) {}
MenuSysteminformation(Battery* mainBattery, Ps3Controller* gamepad);
private:
void printPage() const override;
static String ps3ToString(uint8_t battery);
Battery* mainBattery;
Ps3Controller* gamepad;
};
#endif // MENU_SYSTEMINFORMATION_H