first try working module - fail
This commit is contained in:
Vendored
+1
@@ -82,6 +82,7 @@
|
|||||||
"cSpell.words": [
|
"cSpell.words": [
|
||||||
"Ahnung",
|
"Ahnung",
|
||||||
"akku",
|
"akku",
|
||||||
|
"ardui",
|
||||||
"blox",
|
"blox",
|
||||||
"bluedroid",
|
"bluedroid",
|
||||||
"gast",
|
"gast",
|
||||||
|
|||||||
@@ -33,3 +33,6 @@
|
|||||||
#define UBLOX_GNSS_SPI_CIPO 4
|
#define UBLOX_GNSS_SPI_CIPO 4
|
||||||
#define UBLOX_GNSS_SPI_SCK 5
|
#define UBLOX_GNSS_SPI_SCK 5
|
||||||
///@}
|
///@}
|
||||||
|
|
||||||
|
#define RF24_CSN_PIN 18
|
||||||
|
#define RF24_CE_PIN 2
|
||||||
|
|||||||
@@ -11,41 +11,69 @@
|
|||||||
|
|
||||||
#include "controlPad.h"
|
#include "controlPad.h"
|
||||||
|
|
||||||
ControlPad::ControlPad() {
|
ControlPad::ControlPad(SPIClass *spiPort, uint8_t cePin, uint8_t csnPin) {
|
||||||
|
this->radio = new RF24(cePin, csnPin);
|
||||||
|
|
||||||
|
std::cout << "ControlPad::ControlPad: sizeof ControlPadInput in byte: " << sizeof(ControlPadInput) << std::endl;
|
||||||
|
|
||||||
|
|
||||||
|
if (!this->radio->begin(spiPort)) {
|
||||||
|
std::cout << "ControlPad::ControlPad: Error radio->begin!" << std::endl;
|
||||||
|
while(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// this->radio->setAddressWidth(5);
|
||||||
|
// this->radio->setChannel(7);
|
||||||
|
// this->radio->setDataRate(RF24_1MBPS);
|
||||||
|
// this->radio->setAutoAck(true);
|
||||||
|
// this->radio->enableDynamicPayloads();
|
||||||
|
// this->radio->enableAckPayload();
|
||||||
|
// this->radio->setCRCLength(RF24_CRC_16);
|
||||||
|
|
||||||
|
this->radio->setPALevel(RF24_PA_LOW);
|
||||||
|
|
||||||
|
// this->radio->openWritingPipe(this->address[1]);
|
||||||
|
this->radio->openReadingPipe(0, this->address[0]);
|
||||||
|
|
||||||
|
this->radio->startListening();
|
||||||
|
|
||||||
|
// this->radio->printPrettyDetails();
|
||||||
|
this->radio->printPrettyDetails();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ControlPad::loop() {
|
bool ControlPad::loop() {
|
||||||
|
this->receiveData();
|
||||||
|
|
||||||
if (millis() - this->lastLoopMillis < this->loopDelay)
|
if (millis() - this->lastLoopMillis < this->loopDelay)
|
||||||
return false;
|
return false;
|
||||||
this->lastLoopMillis = millis();
|
this->lastLoopMillis = millis();
|
||||||
|
|
||||||
if(!this->connected)
|
// if(!this->connected)
|
||||||
return false;
|
// return false;
|
||||||
|
|
||||||
if (millis() - this->lastMessageReceive > this->disconnectTime) {
|
// if (millis() - this->lastMessageReceive > this->disconnectTime) {
|
||||||
this->connected = false;
|
// this->connected = false;
|
||||||
return false;
|
// return false;
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (this->menuControl && this->controlInput.buttons > 0 && this->updated)
|
// if (this->menuControl && this->controlInput.buttons > 0 && this->updated)
|
||||||
if (!this->firstButtonPress)
|
// if (!this->firstButtonPress)
|
||||||
this->menuControl->printMenu();
|
// this->menuControl->printMenu();
|
||||||
|
|
||||||
if (ControlPadButton::isControlPadButtonPressed(&this->controlInput, ControlPadButton::PadButton::Left))
|
// if (ControlPadButton::isControlPadButtonPressed(&this->controlInput, ControlPadButton::PadButton::Left))
|
||||||
this->menuControl->left();
|
// this->menuControl->left();
|
||||||
else if (ControlPadButton::isControlPadButtonPressed(&this->controlInput, ControlPadButton::PadButton::Right))
|
// else if (ControlPadButton::isControlPadButtonPressed(&this->controlInput, ControlPadButton::PadButton::Right))
|
||||||
this->menuControl->right();
|
// this->menuControl->right();
|
||||||
else if (ControlPadButton::isControlPadButtonPressed(&this->controlInput, ControlPadButton::PadButton::Up))
|
// else if (ControlPadButton::isControlPadButtonPressed(&this->controlInput, ControlPadButton::PadButton::Up))
|
||||||
this->menuControl->up();
|
// this->menuControl->up();
|
||||||
else if (ControlPadButton::isControlPadButtonPressed(&this->controlInput, ControlPadButton::PadButton::Down))
|
// else if (ControlPadButton::isControlPadButtonPressed(&this->controlInput, ControlPadButton::PadButton::Down))
|
||||||
this->menuControl->down();
|
// this->menuControl->down();
|
||||||
else if (ControlPadButton::isControlPadButtonPressed(&this->controlInput, ControlPadButton::PadButton::Yes))
|
// else if (ControlPadButton::isControlPadButtonPressed(&this->controlInput, ControlPadButton::PadButton::Yes))
|
||||||
this->menuControl->yes();
|
// this->menuControl->yes();
|
||||||
else if (ControlPadButton::isControlPadButtonPressed(&this->controlInput, ControlPadButton::PadButton::No))
|
// else if (ControlPadButton::isControlPadButtonPressed(&this->controlInput, ControlPadButton::PadButton::No))
|
||||||
this->menuControl->no();
|
// this->menuControl->no();
|
||||||
|
|
||||||
this->menuControl->update();
|
// this->menuControl->update();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -55,3 +83,12 @@ const ControlPadInput * ControlPad::getControlPadDataPtr(uint16_t maxElapsedTime
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
return &this->controlInput;
|
return &this->controlInput;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ControlPad::receiveData() {
|
||||||
|
this->radio->startListening();
|
||||||
|
if (this->radio->available()) {
|
||||||
|
ControlPadInput lastInput = this->controlInput;
|
||||||
|
this->radio->read(&this->controlInput, sizeof(ControlPadInput));
|
||||||
|
std::cout << "Data RF24: " << this->controlInput.counter << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -12,12 +12,16 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <menuControl.h>
|
#include <menuControl.h>
|
||||||
|
#include <nRF24L01.h>
|
||||||
|
#include <RF24.h>
|
||||||
|
#include <SPI.h>
|
||||||
|
// #include <printf.h>
|
||||||
|
|
||||||
#include "controlPadInput.h"
|
#include "controlPadInput.h"
|
||||||
|
|
||||||
class ControlPad {
|
class ControlPad {
|
||||||
public:
|
public:
|
||||||
ControlPad();
|
ControlPad(SPIClass *spiPort, uint8_t cePin, uint8_t csnPin);
|
||||||
|
|
||||||
bool loop();
|
bool loop();
|
||||||
|
|
||||||
@@ -29,12 +33,17 @@ class ControlPad {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
MenuControl* menuControl = nullptr;
|
MenuControl* menuControl = nullptr;
|
||||||
|
RF24* radio;
|
||||||
ControlPadInput controlInput;
|
ControlPadInput controlInput;
|
||||||
|
|
||||||
|
void receiveData();
|
||||||
|
|
||||||
bool connected = false;
|
bool connected = false;
|
||||||
bool updated = false;
|
bool updated = false;
|
||||||
bool firstButtonPress = false;
|
bool firstButtonPress = false;
|
||||||
|
|
||||||
|
const uint8_t address[2][6] = { "rover", "ardui" };
|
||||||
|
|
||||||
uint16_t disconnectTime = 50;
|
uint16_t disconnectTime = 50;
|
||||||
uint16_t loopDelay = 5;
|
uint16_t loopDelay = 5;
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ lib_deps =
|
|||||||
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
|
||||||
|
nrf24/RF24@^1.4.5
|
||||||
upload_port = COM3
|
upload_port = COM3
|
||||||
|
|
||||||
[env:release]
|
[env:release]
|
||||||
|
|||||||
@@ -15,12 +15,11 @@ 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, const ControlPadInput *input, bool wifi) {
|
DriveManager::DriveManager(MoveControl *moveControl, SPIClass *spiPort, const ControlPadInput *input, bool wifi) {
|
||||||
this->moveControl = moveControl;
|
this->moveControl = moveControl;
|
||||||
this->input = input;
|
this->input = input;
|
||||||
|
|
||||||
this->spiPort = new SPIClass(HSPI);
|
this->spiPort = spiPort;
|
||||||
spiPort->begin(UBLOX_GNSS_SPI_SCK, UBLOX_GNSS_SPI_CIPO, UBLOX_GNSS_SPI_COPI, UBLOX_GNSS_SPI_CS);
|
|
||||||
this->navigation = new Navigation(spiPort, UBLOX_GNSS_SPI_CS);
|
this->navigation = new Navigation(spiPort, UBLOX_GNSS_SPI_CS);
|
||||||
if (wifi)
|
if (wifi)
|
||||||
this->navigation->initNtrip(NTRIP_HOST, NTRIP_PORT, NTRIP_MOUNT_POINT, NTRIP_USER, NTRIP_PASSWORD);
|
this->navigation->initNtrip(NTRIP_HOST, NTRIP_PORT, NTRIP_MOUNT_POINT, NTRIP_USER, NTRIP_PASSWORD);
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ class DriveManager {
|
|||||||
*
|
*
|
||||||
* @param moveControl
|
* @param moveControl
|
||||||
*/
|
*/
|
||||||
DriveManager(MoveControl *moveControl, const ControlPadInput *input, bool wifi = false);
|
DriveManager(MoveControl *moveControl, SPIClass *spiPort, const ControlPadInput *input, bool wifi = false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Destroy the Drive Manager object
|
* @brief Destroy the Drive Manager object
|
||||||
|
|||||||
+7
-2
@@ -20,6 +20,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
#include <LiquidCrystal_I2C.h>
|
#include <LiquidCrystal_I2C.h>
|
||||||
|
#include <SPI.h>
|
||||||
|
|
||||||
#include "driveModi/driveManager.h"
|
#include "driveModi/driveManager.h"
|
||||||
#include "OutputBuf/outputBuf.h"
|
#include "OutputBuf/outputBuf.h"
|
||||||
@@ -50,6 +51,7 @@ LcdWrapper* lcdWrapper;
|
|||||||
OutputBuf* outputBuf;
|
OutputBuf* outputBuf;
|
||||||
DebugMqtt* debugMqtt = nullptr;
|
DebugMqtt* debugMqtt = nullptr;
|
||||||
Battery* mainBattery;
|
Battery* mainBattery;
|
||||||
|
SPIClass* spiPort;
|
||||||
ControlPad* controlPad;
|
ControlPad* controlPad;
|
||||||
|
|
||||||
bool wifiIsActive;
|
bool wifiIsActive;
|
||||||
@@ -65,8 +67,11 @@ void setup() {
|
|||||||
DebugTimes setupTime;
|
DebugTimes setupTime;
|
||||||
char wifiIndicator = 'X';
|
char wifiIndicator = 'X';
|
||||||
|
|
||||||
|
spiPort = new SPIClass(HSPI);
|
||||||
|
spiPort->begin(UBLOX_GNSS_SPI_SCK, UBLOX_GNSS_SPI_CIPO, UBLOX_GNSS_SPI_COPI, UBLOX_GNSS_SPI_CS);
|
||||||
|
|
||||||
mainBattery = new Battery(35, 692000, 218500);
|
mainBattery = new Battery(35, 692000, 218500);
|
||||||
controlPad = new ControlPad();
|
controlPad = new ControlPad(spiPort, RF24_CE_PIN, RF24_CSN_PIN);
|
||||||
controlPad->setMenuControl(main_m);
|
controlPad->setMenuControl(main_m);
|
||||||
|
|
||||||
Wire.begin(21, 19);
|
Wire.begin(21, 19);
|
||||||
@@ -97,7 +102,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;
|
||||||
|
|
||||||
driveManager = new DriveManager(&moveController, controlPad->getControlPadDataPtr(), wifiIsActive);
|
driveManager = new DriveManager(&moveController, spiPort, controlPad->getControlPadDataPtr(), wifiIsActive);
|
||||||
|
|
||||||
outputBuf->activateMqtt(false);
|
outputBuf->activateMqtt(false);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user