first try working module - fail
This commit is contained in:
Vendored
+1
@@ -82,6 +82,7 @@
|
||||
"cSpell.words": [
|
||||
"Ahnung",
|
||||
"akku",
|
||||
"ardui",
|
||||
"blox",
|
||||
"bluedroid",
|
||||
"gast",
|
||||
|
||||
@@ -33,3 +33,6 @@
|
||||
#define UBLOX_GNSS_SPI_CIPO 4
|
||||
#define UBLOX_GNSS_SPI_SCK 5
|
||||
///@}
|
||||
|
||||
#define RF24_CSN_PIN 18
|
||||
#define RF24_CE_PIN 2
|
||||
|
||||
@@ -11,41 +11,69 @@
|
||||
|
||||
#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() {
|
||||
this->receiveData();
|
||||
|
||||
if (millis() - this->lastLoopMillis < this->loopDelay)
|
||||
return false;
|
||||
this->lastLoopMillis = millis();
|
||||
|
||||
if(!this->connected)
|
||||
return false;
|
||||
// if(!this->connected)
|
||||
// return false;
|
||||
|
||||
if (millis() - this->lastMessageReceive > this->disconnectTime) {
|
||||
this->connected = false;
|
||||
return false;
|
||||
}
|
||||
// if (millis() - this->lastMessageReceive > this->disconnectTime) {
|
||||
// this->connected = false;
|
||||
// return false;
|
||||
// }
|
||||
|
||||
if (this->menuControl && this->controlInput.buttons > 0 && this->updated)
|
||||
if (!this->firstButtonPress)
|
||||
this->menuControl->printMenu();
|
||||
// if (this->menuControl && this->controlInput.buttons > 0 && this->updated)
|
||||
// if (!this->firstButtonPress)
|
||||
// this->menuControl->printMenu();
|
||||
|
||||
if (ControlPadButton::isControlPadButtonPressed(&this->controlInput, ControlPadButton::PadButton::Left))
|
||||
this->menuControl->left();
|
||||
else if (ControlPadButton::isControlPadButtonPressed(&this->controlInput, ControlPadButton::PadButton::Right))
|
||||
this->menuControl->right();
|
||||
else if (ControlPadButton::isControlPadButtonPressed(&this->controlInput, ControlPadButton::PadButton::Up))
|
||||
this->menuControl->up();
|
||||
else if (ControlPadButton::isControlPadButtonPressed(&this->controlInput, ControlPadButton::PadButton::Down))
|
||||
this->menuControl->down();
|
||||
else if (ControlPadButton::isControlPadButtonPressed(&this->controlInput, ControlPadButton::PadButton::Yes))
|
||||
this->menuControl->yes();
|
||||
else if (ControlPadButton::isControlPadButtonPressed(&this->controlInput, ControlPadButton::PadButton::No))
|
||||
this->menuControl->no();
|
||||
// if (ControlPadButton::isControlPadButtonPressed(&this->controlInput, ControlPadButton::PadButton::Left))
|
||||
// this->menuControl->left();
|
||||
// else if (ControlPadButton::isControlPadButtonPressed(&this->controlInput, ControlPadButton::PadButton::Right))
|
||||
// this->menuControl->right();
|
||||
// else if (ControlPadButton::isControlPadButtonPressed(&this->controlInput, ControlPadButton::PadButton::Up))
|
||||
// this->menuControl->up();
|
||||
// else if (ControlPadButton::isControlPadButtonPressed(&this->controlInput, ControlPadButton::PadButton::Down))
|
||||
// this->menuControl->down();
|
||||
// else if (ControlPadButton::isControlPadButtonPressed(&this->controlInput, ControlPadButton::PadButton::Yes))
|
||||
// this->menuControl->yes();
|
||||
// else if (ControlPadButton::isControlPadButtonPressed(&this->controlInput, ControlPadButton::PadButton::No))
|
||||
// this->menuControl->no();
|
||||
|
||||
this->menuControl->update();
|
||||
// this->menuControl->update();
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -55,3 +83,12 @@ const ControlPadInput * ControlPad::getControlPadDataPtr(uint16_t maxElapsedTime
|
||||
return nullptr;
|
||||
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
|
||||
|
||||
#include <menuControl.h>
|
||||
#include <nRF24L01.h>
|
||||
#include <RF24.h>
|
||||
#include <SPI.h>
|
||||
// #include <printf.h>
|
||||
|
||||
#include "controlPadInput.h"
|
||||
|
||||
class ControlPad {
|
||||
public:
|
||||
ControlPad();
|
||||
ControlPad(SPIClass *spiPort, uint8_t cePin, uint8_t csnPin);
|
||||
|
||||
bool loop();
|
||||
|
||||
@@ -29,12 +33,17 @@ class ControlPad {
|
||||
|
||||
private:
|
||||
MenuControl* menuControl = nullptr;
|
||||
RF24* radio;
|
||||
ControlPadInput controlInput;
|
||||
|
||||
void receiveData();
|
||||
|
||||
bool connected = false;
|
||||
bool updated = false;
|
||||
bool firstButtonPress = false;
|
||||
|
||||
const uint8_t address[2][6] = { "rover", "ardui" };
|
||||
|
||||
uint16_t disconnectTime = 50;
|
||||
uint16_t loopDelay = 5;
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ lib_deps =
|
||||
bblanchon/ArduinoJson@^6.20.0
|
||||
mprograms/QMC5883LCompass@^1.1.1
|
||||
https://git.kleiax.de/PlatformIO-Libs/Menu.git#v1.0
|
||||
nrf24/RF24@^1.4.5
|
||||
upload_port = COM3
|
||||
|
||||
[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);
|
||||
}
|
||||
|
||||
DriveManager::DriveManager(MoveControl *moveControl, const ControlPadInput *input, bool wifi) {
|
||||
DriveManager::DriveManager(MoveControl *moveControl, SPIClass *spiPort, const ControlPadInput *input, bool wifi) {
|
||||
this->moveControl = moveControl;
|
||||
this->input = input;
|
||||
|
||||
this->spiPort = new SPIClass(HSPI);
|
||||
spiPort->begin(UBLOX_GNSS_SPI_SCK, UBLOX_GNSS_SPI_CIPO, UBLOX_GNSS_SPI_COPI, UBLOX_GNSS_SPI_CS);
|
||||
this->spiPort = spiPort;
|
||||
this->navigation = new Navigation(spiPort, UBLOX_GNSS_SPI_CS);
|
||||
if (wifi)
|
||||
this->navigation->initNtrip(NTRIP_HOST, NTRIP_PORT, NTRIP_MOUNT_POINT, NTRIP_USER, NTRIP_PASSWORD);
|
||||
|
||||
@@ -52,7 +52,7 @@ class DriveManager {
|
||||
*
|
||||
* @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
|
||||
|
||||
+7
-2
@@ -20,6 +20,7 @@
|
||||
#include <iostream>
|
||||
#include <Wire.h>
|
||||
#include <LiquidCrystal_I2C.h>
|
||||
#include <SPI.h>
|
||||
|
||||
#include "driveModi/driveManager.h"
|
||||
#include "OutputBuf/outputBuf.h"
|
||||
@@ -50,6 +51,7 @@ LcdWrapper* lcdWrapper;
|
||||
OutputBuf* outputBuf;
|
||||
DebugMqtt* debugMqtt = nullptr;
|
||||
Battery* mainBattery;
|
||||
SPIClass* spiPort;
|
||||
ControlPad* controlPad;
|
||||
|
||||
bool wifiIsActive;
|
||||
@@ -65,8 +67,11 @@ void setup() {
|
||||
DebugTimes setupTime;
|
||||
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);
|
||||
controlPad = new ControlPad();
|
||||
controlPad = new ControlPad(spiPort, RF24_CE_PIN, RF24_CSN_PIN);
|
||||
controlPad->setMenuControl(main_m);
|
||||
|
||||
Wire.begin(21, 19);
|
||||
@@ -97,7 +102,7 @@ void setup() {
|
||||
std::cout << "Welcome to Kleiax-Rover" << 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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user