added duplicate console to mqtt
This commit is contained in:
@@ -55,9 +55,8 @@ void MenuAkku::printMenu() {
|
||||
lcd->printf("Controller: %s", buf);
|
||||
lcd->setCursor(0, 1);
|
||||
lcd->printf("Main: %u%%", mainBattery);
|
||||
} else {
|
||||
std::cout << "Controller: " << buf << "Main: " << mainBattery << "%" << std::endl;
|
||||
}
|
||||
std::cout << "Controller: " << buf << " Main: " << (int) mainBattery << "%" << std::endl;
|
||||
}
|
||||
|
||||
void MenuAkku::update() {
|
||||
|
||||
@@ -76,13 +76,12 @@ void MenuGPS::printPage(uint8_t page) const {
|
||||
lcd->setCursor(0, 1);
|
||||
lcd->printf("or no GPS signal");
|
||||
}
|
||||
} else {
|
||||
}
|
||||
if (gps->satellites.isValid() && gps->satellites.value() > 2)
|
||||
std::cout << "Sats: " << gps->satellites.value()
|
||||
<< "HDOP: " << gps->hdop.hdop() << std::endl;
|
||||
else
|
||||
std::cout << "Date isn't valid or no GPS signal" << std::endl;
|
||||
}
|
||||
<< "HDOP: " << gps->hdop.hdop() << std::endl;
|
||||
else
|
||||
std::cout << "Data isn't valid or no GPS signal" << std::endl;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
@@ -98,13 +97,12 @@ void MenuGPS::printPage(uint8_t page) const {
|
||||
lcd->setCursor(0, 1);
|
||||
lcd->printf("or NO GPS signal");
|
||||
}
|
||||
} else {
|
||||
if (gps->satellites.isValid() && gps->satellites.value() > 2)
|
||||
std::cout << "Lat: " << gps->location.lat()
|
||||
<< "Lng: " << gps->location.lng() << std::endl;
|
||||
else
|
||||
std::cout << "Date isn't valid or NO GPS signal" << std::endl;
|
||||
}
|
||||
if (gps->satellites.isValid() && gps->satellites.value() > 2)
|
||||
std::cout << "Lat: " << gps->location.lat()
|
||||
<< "Lng: " << gps->location.lng() << std::endl;
|
||||
else
|
||||
std::cout << "Data isn't valid or NO GPS signal" << std::endl;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
@@ -114,9 +112,8 @@ void MenuGPS::printPage(uint8_t page) const {
|
||||
lcd->printf("Chars processed");
|
||||
lcd->setCursor(0, 1);
|
||||
lcd->printf("-> %u", gps->charsProcessed());
|
||||
} else {
|
||||
std::cout << "Chars processed: " << gps->charsProcessed() << std::endl;
|
||||
}
|
||||
std::cout << "Chars processed: " << gps->charsProcessed() << std::endl;
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -124,9 +121,8 @@ void MenuGPS::printPage(uint8_t page) const {
|
||||
lcd->clear();
|
||||
lcd->setCursor(0, 0);
|
||||
lcd->printf("Page: %u", page);
|
||||
} else {
|
||||
printf("Page: %u", page);
|
||||
}
|
||||
std::cout << "Page: " << (int) page << std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,10 +85,9 @@ void MenuPidSettings::printMenu() {
|
||||
lcd->print(" P I D ");
|
||||
lcd->setCursor(0, 1);
|
||||
lcd->print(buf);
|
||||
} else {
|
||||
std::cout << " P I D " << std::endl;
|
||||
std::cout << buf << std::endl;
|
||||
}
|
||||
std::cout << " P I D " << std::endl;
|
||||
std::cout << buf << std::endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -69,8 +69,8 @@ void MenuAutopilot::printMenu() {
|
||||
this->lcd->setCursor(0, 1);
|
||||
this->lcd->print(buf2);
|
||||
|
||||
} else
|
||||
std::cout << buf1 << " " << buf2 << std::endl;
|
||||
}
|
||||
std::cout << buf1 << " " << buf2 << std::endl;
|
||||
}
|
||||
|
||||
void MenuAutopilot::update() {
|
||||
|
||||
@@ -21,8 +21,8 @@ void MenuCaptureRoute::printMenu() {
|
||||
this->lcd->setCursor(0, 1);
|
||||
this->lcd->print("du fahren. :-)");
|
||||
|
||||
} else
|
||||
std::cout << "Capture du\n fahren. :-)" << std::endl;
|
||||
}
|
||||
std::cout << "Points: " << this->routeInfo.totalPoints << " du fahren. :-)" << std::endl;
|
||||
}
|
||||
|
||||
void MenuCaptureRoute::update() {
|
||||
@@ -37,4 +37,4 @@ void MenuCaptureRoute::init() {
|
||||
this->driveManager->changeModus(Modi::CaptureRoute);
|
||||
this->captureRoute = (CaptureRoute*) this->driveManager->getDriveModiPtr();
|
||||
this->routeInfo = this->captureRoute->getRouteInfo();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,6 @@ void MenuManualControl::printMenu() {
|
||||
this->lcd->setCursor(0, 1);
|
||||
this->lcd->print("du fahren. :-)");
|
||||
|
||||
} else
|
||||
std::cout << "Jetzt kannst du\n fahren. :-)" << std::endl;
|
||||
}
|
||||
}
|
||||
std::cout << "Jetzt kannst du\n fahren. :-)" << std::endl;
|
||||
}
|
||||
|
||||
+116
-99
@@ -9,6 +9,8 @@
|
||||
#include "driveModi/driveManager.h"
|
||||
#include "moveControl.h"
|
||||
#include "network.h"
|
||||
#include "outputBufMqtt.h"
|
||||
#include "debugMqtt.h"
|
||||
|
||||
#include "menu.h"
|
||||
#include "menuAction.h"
|
||||
@@ -23,23 +25,38 @@ MoveControl moveController;
|
||||
DriveManager driveManager(&moveController);
|
||||
Menu* main_m;
|
||||
LiquidCrystal_I2C* lcd;
|
||||
OutputBufMqtt* bufMqtt;
|
||||
DebugMqtt* debugMqtt;
|
||||
|
||||
// TODO: Platzhalter, muss irgendwann weg
|
||||
void dummy(){std::cout << "Dummy in Action" <<std::endl;}
|
||||
|
||||
|
||||
void callbackControllerAction();
|
||||
void callbackControllerConnect();
|
||||
void controllerPrintBattery();
|
||||
void i2cScanner();
|
||||
void restart();
|
||||
void callbackControllerAction(void);
|
||||
void callbackControllerConnect(void);
|
||||
void i2cScanner(void);
|
||||
void restart(void);
|
||||
void makeMenu(void);
|
||||
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
Network::setIps();
|
||||
Network::connectWifi();
|
||||
Network::setupMQTT();
|
||||
Network::checkMQTT();
|
||||
DebugMqtt::init(Network::getMqtttClient(), Loglevel::debug);
|
||||
|
||||
std::cout << "Activate additional output via MQTT..." << std::endl;
|
||||
debugMqtt = new DebugMqtt("Console");
|
||||
bufMqtt = new OutputBufMqtt(debugMqtt);
|
||||
std::cout.rdbuf(bufMqtt);
|
||||
|
||||
std::cout << "Welcome to Kleiax-Rover" << std::endl;
|
||||
std::cout << "All actions from the main programm run on Core -> " << xPortGetCoreID() << std::endl;
|
||||
|
||||
Ps3.attach(callbackControllerAction);
|
||||
Ps3.attachOnConnect(callbackControllerConnect);
|
||||
std::cout << "\nReady to connect a PS3 Controller... \n";
|
||||
Ps3.begin(CONTROLLER_MAC);
|
||||
|
||||
Wire.begin(21, 19);
|
||||
// i2cScanner();
|
||||
lcd = new LiquidCrystal_I2C(0x3F,16,2);
|
||||
@@ -49,14 +66,97 @@ void setup() {
|
||||
lcd->setCursor(0, 1);
|
||||
lcd->print("Press PS-Button");
|
||||
|
||||
Network::setIps();
|
||||
Network::connectWifi();
|
||||
Network::setupMQTT();
|
||||
makeMenu();
|
||||
}
|
||||
|
||||
Ps3.attach(callbackControllerAction);
|
||||
Ps3.attachOnConnect(callbackControllerConnect);
|
||||
std::cout << "\nReady to connect a PS3 Controller... \n";
|
||||
Ps3.begin(CONTROLLER_MAC);
|
||||
void loop() {
|
||||
Network::checkMQTT();
|
||||
driveManager.loop();
|
||||
}
|
||||
|
||||
void callbackControllerAction() {
|
||||
auto isDelayReached = [](bool reset = false) -> bool {
|
||||
static uint32_t lastMillis = 0;
|
||||
if (reset)
|
||||
lastMillis = millis();
|
||||
static const uint16_t delay = 300;
|
||||
bool res = false;
|
||||
|
||||
if (millis() - lastMillis > delay)
|
||||
res = true;
|
||||
return res;
|
||||
};
|
||||
|
||||
// Menu controlling
|
||||
if (isDelayReached()) {
|
||||
if (Ps3.data.button.up)
|
||||
main_m->up();
|
||||
else if (Ps3.data.button.down)
|
||||
main_m->down();
|
||||
else if (Ps3.data.button.left)
|
||||
main_m->left();
|
||||
else if (Ps3.data.button.right)
|
||||
main_m->right();
|
||||
else if (Ps3.data.button.circle)
|
||||
main_m->yes();
|
||||
else if (Ps3.data.button.cross)
|
||||
main_m->no();
|
||||
else if (Ps3.data.button.select)
|
||||
debugMqtt->sendMsg(Loglevel::info, "Here we are: callbackController..");
|
||||
|
||||
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;
|
||||
|
||||
// TODO: Display is not functional without this seconde init, first init is in setup()
|
||||
lcd->init();
|
||||
main_m->printMenu();
|
||||
}
|
||||
|
||||
void i2cScanner() {
|
||||
std::cout << "\nI2C Scanner" << std::endl;
|
||||
|
||||
byte error, address;
|
||||
int nDevices;
|
||||
Serial.println("Scanning...");
|
||||
nDevices = 0;
|
||||
for(address = 1; address < 127; address++ ) {
|
||||
Wire.beginTransmission(address);
|
||||
error = Wire.endTransmission();
|
||||
if (error == 0) {
|
||||
Serial.print("I2C device found at address 0x");
|
||||
if (address<16)
|
||||
Serial.print("0");
|
||||
Serial.println(address,HEX);
|
||||
nDevices++;
|
||||
}
|
||||
else if (error==4) {
|
||||
Serial.print("Unknow error at address 0x");
|
||||
if (address<16)
|
||||
Serial.print("0");
|
||||
Serial.println(address,HEX);
|
||||
}
|
||||
}
|
||||
if (nDevices == 0)
|
||||
Serial.println("No I2C devices found\n");
|
||||
else
|
||||
Serial.println("done\n");
|
||||
}
|
||||
|
||||
void restart() {
|
||||
ESP.restart();
|
||||
}
|
||||
|
||||
void makeMenu() {
|
||||
auto dummy = []() {
|
||||
std::cout << "Dummy in Action" <<std::endl;
|
||||
};
|
||||
|
||||
// Create Menu
|
||||
main_m = new Menu();
|
||||
@@ -112,87 +212,4 @@ void setup() {
|
||||
MenuAction* pidr_e = new MenuAction("Right", pidr_m);
|
||||
pid_m->addEntry(pidl_e);
|
||||
pid_m->addEntry(pidr_e);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
Network::checkMQTT();
|
||||
driveManager.loop();
|
||||
}
|
||||
|
||||
bool isDelayReached(bool reset = false) {
|
||||
static uint32_t lastMillis = 0;
|
||||
if (reset)
|
||||
lastMillis = millis();
|
||||
static const uint16_t delay = 300;
|
||||
bool res = false;
|
||||
|
||||
if (millis() - lastMillis > delay)
|
||||
res = true;
|
||||
return res;
|
||||
}
|
||||
|
||||
void callbackControllerAction() {
|
||||
// Menu controlling
|
||||
if (isDelayReached()) {
|
||||
if (Ps3.data.button.up)
|
||||
main_m->up();
|
||||
else if (Ps3.data.button.down)
|
||||
main_m->down();
|
||||
else if (Ps3.data.button.left)
|
||||
main_m->left();
|
||||
else if (Ps3.data.button.right)
|
||||
main_m->right();
|
||||
else if (Ps3.data.button.circle)
|
||||
main_m->yes();
|
||||
else if (Ps3.data.button.cross)
|
||||
main_m->no();
|
||||
|
||||
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;
|
||||
|
||||
// TODO: Display is not functional without this seconde init, first init is in setup()
|
||||
lcd->init();
|
||||
main_m->printMenu();
|
||||
}
|
||||
|
||||
void i2cScanner() {
|
||||
std::cout << "\nI2C Scanner" << std::endl;
|
||||
|
||||
byte error, address;
|
||||
int nDevices;
|
||||
Serial.println("Scanning...");
|
||||
nDevices = 0;
|
||||
for(address = 1; address < 127; address++ ) {
|
||||
Wire.beginTransmission(address);
|
||||
error = Wire.endTransmission();
|
||||
if (error == 0) {
|
||||
Serial.print("I2C device found at address 0x");
|
||||
if (address<16)
|
||||
Serial.print("0");
|
||||
Serial.println(address,HEX);
|
||||
nDevices++;
|
||||
}
|
||||
else if (error==4) {
|
||||
Serial.print("Unknow error at address 0x");
|
||||
if (address<16)
|
||||
Serial.print("0");
|
||||
Serial.println(address,HEX);
|
||||
}
|
||||
}
|
||||
if (nDevices == 0)
|
||||
Serial.println("No I2C devices found\n");
|
||||
else
|
||||
Serial.println("done\n");
|
||||
}
|
||||
|
||||
void restart() {
|
||||
ESP.restart();
|
||||
}
|
||||
|
||||
+4
-2
@@ -47,7 +47,9 @@ void MoveControl::loop() {
|
||||
|| right_motor_time > 50
|
||||
|| left_speed_time > 50
|
||||
|| right_speed_time > 50) {
|
||||
Serial.printf("left M: %d, right M %d, left S %d, right S %d in moveControl::loop\n", left_motor_time, right_motor_time, left_speed_time, right_speed_time);
|
||||
char buf[128];
|
||||
sprintf(buf, "left M: %d, right M %d, left S %d, right S %d in moveControl::loop\n", left_motor_time, right_motor_time, left_speed_time, right_speed_time);
|
||||
std::cout << buf;
|
||||
}
|
||||
|
||||
static uint64_t last_millis = 0;
|
||||
@@ -162,4 +164,4 @@ void MoveControl::regulateMotors() {
|
||||
void MoveControl::updateCurrentWheelSpeed() {
|
||||
this->wheelspeed_left = this->left_speedometer->getSpeed();
|
||||
this->wheelspeed_right = this->right_speedometer->getSpeed();
|
||||
}
|
||||
}
|
||||
|
||||
+12
-15
@@ -27,12 +27,11 @@ void Network::setIps() {
|
||||
}
|
||||
|
||||
void Network::setupMQTT() {
|
||||
mqtt_client = new PubSubClient(wifi_client);
|
||||
mqtt_client->setServer(mqtt_server, MQTT_PORT);
|
||||
// mqtt_client.setServer(MQTT_SERVER, MQTT_PORT);
|
||||
Network::mqtt_client = new PubSubClient(wifi_client);
|
||||
// mqtt_client->setServer(mqtt_server, MQTT_PORT);
|
||||
Network::mqtt_client->setServer(MQTT_SERVER, MQTT_PORT);
|
||||
Network::mqtt_client->setSocketTimeout(1);
|
||||
mqtt_client->setSocketTimeout(1);
|
||||
connectMQTT();
|
||||
Network::connectMQTT();
|
||||
}
|
||||
|
||||
bool Network::connectMQTT() {
|
||||
@@ -55,24 +54,22 @@ bool Network::connectMQTT() {
|
||||
}
|
||||
void Network::connectWifi() {
|
||||
// Configures static IP address
|
||||
if (!WiFi.config(local_IP, gateway, subnet)) {
|
||||
Serial.println("STA Failed to configure");
|
||||
}
|
||||
if (!WiFi.config(local_IP, gateway, subnet))
|
||||
std::cout << "STA Failed to configure" << std::endl;
|
||||
|
||||
// Connect to Wi-Fi network with SSID and password
|
||||
Serial.print("Connecting to ");
|
||||
Serial.println(WLAN_SSID);
|
||||
std::cout << "Connecting to " << WLAN_SSID << std::endl;
|
||||
WiFi.begin(WLAN_SSID, WLAN_PASSWORD);
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(500);
|
||||
Serial.print(".");
|
||||
std::cout << "." << std::flush;
|
||||
}
|
||||
|
||||
// Print local IP address and start web server
|
||||
Serial.println("");
|
||||
Serial.println("WiFi connected.");
|
||||
Serial.println("IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
std::cout << std::endl;
|
||||
std::cout << "WiFi connected." << std::endl;
|
||||
std::cout << "IP address: " << std::endl;
|
||||
std::cout << WLAN_IP << std::endl;
|
||||
}
|
||||
|
||||
void Network::checkMQTT() {
|
||||
|
||||
Reference in New Issue
Block a user