remove all PS3 things and begin with ControllPad
This commit is contained in:
@@ -0,0 +1,57 @@
|
|||||||
|
/**
|
||||||
|
* @file controllPad.cpp
|
||||||
|
* @author Alexander Klein (alex@kleiax.de)
|
||||||
|
* @brief
|
||||||
|
* @version 0.1
|
||||||
|
* @date 2023-03-30
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2023
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "controllPad.h"
|
||||||
|
|
||||||
|
ControllPad::ControllPad() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ControllPad::loop() {
|
||||||
|
if (millis() - this->lastLoopMillis < this->loopDelay)
|
||||||
|
return false;
|
||||||
|
this->lastLoopMillis = millis();
|
||||||
|
|
||||||
|
if(!this->connected)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (millis() - this->lastMessageRecive > this->disconnectTime) {
|
||||||
|
this->connected = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this->menuControl && this->controllInput.buttons > 0 && this->updated)
|
||||||
|
if (!this->firstButtonPress)
|
||||||
|
this->menuControl->printMenu();
|
||||||
|
|
||||||
|
if (ControllPadButton::isControllPadButtonPressed(&this->controllInput, ControllPadButton::PadButton::Left))
|
||||||
|
this->menuControl->left();
|
||||||
|
else if (ControllPadButton::isControllPadButtonPressed(&this->controllInput, ControllPadButton::PadButton::Right))
|
||||||
|
this->menuControl->right();
|
||||||
|
else if (ControllPadButton::isControllPadButtonPressed(&this->controllInput, ControllPadButton::PadButton::Up))
|
||||||
|
this->menuControl->up();
|
||||||
|
else if (ControllPadButton::isControllPadButtonPressed(&this->controllInput, ControllPadButton::PadButton::Down))
|
||||||
|
this->menuControl->down();
|
||||||
|
else if (ControllPadButton::isControllPadButtonPressed(&this->controllInput, ControllPadButton::PadButton::Yes))
|
||||||
|
this->menuControl->yes();
|
||||||
|
else if (ControllPadButton::isControllPadButtonPressed(&this->controllInput, ControllPadButton::PadButton::No))
|
||||||
|
this->menuControl->no();
|
||||||
|
|
||||||
|
this->menuControl->update();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ControllPadInput * ControllPad::getControllPadDataPtr(uint16_t maxElapsedTime) const {
|
||||||
|
if (maxElapsedTime && millis() - this->lastMessageRecive > maxElapsedTime)
|
||||||
|
return nullptr;
|
||||||
|
return &this->controllInput;
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
/**
|
||||||
|
* @file controllPad.h
|
||||||
|
* @author Alexander Klein (alex@kleiax.de)
|
||||||
|
* @brief
|
||||||
|
* @version 0.1
|
||||||
|
* @date 2023-03-30
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2023
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <menuControl.h>
|
||||||
|
|
||||||
|
#include "controllPadInput.h"
|
||||||
|
|
||||||
|
class ControllPad {
|
||||||
|
public:
|
||||||
|
ControllPad();
|
||||||
|
|
||||||
|
bool loop();
|
||||||
|
|
||||||
|
void setMenuControll(MenuControl* menuControll) { this->menuControl = menuControl; }
|
||||||
|
|
||||||
|
const ControllPadInput * getControllPadDataPtr(uint16_t maxElapsedTime = 0) const;
|
||||||
|
|
||||||
|
bool isControllPadConnected() const { return this->connected; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
MenuControl* menuControl = nullptr;
|
||||||
|
ControllPadInput controllInput;
|
||||||
|
|
||||||
|
bool connected = false;
|
||||||
|
bool updated = false;
|
||||||
|
bool firstButtonPress = false;
|
||||||
|
|
||||||
|
uint16_t disconnectTime = 50;
|
||||||
|
uint16_t loopDelay = 5;
|
||||||
|
|
||||||
|
uint32_t lastMessageRecive = 0;
|
||||||
|
uint32_t lastLoopMillis = 0;
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
/**
|
||||||
|
* @file controllPadInput.h
|
||||||
|
* @author Alexander Klein (alex@kleiax.de)
|
||||||
|
* @brief
|
||||||
|
* @version 0.1
|
||||||
|
* @date 2023-03-30
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2023
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef CONTROLL_PAD_INPUT_H
|
||||||
|
#define CONTROLL_PAD_INPUT_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
struct ControllPadInput {
|
||||||
|
uint8_t buttons;
|
||||||
|
uint8_t x;
|
||||||
|
uint8_t y;
|
||||||
|
uint8_t counter;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class ControllPadButton {
|
||||||
|
public:
|
||||||
|
enum PadButton {
|
||||||
|
Left,
|
||||||
|
Right,
|
||||||
|
Up,
|
||||||
|
Down,
|
||||||
|
Yes,
|
||||||
|
No,
|
||||||
|
Action
|
||||||
|
};
|
||||||
|
|
||||||
|
static bool isControllPadButtonPressed(const ControllPadInput *input, PadButton button) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // CONTROLL_PAD_INPUT_H
|
||||||
@@ -17,12 +17,10 @@ monitor_speed = 115200
|
|||||||
upload_speed = 921600
|
upload_speed = 921600
|
||||||
monitor_port = COM3
|
monitor_port = COM3
|
||||||
lib_deps =
|
lib_deps =
|
||||||
jvpernis/PS3 Controller Host@^1.1.0
|
|
||||||
sparkfun/SparkFun u-blox GNSS Arduino Library@^2.2.7
|
sparkfun/SparkFun u-blox GNSS Arduino Library@^2.2.7
|
||||||
knolleary/PubSubClient@^2.8
|
knolleary/PubSubClient@^2.8
|
||||||
br3ttb/PID@^1.2.1
|
br3ttb/PID@^1.2.1
|
||||||
marcoschwartz/LiquidCrystal_I2C@^1.1.4
|
marcoschwartz/LiquidCrystal_I2C@^1.1.4
|
||||||
marian-craciunescu/ESP32Ping@^1.7
|
|
||||||
bblanchon/ArduinoJson@^6.20.0
|
bblanchon/ArduinoJson@^6.20.0
|
||||||
mprograms/QMC5883LCompass@^1.1.1
|
mprograms/QMC5883LCompass@^1.1.1
|
||||||
https://git.kleiax.de/PlatformIO-Libs/Menu.git#v1.0
|
https://git.kleiax.de/PlatformIO-Libs/Menu.git#v1.0
|
||||||
|
|||||||
@@ -11,10 +11,9 @@
|
|||||||
|
|
||||||
#include "menuSysteminformation.h"
|
#include "menuSysteminformation.h"
|
||||||
|
|
||||||
MenuSysteminformation::MenuSysteminformation(Battery* mainBattery, Ps3Controller* gamepad)
|
MenuSysteminformation::MenuSysteminformation(Battery* mainBattery)
|
||||||
: MenuInformationSites(5) {
|
: MenuInformationSites(5) {
|
||||||
this->mainBattery = mainBattery;
|
this->mainBattery = mainBattery;
|
||||||
this->gamepad = gamepad;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuSysteminformation::printPage() const {
|
void MenuSysteminformation::printPage() const {
|
||||||
@@ -44,11 +43,11 @@ void MenuSysteminformation::printPage() const {
|
|||||||
lineTwo.concat(this->mainBattery->getBatteryVoltage());
|
lineTwo.concat(this->mainBattery->getBatteryVoltage());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 4:
|
// case 4:
|
||||||
lineOne = "PS3 battery";
|
// lineOne = "PS3 battery";
|
||||||
lineTwo = "is ";
|
// lineTwo = "is ";
|
||||||
lineTwo.concat(MenuSysteminformation::ps3ToString(this->gamepad->data.status.battery));
|
// lineTwo.concat(MenuSysteminformation::ps3ToString(this->gamepad->data.status.battery));
|
||||||
break;
|
// break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
this->printDefault();
|
this->printDefault();
|
||||||
@@ -58,12 +57,3 @@ void MenuSysteminformation::printPage() const {
|
|||||||
this->print(lineOne, lineTwo);
|
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,8 +13,8 @@
|
|||||||
#define MENU_SYSTEMINFORMATION_H
|
#define MENU_SYSTEMINFORMATION_H
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <Ps3Controller.h>
|
|
||||||
|
|
||||||
|
#include "controllPadInput.h"
|
||||||
#include "menuInformationSites.h"
|
#include "menuInformationSites.h"
|
||||||
#include "battery.h"
|
#include "battery.h"
|
||||||
|
|
||||||
@@ -31,14 +31,12 @@ class MenuSysteminformation : public MenuInformationSites {
|
|||||||
* @param mainBattery
|
* @param mainBattery
|
||||||
* @param gamepad
|
* @param gamepad
|
||||||
*/
|
*/
|
||||||
MenuSysteminformation(Battery* mainBattery, Ps3Controller* gamepad);
|
MenuSysteminformation(Battery* mainBattery);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void printPage() const override;
|
void printPage() const override;
|
||||||
static String ps3ToString(uint8_t battery);
|
|
||||||
|
|
||||||
Battery* mainBattery;
|
Battery* mainBattery;
|
||||||
Ps3Controller* gamepad;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MENU_SYSTEMINFORMATION_H
|
#endif // MENU_SYSTEMINFORMATION_H
|
||||||
|
|||||||
@@ -11,8 +11,8 @@
|
|||||||
|
|
||||||
#include "driveModi/Modi/Autopilot/autopilot.h"
|
#include "driveModi/Modi/Autopilot/autopilot.h"
|
||||||
|
|
||||||
Autopilot::Autopilot(MoveControl* moveControl, Ps3Controller *gamepad, Navigation* navigation)
|
Autopilot::Autopilot(MoveControl* moveControl, const ControllPadInput *input, Navigation* navigation)
|
||||||
: ManualControl(moveControl, gamepad) {
|
: ManualControl(moveControl, input) {
|
||||||
this->navigation = navigation;
|
this->navigation = navigation;
|
||||||
this->navigationStarted = this->navigation->startNavigation();
|
this->navigationStarted = this->navigation->startNavigation();
|
||||||
this->routeInfo = this->navigation->getRouteInfo();
|
this->routeInfo = this->navigation->getRouteInfo();
|
||||||
@@ -45,7 +45,7 @@ void Autopilot::runAutopilot() {
|
|||||||
this->selfDrivingAvailable = true;
|
this->selfDrivingAvailable = true;
|
||||||
|
|
||||||
if (!this->selfDriving && this->selfDrivingAvailable)
|
if (!this->selfDriving && this->selfDrivingAvailable)
|
||||||
this->setSelfDriving(this->gamepad->data.button.triangle);
|
this->setSelfDriving(ControllPadButton::isControllPadButtonPressed(this->input, ControllPadButton::PadButton::Action));
|
||||||
|
|
||||||
if (this->routeInfo.currentPoint == this->routeInfo.totalPoints) {
|
if (this->routeInfo.currentPoint == this->routeInfo.totalPoints) {
|
||||||
this->navigationEnded = true;
|
this->navigationEnded = true;
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ class Autopilot : public ManualControl {
|
|||||||
* @param moveControl for ManualControl
|
* @param moveControl for ManualControl
|
||||||
* @param navigation for route instructions
|
* @param navigation for route instructions
|
||||||
*/
|
*/
|
||||||
Autopilot(MoveControl* moveControl, Ps3Controller *gamepad, Navigation* navigation);
|
Autopilot(MoveControl* moveControl, const ControllPadInput *input, Navigation* navigation);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Calls runAutopilot or ManualControl loop
|
* @brief Calls runAutopilot or ManualControl loop
|
||||||
|
|||||||
@@ -11,8 +11,8 @@
|
|||||||
|
|
||||||
#include "driveModi/Modi/CaptureRoute/captureRoute.h"
|
#include "driveModi/Modi/CaptureRoute/captureRoute.h"
|
||||||
|
|
||||||
CaptureRoute::CaptureRoute(MoveControl* moveControl, Ps3Controller *gamepad, Navigation* navigation)
|
CaptureRoute::CaptureRoute(MoveControl* moveControl, const ControllPadInput *input, Navigation* navigation)
|
||||||
: ManualControl(moveControl, gamepad) {
|
: ManualControl(moveControl, input) {
|
||||||
this->navigation = navigation;
|
this->navigation = navigation;
|
||||||
this->routeInfo = navigation->getRouteInfo();
|
this->routeInfo = navigation->getRouteInfo();
|
||||||
}
|
}
|
||||||
@@ -28,7 +28,7 @@ void CaptureRoute::loop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CaptureRoute::runCaptureRoute() {
|
void CaptureRoute::runCaptureRoute() {
|
||||||
if (this->gamepad->data.button.triangle) {
|
if (ControllPadButton::isControllPadButtonPressed(this->input, ControllPadButton::PadButton::Action)) {
|
||||||
if (this->navigation->addCurrentPosToRoute()) {
|
if (this->navigation->addCurrentPosToRoute()) {
|
||||||
this->routeInfo = navigation->getRouteInfo();
|
this->routeInfo = navigation->getRouteInfo();
|
||||||
this->updateDisplay = true;
|
this->updateDisplay = true;
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ class CaptureRoute : public ManualControl {
|
|||||||
* @param moveControl for ManualControl
|
* @param moveControl for ManualControl
|
||||||
* @param navigation to add Points
|
* @param navigation to add Points
|
||||||
*/
|
*/
|
||||||
CaptureRoute(MoveControl* moveControl, Ps3Controller *gamepad, Navigation* navigation);
|
CaptureRoute(MoveControl* moveControl, const ControllPadInput *input, Navigation* navigation);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Calls runCaptureRoute and ManualControl::loop
|
* @brief Calls runCaptureRoute and ManualControl::loop
|
||||||
|
|||||||
@@ -10,9 +10,9 @@
|
|||||||
*/
|
*/
|
||||||
#include "manualControl.h"
|
#include "manualControl.h"
|
||||||
|
|
||||||
ManualControl::ManualControl(MoveControl *moveControl, Ps3Controller *gamepad) {
|
ManualControl::ManualControl(MoveControl *moveControl, const ControllPadInput *input) {
|
||||||
this->moveControl = moveControl;
|
this->moveControl = moveControl;
|
||||||
this->gamepad = gamepad;
|
this->input = input;
|
||||||
this->moveControl->setDrivingStatus(DrivingStatus::drive);
|
this->moveControl->setDrivingStatus(DrivingStatus::drive);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,8 +31,8 @@ void ManualControl::loop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ManualControl::runManualControl() {
|
void ManualControl::runManualControl() {
|
||||||
int8_t x = this->gamepad->data.analog.stick.lx;
|
int8_t x = this->input->x;
|
||||||
int8_t y = this->gamepad->data.analog.stick.ly;
|
int8_t y = this->input->y;
|
||||||
|
|
||||||
double value_per_step = this->max_speed * 2 / 256;
|
double value_per_step = this->max_speed * 2 / 256;
|
||||||
this->moveControl->setSpeed((y * -1) * value_per_step);
|
this->moveControl->setSpeed((y * -1) * value_per_step);
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
#include "moveControl.h"
|
#include "moveControl.h"
|
||||||
#include "driveModi/driveModi.h"
|
#include "driveModi/driveModi.h"
|
||||||
|
#include "controllPadInput.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Drive the Rover with a Joystick
|
* @brief Drive the Rover with a Joystick
|
||||||
@@ -24,7 +25,7 @@
|
|||||||
*/
|
*/
|
||||||
class ManualControl : public DriveModi {
|
class ManualControl : public DriveModi {
|
||||||
public:
|
public:
|
||||||
ManualControl(MoveControl *moveControl, Ps3Controller *gamepad);
|
ManualControl(MoveControl *moveControl, const ControllPadInput *input);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Destroy the Manual Control object
|
* @brief Destroy the Manual Control object
|
||||||
@@ -71,7 +72,7 @@ class ManualControl : public DriveModi {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
MoveControl *moveControl;
|
MoveControl *moveControl;
|
||||||
Ps3Controller *gamepad;
|
const ControllPadInput* input;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint32_t lastMillis = 0;
|
uint32_t lastMillis = 0;
|
||||||
|
|||||||
@@ -15,9 +15,9 @@ Modi& operator++(Modi& m, int) {
|
|||||||
return m = (m == Modi::TestMode) ? Modi::Off : static_cast<Modi>(static_cast<int>(m)+1);
|
return m = (m == Modi::TestMode) ? Modi::Off : static_cast<Modi>(static_cast<int>(m)+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
DriveManager::DriveManager(MoveControl *moveControl, Ps3Controller *gamepad, bool wifi) {
|
DriveManager::DriveManager(MoveControl *moveControl, const ControllPadInput *input, bool wifi) {
|
||||||
this->moveControl = moveControl;
|
this->moveControl = moveControl;
|
||||||
this->gamepad = gamepad;
|
this->input = input;
|
||||||
|
|
||||||
this->spiPort = new SPIClass(HSPI);
|
this->spiPort = new SPIClass(HSPI);
|
||||||
spiPort->begin(UBLOX_GNSS_SPI_SCK, UBLOX_GNSS_SPI_CIPO, UBLOX_GNSS_SPI_COPI, UBLOX_GNSS_SPI_CS);
|
spiPort->begin(UBLOX_GNSS_SPI_SCK, UBLOX_GNSS_SPI_CIPO, UBLOX_GNSS_SPI_COPI, UBLOX_GNSS_SPI_CS);
|
||||||
@@ -66,17 +66,17 @@ void DriveManager::changeModus(Modi modus) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case Modi::ManualControl: {
|
case Modi::ManualControl: {
|
||||||
this->currentModusPtr = new ManualControl(this->moveControl, this->gamepad);
|
this->currentModusPtr = new ManualControl(this->moveControl, this->input);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Modi::CaptureRoute: {
|
case Modi::CaptureRoute: {
|
||||||
this->currentModusPtr = new CaptureRoute(this->moveControl, this->gamepad, this->navigation);
|
this->currentModusPtr = new CaptureRoute(this->moveControl, this->input, this->navigation);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Modi::Autopilot: {
|
case Modi::Autopilot: {
|
||||||
this->currentModusPtr = new Autopilot(this->moveControl, this->gamepad, this->navigation);
|
this->currentModusPtr = new Autopilot(this->moveControl, this->input, this->navigation);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "networkConfig.h"
|
#include "networkConfig.h"
|
||||||
#include "debugTimes.h"
|
#include "debugTimes.h"
|
||||||
|
#include "controllPadInput.h"
|
||||||
|
|
||||||
// All Drive Modi
|
// All Drive Modi
|
||||||
#include "driveModi/Modi/ManualControl/manualControl.h"
|
#include "driveModi/Modi/ManualControl/manualControl.h"
|
||||||
@@ -51,7 +52,7 @@ class DriveManager {
|
|||||||
*
|
*
|
||||||
* @param moveControl
|
* @param moveControl
|
||||||
*/
|
*/
|
||||||
DriveManager(MoveControl *moveControl, Ps3Controller *gamepad, bool wifi = false);
|
DriveManager(MoveControl *moveControl, const ControllPadInput *input, bool wifi = false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Destroy the Drive Manager object
|
* @brief Destroy the Drive Manager object
|
||||||
@@ -117,7 +118,7 @@ class DriveManager {
|
|||||||
private:
|
private:
|
||||||
Modi currentModus = Modi::Off;
|
Modi currentModus = Modi::Off;
|
||||||
MoveControl *moveControl;
|
MoveControl *moveControl;
|
||||||
Ps3Controller *gamepad;
|
const ControllPadInput* input;
|
||||||
DriveModi *currentModusPtr = nullptr;
|
DriveModi *currentModusPtr = nullptr;
|
||||||
Navigation* navigation;
|
Navigation* navigation;
|
||||||
SPIClass* spiPort;
|
SPIClass* spiPort;
|
||||||
|
|||||||
@@ -12,8 +12,6 @@
|
|||||||
#ifndef DRIVEMODI_H
|
#ifndef DRIVEMODI_H
|
||||||
#define DRIVEMODI_H
|
#define DRIVEMODI_H
|
||||||
|
|
||||||
#include <Ps3Controller.h>
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Baseclass to build DriveModi
|
* @brief Baseclass to build DriveModi
|
||||||
*
|
*
|
||||||
|
|||||||
+7
-105
@@ -17,13 +17,9 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include <Ps3Controller.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
#include <LiquidCrystal_I2C.h>
|
#include <LiquidCrystal_I2C.h>
|
||||||
#include <ESP32Ping.h>
|
|
||||||
#include <BluetoothSerial.h>
|
|
||||||
#include <esp_bt_main.h>
|
|
||||||
|
|
||||||
#include "driveModi/driveManager.h"
|
#include "driveModi/driveManager.h"
|
||||||
#include "OutputBuf/outputBuf.h"
|
#include "OutputBuf/outputBuf.h"
|
||||||
@@ -33,6 +29,7 @@
|
|||||||
#include "debugMqtt.h"
|
#include "debugMqtt.h"
|
||||||
#include "battery.h"
|
#include "battery.h"
|
||||||
#include "debugTimes.h"
|
#include "debugTimes.h"
|
||||||
|
#include "controllPad.h"
|
||||||
|
|
||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
#include "menuAction.h"
|
#include "menuAction.h"
|
||||||
@@ -53,21 +50,13 @@ LcdWrapper* lcdWrapper;
|
|||||||
OutputBuf* outputBuf;
|
OutputBuf* outputBuf;
|
||||||
DebugMqtt* debugMqtt = nullptr;
|
DebugMqtt* debugMqtt = nullptr;
|
||||||
Battery* mainBattery;
|
Battery* mainBattery;
|
||||||
Ps3Controller* gamepad;
|
ControllPad* controllPad;
|
||||||
BluetoothSerial SerialBT;
|
|
||||||
|
|
||||||
bool wifiIsActive;
|
bool wifiIsActive;
|
||||||
bool disconnectPs3 = false;
|
|
||||||
|
|
||||||
|
|
||||||
void configureController(void);
|
|
||||||
void callbackControllerAction(void);
|
|
||||||
void callbackControllerConnect(void);
|
|
||||||
void callbackControllerDisconnect(void);
|
|
||||||
void i2cScanner(void);
|
void i2cScanner(void);
|
||||||
void makeMenu(void);
|
void makeMenu(void);
|
||||||
void restart(void);
|
void restart(void);
|
||||||
void disconnectController(void);
|
|
||||||
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
@@ -77,6 +66,8 @@ void setup() {
|
|||||||
char wifiIndicator = 'X';
|
char wifiIndicator = 'X';
|
||||||
|
|
||||||
mainBattery = new Battery(35, 692000, 218500);
|
mainBattery = new Battery(35, 692000, 218500);
|
||||||
|
controllPad = new ControllPad();
|
||||||
|
controllPad->setMenuControll(main_m);
|
||||||
|
|
||||||
Wire.begin(21, 19);
|
Wire.begin(21, 19);
|
||||||
Wire.setClock(400000);
|
Wire.setClock(400000);
|
||||||
@@ -90,14 +81,6 @@ void setup() {
|
|||||||
Network::setupMQTT();
|
Network::setupMQTT();
|
||||||
wifiIsActive = Network::connectWifi();
|
wifiIsActive = Network::connectWifi();
|
||||||
if (wifiIsActive) {
|
if (wifiIsActive) {
|
||||||
|
|
||||||
// const char* remoteHost = "www.google.com";
|
|
||||||
// std::cout << "Pinging host: " << remoteHost << std::endl;
|
|
||||||
// if (Ping.ping(remoteHost))
|
|
||||||
// std::cout << "Ping successful..." << std::endl;
|
|
||||||
// else
|
|
||||||
// std::cout << "Ping failed. :/" << std::endl;
|
|
||||||
|
|
||||||
if (Network::checkMQTT()) {
|
if (Network::checkMQTT()) {
|
||||||
DebugMqtt::init(Network::getMqttClient(), Loglevel::debug);
|
DebugMqtt::init(Network::getMqttClient(), Loglevel::debug);
|
||||||
std::cout << "Activate additional output via MQTT..." << std::endl;
|
std::cout << "Activate additional output via MQTT..." << std::endl;
|
||||||
@@ -114,9 +97,7 @@ void setup() {
|
|||||||
std::cout << "Welcome to Kleiax-Rover" << std::endl;
|
std::cout << "Welcome to Kleiax-Rover" << std::endl;
|
||||||
std::cout << "All actions from the main program run on Core -> " << xPortGetCoreID() << std::endl;
|
std::cout << "All actions from the main program run on Core -> " << xPortGetCoreID() << std::endl;
|
||||||
|
|
||||||
gamepad = new Ps3Controller;
|
driveManager = new DriveManager(&moveController, controllPad->getControllPadDataPtr(), wifiIsActive);
|
||||||
driveManager = new DriveManager(&moveController, gamepad, wifiIsActive);
|
|
||||||
configureController();
|
|
||||||
|
|
||||||
outputBuf->activateMqtt(false);
|
outputBuf->activateMqtt(false);
|
||||||
|
|
||||||
@@ -139,6 +120,7 @@ void loop() {
|
|||||||
wifiTime.stopConsol("WiFi-Time", 10);
|
wifiTime.stopConsol("WiFi-Time", 10);
|
||||||
}
|
}
|
||||||
driveManager->loop();
|
driveManager->loop();
|
||||||
|
controllPad->loop();
|
||||||
lcdWrapper->loop();
|
lcdWrapper->loop();
|
||||||
|
|
||||||
mainBattery->loop();
|
mainBattery->loop();
|
||||||
@@ -156,75 +138,6 @@ void loop() {
|
|||||||
|
|
||||||
while (true);
|
while (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (disconnectPs3) {
|
|
||||||
DebugTimes disconnectPS3Time;
|
|
||||||
std::cout << "Disconnect PS3 Controller." << std::endl;
|
|
||||||
gamepad->end();
|
|
||||||
esp_bluedroid_disable();
|
|
||||||
esp_bluedroid_deinit();
|
|
||||||
configureController();
|
|
||||||
disconnectPs3 = false;
|
|
||||||
disconnectPS3Time.stopConsol("Ps3 Disconnect");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void configureController() {
|
|
||||||
|
|
||||||
gamepad->attach(callbackControllerAction);
|
|
||||||
gamepad->attachOnConnect(callbackControllerConnect);
|
|
||||||
gamepad->attachOnDisconnect(callbackControllerDisconnect);
|
|
||||||
std::cout << "\nReady to connect a PS3 Controller... \n";
|
|
||||||
|
|
||||||
gamepad->begin(CONTROLLER_MAC);
|
|
||||||
}
|
|
||||||
|
|
||||||
void callbackControllerAction() {
|
|
||||||
auto isDelayReached = [](bool reset = false) -> bool {
|
|
||||||
static uint32_t lastMillis = 0;
|
|
||||||
if (reset)
|
|
||||||
lastMillis = millis();
|
|
||||||
static const uint16_t delay = 100;
|
|
||||||
bool res = false;
|
|
||||||
|
|
||||||
if (millis() - lastMillis > delay)
|
|
||||||
res = true;
|
|
||||||
return res;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Menu controlling
|
|
||||||
if (isDelayReached()) {
|
|
||||||
if (gamepad->data.button.up)
|
|
||||||
main_m->up();
|
|
||||||
else if (gamepad->data.button.down)
|
|
||||||
main_m->down();
|
|
||||||
else if (gamepad->data.button.left)
|
|
||||||
main_m->left();
|
|
||||||
else if (gamepad->data.button.right)
|
|
||||||
main_m->right();
|
|
||||||
else if (gamepad->data.button.circle)
|
|
||||||
main_m->yes();
|
|
||||||
else if (gamepad->data.button.cross)
|
|
||||||
main_m->no();
|
|
||||||
else if (gamepad->data.button.select)
|
|
||||||
std::cout << "main.cpp callbackControllerAction - Here we are!" << std::endl;
|
|
||||||
|
|
||||||
isDelayReached(true);
|
|
||||||
}
|
|
||||||
// This have to be stand here because it have to be run on the other Core
|
|
||||||
main_m->update();
|
|
||||||
}
|
|
||||||
|
|
||||||
void callbackControllerConnect() {
|
|
||||||
std::cout << "Controller connected to ESP32" << std::endl;
|
|
||||||
std::cout << "All actions from the Controller run on Core -> " << xPortGetCoreID() << std::endl;
|
|
||||||
|
|
||||||
main_m->printMenu();
|
|
||||||
}
|
|
||||||
|
|
||||||
void callbackControllerDisconnect() {
|
|
||||||
std::cout << "Controller disconnected..." << std::endl;
|
|
||||||
// gamepad->end();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void i2cScanner() {
|
void i2cScanner() {
|
||||||
@@ -274,7 +187,7 @@ void makeMenu() {
|
|||||||
MenuAutopilot* auto_m = new MenuAutopilot(driveManager);
|
MenuAutopilot* auto_m = new MenuAutopilot(driveManager);
|
||||||
MenuTestMode* testM_m = new MenuTestMode(driveManager);
|
MenuTestMode* testM_m = new MenuTestMode(driveManager);
|
||||||
MenuGPS* gps_m = new MenuGPS(driveManager);
|
MenuGPS* gps_m = new MenuGPS(driveManager);
|
||||||
MenuSysteminformation* sys_m = new MenuSysteminformation(mainBattery, gamepad);
|
MenuSysteminformation* sys_m = new MenuSysteminformation(mainBattery);
|
||||||
MenuRoute* rout_m = new MenuRoute(driveManager->getNavigation()->getRoute());
|
MenuRoute* rout_m = new MenuRoute(driveManager->getNavigation()->getRoute());
|
||||||
|
|
||||||
// Set Menus on LCD
|
// Set Menus on LCD
|
||||||
@@ -297,7 +210,6 @@ void makeMenu() {
|
|||||||
MenuAction* gps_e = new MenuAction("GPS", gps_m);
|
MenuAction* gps_e = new MenuAction("GPS", gps_m);
|
||||||
MenuAction* pid_e = new MenuAction("PID", pid_m);
|
MenuAction* pid_e = new MenuAction("PID", pid_m);
|
||||||
MenuAction* restart_e = new MenuAction("Restart", restart);
|
MenuAction* restart_e = new MenuAction("Restart", restart);
|
||||||
MenuAction* contr_e = new MenuAction("Remove PS3", disconnectController);
|
|
||||||
MenuAction* sys_e = new MenuAction("Systeminfo", sys_m);
|
MenuAction* sys_e = new MenuAction("Systeminfo", sys_m);
|
||||||
MenuAction* rout_e = new MenuAction("Route", rout_m);
|
MenuAction* rout_e = new MenuAction("Route", rout_m);
|
||||||
main_m->addEntry(mode_e);
|
main_m->addEntry(mode_e);
|
||||||
@@ -305,7 +217,6 @@ void makeMenu() {
|
|||||||
main_m->addEntry(rout_e);
|
main_m->addEntry(rout_e);
|
||||||
main_m->addEntry(pid_e);
|
main_m->addEntry(pid_e);
|
||||||
main_m->addEntry(sys_e);
|
main_m->addEntry(sys_e);
|
||||||
main_m->addEntry(contr_e);
|
|
||||||
main_m->addEntry(restart_e);
|
main_m->addEntry(restart_e);
|
||||||
|
|
||||||
// Entry for the mode Menu
|
// Entry for the mode Menu
|
||||||
@@ -344,12 +255,3 @@ void restart(void) {
|
|||||||
lcdWrapper->print("Rebooting ...");
|
lcdWrapper->print("Rebooting ...");
|
||||||
ESP.restart();
|
ESP.restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
void disconnectController(void) {
|
|
||||||
disconnectPs3 = true;
|
|
||||||
lcdWrapper->clear();
|
|
||||||
lcdWrapper->setCursor(0, 0);
|
|
||||||
lcdWrapper->print("Controller is");
|
|
||||||
lcdWrapper->setCursor(0, 1);
|
|
||||||
lcdWrapper->print("disconnected.");
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user