Browse Source

Temporary removed core 0 and put back all codes to core 1 for stability.

master
Englebert 4 years ago
parent
commit
182dfb50aa
  1. 2
      OpenFlightTX.h
  2. 152
      OpenFlightTX.ino

2
OpenFlightTX.h

@ -45,6 +45,8 @@ void rx_binding(void);
void setup_rxsync_server(void);
void setup_nrf_sync(void);
void restore_radio(void);
void tx_data(void);
void update_display(void);
/*
void disableRX(void);

152
OpenFlightTX.ino

@ -704,6 +704,7 @@ uint32_t uptime = 0;
#define VBAT 4
uint64_t last_update = 0;
uint64_t update_delay = 0;
uint64_t last_menu_stick_read = 0;
uint64_t last_menu_item_moved = 0;
@ -1103,18 +1104,18 @@ void setup() {
/* Starting up 2nd core... */
// Creating Lora Task on Core 0. This will keep sending over and over again...
xTaskCreatePinnedToCore(
SignalHandler, /* Task function. */
"SignalHandler", /* name of task. */
10000, /* Stack size of task */
NULL, /* parameter of the task */
0, /* priority of the task */
&SignalTask, /* Task handle to keep track of created task */
0); /* pin task to core 0 */
// xTaskCreatePinnedToCore(
// SignalHandler, /* Task function. */
// "SignalHandler", /* name of task. */
// 10000, /* Stack size of task */
// NULL, /* parameter of the task */
// 0, /* priority of the task */
// &SignalTask, /* Task handle to keep track of created task */
// 0); /* pin task to core 0 */
//
}
// Sending / Receive signals at Core 0
/*
void SignalHandler(void *pvParameters) {
// Forever loop in this loop :P
for(;;) {
@ -1200,6 +1201,7 @@ void SignalHandler(void *pvParameters) {
} // End of for(;;)
}
*/
void loop() {
@ -1252,6 +1254,12 @@ void loop() {
read_all_voltage();
/* Sending Signal */
tx_data();
// Update display
update_display();
// Serial.println(throttle_raw + " : " + yaw_raw);
/*
Serial.print("T [");
@ -1271,6 +1279,28 @@ void loop() {
Serial.println(sw6);
*/
/*
//if(millis() - last_update >= 2) {
// Send LoRa packet to receiver
//while(true) {
LoRa.setTxPower(20);
LoRa.beginPacket();
// LoRa.print("hello ");
LoRa.print(counter);
LoRa.endPacket();
counter++;
//delay(100);
// delayMicroseconds(1500);
// }
last_update = millis();
//}
*/
}
void update_display(void) {
if(millis() > last_update) {
// Determine stick position
if(millis() > last_menu_stick_read) {
@ -1310,6 +1340,9 @@ void loop() {
if(
!menu_entry_alpha_selected
) {
// Must be out of the menu...
update_delay = 10;
// Determine the menu position
if(stick_navigation_position == MENU_RIGHT) {
to_right(&destination_alpha_state);
@ -1371,8 +1404,10 @@ void loop() {
// u8g2_right.sendBuffer();
}
} else {
update_delay = 10;
if(menu_entry_alpha_list[destination_alpha_state.position].name == "RC Controller") {
require_unlock = true;
update_delay = 100;
rc_controller();
} else if(menu_entry_alpha_list[destination_alpha_state.position].name == "Battery") {
require_unlock = false;
@ -1427,27 +1462,90 @@ void loop() {
}
last_update = millis() + 1;
last_update = millis() + update_delay;
}
}
/*
//if(millis() - last_update >= 2) {
// Send LoRa packet to receiver
//while(true) {
LoRa.setTxPower(20);
LoRa.beginPacket();
// LoRa.print("hello ");
LoRa.print(counter);
LoRa.endPacket();
counter++;
//delay(100);
// delayMicroseconds(1500);
// }
void tx_data(void) {
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++) {
last_update = millis();
//}
*/
// 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)
}
void rx_checker(void) {

Loading…
Cancel
Save