From 257cae4711930d483449b7332ef4f1c6ebb4ab69 Mon Sep 17 00:00:00 2001 From: "Schoenberger, Philipp" Date: Tue, 16 Apr 2019 20:48:42 +0200 Subject: [PATCH] add hf cfg state --- remote/include/state.h | 12 ++++++ remote/src/Multiprotocol.cpp | 1 - remote/src/state_hd_calib.cpp | 69 +++++++++++++++++++++++++++++++++++ remote/src/state_menu.cpp | 6 +-- 4 files changed, 84 insertions(+), 4 deletions(-) create mode 100644 remote/src/state_hd_calib.cpp diff --git a/remote/include/state.h b/remote/include/state.h index 94582fd..e85b2f6 100644 --- a/remote/include/state.h +++ b/remote/include/state.h @@ -112,6 +112,18 @@ public: extern State *s_usb; #endif +class LCD_state_hf_cfg: public State { +private: + unsigned long time_enter; + bool changed; +public: + LCD_state_hf_cfg(void); + void enter(void); + void update(void); + void leave(void); +}; +extern State *s_hf_cfg; + extern State *curr_state; extern State *new_state; diff --git a/remote/src/Multiprotocol.cpp b/remote/src/Multiprotocol.cpp index 28e0834..b79ed80 100644 --- a/remote/src/Multiprotocol.cpp +++ b/remote/src/Multiprotocol.cpp @@ -99,7 +99,6 @@ void setup() //frquency offset initialization { freq_offset = 0; - debug("freq offset: %d\n", freq_offset); CC2500_Reset(); //Wait for cc2500 to reset diff --git a/remote/src/state_hd_calib.cpp b/remote/src/state_hd_calib.cpp new file mode 100644 index 0000000..243cb00 --- /dev/null +++ b/remote/src/state_hd_calib.cpp @@ -0,0 +1,69 @@ +#include +#include +#include "Arduino.h" +#include "FrSkyD_cc2500.h" +#include "state.h" +#include "input.h" +#include "eeprom.h" +#include "debug.h" +#include "tx_def.h" +#include "config.h" + + +LCD_state_hf_cfg::LCD_state_hf_cfg(void) { +} +void LCD_state_hf_cfg::enter(void) { + lcd.setCursor(0,0); + lcd.print("enter hf config "); + lcd.setCursor(0,1); + lcd.print(" "); + this->time_enter = millis(); + this->changed = false; +} + +void LCD_state_hf_cfg::update(void) +{ + char line[17]; + input.update(); + lcd.setCursor(0,0); + lcd.print("freq offset: "); + // print on lcd + lcd.setCursor(0,1); + snprintf(line,sizeof(line),"%02lu",freq_offset); + lcd.print(line); + + if (input.is_menu_triggered()) { + debug("%lu menu button trigger\n", millis); + new_state = s_menu; + } + + bool wait = false; + if (input.is_high(Input::MENU_UP_DOWN)) { + freq_offset +=1; + this->changed = true; + wait = true; + } + if (input.is_low(Input::MENU_UP_DOWN)) { + freq_offset -=1; + this->changed = true; + wait = true; + } + if(wait) + delay(150); +} + +void LCD_state_hf_cfg::leave(void) +{ + if (this->changed) { + eeprom_config.set_freq_offset(freq_offset); + eeprom_config.write(); + eeprom_config.read(); + if (eeprom_config.validate()) { + debugln("ok calib\n"); + }else { + debugln("failed calib\n"); + } + this->changed = false; + } + lcd.clear(); +} diff --git a/remote/src/state_menu.cpp b/remote/src/state_menu.cpp index 7d39cf1..fe60e7a 100644 --- a/remote/src/state_menu.cpp +++ b/remote/src/state_menu.cpp @@ -30,7 +30,7 @@ void LCD_state_menu::update(void) { "Joy usb ", s_usb}, #endif { "Joy calib ", s_joy }, - { "HF calib ", NULL }, + { "HF config ", s_hf_cfg }, { " ", NULL }, }; @@ -48,8 +48,8 @@ void LCD_state_menu::update(void) if (false == input.is_centered(Input::MENU_UP_DOWN)) { if (input.is_low(Input::MENU_UP_DOWN)){ this->curr_selected +=1; - if ( this->curr_selected > 3) - this->curr_selected = 3; + if ( this->curr_selected > 4) + this->curr_selected = 4; else wait = true; }