|
|
@ -5,7 +5,12 @@ |
|
|
|
* |
|
|
|
* Every power cycle: |
|
|
|
* 1. Read configuration from EEPROM |
|
|
|
* |
|
|
|
* |
|
|
|
* TODO: |
|
|
|
* 1. Reboot from menu |
|
|
|
* 2. Add current reading [ NOT WORKING DUE TO WRONG RESISTOR ] |
|
|
|
* 3. Add one more switch channel at D2 [ DONE ] |
|
|
|
* 4. Added another channel to the receiving side and slit into the throttle value. [ DONE ] |
|
|
|
*/ |
|
|
|
|
|
|
|
#include <Arduino.h>
|
|
|
@ -40,7 +45,7 @@ |
|
|
|
|
|
|
|
// For channel scanner
|
|
|
|
#define MAX_CHANNELS 125
|
|
|
|
#define MAX_SAMPLES 30
|
|
|
|
#define MAX_SAMPLES 10
|
|
|
|
|
|
|
|
// For RC Deadband
|
|
|
|
#define RC_DEADBAND 5
|
|
|
@ -386,7 +391,7 @@ input[type=button] { |
|
|
|
|
|
|
|
|
|
|
|
/*** Index Page ***/ |
|
|
|
const char* index_html PROGMEM = R"rawliteral(<pre><strong>OpenFlightTX v1.2.4</strong> |
|
|
|
const char* index_html PROGMEM = R"rawliteral(<pre><strong>OpenFlightTX v1.2.5</strong> |
|
|
|
)rawliteral"; |
|
|
|
|
|
|
|
// WebPages ----- END
|
|
|
@ -513,6 +518,7 @@ struct menu_entry_type menu_entry_alpha_list[] = { |
|
|
|
{ u8g2_font_open_iconic_all_2x_t, 90, "Battery"}, |
|
|
|
{ u8g2_font_open_iconic_all_2x_t, 142, "Save Settings"}, |
|
|
|
{ u8g2_font_open_iconic_all_2x_t, 205, "Reset Default"}, |
|
|
|
{ u8g2_font_open_iconic_all_2x_t, 235, "Reboot"}, |
|
|
|
{ NULL, 0, NULL } |
|
|
|
}; |
|
|
|
|
|
|
@ -617,9 +623,9 @@ uint32_t last_nrf_scanned = 0; |
|
|
|
uint32_t last_ble_sent = 0; |
|
|
|
|
|
|
|
//define the pins used by the transceiver module
|
|
|
|
#define SS 5
|
|
|
|
#define RST 14
|
|
|
|
#define DIO0 2
|
|
|
|
// #define SS 5
|
|
|
|
// #define RST 14
|
|
|
|
// #define DIO0 2
|
|
|
|
|
|
|
|
int counter = 0; |
|
|
|
|
|
|
@ -630,7 +636,7 @@ int counter = 0; |
|
|
|
#define ROLL_PIN 35
|
|
|
|
|
|
|
|
#define VBAT_PIN 32
|
|
|
|
#define VCC_PIN 33
|
|
|
|
#define VCUR_PIN 33
|
|
|
|
|
|
|
|
#define SW1_PIN 25
|
|
|
|
#define SW2_PIN 26
|
|
|
@ -640,6 +646,10 @@ int counter = 0; |
|
|
|
#define SW6_PIN 13
|
|
|
|
#define SW7_PIN 17
|
|
|
|
#define SW8_PIN 16
|
|
|
|
#define SW9_PIN 2
|
|
|
|
|
|
|
|
// Accidentally shorted the pin for buzzer. So I am turning it to be the same as SW9_PIN
|
|
|
|
#define SW9_PIN_SHORTED 15
|
|
|
|
|
|
|
|
uint16_t throttle_raw = 0; |
|
|
|
uint16_t yaw_raw = 0; |
|
|
@ -647,13 +657,14 @@ uint16_t pitch_raw = 0; |
|
|
|
uint16_t roll_raw = 0; |
|
|
|
|
|
|
|
uint16_t vbat_raw = 0; |
|
|
|
uint16_t vcc_raw = 0; |
|
|
|
uint16_t vcur_raw = 0; |
|
|
|
|
|
|
|
uint16_t throttle_value = 0; |
|
|
|
uint16_t yaw_value = 0; |
|
|
|
uint16_t pitch_value = 0; |
|
|
|
uint16_t roll_value = 0; |
|
|
|
uint64_t vbat_value = 0; |
|
|
|
uint64_t vcur_value = 0; |
|
|
|
/*
|
|
|
|
uint16_t tx_throttle = 0; |
|
|
|
uint16_t tx_yaw = 0; |
|
|
@ -682,6 +693,7 @@ bool sw5 = 0; |
|
|
|
bool sw6 = 0; |
|
|
|
bool sw7 = 0; |
|
|
|
bool sw8 = 0; |
|
|
|
bool sw9 = 0; |
|
|
|
|
|
|
|
uint8_t switches_value = 0; |
|
|
|
|
|
|
@ -710,6 +722,7 @@ uint32_t uptime = 0; |
|
|
|
#define PITCH 2
|
|
|
|
#define ROLL 3
|
|
|
|
#define VBAT 4
|
|
|
|
#define VCUR 5
|
|
|
|
|
|
|
|
uint64_t last_update = 0; |
|
|
|
uint64_t update_delay = 0; |
|
|
@ -721,6 +734,7 @@ uint16_t yaw_pool[MEDIAN_TOTAL]; |
|
|
|
uint16_t pitch_pool[MEDIAN_TOTAL]; |
|
|
|
uint16_t roll_pool[MEDIAN_TOTAL]; |
|
|
|
uint16_t vbat_pool[MEDIAN_TOTAL]; |
|
|
|
uint16_t vcur_pool[MEDIAN_TOTAL]; |
|
|
|
|
|
|
|
uint16_t tmp_median_store[MEDIAN_TOTAL]; |
|
|
|
|
|
|
@ -785,7 +799,9 @@ uint16_t median_get(uint8_t median_type) { |
|
|
|
median_tmp[0] = roll_pool[0]; |
|
|
|
} else if(median_type == VBAT) { |
|
|
|
median_tmp[0] = vbat_pool[0]; |
|
|
|
} |
|
|
|
} else if(median_type == VCUR) { |
|
|
|
median_tmp[0] = vcur_pool[0]; |
|
|
|
} |
|
|
|
|
|
|
|
// Loop insert and sort
|
|
|
|
for(int raw_count = 1; raw_count < MEDIAN_TOTAL; raw_count++) { |
|
|
@ -801,6 +817,8 @@ uint16_t median_get(uint8_t median_type) { |
|
|
|
temp_val = roll_pool[raw_count]; |
|
|
|
} else if(median_type == VBAT) { |
|
|
|
temp_val = vbat_pool[raw_count]; |
|
|
|
} else if(median_type == VCUR) { |
|
|
|
temp_val = vcur_pool[raw_count]; |
|
|
|
} |
|
|
|
|
|
|
|
for(int median_count = 0; median_count < total_insert; median_count++) { |
|
|
@ -882,6 +900,8 @@ uint16_t median_get(uint8_t median_type) { |
|
|
|
} |
|
|
|
} else if(median_type == VBAT) { |
|
|
|
return median_tmp[MEDIAN_POS]; |
|
|
|
} else if(median_type == VCUR) { |
|
|
|
return median_tmp[MEDIAN_POS]; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
@ -955,6 +975,8 @@ uint16_t pool_insert(uint8_t pool_type, uint16_t val) { |
|
|
|
roll_pool[i - 1] = roll_pool[i]; |
|
|
|
} else if(pool_type == VBAT) { |
|
|
|
vbat_pool[i - 1] = vbat_pool[i]; |
|
|
|
} else if(pool_type == VCUR) { |
|
|
|
vcur_pool[i - 1] = vcur_pool[i]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -969,6 +991,8 @@ uint16_t pool_insert(uint8_t pool_type, uint16_t val) { |
|
|
|
pitch_pool[MEDIAN_TOTAL - 1] = val; |
|
|
|
} else if(pool_type == VBAT) { |
|
|
|
vbat_pool[MEDIAN_TOTAL - 1] = val; |
|
|
|
} else if(pool_type == VCUR) { |
|
|
|
vcur_pool[MEDIAN_TOTAL - 1] = val; |
|
|
|
} |
|
|
|
return median_get(pool_type); |
|
|
|
} |
|
|
@ -1016,6 +1040,7 @@ void read_all_voltage() { |
|
|
|
roll_raw = analogRead(ROLL_PIN) + 150; |
|
|
|
} |
|
|
|
vbat_raw = analogRead(VBAT_PIN); |
|
|
|
// vcur_raw = analogRead(VCUR_PIN);
|
|
|
|
|
|
|
|
// Serial.print("T:");Serial.print(throttle_raw);Serial.print(" Y:");Serial.print(yaw_raw);Serial.print(" P:");Serial.print(pitch_raw);Serial.print("R:");Serial.println(roll_raw);
|
|
|
|
|
|
|
@ -1027,6 +1052,7 @@ void read_all_voltage() { |
|
|
|
sw6 = !digitalRead(SW6_PIN); |
|
|
|
sw7 = !digitalRead(SW7_PIN); |
|
|
|
sw8 = !digitalRead(SW8_PIN); |
|
|
|
sw9 = !digitalRead(SW9_PIN); |
|
|
|
|
|
|
|
// Combine values to one byte...
|
|
|
|
// NNssssss
|
|
|
@ -1062,7 +1088,9 @@ void read_all_voltage() { |
|
|
|
roll_value = pool_insert(ROLL, roll_raw) + (trim_roll << 3); |
|
|
|
else |
|
|
|
roll_value = pool_insert(ROLL, roll_raw) - (trim_roll << 3); |
|
|
|
|
|
|
|
vbat_value = pool_insert(VBAT, vbat_raw); |
|
|
|
// vcur_value = pool_insert(VCUR, vcur_raw);
|
|
|
|
} |
|
|
|
|
|
|
|
void battery_management() { |
|
|
@ -1117,7 +1145,7 @@ void setup() { |
|
|
|
EEPROM.begin(512); |
|
|
|
|
|
|
|
// PIN Initialization
|
|
|
|
pinMode(BUZZER_PIN, OUTPUT); |
|
|
|
// pinMode(BUZZER_PIN, OUTPUT);
|
|
|
|
pinMode(SW1_PIN, INPUT_PULLUP); |
|
|
|
pinMode(SW2_PIN, INPUT_PULLUP); |
|
|
|
pinMode(SW3_PIN, INPUT_PULLUP); |
|
|
@ -1126,6 +1154,8 @@ void setup() { |
|
|
|
pinMode(SW6_PIN, INPUT_PULLUP); |
|
|
|
pinMode(SW7_PIN, INPUT_PULLUP); |
|
|
|
pinMode(SW8_PIN, INPUT_PULLUP); |
|
|
|
pinMode(SW9_PIN, INPUT_PULLUP); |
|
|
|
pinMode(SW9_PIN_SHORTED, INPUT_PULLUP); |
|
|
|
|
|
|
|
// For more precise analog readings
|
|
|
|
// analogSetCycles(128);
|
|
|
@ -1478,7 +1508,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.4")); |
|
|
|
u8g2_left.print(F("OpenFlightTX - 1.2.5")); |
|
|
|
|
|
|
|
// Battery
|
|
|
|
show_battery_level(115, 56); |
|
|
@ -1557,6 +1587,9 @@ void update_display(void) { |
|
|
|
} else if(menu_entry_alpha_list[destination_alpha_state.position].name == "RX Binding") { |
|
|
|
require_unlock = false; |
|
|
|
rx_binding(); |
|
|
|
} else if(menu_entry_alpha_list[destination_alpha_state.position].name == "Reboot") { |
|
|
|
require_unlock = false; |
|
|
|
reboot_system(); |
|
|
|
} |
|
|
|
|
|
|
|
//// u8g2_right.clearBuffer();
|
|
|
@ -1611,8 +1644,8 @@ void tx_data(void) { |
|
|
|
} |
|
|
|
} |
|
|
|
// Debug
|
|
|
|
Serial.print("Channel: "); |
|
|
|
Serial.println(i); |
|
|
|
// Serial.print("Channel: ");
|
|
|
|
// Serial.println(i);
|
|
|
|
} |
|
|
|
|
|
|
|
// Wait for next second...
|
|
|
@ -1634,7 +1667,12 @@ void tx_data(void) { |
|
|
|
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.throttle = map(throttle_value, throttle_min, throttle_max, 1000, 2000);
|
|
|
|
|
|
|
|
// 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); |
|
|
@ -1771,10 +1809,10 @@ void rc_controller(void) { |
|
|
|
|
|
|
|
switch(freq_txpower) { |
|
|
|
case 0: |
|
|
|
sprintf(buf, "TX MIN"); |
|
|
|
sprintf(buf, "TX LOW"); |
|
|
|
break; |
|
|
|
case 1: |
|
|
|
sprintf(buf, "TX LOW"); |
|
|
|
sprintf(buf, "TX MIN"); |
|
|
|
break; |
|
|
|
case 2: |
|
|
|
sprintf(buf, "TX HIGH"); |
|
|
@ -1825,6 +1863,24 @@ void rc_controller(void) { |
|
|
|
u8g2_left.print(F("G")); |
|
|
|
} |
|
|
|
|
|
|
|
if(sw9) { |
|
|
|
u8g2_left.setCursor(35, 48); |
|
|
|
u8g2_left.print(F("H")); |
|
|
|
} |
|
|
|
|
|
|
|
// Display current usage
|
|
|
|
/***** Fix the resistor to read the right values.
|
|
|
|
u8g2_left.setCursor(0, 56); |
|
|
|
sprintf(buf, "%d A", vcur_raw); |
|
|
|
u8g2_left.drawStr(0, 56, buf); |
|
|
|
****/ |
|
|
|
|
|
|
|
/*
|
|
|
|
u8g2_left.setCursor(0,56); |
|
|
|
String debugMe = String(analogRead(2)); |
|
|
|
u8g2_left.print(debugMe); |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
u8g2_left.nextPage(); |
|
|
|
} |
|
|
@ -1863,14 +1919,14 @@ void stick_trims(void) { |
|
|
|
// Limit counts
|
|
|
|
if(stick_position_pointer > 3) stick_position_pointer = 0; |
|
|
|
|
|
|
|
if(trim_throttle < -15) trim_throttle = -15; |
|
|
|
if(trim_throttle > 15) trim_throttle = 15; |
|
|
|
if(trim_yaw < -15) trim_yaw = -15; |
|
|
|
if(trim_yaw > 15) trim_yaw = 15; |
|
|
|
if(trim_pitch < -15) trim_pitch = -15; |
|
|
|
if(trim_pitch > 15) trim_pitch = 15; |
|
|
|
if(trim_roll < -15) trim_roll = -15; |
|
|
|
if(trim_roll > 15) trim_roll = 15; |
|
|
|
if(trim_throttle < -30) trim_throttle = -30; |
|
|
|
if(trim_throttle > 30) trim_throttle = 30; |
|
|
|
if(trim_yaw < -30) trim_yaw = -30; |
|
|
|
if(trim_yaw > 30) trim_yaw = 30; |
|
|
|
if(trim_pitch < -30) trim_pitch = -30; |
|
|
|
if(trim_pitch > 30) trim_pitch = 30; |
|
|
|
if(trim_roll < -30) trim_roll = -30; |
|
|
|
if(trim_roll > 30) trim_roll = 30; |
|
|
|
|
|
|
|
// Displaying...
|
|
|
|
u8g2_left.clearBuffer(); |
|
|
@ -2801,6 +2857,51 @@ void show_battery_level(uint8_t x, uint8_t y) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void reboot_system(void) { |
|
|
|
u8g2_left.clearBuffer(); |
|
|
|
u8g2_left.firstPage(); |
|
|
|
u8g2_left.setFontMode(1); |
|
|
|
u8g2_left.setFont(u8g2_font_VCR_OSD_tr); |
|
|
|
|
|
|
|
static char buf[6]; |
|
|
|
|
|
|
|
// u8g2_left.drawStr(45, 15, buf);
|
|
|
|
// strcpy(buf, ltoa(vbat_value, buf, 10));
|
|
|
|
// u8g2_left.drawStr(0, 30, buf);
|
|
|
|
|
|
|
|
static bool wifi_selections = false; |
|
|
|
|
|
|
|
u8g2_left.setFont(u8g2_font_ImpactBits_tr); |
|
|
|
u8g2_left.setCursor(15, 25); |
|
|
|
u8g2_left.print(F("Reboot System?")); |
|
|
|
u8g2_left.setCursor(30, 55); |
|
|
|
u8g2_left.print(F("Yes No")); |
|
|
|
|
|
|
|
// TODO: Working on WiFi. Manually on...
|
|
|
|
if(stick_navigation_position == MENU_LEFT) { |
|
|
|
wifi_selections = true; |
|
|
|
} else if(stick_navigation_position == MENU_RIGHT) { |
|
|
|
wifi_selections = false; |
|
|
|
} else if(stick_navigation_position == MENU_OK) { |
|
|
|
// Wifi...
|
|
|
|
if(wifi_selections) { |
|
|
|
reboot(); |
|
|
|
} |
|
|
|
|
|
|
|
// Simulate...so it will return back..
|
|
|
|
menu_entry_alpha_selected = false; |
|
|
|
last_menu_stick_read = millis() + 200; |
|
|
|
} |
|
|
|
|
|
|
|
if(wifi_selections) { |
|
|
|
u8g2_left.drawFrame(26, 40, 30, 20); |
|
|
|
} else { |
|
|
|
u8g2_left.drawFrame(62, 40, 30, 20); |
|
|
|
} |
|
|
|
u8g2_left.nextPage(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
void wifi_enabler(void) { |
|
|
|
/*
|
|
|
|
u8g2_left.clearBuffer(); |
|
|
|