diff --git a/main/ESPRotary.cpp b/main/ESPRotary.cpp index cf2a14bb..0999079f 100644 --- a/main/ESPRotary.cpp +++ b/main/ESPRotary.cpp @@ -30,6 +30,7 @@ bool ESPRotary::longPressed = false; #define ROTARY_SINGLE_INC 0 #define ROTARY_DOUBLE_INC 1 + static TaskHandle_t pid = NULL; void ESPRotary::attach(RotaryObserver *obs) { @@ -176,7 +177,7 @@ void ESPRotary::informObservers( void * args ) { while( 1 ) { if( Flarm::bincom ) { - vTaskDelay(20 / portTICK_PERIOD_MS); + vTaskDelay(100 / portTICK_PERIOD_MS); continue; } int button = gpio_get_level((gpio_num_t)sw); @@ -184,7 +185,7 @@ void ESPRotary::informObservers( void * args ) timer++; released = false; pressed = false; - if( timer > 20 ){ // > 400 mS + if( timer > 20/5 ){ // > 400 mS if( !longPressed ){ sendLongPress(); sendRelease(); @@ -196,7 +197,7 @@ void ESPRotary::informObservers( void * args ) if( !released ){ // ESP_LOGI(FNAME,"timer=%d", timer ); longPressed = false; - if( timer < 20 ){ // > 400 mS + if( timer < 20/5 ){ // > 400 mS if( !pressed ){ sendPress(); sendRelease(); @@ -241,6 +242,6 @@ void ESPRotary::informObservers( void * args ) } if( uxTaskGetStackHighWaterMark( pid ) < 256 ) ESP_LOGW(FNAME,"Warning rotary task stack low: %d bytes", uxTaskGetStackHighWaterMark( pid ) ); - vTaskDelay(20 / portTICK_PERIOD_MS); + vTaskDelay(100 / portTICK_PERIOD_MS); } } diff --git a/main/ESPRotary.h b/main/ESPRotary.h index 623b7444..2ab47ab9 100644 --- a/main/ESPRotary.h +++ b/main/ESPRotary.h @@ -17,8 +17,6 @@ #include "esp_system.h" #include "driver/pcnt.h" - - enum _event { NONE, PRESS, LONG_PRESS, RELEASE, UP, DOWN, ERROR, MAX_EVENT }; class RotaryObserver; @@ -39,6 +37,10 @@ class ESPRotary { static void sendDown( int diff ); static void sendEsc(); static bool readSwitch(); // returns true if pressed + static void setPollPeriod( const int16_t value ) { + if( value > 0 ) pollPeriod = value; + } + static int16_t getPollPeriod() { return pollPeriod; } private: static std::list observers; @@ -48,6 +50,7 @@ class ESPRotary { static int16_t r_enc_count; static int16_t r_enc2_count; static int timer; + static int16_t pollPeriod; static bool released; static bool longPressed; static bool pressed; diff --git a/main/SetupMenu.cpp b/main/SetupMenu.cpp index cbeeb9c8..41e91b82 100644 --- a/main/SetupMenu.cpp +++ b/main/SetupMenu.cpp @@ -2206,6 +2206,7 @@ void SetupMenu::setup_create_root(MenuEntry *top ){ SetupMenuValFloat * afe = new SetupMenuValFloat( "Airfield Elevation", "", -1, 3000, 1, 0, true, &elevation ); afe->setHelp( "Airfield elevation in meters for QNH auto adjust on ground according to this elevation"); + afe->setDynamic( 3.0 ); top->addEntry( afe ); // Clear student mode, password correct diff --git a/main/SetupMenuValFloat.cpp b/main/SetupMenuValFloat.cpp index 8e597804..9658f5af 100644 --- a/main/SetupMenuValFloat.cpp +++ b/main/SetupMenuValFloat.cpp @@ -19,7 +19,8 @@ SetupMenuValFloat * SetupMenuValFloat::qnh_menu = 0; SetupMenuValFloat * SetupMenuValFloat::meter_adj_menu = 0; char SetupMenuValFloat::_val_str[20]; -SetupMenuValFloat::SetupMenuValFloat( const char* title, const char *unit, float min, float max, float step, int (*action)( SetupMenuValFloat *p ), bool end_menu, SetupNG *anvs, e_restart_mode_t restart, bool sync, bool live_update ) { +SetupMenuValFloat::SetupMenuValFloat( const char* title, const char *unit, float min, float max, float step, int (*action)( SetupMenuValFloat *p ), bool end_menu, SetupNG *anvs, e_restart_mode_t restart, bool sync, bool live_update ): + _dynamic(1.0) { // ESP_LOGI(FNAME,"SetupMenuValFloat( %s ) ", title.c_str() ); attach(this); _title = title; @@ -107,7 +108,7 @@ void SetupMenuValFloat::display( int mode ){ void SetupMenuValFloat::displayVal() { - ESP_LOGI(FNAME,"displayVal %s", value() ); + // ESP_LOGI(FNAME,"displayVal %s", value() ); xSemaphoreTake(spiMutex,portMAX_DELAY ); ucg->setPrintPos( 1, 70 ); ucg->setFont(ucg_font_fub25_hf, true); @@ -133,14 +134,19 @@ void SetupMenuValFloat::down( int count ){ return; // ESP_LOGI(FNAME,"val down %d times ", count ); _value = _nvs->get(); - while( (_value > _min) && count ) { + // float start = _value; + int _count = std::pow( count, _dynamic ); + while( (_value > _min) && _count ) { + _value -= step( _step ); + _count --; + } - _value -= step( _step ); - count --; - } if( _value < _min ) _value = _min; - _nvs->set(_value ); + _nvs->set( _value ); + + // ESP_LOGI(FNAME,"val down diff=%f", start-_value ); + displayVal(); if( _action != 0 ) (*_action)( this ); @@ -151,12 +157,17 @@ void SetupMenuValFloat::up( int count ){ return; // ESP_LOGI(FNAME,"val up %d times ", count ); _value = _nvs->get(); - while( (_value < _max) && count ) { + // float start = _value; + int _count = std::pow( count, _dynamic ); + while( (_value < _max) && _count ) { _value += step( _step ); - count--; - } + _count--; + } + if( _value > _max ) _value = _max; + + // ESP_LOGI(FNAME,"val up diff=%f", _value-start ); _nvs->set(_value ); displayVal(); if( _action != 0 ) @@ -171,8 +182,9 @@ void SetupMenuValFloat::press(){ if( selected != this ) return; ESP_LOGI(FNAME,"SetupMenuValFloat press %d", pressed ); + if ( pressed ){ - // ESP_LOGI(FNAME,"pressed, value: %f", _value ); + ESP_LOGI(FNAME,"pressed, value: %f", _value ); _nvs->set( _value ); display( 1 ); if( bits._end_menu ) diff --git a/main/SetupMenuValFloat.h b/main/SetupMenuValFloat.h index 74ea986c..7c836473 100644 --- a/main/SetupMenuValFloat.h +++ b/main/SetupMenuValFloat.h @@ -35,6 +35,7 @@ class SetupMenuValFloat: public MenuEntry { void escape() {}; // ignore, base class takes care void setStep( float val ) { _step = val; }; void setMax( float max ) { _max = max; }; + void setDynamic( float value ) { _dynamic = value; } float _value; static SetupMenuValFloat * qnh_menu; static SetupMenuValFloat * meter_adj_menu; @@ -48,4 +49,5 @@ class SetupMenuValFloat: public MenuEntry { const char * _unit; int (*_action)( SetupMenuValFloat *p ); SetupNG * _nvs; + float _dynamic; };