Browse Source

Changed to using NRF to sync

master
Englebert 4 years ago
parent
commit
ccef0c6e9f
  1. 4
      OpenFlightTX.h
  2. 154
      OpenFlightTX.ino
  3. 5
      README.md

4
OpenFlightTX.h

@ -41,6 +41,10 @@ void setRegister(byte r, byte v);
byte getRegister(byte r);
void SignalHandler(void *pvParameters);
void setup_nrf_tx(void);
void rx_binding(void);
void setup_rxsync_server(void);
void setup_nrf_sync(void);
void restore_radio(void);
/*
void disableRX(void);

154
OpenFlightTX.ino

@ -3,19 +3,14 @@
* Manual - https://www.seeedstudio.com/blog/2019/07/05/u8g2-for-seeeduino-boards/
* Dual OLED - https://github.com/olikraus/u8g2/issues/77
*
*
* TODO:
* [ ] - Binding with receiver
* [ ] - HostAP for the receiver to bind
* [ ] - Changing transmission code
*
* Every power cycle:
* 1. Read configuration from EEPROM
* 2. Set the:
* a. Address: 0x0000 ~ 0xFFFF
* b. Channel: 0x00 ~ 0x1F (900Mhz ~ 931Mhz) (Default at 915Mhz) (Msia: 919 ~ 923)
* c. TXPower: 10dBm, 14dBm, 17dBm, 20dBm
* d. AirRate: 0.3kbps ~ 19.2kbps (Default at 2.4kbps)
*
* E32 ESP32 (OpenFlightTX Board)
* M0 - 2
* M1 - 5
* AUX - 4
*
*/
#include <Arduino.h>
@ -53,10 +48,11 @@
#define MAX_SAMPLES 100
int channel_loads[MAX_CHANNELS]; // Channel 0 ~ Channel 124
const uint64_t pipeIn = 0xE8E8F0F0E1LL; // TODO: set it to EEPROM
uint64_t pipeIn = 0xE8E8F0F0E1LL; // TODO: set it to EEPROM
RF24 radio(NRF24_CE, NRF24_CSN); // Starting up the module on GPIO5 (CE), GPIO4 (CSN)
bool nrf_enable = false;
bool nrf_scanner = false;
bool binding = false;
bool channel_used[MAX_CHANNELS];
uint8_t graph_type = 0;
uint32_t delay_maxrf_time = 0;
@ -75,6 +71,12 @@ struct TxMessage {
};
TxMessage txmessage;
struct SyncData {
uint8_t freq_channel;
uint64_t pipe;
};
SyncData syncdata;
bool wifi_enable = false;
bool webserver_setup = false;
@ -384,7 +386,7 @@ input[type=button] {
/*** Index Page ***/
const char* index_html PROGMEM = R"rawliteral(<pre><strong>OpenFlightTX v1.0.7</strong>
const char* index_html PROGMEM = R"rawliteral(<pre><strong>OpenFlightTX v1.0.9</strong>
)rawliteral";
// WebPages ----- END
@ -505,6 +507,7 @@ struct menu_entry_type menu_entry_alpha_list[] = {
{ u8g2_font_open_iconic_all_2x_t, 242, "Stick Positions"},
{ u8g2_font_open_iconic_all_2x_t, 246, "Trims"},
{ u8g2_font_open_iconic_all_2x_t, 281, "WiFi"},
{ u8g2_font_open_iconic_all_2x_t, 198, "RX Binding"},
{ u8g2_font_open_iconic_all_2x_t, 253, "RF Settings"},
{ u8g2_font_open_iconic_all_2x_t, 207, "RF Scanners"},
{ u8g2_font_open_iconic_all_2x_t, 90, "Battery"},
@ -1177,12 +1180,20 @@ void SignalHandler(void *pvParameters) {
txmessage.roll = map(roll_value, roll_min, roll_max, 1000, 2000);
txmessage.switches = switches_value;
// Sending Data ove NRF
// Sending Data over NRF
radio.write(&txmessage, sizeof(txmessage));
// Profiling..
nrf_profiling_raw++;
// delay(1);
} else if(binding) {
syncdata.freq_channel = freq_channel;
syncdata.pipe = pipeIn;
// Sending Data over NRF
radio.write(&syncdata, sizeof(syncdata));
nrf_profiling_raw++;
} else {
delay(10);
} // End of if(nrf_scanner)
@ -1321,7 +1332,7 @@ void loop() {
// u8g2_left.setFont(u8g2_font_micro_tr);
u8g2_left.setFont(u8g2_font_5x7_tf);
u8g2_left.setCursor(0,62);
u8g2_left.print(F("OpenFlightTX - 1.0"));
u8g2_left.print(F("OpenFlightTX - 1.0.9"));
// Battery
show_battery_level(115, 56);
@ -1337,6 +1348,10 @@ void loop() {
u8g2_left.setCursor(0, 55);
u8g2_left.print(WiFi.localIP());
}
} else if(binding) {
u8g2_left.setFont(u8g2_font_5x7_tf);
u8g2_left.setCursor(0, 55);
u8g2_left.print(F("RX Binding in Progress"));
}
u8g2_left.nextPage();
@ -1389,6 +1404,9 @@ void loop() {
} else if(menu_entry_alpha_list[destination_alpha_state.position].name == "RF Scanners") {
require_unlock = true;
rf_scanners();
} else if(menu_entry_alpha_list[destination_alpha_state.position].name == "RX Binding") {
require_unlock = false;
rx_binding();
}
//// u8g2_right.clearBuffer();
@ -2596,6 +2614,26 @@ void setup_nrf_scanner() {
nrf_scanner = true;
}
void setup_nrf_sync(void) {
// Setting NRF24L01
// printf_begin();
radio.begin();
// radio.setAutoAck(true);
radio.setAutoAck(false); // Seems like i am doing this on the last version...
radio.setPayloadSize(sizeof(SyncData));
radio.setChannel(0); // 0: Sync channel (2400MHz)
radio.setDataRate(RF24_250KBPS); // Lowest.. at 250kbps
radio.setPALevel(RF24_PA_MIN);
// delay_maxrf_time = millis() + 2000; // Delay 2 seconds later
// delay_maxrf = true;
// radio.setPALevel(RF24_PA_MAX); // Set the transmit power to Maximum... Later make it configurable.
const uint64_t pipe = 0x1111111111LL;
radio.openWritingPipe(pipe);
// radio.printDetails();
}
void setup_nrf_tx(void) {
// Setting NRF24L01
// printf_begin();
@ -2625,14 +2663,96 @@ void setup_nrf_tx(void) {
// radio.setPALevel(RF24_PA_MAX); // Set the transmit power to Maximum... Later make it configurable.
const uint64_t pipe = 0xE8E8F0F0E1LL;
radio.openWritingPipe(pipe);
// const uint64_t pipe = 0xE8E8F0F0E1LL;
radio.openWritingPipe(pipeIn);
// radio.printDetails();
Serial.println("SET nrf_scanner = TRUE");
nrf_enable = true;
}
void restore_radio(void) {
radio.setAutoAck(false);
radio.setPayloadSize(sizeof(TxMessage));
radio.setChannel(freq_channel);
switch(freq_txpower) { // Set the transmit power
case 0:
radio.setPALevel(RF24_PA_MIN);
break;
case 1:
radio.setPALevel(RF24_PA_LOW);
break;
case 2:
radio.setPALevel(RF24_PA_HIGH);
break;
case 3:
radio.setPALevel(RF24_PA_MAX);
break;
}
// const uint64_t pipe = 0xE8E8F0F0E1LL;
radio.openWritingPipe(pipeIn);
nrf_enable = true;
}
void setup_rxsync_server(void) {
static char sync_html[128];
sprintf(sync_html, "%d|%ld", freq_channel, pipeIn);
server.on("/", HTTP_GET, []() {
server.sendHeader("Connection", "close");
server.send(200, "text/html", sync_html);
});
// Starting up Server
server.begin();
}
void rx_binding(void) {
u8g2_left.clearBuffer();
u8g2_left.firstPage();
static bool binding_selections = false;
u8g2_left.setFont(u8g2_font_ImpactBits_tr);
u8g2_left.setCursor(15, 25);
u8g2_left.print(F("Enable Binding?"));
u8g2_left.setCursor(30, 55);
u8g2_left.print(F("Yes No"));
// TODO: Working on WiFi. Manually on...
if(stick_navigation_position == MENU_LEFT) {
binding_selections = true;
} else if(stick_navigation_position == MENU_RIGHT) {
binding_selections = false;
} else if(stick_navigation_position == MENU_OK) {
// Wifi...
if(binding_selections) {
if(!binding) {
// WiFi.softAP("OpenFlightTX", "12345678");
setup_nrf_sync();
// setup_rxsync_server();
binding = true;
}
} else {
binding = false;
restore_radio();
}
// Simulate...so it will return back..
menu_entry_alpha_selected = false;
last_menu_stick_read = millis() + 200;
}
if(binding_selections) {
u8g2_left.drawFrame(26, 40, 30, 20);
} else {
u8g2_left.drawFrame(62, 40, 30, 20);
}
// Just need to know the receiver's channel, encryption code
u8g2_left.nextPage();
}
void rf_scanners(void) {
int y = 0;
static char buf[10];

5
README.md

@ -20,3 +20,8 @@ TTTTTTTTTTTTYYYYYYYYYYYYPPPPPPPPPPPPRRRRRRRRRRRRSSSSSSSSCCCCCCCC
TTTT TTTT TTTT ---- YYYY YYYY YYYY ---- PPPP PPPP PPPP ---- RRRR RRRR RRRR ---- SSSS SSSS = 72-bits ( 9 bytes )
TTTT TTTT TTTT ---- YYYY YYYY YYYY ---- PPPP PPPP PPPP ---- RRRR RRRR RRRR ---- SSSS SSSS CCCC CCCC = 80-bits ( 10 bytes )
TTTTTTTTTTTT----YYYYYYYYYYYY----PPPPPPPPPPPP----RRRRRRRRRRRR----SSSSSSSSCCCCCCCC
### Steps to binding with receiver
1. Turn on Binding mode at TX
2. Turn on Receiver
3. Once receiver started within 10 seconds, it will auto bind and linked. LED will lit up.
Loading…
Cancel
Save