Browse Source

Changed the transmission structure to be less and faster

master
Englebert 3 years ago
parent
commit
1230fff5fe
  1. 177
      OpenFlightTX.ino

177
OpenFlightTX.ino

@ -64,14 +64,22 @@ bool delay_maxrf = false;
TaskHandle_t SignalTask;
// Data Structure:
// Old format:
// TTTT TTTT TTTT ---- YYYY YYYY YYYY ---- PPPP PPPP PPPP ---- RRRR RRRR RRRR ---- SSSS SSSS = 72-bits ( 9 bytes )
// Data Structure
//
// 2021 New Data format for saving 2 bytes:
// 1234 5678 9TTT TTTT TTTT -YYY YYYY YYYY -PPP PPPP PPPP -RRR RRRR RRRR (7 Bytes)
// |-------| |-------| |-------| |-------| |-------| |-------| |-------|
// Byte 00 Byte 01 Byte 02 Byte 03 Byte 04 Byte 05 Byte 06
struct TxMessage {
uint16_t throttle;
uint16_t yaw;
uint16_t pitch;
uint16_t roll;
uint8_t switches;
uint8_t Byte00;
uint8_t Byte01;
uint8_t Byte02;
uint8_t Byte03;
uint8_t Byte04;
uint8_t Byte05;
uint8_t Byte06;
};
TxMessage txmessage;
@ -391,7 +399,7 @@ input[type=button] {
/*** Index Page ***/
const char* index_html PROGMEM = R"rawliteral(<pre><strong>OpenFlightTX v1.2.5</strong>
const char* index_html PROGMEM = R"rawliteral(<pre><strong>OpenFlightTX v1.2.6</strong>
)rawliteral";
// WebPages ----- END
@ -685,17 +693,17 @@ uint16_t roll_min = 4096;
uint8_t freq_channel = 0;
uint8_t freq_txpower = 0; // 0: LOW, 1: MIN, 2: HIGH, 3: MAX
bool sw1 = 0;
bool sw2 = 0;
bool sw3 = 0;
bool sw4 = 0;
bool sw5 = 0;
bool sw6 = 0;
bool sw7 = 0;
bool sw8 = 0;
bool sw9 = 0;
uint8_t sw1 = 0;
uint8_t sw2 = 0;
uint8_t sw3 = 0;
uint8_t sw4 = 0;
uint8_t sw5 = 0;
uint8_t sw6 = 0;
uint8_t sw7 = 0;
uint8_t sw8 = 0;
uint8_t sw9 = 0;
uint8_t switches_value = 0;
// uint8_t switches_value = 0;
bool invert_throttle = false;
bool invert_yaw = false;
@ -1058,6 +1066,7 @@ void read_all_voltage() {
// NNssssss
// IIwwwwww
// switches_value = LL654321
/********
switches_value = 0;
switches_value |= (sw8) ? 1 << 7 : 0;
switches_value |= (sw7) ? 1 << 6 : 0;
@ -1067,6 +1076,7 @@ void read_all_voltage() {
switches_value |= (sw3) ? 1 << 2 : 0;
switches_value |= (sw2) ? 1 << 1 : 0;
switches_value |= (sw1) ? 1 << 0 : 0;
********/
throttle_value = pool_insert(THROTTLE, throttle_raw);
if(!invert_throttle)
@ -1245,95 +1255,23 @@ void setup() {
// 0); /* pin task to core 0 */
//
Serial.println(F("OpenFlightTX is Running"));
}
/*
void SignalHandler(void *pvParameters) {
// Forever loop in this loop :P
for(;;) {
if(nrf_scanner == true) {
if(millis() > last_nrf_scanned) {
Serial.println("Inside nrf_scanner loop...");
// Collecting X number of samples on each channel
for(int i = 0; i < MAX_CHANNELS; i++) {
channel_loads[i] = 0x00;
for(int j = 0; j < MAX_SAMPLES; j++) {
// Select a new channel...
radio.setChannel(i);
// Listening for a while
radio.startListening();
// Delay for a while...
delayMicroseconds(128);
// Stop Listening
radio.stopListening();
// Read out RPD flag... set to 1 if received power > -64dBm
// return ( read_register(RPD) & 1 ) ;
if(radio.testCarrier()) {
channel_loads[i]++;
}
}
// Debug
Serial.print("Channel: ");
Serial.println(i);
}
// Wait for next second...
last_nrf_scanned = millis() + 100;
}
} else if(nrf_enable) {
// Disable it first...
if(nrf_scanner)
nrf_scanner = false;
// Assign values...
throttle_value = (throttle_value > throttle_max) ? throttle_max : throttle_value; // Play safe... before mapping
throttle_value = (throttle_value < throttle_min) ? throttle_min : throttle_value;
yaw_value = (yaw_value > yaw_max) ? yaw_max : yaw_value; // Play safe... before mapping
yaw_value = (yaw_value < yaw_min) ? yaw_min : yaw_value;
pitch_value = (pitch_value > pitch_max) ? pitch_max : pitch_value; // Play safe... before mapping
pitch_value = (pitch_value < pitch_min) ? pitch_min : pitch_value;
roll_value = (roll_value > roll_max) ? roll_max : roll_value; // Play safe... before mapping
roll_value = (roll_value < roll_min) ? roll_min : roll_value;
// Mapping before sending...
txmessage.throttle = map(throttle_value, throttle_min, throttle_max, 1000, 2000);
txmessage.yaw = map(yaw_value, yaw_min, yaw_max, 2000, 1000);
txmessage.pitch = map(pitch_value, pitch_min, pitch_max, 2000, 1000);
txmessage.roll = map(roll_value, roll_min, roll_max, 1000, 2000);
txmessage.switches = switches_value;
// Sending Data over NRF
radio.write(&txmessage, sizeof(txmessage));
// Profiling..
nrf_profiling_raw++;
// delay(1);
} else if(binding) {
Serial.print(F("Sending Binding Channel:"));
Serial.println(freq_channel);
syncdata.freq_channel = (uint8_t) freq_channel;
syncdata.dummy = 100;
syncdata.fixed = 88;
// syncdata.pipe = pipeIn;
// Sending Data over NRF
radio.write(&syncdata, sizeof(SyncData));
nrf_profiling_raw++;
} else {
delay(1);
} // End of if(nrf_scanner)
} // End of for(;;)
// Enabling wifi if all switches is at ON position
read_all_voltage();
if(
sw1 == 1 &&
sw2 == 1 &&
sw3 == 1 &&
sw4 == 1 &&
sw5 == 1 &&
sw6 == 1 &&
sw7 == 1 &&
sw8 == 1 &&
sw9 == 1
) {
wifi_enable = true;
}
}
*/
void loop() {
@ -1508,7 +1446,7 @@ void update_display(void) {
// 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.2.5"));
u8g2_left.print(F("OpenFlightTX - 1.2.6"));
// Battery
show_battery_level(115, 56);
@ -1671,12 +1609,31 @@ void tx_data(void) {
// Trying to add in another bits of the switch here so we can save more bandwidth using the same rate
// txmessage.throttle = map(throttle_value, throttle_min, throttle_max, 1000, 2000);
txmessage.throttle = (sw9) ? 1 << 15 + map(throttle_value, throttle_min, throttle_max, 1000, 2000) : map(throttle_value, throttle_min, throttle_max, 1000, 2000);
txmessage.yaw = map(yaw_value, yaw_min, yaw_max, 2000, 1000);
txmessage.pitch = map(pitch_value, pitch_min, pitch_max, 2000, 1000);
txmessage.roll = map(roll_value, roll_min, roll_max, 1000, 2000);
txmessage.switches = switches_value;
// 1234 5678 9TTT TTTT TTTT -YYY YYYY YYYY -PPP PPPP PPPP -RRR RRRR RRRR (7 Bytes)
// |-------| |-------| |-------| |-------| |-------| |-------| |-------|
// Byte 00 Byte 01 Byte 02 Byte 03 Byte 04 Byte 05 Byte 06
// Generating the data
uint16_t raw_data1 = 0;
uint16_t raw_data2 = 0;
// Byte00 ~ Byte06 - START
raw_data1 = map(throttle_value, throttle_min, throttle_max, 1000, 2000);
txmessage.Byte00 = sw1 << 7 | sw2 << 6 | sw3 << 5 | sw4 << 4 | sw5 << 3 | sw6 << 2 | sw7 << 1 | sw8;
txmessage.Byte01 = sw9 << 7 | (raw_data1 >> 4);
raw_data2 = map(yaw_value, yaw_min, yaw_max, 2000, 1000);
txmessage.Byte02 = (raw_data1 & 0x000F) << 4 | raw_data2 >> 8;
txmessage.Byte03 = (raw_data2 & 0x00FF);
raw_data1 = map(pitch_value, pitch_min, pitch_max, 2000, 1000);
txmessage.Byte04 = raw_data1 >> 4;
raw_data2 = map(roll_value, roll_min, roll_max, 1000, 2000);
txmessage.Byte05 = (raw_data1 & 0x000F) << 4 | raw_data2 >> 8;
txmessage.Byte06 = (raw_data2 & 0x00FF);
// Byte00 ~ Byte06 - END
// Sending Data over NRF
radio.write(&txmessage, sizeof(txmessage));

Loading…
Cancel
Save