From 2cc88fdec9db36ace9a519a0f327b94f90bd60c3 Mon Sep 17 00:00:00 2001 From: MikyM0use Date: Fri, 4 Nov 2016 11:40:26 +0100 Subject: [PATCH] small bugs fix in case of STANDALONE --- jafar_sketch/const.h | 4 +++- jafar_sketch/jafar_oled.ino | 6 +++-- jafar_sketch/jafar_sketch.ino | 41 +++++++++++++++++------------------ jafar_sketch/jafar_util.ino | 31 +++++++++++++++++++------- 4 files changed, 50 insertions(+), 32 deletions(-) diff --git a/jafar_sketch/const.h b/jafar_sketch/const.h index 409b4ce..464bc09 100644 --- a/jafar_sketch/const.h +++ b/jafar_sketch/const.h @@ -57,11 +57,13 @@ This file is part of Fatshark© goggle rx module project (JAFaR). #ifdef STANDALONE -#define LOOPTIME 200 +#define LOOPTIME 100 #else #define LOOPTIME 1000 #endif +#define JAFARE_DEBOUCE_TIME 180 + #define TIMER_INIT_VALUE 5.0 #define CH1 2 #define CH2 3 diff --git a/jafar_sketch/jafar_oled.ino b/jafar_sketch/jafar_oled.ino index f49a7cc..692fda0 100644 --- a/jafar_sketch/jafar_oled.ino +++ b/jafar_sketch/jafar_oled.ino @@ -99,8 +99,10 @@ uint8_t oled_submenu(uint8_t menu_pos, uint8_t band) { u8g.drawStr( 0, 8 + i * 8, j_buf); } #ifndef STANDALONE - u8g.setPrintPos(110, 10); - u8g.print((int)timer); + if (timer > 0) { + u8g.setPrintPos(110, 10); + u8g.print((int)timer); + } #endif } while ( u8g.nextPage() ); diff --git a/jafar_sketch/jafar_sketch.ino b/jafar_sketch/jafar_sketch.ino index f530176..e545bc1 100644 --- a/jafar_sketch/jafar_sketch.ino +++ b/jafar_sketch/jafar_sketch.ino @@ -109,6 +109,10 @@ void setup() { last_used_freq_id = EEPROM.read(EEPROM_ADDR_LAST_FREQ_ID); last_used_freq = pgm_read_word_near(channelFreqTable + (8 * last_used_band) + last_used_freq_id); //freq +#ifdef USE_I2C_OLED //default - set the last freq + rx5808.setFreq(last_used_freq); //set the last freq +#endif + _init_selection = readSwitch(); } @@ -135,12 +139,7 @@ void autoscan() { last_post_switch = menu_pos; -#ifdef USE_OLED //debounce and peace - delay(LOOPTIME); -#endif -#ifdef USE_OSD - TV.delay(LOOPTIME); -#endif //OLED + jafar_delay(LOOPTIME); timer -= (LOOPTIME / 1000.0); } @@ -176,15 +175,19 @@ void loop(void) { if (last_post_switch != menu_pos) { flag_first_pos = 0; timer = TIMER_INIT_VALUE; +#ifdef STANDALONE //debounce + jafar_delay(JAFARE_DEBOUCE_TIME); +#endif +#ifdef USE_I2C_OLED //changing freq every pression + if (!in_mainmenu) + rx5808.setFreq(pgm_read_word_near(channelFreqTable + (8 * menu_band) + menu_pos)); +#endif } +#ifndef STANDALONE //no timer in standalone else { -#ifdef STANDALONE - if (timer > 0) - return; //force no refresh of OSD -#else timer -= (LOOPTIME / 1000.0); -#endif } +#endif last_post_switch = menu_pos; @@ -203,15 +206,14 @@ void loop(void) { else { in_mainmenu = 0; menu_band = ((menu_pos - 1 - _init_selection + 8) % 8); +#ifdef USE_I2C_OLED + set_and_wait(menu_band, menu_pos); +#else timer = TIMER_INIT_VALUE; +#endif } -#ifdef USE_OLED //debounce and peace - delay(200); -#endif -#ifdef USE_OSD - TV.delay(200); -#endif //OLED + jafar_delay(200); } else { //if in submenu //after selection of band AND freq by the user @@ -224,21 +226,18 @@ void loop(void) { if (in_mainmenu) { //on main menu #ifdef USE_OLED oled_mainmenu(menu_pos); - delay(LOOPTIME); #endif #ifdef USE_OSD osd_mainmenu(menu_pos) ; - TV.delay(LOOPTIME); #endif } else { //on submenu #ifdef USE_OLED oled_submenu(menu_pos, menu_band); - delay(LOOPTIME); #endif #ifdef USE_OSD osd_submenu(menu_pos, menu_band); - TV.delay(LOOPTIME); #endif } + jafar_delay(LOOPTIME); } diff --git a/jafar_sketch/jafar_util.ino b/jafar_sketch/jafar_util.ino index 0a8f09f..5c28bfc 100644 --- a/jafar_sketch/jafar_util.ino +++ b/jafar_sketch/jafar_util.ino @@ -38,11 +38,11 @@ inline uint8_t readSwitch() { #endif } -void jafar_delay(uint16_t _delay) { +void inline jafar_delay(const uint16_t __delay) { #ifdef USE_OSD - TV.delay(2000); + TV.delay(__delay); #else - delay(2000); + delay(__delay); #endif } void set_and_wait(uint8_t band, uint8_t menu_pos) { @@ -69,8 +69,6 @@ void set_and_wait(uint8_t band, uint8_t menu_pos) { SELECT_B; current_rx = RX_B; - //jafar_delay(3000); - #else SELECT_A; current_rx = RX_A; @@ -101,6 +99,9 @@ void set_and_wait(uint8_t band, uint8_t menu_pos) { EEPROM.write(EEPROM_ADDR_LAST_FREQ_ID, menu_pos); //freq id EEPROM.write(EEPROM_ADDR_LAST_BAND_ID, band); //channel name +#ifdef USE_I2C_OLED //force screen refresh + oled_submenu(menu_pos, band); +#endif /* //TODO: this is the entry point for the re-init of oled U8GLIB_SSD1306_128X64 u8g2(8, A1, A4, 11 , 13); //CLK, MOSI, CS, DC, RESET u8g2.setFont(u8g_font_8x13); @@ -118,9 +119,13 @@ void set_and_wait(uint8_t band, uint8_t menu_pos) { } while ( u8g2.nextPage() ); delay(4000); */ - global_max_rssi = max(rx5808.getRssiMax(), rx5808B.getRssiMax()); + //MAIN LOOP - change channel and log while (1) { +#ifdef USE_DIVERSITY + + global_max_rssi = max(rx5808.getRssiMax(), rx5808B.getRssiMax()); + rssi_a = rx5808.getCurrentRSSI(); if (rssi_a > rx5808.getRssiMax()) { //update to new max if needed rx5808.setRssiMax(rssi_a); @@ -132,7 +137,7 @@ void set_and_wait(uint8_t band, uint8_t menu_pos) { rssi_a_norm = constrain(rssi_a, rx5808.getRssiMin(), rx5808.getRssiMax()); rssi_a_norm = map(rssi_a_norm, rx5808.getRssiMin(), rx5808.getRssiMax(), 1, global_max_rssi); -#ifdef USE_DIVERSITY + rssi_b = rx5808B.getCurrentRSSI(); if (rssi_b > rx5808B.getRssiMax()) { //this solve a bug when the goggles are powered on with no VTX around @@ -190,7 +195,6 @@ void set_and_wait(uint8_t band, uint8_t menu_pos) { Serial.println(rssi_a_norm_filt, DEC); //delay(100); -#endif #endif prev_rssi_b_norm = rssi_b_norm_filt; prev_rssi_a_norm = rssi_a_norm_filt; @@ -230,6 +234,8 @@ void set_and_wait(uint8_t band, uint8_t menu_pos) { #endif //DEBUG +#endif //DIVERSITY + menu_pos = readSwitch(); if (last_post_switch != menu_pos) { //something changed by user @@ -257,6 +263,15 @@ void set_and_wait(uint8_t band, uint8_t menu_pos) { rx5808.setFreq(pgm_read_word_near(channelFreqTable + (8 * band) + menu_pos)); //set the selected freq EEPROM.write(EEPROM_ADDR_LAST_FREQ_ID, menu_pos); + +#ifdef USE_I2C_OLED + oled_submenu(menu_pos, band); //refresh screen + jafar_delay(JAFARE_DEBOUCE_TIME); +#endif +#ifdef STANDALONE + jafar_delay(JAFARE_DEBOUCE_TIME); //debounce +#endif + } last_post_switch = menu_pos;