working remoteControl via espNow
This commit is contained in:
+18
-21
@@ -59,8 +59,9 @@ bool wifiIsActive;
|
||||
void i2cScanner(void);
|
||||
void makeMenu(void);
|
||||
void restart(void);
|
||||
void recieveCallback (const uint8_t * mac, const uint8_t *incomingData, int len);
|
||||
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[][DISPLAY_WRAPPER_ROWS], uint8_t lines, uint8_t rows);
|
||||
|
||||
|
||||
void setup() {
|
||||
@@ -78,7 +79,6 @@ void setup() {
|
||||
|
||||
mainBattery = new Battery(35, 692000, 218500);
|
||||
controlPad = new ControlPad();
|
||||
controlPad->setMenuControl(main_m);
|
||||
|
||||
Wire.begin(21, 19);
|
||||
Wire.setClock(400000);
|
||||
@@ -104,7 +104,7 @@ void setup() {
|
||||
outputBuf = new OutputBuf();
|
||||
std::cout.rdbuf(outputBuf);
|
||||
|
||||
Network::connectEspNow(recieveCallback, sendCallback);
|
||||
Network::connectEspNow(receiveCallback, sendCallback);
|
||||
|
||||
std::cout << "Welcome to Kleiax-Rover" << std::endl;
|
||||
std::cout << "All actions from the main program run on Core -> " << xPortGetCoreID() << std::endl;
|
||||
@@ -118,6 +118,7 @@ void setup() {
|
||||
lcd->setCursor(0, 1);
|
||||
lcd->print("Press PS-Button");
|
||||
lcdWrapper = new LcdWrapper(lcd);
|
||||
lcdWrapper->setCallback(lcdWrapperCallback);
|
||||
|
||||
makeMenu();
|
||||
|
||||
@@ -125,23 +126,6 @@ void setup() {
|
||||
}
|
||||
|
||||
void loop() {
|
||||
static uint32_t lastMillis = 0;
|
||||
if (millis() - lastMillis > 5000) {
|
||||
lastMillis = millis();
|
||||
char blub[] = {"Du dumme Bla"};
|
||||
esp_err_t result = esp_now_send(Network::getBroadcastAddress(), (uint8_t *) blub, sizeof(blub));
|
||||
|
||||
if (result == ESP_OK) {
|
||||
Serial.println("Sent with success");
|
||||
}
|
||||
else {
|
||||
Serial.println("Error sending the data");
|
||||
}
|
||||
// debugMqtt->sendMsg(Loglevel::info, "Alive");
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (wifiIsActive) {
|
||||
DebugTimes wifiTime;
|
||||
Network::checkWiFi();
|
||||
@@ -150,6 +134,7 @@ void loop() {
|
||||
}
|
||||
driveManager->loop();
|
||||
controlPad->loop();
|
||||
main_m->update();
|
||||
lcdWrapper->loop();
|
||||
|
||||
mainBattery->loop();
|
||||
@@ -276,6 +261,8 @@ void makeMenu() {
|
||||
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());
|
||||
|
||||
controlPad->setMenuControl(main_m);
|
||||
}
|
||||
|
||||
void restart(void) {
|
||||
@@ -285,7 +272,7 @@ void restart(void) {
|
||||
ESP.restart();
|
||||
}
|
||||
|
||||
void recieveCallback (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);
|
||||
@@ -295,3 +282,13 @@ 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[][DISPLAY_WRAPPER_ROWS], uint8_t lines, uint8_t rows) {
|
||||
if (!controlPad->isControlPadConnected())
|
||||
return;
|
||||
|
||||
esp_err_t result = esp_now_send(Network::getBroadcastAddress(), (uint8_t *) data, lines * rows);
|
||||
|
||||
if (result != ESP_OK)
|
||||
Serial.println("Error sending the data");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user