Added Battery to MenuBattery
This commit is contained in:
+2
-10
@@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* @file battery.cpp
|
* @file battery.cpp
|
||||||
* @author Alexander Klein (alex@kleiax.de)
|
* @author Alexander Klein (alex@kleiax.de)
|
||||||
* @brief
|
* @brief Contains the implementation of the class Battery
|
||||||
* @version 0.1
|
* @version 0.1
|
||||||
* @date 2022-02-05
|
* @date 2022-02-05
|
||||||
*
|
*
|
||||||
@@ -28,14 +28,6 @@ void Battery::loop() {
|
|||||||
this->lastMillis = millis();
|
this->lastMillis = millis();
|
||||||
}
|
}
|
||||||
|
|
||||||
double Battery::getBatteryVoltage() {
|
|
||||||
return this->batteryVoltage;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t Battery::getBatteryPercent() {
|
|
||||||
return this->batteryPercent;
|
|
||||||
}
|
|
||||||
|
|
||||||
double Battery::readInputVoltage() {
|
double Battery::readInputVoltage() {
|
||||||
// Reference voltage is 3v3 so maximum reading is 3v3 = 4095 in range 0 to 4095
|
// Reference voltage is 3v3 so maximum reading is 3v3 = 4095 in range 0 to 4095
|
||||||
double reading = analogRead(this->pin);
|
double reading = analogRead(this->pin);
|
||||||
@@ -52,7 +44,7 @@ void Battery::calculateBatteryVoltage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Battery::calculateBatteryPercent() {
|
void Battery::calculateBatteryPercent() {
|
||||||
int8_t size = sizeof(this->capacityVoltages) / sizeof(this->capacityVoltages);
|
int8_t size = sizeof(this->capacityVoltages) / sizeof(*this->capacityVoltages);
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
for (i = 0; i < size; i++) {
|
for (i = 0; i < size; i++) {
|
||||||
if (this->batteryVoltage <= this->capacityVoltages[i])
|
if (this->batteryVoltage <= this->capacityVoltages[i])
|
||||||
|
|||||||
@@ -11,8 +11,8 @@
|
|||||||
|
|
||||||
#include "menuAkku.h"
|
#include "menuAkku.h"
|
||||||
|
|
||||||
MenuAkku::MenuAkku() {
|
MenuAkku::MenuAkku(Battery* mainBattery) {
|
||||||
|
this->mainBattery = mainBattery;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuAkku::right() {
|
void MenuAkku::right() {
|
||||||
@@ -35,7 +35,7 @@ void MenuAkku::yes() {
|
|||||||
void MenuAkku::printMenu() {
|
void MenuAkku::printMenu() {
|
||||||
char buf[17];
|
char buf[17];
|
||||||
uint8_t controllerBattery = -1;
|
uint8_t controllerBattery = -1;
|
||||||
uint8_t mainBattery = 77;
|
uint8_t mainBattery = this->mainBattery->getBatteryPercent();
|
||||||
|
|
||||||
if( controllerBattery != Ps3.data.status.battery ){
|
if( controllerBattery != Ps3.data.status.battery ){
|
||||||
controllerBattery = Ps3.data.status.battery;
|
controllerBattery = Ps3.data.status.battery;
|
||||||
|
|||||||
@@ -15,9 +15,10 @@
|
|||||||
#include <Ps3Controller.h>
|
#include <Ps3Controller.h>
|
||||||
|
|
||||||
#include "menuControl.h"
|
#include "menuControl.h"
|
||||||
|
#include "battery.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This class shows Akku informations
|
* @brief This class shows battery informations
|
||||||
*
|
*
|
||||||
* Provide information for main battery pack and
|
* Provide information for main battery pack and
|
||||||
* PS3-Controller battery pack
|
* PS3-Controller battery pack
|
||||||
@@ -29,7 +30,7 @@ class MenuAkku : public MenuControl {
|
|||||||
* @brief Construct a new Menu Akku object
|
* @brief Construct a new Menu Akku object
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
MenuAkku();
|
MenuAkku(Battery* mainBattery);
|
||||||
|
|
||||||
void down() override {}
|
void down() override {}
|
||||||
void up() override {}
|
void up() override {}
|
||||||
@@ -53,9 +54,11 @@ class MenuAkku : public MenuControl {
|
|||||||
void update() override;
|
void update() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const uint16_t delay = 5000;
|
const uint16_t delay = 15000;
|
||||||
uint32_t last_millis = 0;
|
uint32_t last_millis = 0;
|
||||||
|
|
||||||
|
Battery* mainBattery;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MENU_AKKU_H
|
#endif // MENU_AKKU_H
|
||||||
|
|||||||
+6
-1
@@ -27,6 +27,7 @@
|
|||||||
#include "moveControl.h"
|
#include "moveControl.h"
|
||||||
#include "network.h"
|
#include "network.h"
|
||||||
#include "debugMqtt.h"
|
#include "debugMqtt.h"
|
||||||
|
#include "battery.h"
|
||||||
|
|
||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
#include "menuAction.h"
|
#include "menuAction.h"
|
||||||
@@ -44,6 +45,7 @@ LiquidCrystal_I2C* lcd;
|
|||||||
OutputBuf* outputBuf;
|
OutputBuf* outputBuf;
|
||||||
DebugMqtt* debugMqtt = nullptr;
|
DebugMqtt* debugMqtt = nullptr;
|
||||||
BluetoothSerial* serialBT = nullptr;
|
BluetoothSerial* serialBT = nullptr;
|
||||||
|
Battery* mainBattery;
|
||||||
|
|
||||||
bool wifiIsActive;
|
bool wifiIsActive;
|
||||||
|
|
||||||
@@ -57,6 +59,8 @@ void setup() {
|
|||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
char wifiIndicator = 'X';
|
char wifiIndicator = 'X';
|
||||||
|
|
||||||
|
mainBattery = new Battery(35, 690000, 220000);
|
||||||
|
|
||||||
Wire.begin(21, 19);
|
Wire.begin(21, 19);
|
||||||
// i2cScanner();
|
// i2cScanner();
|
||||||
lcd = new LiquidCrystal_I2C(0x3F,16,2);
|
lcd = new LiquidCrystal_I2C(0x3F,16,2);
|
||||||
@@ -109,6 +113,7 @@ void loop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
driveManager.loop();
|
driveManager.loop();
|
||||||
|
mainBattery->loop();
|
||||||
|
|
||||||
// static uint32_t lastMillis = 0;
|
// static uint32_t lastMillis = 0;
|
||||||
// if (millis() - lastMillis > 2000) {
|
// if (millis() - lastMillis > 2000) {
|
||||||
@@ -215,7 +220,7 @@ void makeMenu() {
|
|||||||
MenuCaptureRoute* cap_m = new MenuCaptureRoute(&driveManager);
|
MenuCaptureRoute* cap_m = new MenuCaptureRoute(&driveManager);
|
||||||
MenuAutopilot* auto_m = new MenuAutopilot(&driveManager);
|
MenuAutopilot* auto_m = new MenuAutopilot(&driveManager);
|
||||||
MenuGPS* gps_m = new MenuGPS(driveManager.getNavigation()->getGPS());
|
MenuGPS* gps_m = new MenuGPS(driveManager.getNavigation()->getGPS());
|
||||||
MenuAkku* akku_m = new MenuAkku();
|
MenuAkku* akku_m = new MenuAkku(mainBattery);
|
||||||
|
|
||||||
// Set Menus on LCD
|
// Set Menus on LCD
|
||||||
main_m->setLcd(lcd);
|
main_m->setLcd(lcd);
|
||||||
|
|||||||
Reference in New Issue
Block a user