wireless working

This commit is contained in:
2019-05-26 22:58:04 +02:00
parent ee57e22b26
commit c3958b5eec
4 changed files with 26 additions and 49 deletions
+1 -1
View File
@@ -112,7 +112,7 @@ joyStickdataStruct JoystickGet(bool debug = false)
{
Serial.print(i);
Serial.print("_");
Serial.print(outputValue);
Serial.print(myJoyStickdataStruct.value[i]);
if (i != 5)
Serial.print(",");
// Serial.print(" ");
+19 -41
View File
@@ -1,65 +1,43 @@
#include <SPI.h>
#include "RF24.h"
#include <RF24Network.h>
#include "TransferDataStructure.h"
// Nrf24 settings
byte addresses[][6] = {"1Node", "2Node"};
RF24 radio(9, 10); // CE, CSN
RF24Network network(radio);
const uint16_t this_node = 00; // Address of our node in Octal format
const uint16_t other_node = 01; // Address of the other node in Octal format
void NrfInit()
{
SPI.begin();
radio.begin();
network.begin(/*channel*/ 90, /*node address*/ this_node);
// Set the PA Level low to prevent power supply related issues since this is a
// getting_started sketch, and the likelihood of close proximity of the devices. RF24_PA_MAX is default.
radio.setPALevel(RF24_PA_LOW);
radio.openWritingPipe(addresses[0]);
radio.openReadingPipe(1, addresses[1]);
// Possibly init data object here
radio.startListening();
}
dataStruct2 NrfSendData(dataStruct2 data, bool debug = false)
{
radio.stopListening();
// First, stop listening so we can talk.
network.update();
if (debug)
Serial.println(F("Now sending"));
Serial.print("Sending...");
if (!radio.write( &data, sizeof(data) )) {
if (debug)
Serial.println(F("failed"));
return data;
RF24NetworkHeader header(/*to node*/ other_node);
bool ok = network.write(header, &data, sizeof(data));
if (debug)
{
if (ok)
Serial.println("ok.");
else
Serial.println("failed.");
}
radio.startListening();
// Now, continue listening
unsigned long started_waiting_at = micros();
// Set up a timeout period, get the current microseconds
boolean timeout = false;
// Set up a variable to indicate if a response was received or not
while ( ! radio.available() ) {
if (micros() - started_waiting_at > 200000 ) {
// If waited longer than 200ms, indicate timeout and exit while loop
timeout = true;
break;
}
}
if ( timeout ) {
if (debug)
Serial.println(F("Failed, response timed out."));
return data;
} else {
// Grab the response, compare, and send to debugging spew
radio.read( &data, sizeof(data) );
return data;
}
return data;
}
+3 -3
View File
@@ -19,12 +19,12 @@ dataStruct2 GetSerialData(dataStruct2 dataIn, bool debug = false)
angle = data_word.substring(data_word.indexOf('_') + 1);
if (isDigit(angle[0])) // prevent error overwriting first entry.
// dataIn.servoPositions[channel.toInt()] = angle.toFloat();
dataIn.servoPositions[channel.toInt()] = angle.toFloat();
index = next_index + 1;
} while ((next_index != -1) && (next_index < maxIndex));
// dataIn.remotePasstroughControl = true;
dataIn.remotePasstroughControl = true;
if (debug)
{
@@ -35,7 +35,7 @@ dataStruct2 GetSerialData(dataStruct2 dataIn, bool debug = false)
{
Serial.print(i);
Serial.print(", ");
// Serial.print(dataIn.servoPositions[i]);
Serial.print(dataIn.servoPositions[i]);
Serial.println("");
}
Serial.println("");
+2 -3
View File
@@ -47,12 +47,11 @@ void loop() {
// Serial.print(" / AngZ = ");
// Serial.println(mpu.GetAngZ());
joystickData = JoystickGet(true);
joystickData = JoystickGet(false);
data = GetSerialData(data, false);
// data.servoPositions[0] = joystickData.value[0];
data.remotePasstroughControl = data.remotePasstroughControl + 1;
data.servoPositions[0] = joystickData.value[0];
data = NrfSendData(data, true);