clangtidy corrections part 1
This commit is contained in:
+157
-99
@@ -2,15 +2,15 @@
|
||||
* @file main.cpp
|
||||
* @author Alexander Klein (alex@kleiax.de)
|
||||
* @brief The main file.
|
||||
*
|
||||
*
|
||||
* Sets up Network stuff, PS3-Controller, Menu and Lcd
|
||||
* Handles Controller Input
|
||||
*
|
||||
*
|
||||
* @version 0.1
|
||||
* @date 2022-02-15
|
||||
*
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
@@ -50,61 +50,71 @@
|
||||
#include "SpecialMenus/CalibrateBattery/menuCalibrateBattery.h"
|
||||
|
||||
MoveControl moveController;
|
||||
Network* network;
|
||||
DriveManager* driveManager;
|
||||
Menu* main_m;
|
||||
LiquidCrystal_I2C* lcd;
|
||||
LcdWrapper* lcdWrapper;
|
||||
OutputBuf* outputBuf;
|
||||
DebugMqtt* debugMqtt = nullptr;
|
||||
Battery* mainBattery;
|
||||
SPIClass* spiPort;
|
||||
SensorData* sensorData;
|
||||
ControlPad* controlPad;
|
||||
Network *network;
|
||||
DriveManager *driveManager;
|
||||
Menu *main_m;
|
||||
LiquidCrystal_I2C *lcd;
|
||||
LcdWrapper *lcdWrapper;
|
||||
OutputBuf *outputBuf;
|
||||
DebugMqtt *debugMqtt = nullptr;
|
||||
Battery *mainBattery;
|
||||
SPIClass *spiPort;
|
||||
SensorData *sensorData;
|
||||
ControlPad *controlPad;
|
||||
|
||||
bool wifiIsActive;
|
||||
constexpr uint16_t displayUpdateDelay = 500;
|
||||
|
||||
void i2cScanner(void);
|
||||
void makeMenu(void);
|
||||
void restart(void);
|
||||
void receiveCallback (const uint8_t * mac, const uint8_t *incomingData, int len);
|
||||
void sendCallback (const uint8_t *mac_addr, esp_now_send_status_t status);
|
||||
void lcdWrapperCallback (const char data[][LcdWrapper::totalRows], uint8_t lines, uint8_t rows);
|
||||
NetworkAdresses setIPs(void);
|
||||
void i2cScanner();
|
||||
void makeMenu();
|
||||
void restart();
|
||||
void receiveCallback(const uint8_t *mac, const uint8_t *incomingData, int len);
|
||||
void sendCallback(const uint8_t *mac_addr, esp_now_send_status_t status);
|
||||
void lcdWrapperCallback(const char data[][LcdWrapper::totalRows], uint8_t lines, uint8_t rows);
|
||||
NetworkAdresses setIPs();
|
||||
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(Settings::baudRate);
|
||||
// DebugTimes::setConsolOutput(true);
|
||||
DebugTimes setupTime;
|
||||
|
||||
spiPort = new SPIClass(HSPI);
|
||||
spiPort->begin(PinNumbers::spiSck, PinNumbers::spiCipo, PinNumbers::spiCopi, PinNumbers::gnssSpiCs);
|
||||
|
||||
mainBattery = new Battery(35);
|
||||
mainBattery = new Battery(PinNumbers::battery);
|
||||
controlPad = new ControlPad();
|
||||
|
||||
Wire.begin(21, 19);
|
||||
Wire.setClock(400000);
|
||||
Wire.begin(PinNumbers::sda, PinNumbers::scl);
|
||||
Wire.setClock(Settings::i2cSpeed);
|
||||
i2cScanner();
|
||||
lcd = new LiquidCrystal_I2C(0x3F,16,2);
|
||||
lcd = new LiquidCrystal_I2C(0x3F, 16, 2);
|
||||
lcd->init();
|
||||
lcd->clear();
|
||||
lcd->noBacklight();
|
||||
|
||||
network = new Network(NetworkConfig::ssid, NetworkConfig::password, setIPs());
|
||||
network = new Network(static_cast<const char*>(NetworkConfig::ssid),
|
||||
static_cast<const char*>(NetworkConfig::password),
|
||||
setIPs());
|
||||
network->activateEspNow(receiveCallback, sendCallback);
|
||||
if (NetworkConfig::mqtt) {
|
||||
if (network->activateMqtt(MqttConfig::user, MqttConfig::password)) {
|
||||
if (NetworkConfig::mqtt)
|
||||
{
|
||||
if (network->activateMqtt(static_cast<const char*>(MqttConfig::user),
|
||||
static_cast<const char*>(MqttConfig::password)))
|
||||
{
|
||||
DebugMqtt::init(network->getMqttClient(), Loglevel::debug);
|
||||
debugMqtt = new DebugMqtt("Console");
|
||||
outputBuf = new OutputBuf(debugMqtt);
|
||||
outputBuf->activateMqtt(true);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
outputBuf = new OutputBuf();
|
||||
}
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
outputBuf = new OutputBuf();
|
||||
}
|
||||
std::cout.rdbuf(outputBuf);
|
||||
|
||||
std::cout << "Welcome to Kleiax-Rover" << std::endl;
|
||||
@@ -115,13 +125,19 @@ void setup() {
|
||||
sensorData = new SensorData();
|
||||
sensorData->enableGnss(spiPort, PinNumbers::gnssSpiCs);
|
||||
sensorData->enableRealCompass();
|
||||
sensorData->enableNtrip(NtripConfig::host, NtripConfig::port, NtripConfig::mountPoint, NtripConfig::user, NtripConfig::password);
|
||||
sensorData->enableNtrip(static_cast<const char*>(NtripConfig::host),
|
||||
NtripConfig::port,
|
||||
static_cast<const char*>(NtripConfig::mountPoint),
|
||||
static_cast<const char*>(NtripConfig::user),
|
||||
static_cast<const char*>(NtripConfig::password));
|
||||
// sensorData->enableGyroskop();
|
||||
driveManager = new DriveManager(&moveController, sensorData, controlPad->getControlPadDataPtr());
|
||||
|
||||
char wifiIndicator = 'X';
|
||||
if (network->isWifiConnected())
|
||||
{
|
||||
wifiIndicator = '-';
|
||||
}
|
||||
lcd->backlight();
|
||||
lcd->printf("%c Kleiax-Rover %c", wifiIndicator, wifiIndicator);
|
||||
lcd->setCursor(0, 1);
|
||||
@@ -134,7 +150,8 @@ void setup() {
|
||||
setupTime.stopConsol("Setup");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
void loop()
|
||||
{
|
||||
network->loop();
|
||||
sensorData->loop();
|
||||
driveManager->loop();
|
||||
@@ -143,86 +160,113 @@ void loop() {
|
||||
lcdWrapper->loop();
|
||||
mainBattery->loop();
|
||||
|
||||
// new Value ervery 0.5s
|
||||
if (mainBattery->isNewValue()) {
|
||||
// new Value ervery 0.5s
|
||||
if (mainBattery->isNewValue())
|
||||
{
|
||||
static uint8_t batteryLowCounter = 0;
|
||||
if (mainBattery->isBatteryLow(10))
|
||||
static constexpr uint8_t minVoltage = 10;
|
||||
if (mainBattery->isBatteryLow(minVoltage))
|
||||
{
|
||||
batteryLowCounter++;
|
||||
}
|
||||
else
|
||||
{
|
||||
batteryLowCounter = 0;
|
||||
}
|
||||
|
||||
if (batteryLowCounter >= 10) {
|
||||
if (batteryLowCounter >= 10)
|
||||
{
|
||||
moveController.emergencyStop();
|
||||
uint16_t voltage = (uint16_t) (mainBattery->getBatteryVoltage() * 100);
|
||||
const auto voltage = static_cast<uint16_t>(mainBattery->getBatteryVoltage() * 100);
|
||||
lcd->setCursor(0, 0);
|
||||
lcd->printf("Low Battery: %u", voltage);
|
||||
lcd->setCursor(0, 1);
|
||||
lcd->print("Please turn off.");
|
||||
|
||||
while (true);
|
||||
|
||||
while (true)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void i2cScanner() {
|
||||
void i2cScanner()
|
||||
{
|
||||
constexpr uint8_t checkForLength = 16;
|
||||
constexpr uint8_t maxAdresses = UINT8_MAX / 2;
|
||||
std::cout << "\nI2C Scanner" << std::endl;
|
||||
|
||||
byte error, address;
|
||||
int nDevices;
|
||||
byte error = 0;
|
||||
byte address = 0;
|
||||
int nDevices = 0;
|
||||
std::cout << "Scanning..." << std::endl;
|
||||
nDevices = 0;
|
||||
for(address = 1; address < 127; address++ ) {
|
||||
for (address = 1; address < maxAdresses; address++)
|
||||
{
|
||||
Wire.beginTransmission(address);
|
||||
error = Wire.endTransmission();
|
||||
if (error == 0) {
|
||||
if (error == 0)
|
||||
{
|
||||
std::cout << "I2C device found at address 0x";
|
||||
if (address<16)
|
||||
if (address < checkForLength)
|
||||
{
|
||||
std::cout << "0";
|
||||
std::cout << std::hex << (int) address << std::dec << std::endl;
|
||||
}
|
||||
std::cout << std::hex << static_cast<int>(address) << std::dec << std::endl;
|
||||
// std::cout << (int) address << std::endl;
|
||||
nDevices++;
|
||||
}
|
||||
else if (error==4) {
|
||||
else if (error == 4)
|
||||
{
|
||||
std::cout << "Unknow error at address 0x";
|
||||
if (address<16)
|
||||
if (address < checkForLength)
|
||||
{
|
||||
std::cout << "0";
|
||||
std::cout << std::hex << (int) address << std::dec << std::endl;
|
||||
}
|
||||
}
|
||||
std::cout << std::hex << static_cast<int>(address) << std::dec << std::endl;
|
||||
}
|
||||
}
|
||||
if (nDevices == 0)
|
||||
std::cout << "No I2C devices found\n" << std::endl;
|
||||
{
|
||||
std::cout << "No I2C devices found\n"
|
||||
<< std::endl;
|
||||
}
|
||||
else
|
||||
std::cout << "done\n" << std::endl;
|
||||
{
|
||||
std::cout << "done\n"
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void makeMenu() {
|
||||
auto dummy = []() {
|
||||
std::cout << "Dummy in Action" <<std::endl;
|
||||
void makeMenu()
|
||||
{
|
||||
auto dummy = []()
|
||||
{
|
||||
std::cout << "Dummy in Action" << std::endl;
|
||||
};
|
||||
|
||||
// Create Menu
|
||||
main_m = new Menu();
|
||||
main_m->setLcd(lcdWrapper);
|
||||
auto mode_m = new Menu();
|
||||
auto set_m = new Menu();
|
||||
auto pid_m = new Menu();
|
||||
auto pidl_m = new MenuIntInput(3, new MenuPidSettings(moveController.getPID(0)));
|
||||
auto pidr_m = new MenuIntInput(3, new MenuPidSettings(moveController.getPID(1)));
|
||||
auto speed_m = new MenuIntInput(2, new MenuSpeed(driveManager->getDrivingSpeedsRef()));
|
||||
auto man_m = new MenuManualControl(driveManager);
|
||||
auto cap_m = new MenuCaptureRoute(driveManager);
|
||||
auto auto_m = new MenuAutopilot(driveManager);
|
||||
auto testM_m = new MenuTestMode(driveManager);
|
||||
auto comp_m = new MenuCalibrateCompass(driveManager);
|
||||
auto sys_m = new MenuSysteminformation(mainBattery);
|
||||
auto sen_m = new MenuSensorData(sensorData);
|
||||
//TODO: Wie bekommt jeder die dumme Route?
|
||||
auto rout_m = new MenuRoute(new Route());
|
||||
auto bat_m = new MenuCalibrateBattery(mainBattery);
|
||||
auto *mode_m = new Menu();
|
||||
auto *set_m = new Menu();
|
||||
auto *pid_m = new Menu();
|
||||
auto *pidl_m = new MenuIntInput(3, new MenuPidSettings(moveController.getPID(0)));
|
||||
auto *pidr_m = new MenuIntInput(3, new MenuPidSettings(moveController.getPID(1)));
|
||||
auto *speed_m = new MenuIntInput(2, new MenuSpeed(driveManager->getDrivingSpeedsRef()));
|
||||
auto *man_m = new MenuManualControl(driveManager);
|
||||
auto *cap_m = new MenuCaptureRoute(driveManager);
|
||||
auto *auto_m = new MenuAutopilot(driveManager);
|
||||
auto *testM_m = new MenuTestMode(driveManager);
|
||||
auto *comp_m = new MenuCalibrateCompass(driveManager);
|
||||
auto *sys_m = new MenuSysteminformation(mainBattery);
|
||||
auto *sen_m = new MenuSensorData(sensorData);
|
||||
// TODO: Wie bekommt jeder die dumme Route?
|
||||
auto *rout_m = new MenuRoute(new Route());
|
||||
auto *bat_m = new MenuCalibrateBattery(mainBattery);
|
||||
|
||||
auto_m->setUpdateDelay(1000);
|
||||
sys_m->setUpdateDelay(1500);
|
||||
sen_m->setUpdateDelay(500);
|
||||
auto_m->setUpdateDelay(displayUpdateDelay);
|
||||
sys_m->setUpdateDelay(displayUpdateDelay);
|
||||
sen_m->setUpdateDelay(displayUpdateDelay);
|
||||
|
||||
// Entry for the main menu
|
||||
main_m->addEntry(new MenuAction("Mode", mode_m));
|
||||
@@ -253,14 +297,14 @@ void makeMenu() {
|
||||
|
||||
// Other config
|
||||
pidl_m->setMinMax(0, UINT8_MAX);
|
||||
pidl_m->setEntry(0, "P-Part", (uint8_t) moveController.getPID(0)->GetKp());
|
||||
pidl_m->setEntry(1, "I-Part", (uint8_t) moveController.getPID(0)->GetKi());
|
||||
pidl_m->setEntry(2, "D-Part", (uint8_t) moveController.getPID(0)->GetKd());
|
||||
pidl_m->setEntry(0, "P-Part", static_cast<uint8_t>(moveController.getPID(0)->GetKp()));
|
||||
pidl_m->setEntry(1, "I-Part", static_cast<uint8_t>(moveController.getPID(0)->GetKi()));
|
||||
pidl_m->setEntry(2, "D-Part", static_cast<uint8_t>(moveController.getPID(0)->GetKd()));
|
||||
|
||||
pidr_m->setMinMax(0, UINT8_MAX);
|
||||
pidr_m->setEntry(0, "P-Part", (uint8_t) moveController.getPID(1)->GetKp());
|
||||
pidr_m->setEntry(1, "I-Part", (uint8_t) moveController.getPID(1)->GetKi());
|
||||
pidr_m->setEntry(2, "D-Part", (uint8_t) moveController.getPID(1)->GetKd());
|
||||
pidr_m->setEntry(0, "P-Part", static_cast<uint8_t>(moveController.getPID(1)->GetKp()));
|
||||
pidr_m->setEntry(1, "I-Part", static_cast<uint8_t>(moveController.getPID(1)->GetKi()));
|
||||
pidr_m->setEntry(2, "D-Part", static_cast<uint8_t>(moveController.getPID(1)->GetKd()));
|
||||
|
||||
speed_m->setMinMax(5, UINT8_MAX);
|
||||
speed_m->setEntry(0, "x m/s e-1", driveManager->getDrivingSpeedsRef().x * 10);
|
||||
@@ -271,42 +315,56 @@ void makeMenu() {
|
||||
controlPad->setMenuControl(main_m);
|
||||
}
|
||||
|
||||
void restart() {
|
||||
void restart()
|
||||
{
|
||||
lcdWrapper->clear();
|
||||
lcdWrapper->setCursor(0, 0);
|
||||
lcdWrapper->print("Rebooting ...");
|
||||
ESP.restart();
|
||||
}
|
||||
|
||||
void receiveCallback (const uint8_t * mac, const uint8_t *incomingData, int len) {
|
||||
void receiveCallback(const uint8_t *mac, const uint8_t *incomingData, int len)
|
||||
{
|
||||
if (len != sizeof(ControlPadInput))
|
||||
{
|
||||
return;
|
||||
}
|
||||
controlPad->insertData(incomingData);
|
||||
}
|
||||
|
||||
void sendCallback (const uint8_t *mac_addr, esp_now_send_status_t status) {
|
||||
void sendCallback(const uint8_t *mac_addr, esp_now_send_status_t status)
|
||||
{
|
||||
if (status != ESP_NOW_SEND_SUCCESS)
|
||||
{
|
||||
std::cout << "sendCallback - Delivery Fail" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void lcdWrapperCallback (const char data[][LcdWrapper::totalRows], uint8_t lines, uint8_t rows) {
|
||||
void lcdWrapperCallback(const char data[][LcdWrapper::totalRows], uint8_t lines, uint8_t rows)
|
||||
{
|
||||
if (!controlPad->isControlPadConnected())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const esp_err_t result = esp_now_send(network->getBroadcastAddress(), reinterpret_cast<const uint8_t *>(data), lines * rows);
|
||||
|
||||
esp_err_t result = esp_now_send(network->getBroadcastAddress(), (uint8_t *) data, lines * rows);
|
||||
|
||||
if (result != ESP_OK)
|
||||
{
|
||||
Serial.println("Error sending the data");
|
||||
}
|
||||
}
|
||||
|
||||
NetworkAdresses setIPs() {
|
||||
NetworkAdresses setIPs()
|
||||
{
|
||||
NetworkAdresses adresses;
|
||||
adresses.localIP.fromString(NetworkConfig::ip);
|
||||
adresses.subnet.fromString(NetworkConfig::subnet);
|
||||
adresses.gateway.fromString(NetworkConfig::gateway);
|
||||
adresses.dnsServer.fromString(NetworkConfig::dns);
|
||||
if (NetworkConfig::mqtt) {
|
||||
adresses.mqttServer.fromString(MqttConfig::server);
|
||||
adresses.localIP.fromString(static_cast<const char *>(NetworkConfig::ip));
|
||||
adresses.subnet.fromString(static_cast<const char *>(NetworkConfig::subnet));
|
||||
adresses.gateway.fromString(static_cast<const char *>(NetworkConfig::gateway));
|
||||
adresses.dnsServer.fromString(static_cast<const char *>(NetworkConfig::dns));
|
||||
if (NetworkConfig::mqtt)
|
||||
{
|
||||
adresses.mqttServer.fromString(static_cast<const char *>(MqttConfig::server));
|
||||
adresses.mqttPort = MqttConfig::port;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user