From c3958b5eec5287f23f038d35d1aa7e180f071a3d Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 26 May 2019 22:58:04 +0200 Subject: [PATCH] wireless working --- Joysticks.h | 2 +- Nrf.h | 60 +++++++++++++++------------------------------- SerialPasstrough.h | 8 +++---- remote.ino | 5 ++-- 4 files changed, 26 insertions(+), 49 deletions(-) diff --git a/Joysticks.h b/Joysticks.h index eff45ab..81cb537 100644 --- a/Joysticks.h +++ b/Joysticks.h @@ -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(" "); diff --git a/Nrf.h b/Nrf.h index 93c4a56..4c0348d 100644 --- a/Nrf.h +++ b/Nrf.h @@ -1,65 +1,43 @@ #include #include "RF24.h" +#include #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; } diff --git a/SerialPasstrough.h b/SerialPasstrough.h index 3bdc98f..9b8648e 100644 --- a/SerialPasstrough.h +++ b/SerialPasstrough.h @@ -19,23 +19,23 @@ 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) { Serial.println("Enabled Servo Passtrough mode!"); - + Serial.println("Output line: "); for (int i = 0; i < 18; i++) { Serial.print(i); Serial.print(", "); -// Serial.print(dataIn.servoPositions[i]); + Serial.print(dataIn.servoPositions[i]); Serial.println(""); } Serial.println(""); diff --git a/remote.ino b/remote.ino index 31d73a1..3f80c7f 100644 --- a/remote.ino +++ b/remote.ino @@ -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);