Browse Source

Added new switch and also commiting old codes.

master
Englebert 3 years ago
parent
commit
f0ec73f8a3
  1. 82
      OpenFlightTX.ino

82
OpenFlightTX.ino

@ -51,6 +51,7 @@ RF24 radio(NRF24_CE, NRF24_CSN); // Starting up the module on GPIO5 (
bool nrf_enable = false;
bool nrf_scanner = false;
bool binding = false;
bool need_to_initialize = false;
bool channel_used[MAX_CHANNELS];
uint8_t graph_type = 0;
uint32_t delay_maxrf_time = 0;
@ -637,6 +638,8 @@ int counter = 0;
#define SW4_PIN 14
#define SW5_PIN 12
#define SW6_PIN 13
#define SW7_PIN 17
#define SW8_PIN 16
uint16_t throttle_raw = 0;
uint16_t yaw_raw = 0;
@ -677,6 +680,8 @@ bool sw3 = 0;
bool sw4 = 0;
bool sw5 = 0;
bool sw6 = 0;
bool sw7 = 0;
bool sw8 = 0;
uint8_t switches_value = 0;
@ -1020,12 +1025,16 @@ void read_all_voltage() {
sw4 = !digitalRead(SW4_PIN);
sw5 = !digitalRead(SW5_PIN);
sw6 = !digitalRead(SW6_PIN);
sw7 = !digitalRead(SW7_PIN);
sw8 = !digitalRead(SW8_PIN);
// Combine values to one byte...
// NNssssss
// IIwwwwww
// switches_value = LL654321
switches_value = 0;
switches_value |= (sw8) ? 1 << 7 : 0;
switches_value |= (sw7) ? 1 << 6 : 0;
switches_value |= (sw6) ? 1 << 5 : 0;
switches_value |= (sw5) ? 1 << 4 : 0;
switches_value |= (sw4) ? 1 << 3 : 0;
@ -1115,6 +1124,8 @@ void setup() {
pinMode(SW4_PIN, INPUT_PULLUP);
pinMode(SW5_PIN, INPUT_PULLUP);
pinMode(SW6_PIN, INPUT_PULLUP);
pinMode(SW7_PIN, INPUT_PULLUP);
pinMode(SW8_PIN, INPUT_PULLUP);
// For more precise analog readings
// analogSetCycles(128);
@ -1203,6 +1214,7 @@ void setup() {
// &SignalTask, /* Task handle to keep track of created task */
// 0); /* pin task to core 0 */
//
Serial.println(F("OpenFlightTX is Running"));
}
/*
@ -1397,27 +1409,34 @@ void update_display(void) {
if(millis() > last_update) {
// Determine stick position
if(millis() > last_menu_stick_read) {
if(roll_value > MENU_STICK_ROLL_MAX) {
stick_navigation_position = MENU_RIGHT;
} else if(roll_value < MENU_STICK_ROLL_MIN) {
stick_navigation_position = MENU_LEFT;
} else if(pitch_value > MENU_STICK_PITCH_MAX) {
stick_navigation_position = MENU_OK;
} else if(pitch_value < MENU_STICK_PITCH_MIN) {
stick_navigation_position = MENU_BACK;
} else if(yaw_value > MENU_STICK_YAW_MAX) {
if(!invert_yaw)
stick_navigation_position = MENU_EXTEND_RIGHT;
else
stick_navigation_position = MENU_EXTEND_LEFT;
} else if(yaw_value < MENU_STICK_YAW_MIN) {
if(!invert_yaw)
stick_navigation_position = MENU_EXTEND_LEFT;
else
stick_navigation_position = MENU_EXTEND_RIGHT;
// Force to set first...
if(need_to_initialize) {
/// menu_entry_alpha_list[destination_alpha_state.position].name = "Stick Calibration";
destination_alpha_state.position = 2;
need_to_initialize = false;
} else {
stick_navigation_position = MENU_NONE;
}
if(roll_value > MENU_STICK_ROLL_MAX) {
stick_navigation_position = MENU_RIGHT;
} else if(roll_value < MENU_STICK_ROLL_MIN) {
stick_navigation_position = MENU_LEFT;
} else if(pitch_value > MENU_STICK_PITCH_MAX) {
stick_navigation_position = MENU_OK;
} else if(pitch_value < MENU_STICK_PITCH_MIN) {
stick_navigation_position = MENU_BACK;
} else if(yaw_value > MENU_STICK_YAW_MAX) {
if(!invert_yaw)
stick_navigation_position = MENU_EXTEND_RIGHT;
else
stick_navigation_position = MENU_EXTEND_LEFT;
} else if(yaw_value < MENU_STICK_YAW_MIN) {
if(!invert_yaw)
stick_navigation_position = MENU_EXTEND_LEFT;
else
stick_navigation_position = MENU_EXTEND_RIGHT;
} else {
stick_navigation_position = MENU_NONE;
}
}
// Next reading...
last_menu_stick_read = millis() + 200;
@ -1487,7 +1506,7 @@ void update_display(void) {
} else {
if(stick_navigation_position == MENU_BACK) {
if(require_unlock) {
if(sw6) {
if(sw7) {
menu_entry_alpha_selected = false;
// u8g2_right.clearBuffer();
// u8g2_right.sendBuffer();
@ -1766,7 +1785,7 @@ void rc_controller(void) {
}
u8g2_left.drawStr(0, 40, buf);
if(!sw6) {
if(!sw7) {
u8g2_left.setCursor(20, 63);
u8g2_left.print(F("LOCKED"));
}
@ -1796,6 +1815,16 @@ void rc_controller(void) {
u8g2_left.print(F("E"));
}
if(sw6) {
u8g2_left.setCursor(25, 48);
u8g2_left.print(F("F"));
}
if(sw8) {
u8g2_left.setCursor(30, 48);
u8g2_left.print(F("G"));
}
u8g2_left.nextPage();
}
@ -2138,7 +2167,10 @@ void read_settings(void) {
throttle_max = EEPROM.read(addr) | EEPROM.read(addr + 1) << 8;
// New unit / reset.... dont need to read....
if(throttle_max == 0) return;
if(throttle_max == 0) {
need_to_initialize = true;
return;
}
// Throttle Min
addr = 2;
@ -2655,7 +2687,7 @@ void bluetooth_gamepad() {
strcpy(buf, ltoa(ble_profiling, buf, 10));
u8g2_left.drawStr(99, 57,buf);
if(!sw6) {
if(!sw7) {
u8g2_left.setCursor(99, 64);
u8g2_left.print(F("LOCKED"));
}
@ -3029,7 +3061,7 @@ void rf_scanners(void) {
u8g2_left.print(F("RF SCANNER"));
u8g2_left.setFont(u8g2_font_5x7_tf);
if(!sw6) {
if(!sw7) {
u8g2_left.setCursor(85, 15);
u8g2_left.print(F("LOCKED"));
}

Loading…
Cancel
Save