fix reconnect gamepad
This commit is contained in:
Vendored
+1
@@ -83,6 +83,7 @@
|
|||||||
"Ahnung",
|
"Ahnung",
|
||||||
"akku",
|
"akku",
|
||||||
"blox",
|
"blox",
|
||||||
|
"bluedroid",
|
||||||
"gast",
|
"gast",
|
||||||
"GNSS",
|
"GNSS",
|
||||||
"GPGGA",
|
"GPGGA",
|
||||||
|
|||||||
@@ -3,4 +3,6 @@
|
|||||||
-> Program battery pack tracking
|
-> Program battery pack tracking
|
||||||
-> Add an beeper
|
-> Add an beeper
|
||||||
-> Program the beeper
|
-> Program the beeper
|
||||||
|
-> GPS-Menu without Wlan NtripClient
|
||||||
|
-> CaptureRoute Modus crash when someone try's to save a point
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
ps3.h
|
||||||
|
void ps3ResetGlobals();
|
||||||
|
|
||||||
|
ps3.c
|
||||||
|
void ps3ResetGlobals() {
|
||||||
|
// Own Code
|
||||||
|
is_active = false;
|
||||||
|
ps3_connection_cb = NULL;
|
||||||
|
ps3_connection_object_cb = NULL;
|
||||||
|
ps3_connection_object = NULL;
|
||||||
|
ps3_event_cb = NULL;
|
||||||
|
ps3_event_object_cb = NULL;
|
||||||
|
ps3_event_object = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ps3Controller.h
|
||||||
|
private
|
||||||
|
void resetGlobals();
|
||||||
|
|
||||||
|
Ps3Controller.cpp
|
||||||
|
void Ps3Controller::resetGlobals() {
|
||||||
|
ps3ResetGlobals();
|
||||||
|
}
|
||||||
|
|
||||||
|
in -> Ps3Controller::begin
|
||||||
|
this->resetGlobals();
|
||||||
@@ -15,6 +15,14 @@
|
|||||||
* The PS3-Controller only connects to the address which is saved in it.
|
* The PS3-Controller only connects to the address which is saved in it.
|
||||||
*/
|
*/
|
||||||
#define CONTROLLER_MAC "24:62:AB:F2:4B:3A"
|
#define CONTROLLER_MAC "24:62:AB:F2:4B:3A"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Prevents creation of the global object
|
||||||
|
*
|
||||||
|
* The PS3-Controller class creates a global object to use.
|
||||||
|
*/
|
||||||
|
#define NO_GLOBAL_INSTANCES
|
||||||
|
|
||||||
#define UBLOX_GNSS_SPI_CS 17
|
#define UBLOX_GNSS_SPI_CS 17
|
||||||
#define UBLOX_GNSS_SPI_COPI 16
|
#define UBLOX_GNSS_SPI_COPI 16
|
||||||
#define UBLOX_GNSS_SPI_CIPO 4
|
#define UBLOX_GNSS_SPI_CIPO 4
|
||||||
|
|||||||
@@ -80,13 +80,13 @@ void Navigation::loop() {
|
|||||||
this->updateCurrentLocation();
|
this->updateCurrentLocation();
|
||||||
std::cout << "duration between: " << millis() - lastTime << std::endl;
|
std::cout << "duration between: " << millis() - lastTime << std::endl;
|
||||||
lastTime = millis();
|
lastTime = millis();
|
||||||
} else if (millis() - lastTime > 20000) {
|
} else if (millis() - lastTime > 20000 && !this->gps->getGnssFixOk()) {
|
||||||
std::cout << "Keine Daten mehr!" << std::endl;
|
std::cout << "No Data from ZED arrived since a long time. Navigation::loop" << std::endl;
|
||||||
this->gps->flushPVT();
|
this->gps->flushPVT();
|
||||||
this->gps->softwareResetGNSSOnly();
|
this->gps->softwareResetGNSSOnly();
|
||||||
lastTime = millis();
|
lastTime = millis();
|
||||||
|
|
||||||
// std::cout
|
//std::cout
|
||||||
// << "checkUblox: " << this->gps->checkUblox() << " -|- "
|
// << "checkUblox: " << this->gps->checkUblox() << " -|- "
|
||||||
// << "getGnssFixOk: " << this->gps->getGnssFixOk() << " -|- "
|
// << "getGnssFixOk: " << this->gps->getGnssFixOk() << " -|- "
|
||||||
// << "getHWstatus: " << this->gps->getHWstatus() << " -|- "
|
// << "getHWstatus: " << this->gps->getHWstatus() << " -|- "
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ bool DebugTimes::printWarning = true;
|
|||||||
DebugTimes::DebugTimes() {
|
DebugTimes::DebugTimes() {
|
||||||
this->startTime = millis();
|
this->startTime = millis();
|
||||||
|
|
||||||
if (!DebugTimes::printWarning) {
|
if (DebugTimes::printWarning) {
|
||||||
std::cout << std::endl << "Warning: DebugTimes is muuted, no times are be shown." << std::endl << std::endl;
|
std::cout << std::endl << "Warning: DebugTimes is muuted, no times are be shown." << std::endl << std::endl;
|
||||||
DebugTimes::printWarning = false;
|
DebugTimes::printWarning = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,8 +11,9 @@
|
|||||||
|
|
||||||
#include "menuAkku.h"
|
#include "menuAkku.h"
|
||||||
|
|
||||||
MenuAkku::MenuAkku(Battery* mainBattery) {
|
MenuAkku::MenuAkku(Battery* mainBattery, Ps3Controller* gamepad) {
|
||||||
this->mainBattery = mainBattery;
|
this->mainBattery = mainBattery;
|
||||||
|
this->gamepad = gamepad;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuAkku::right() {
|
void MenuAkku::right() {
|
||||||
@@ -38,8 +39,8 @@ void MenuAkku::printMenu() {
|
|||||||
uint8_t mainBattery = this->mainBattery->getBatteryPercent();
|
uint8_t mainBattery = this->mainBattery->getBatteryPercent();
|
||||||
double mainBatteryVolt = this->mainBattery->getBatteryVoltage();
|
double mainBatteryVolt = this->mainBattery->getBatteryVoltage();
|
||||||
|
|
||||||
if( controllerBattery != Ps3.data.status.battery ){
|
if( controllerBattery != this->gamepad->data.status.battery ){
|
||||||
controllerBattery = Ps3.data.status.battery;
|
controllerBattery = this->gamepad->data.status.battery;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( controllerBattery == ps3_status_battery_charging ) sprintf(buf, "LOAD");
|
if( controllerBattery == ps3_status_battery_charging ) sprintf(buf, "LOAD");
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ class MenuAkku : public MenuControl {
|
|||||||
* @brief Construct a new Menu Akku object
|
* @brief Construct a new Menu Akku object
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
MenuAkku(Battery* mainBattery);
|
MenuAkku(Battery* mainBattery, Ps3Controller* gamepad);
|
||||||
|
|
||||||
void down() override {}
|
void down() override {}
|
||||||
void up() override {}
|
void up() override {}
|
||||||
@@ -58,6 +58,7 @@ class MenuAkku : public MenuControl {
|
|||||||
uint32_t lastMillis = 0;
|
uint32_t lastMillis = 0;
|
||||||
|
|
||||||
Battery* mainBattery;
|
Battery* mainBattery;
|
||||||
|
Ps3Controller* gamepad;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ void DriveManager::loop() {
|
|||||||
|
|
||||||
DebugTimes navigationTime;
|
DebugTimes navigationTime;
|
||||||
this->navigation->loop();
|
this->navigation->loop();
|
||||||
navigationTime.stopConsol("NavigationTime", 5);
|
navigationTime.stopConsol("NavigationTime", 20);
|
||||||
|
|
||||||
if (currentModusPtr)
|
if (currentModusPtr)
|
||||||
this->currentModusPtr->loop();
|
this->currentModusPtr->loop();
|
||||||
|
|||||||
+49
-32
@@ -14,14 +14,16 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
#include <Ps3Controller.h>
|
#include <Ps3Controller.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
#include <LiquidCrystal_I2C.h>
|
#include <LiquidCrystal_I2C.h>
|
||||||
#include <BluetoothSerial.h>
|
|
||||||
#include <ESP32Ping.h>
|
#include <ESP32Ping.h>
|
||||||
|
#include <BluetoothSerial.h>
|
||||||
#include "config.h"
|
#include <esp_bt_main.h>
|
||||||
|
|
||||||
#include "driveModi/driveManager.h"
|
#include "driveModi/driveManager.h"
|
||||||
#include "OutputBuf/outputBuf.h"
|
#include "OutputBuf/outputBuf.h"
|
||||||
@@ -47,11 +49,15 @@ Menu* main_m;
|
|||||||
LiquidCrystal_I2C* lcd;
|
LiquidCrystal_I2C* lcd;
|
||||||
OutputBuf* outputBuf;
|
OutputBuf* outputBuf;
|
||||||
DebugMqtt* debugMqtt = nullptr;
|
DebugMqtt* debugMqtt = nullptr;
|
||||||
BluetoothSerial* serialBT = nullptr;
|
|
||||||
Battery* mainBattery;
|
Battery* mainBattery;
|
||||||
|
Ps3Controller* gamepad;
|
||||||
|
BluetoothSerial SerialBT;
|
||||||
|
|
||||||
bool wifiIsActive;
|
bool wifiIsActive;
|
||||||
|
bool disconnectPs3 = false;
|
||||||
|
|
||||||
|
|
||||||
|
void configureController(void);
|
||||||
void callbackControllerAction(void);
|
void callbackControllerAction(void);
|
||||||
void callbackControllerConnect(void);
|
void callbackControllerConnect(void);
|
||||||
void callbackControllerDisconnect(void);
|
void callbackControllerDisconnect(void);
|
||||||
@@ -61,7 +67,7 @@ void makeMenu(void);
|
|||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
// DebugTimes::setConsolOutput(true);
|
DebugTimes::setConsolOutput(true);
|
||||||
DebugTimes setupTime;
|
DebugTimes setupTime;
|
||||||
char wifiIndicator = 'X';
|
char wifiIndicator = 'X';
|
||||||
|
|
||||||
@@ -104,18 +110,9 @@ 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;
|
||||||
|
|
||||||
Ps3.attach(callbackControllerAction);
|
gamepad = new Ps3Controller;
|
||||||
Ps3.attachOnConnect(callbackControllerConnect);
|
configureController();
|
||||||
Ps3.attachOnDisconnect(callbackControllerDisconnect);
|
|
||||||
std::cout << "\nReady to connect a PS3 Controller... \n";
|
|
||||||
|
|
||||||
// Need to be connected befor an other device connect
|
|
||||||
Ps3.begin(CONTROLLER_MAC);
|
|
||||||
|
|
||||||
std::cout << "Activate additional output via Bluetooth..." << std::endl;
|
|
||||||
serialBT = new BluetoothSerial;
|
|
||||||
serialBT->begin("Kleiax-Rover");
|
|
||||||
outputBuf->setSerialBT(serialBT);
|
|
||||||
outputBuf->activateMqtt(false);
|
outputBuf->activateMqtt(false);
|
||||||
|
|
||||||
lcd->backlight();
|
lcd->backlight();
|
||||||
@@ -141,11 +138,26 @@ void loop() {
|
|||||||
mainBattery->loop();
|
mainBattery->loop();
|
||||||
mainBatteryTime.stopConsol("MainBatteryTime", 5);
|
mainBatteryTime.stopConsol("MainBatteryTime", 5);
|
||||||
|
|
||||||
// static uint32_t lastMillis = 0;
|
if (disconnectPs3) {
|
||||||
// if (millis() - lastMillis > 2000) {
|
DebugTimes disconnectPS3Time;
|
||||||
// std::cout << "Is BT-Consol connected: " << serialBT->connected() << std::endl;
|
std::cout << "Disconnect PS3 Controller." << std::endl;
|
||||||
// lastMillis = millis();
|
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() {
|
void callbackControllerAction() {
|
||||||
@@ -153,7 +165,7 @@ void callbackControllerAction() {
|
|||||||
static uint32_t lastMillis = 0;
|
static uint32_t lastMillis = 0;
|
||||||
if (reset)
|
if (reset)
|
||||||
lastMillis = millis();
|
lastMillis = millis();
|
||||||
static const uint16_t delay = 300;
|
static const uint16_t delay = 100;
|
||||||
bool res = false;
|
bool res = false;
|
||||||
|
|
||||||
if (millis() - lastMillis > delay)
|
if (millis() - lastMillis > delay)
|
||||||
@@ -163,19 +175,19 @@ void callbackControllerAction() {
|
|||||||
|
|
||||||
// Menu controlling
|
// Menu controlling
|
||||||
if (isDelayReached()) {
|
if (isDelayReached()) {
|
||||||
if (Ps3.data.button.up)
|
if (gamepad->data.button.up)
|
||||||
main_m->up();
|
main_m->up();
|
||||||
else if (Ps3.data.button.down)
|
else if (gamepad->data.button.down)
|
||||||
main_m->down();
|
main_m->down();
|
||||||
else if (Ps3.data.button.left)
|
else if (gamepad->data.button.left)
|
||||||
main_m->left();
|
main_m->left();
|
||||||
else if (Ps3.data.button.right)
|
else if (gamepad->data.button.right)
|
||||||
main_m->right();
|
main_m->right();
|
||||||
else if (Ps3.data.button.circle)
|
else if (gamepad->data.button.circle)
|
||||||
main_m->yes();
|
main_m->yes();
|
||||||
else if (Ps3.data.button.cross)
|
else if (gamepad->data.button.cross)
|
||||||
main_m->no();
|
main_m->no();
|
||||||
else if (Ps3.data.button.select)
|
else if (gamepad->data.button.select)
|
||||||
debugMqtt->sendMsg(Loglevel::info, "Here we are: callbackController..");
|
debugMqtt->sendMsg(Loglevel::info, "Here we are: callbackController..");
|
||||||
|
|
||||||
isDelayReached(true);
|
isDelayReached(true);
|
||||||
@@ -185,18 +197,23 @@ void callbackControllerAction() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void callbackControllerConnect() {
|
void callbackControllerConnect() {
|
||||||
|
static bool firstConnect = true;
|
||||||
|
|
||||||
std::cout << "Controller connected to ESP32" << std::endl;
|
std::cout << "Controller connected to ESP32" << std::endl;
|
||||||
std::cout << "All actions from the Controller run on Core -> " << xPortGetCoreID() << std::endl;
|
std::cout << "All actions from the Controller run on Core -> " << xPortGetCoreID() << std::endl;
|
||||||
|
|
||||||
// Display is not functional without this seconde init, first init is in setup(),
|
// Display is not functional without this seconde init, first init is in setup(),
|
||||||
// because after the setup the other core control the display.
|
// because after the setup the other core control the display.
|
||||||
|
if (firstConnect) {
|
||||||
lcd->init();
|
lcd->init();
|
||||||
main_m->printMenu();
|
main_m->printMenu();
|
||||||
|
firstConnect = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void callbackControllerDisconnect() {
|
void callbackControllerDisconnect() {
|
||||||
std::cout << "Controller disconnected..." << std::endl;
|
std::cout << "Controller disconnected..." << std::endl;
|
||||||
// Ps3.end();
|
// gamepad->end();
|
||||||
}
|
}
|
||||||
|
|
||||||
void i2cScanner() {
|
void i2cScanner() {
|
||||||
@@ -243,7 +260,7 @@ void makeMenu() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
auto disconnectController = [&]() {
|
auto disconnectController = [&]() {
|
||||||
Ps3.end();
|
disconnectPs3 = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create Menu
|
// Create Menu
|
||||||
@@ -257,7 +274,7 @@ void makeMenu() {
|
|||||||
MenuAutopilot* auto_m = new MenuAutopilot(driveManager);
|
MenuAutopilot* auto_m = new MenuAutopilot(driveManager);
|
||||||
MenuTestMode* test_m = new MenuTestMode(driveManager);
|
MenuTestMode* test_m = new MenuTestMode(driveManager);
|
||||||
MenuGPS* gps_m = new MenuGPS(driveManager);
|
MenuGPS* gps_m = new MenuGPS(driveManager);
|
||||||
MenuAkku* akku_m = new MenuAkku(mainBattery);
|
MenuAkku* akku_m = new MenuAkku(mainBattery, gamepad);
|
||||||
|
|
||||||
// Set Menus on LCD
|
// Set Menus on LCD
|
||||||
main_m->setLcd(lcd);
|
main_m->setLcd(lcd);
|
||||||
|
|||||||
Reference in New Issue
Block a user