From 9c245a0527fe5e568de5796814ecd2bb0e0e8bb9 Mon Sep 17 00:00:00 2001 From: Axel pauli Date: Fri, 22 Mar 2024 16:07:04 +0100 Subject: [PATCH 1/6] two new methods added for poll period handling --- main/ESPRotary.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/main/ESPRotary.h b/main/ESPRotary.h index 623b74443..1c55bab21 100644 --- a/main/ESPRotary.h +++ b/main/ESPRotary.h @@ -17,7 +17,7 @@ #include "esp_system.h" #include "driver/pcnt.h" - +#define ROTARY_POLL_PERIOD 20 // default polling period in ms enum _event { NONE, PRESS, LONG_PRESS, RELEASE, UP, DOWN, ERROR, MAX_EVENT }; @@ -39,6 +39,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 +52,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; From 5f05e2af02df5b7ef83f0607b24b7ea1a35491d2 Mon Sep 17 00:00:00 2001 From: Axel pauli Date: Fri, 22 Mar 2024 16:09:21 +0100 Subject: [PATCH 2/6] poll period value made configurable --- main/ESPRotary.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/main/ESPRotary.cpp b/main/ESPRotary.cpp index cf2a14bb8..a1091e48b 100644 --- a/main/ESPRotary.cpp +++ b/main/ESPRotary.cpp @@ -24,12 +24,14 @@ pcnt_config_t ESPRotary::enc2; int16_t ESPRotary::r_enc_count = 0; int16_t ESPRotary::r_enc2_count = 0; int ESPRotary::timer = 0; +int16_t ESPRotary::pollPeriod = ROTARY_POLL_PERIOD; bool ESPRotary::released = true; bool ESPRotary::pressed = false; 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 +178,7 @@ void ESPRotary::informObservers( void * args ) { while( 1 ) { if( Flarm::bincom ) { - vTaskDelay(20 / portTICK_PERIOD_MS); + vTaskDelay(pollPeriod / portTICK_PERIOD_MS); continue; } int button = gpio_get_level((gpio_num_t)sw); @@ -241,6 +243,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(pollPeriod / portTICK_PERIOD_MS); } } From f44e8a506da91686f70cbe9f9719b2a5eff7239b Mon Sep 17 00:00:00 2001 From: Axel pauli Date: Fri, 22 Mar 2024 16:10:44 +0100 Subject: [PATCH 3/6] dymanic setting added to airfield elevation setting --- main/SetupMenu.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/main/SetupMenu.cpp b/main/SetupMenu.cpp index cbeeb9c83..41e91b82a 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 From 23a5e6b07f775d97739d2e3916f048f0a76216f2 Mon Sep 17 00:00:00 2001 From: Axel pauli Date: Fri, 22 Mar 2024 16:11:57 +0100 Subject: [PATCH 4/6] dynamic handling for rotary added --- main/SetupMenuValFloat.cpp | 50 ++++++++++++++++++++++++++++++-------- main/SetupMenuValFloat.h | 3 +++ 2 files changed, 43 insertions(+), 10 deletions(-) diff --git a/main/SetupMenuValFloat.cpp b/main/SetupMenuValFloat.cpp index 8e5978046..af22f21b1 100644 --- a/main/SetupMenuValFloat.cpp +++ b/main/SetupMenuValFloat.cpp @@ -12,6 +12,7 @@ #include "Polars.h" #include "sensor.h" #include "ESPAudio.h" +#include "ESPRotary.h" #include @@ -19,7 +20,9 @@ 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), + _roteryPollingChanged(false) { // ESP_LOGI(FNAME,"SetupMenuValFloat( %s ) ", title.c_str() ); attach(this); _title = title; @@ -107,7 +110,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 +136,25 @@ void SetupMenuValFloat::down( int count ){ return; // ESP_LOGI(FNAME,"val down %d times ", count ); _value = _nvs->get(); - while( (_value > _min) && count ) { + // float start = _value; - _value -= step( _step ); - count --; + if( _dynamic > 1.0 && _roteryPollingChanged == false ) { + ESPRotary::setPollPeriod( 100 ); // Increase poll period of rotary + _roteryPollingChanged = true; } + + int _count = std::pow( count, _dynamic ); + while( (_value > _min) && _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 +165,23 @@ void SetupMenuValFloat::up( int count ){ return; // ESP_LOGI(FNAME,"val up %d times ", count ); _value = _nvs->get(); - while( (_value < _max) && count ) { - _value += step( _step ); - count--; + // float start = _value; + + if( _dynamic > 1.0 && _roteryPollingChanged == false ) { + ESPRotary::setPollPeriod( 100 ); // Increase poll period of rotary + _roteryPollingChanged = true; } + + int _count = std::pow( count, _dynamic ); + while( (_value < _max) && _count ) { + _value += step( _step ); + _count--; + } + if( _value > _max ) _value = _max; + + // ESP_LOGI(FNAME,"val up diff=%f", _value-start ); _nvs->set(_value ); displayVal(); if( _action != 0 ) @@ -171,8 +196,13 @@ void SetupMenuValFloat::press(){ if( selected != this ) return; ESP_LOGI(FNAME,"SetupMenuValFloat press %d", pressed ); + + if( _roteryPollingChanged ) { + _roteryPollingChanged = false; + ESPRotary::setPollPeriod( ROTARY_POLL_PERIOD ); // reset poll period of rotary to default + } 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 74ea986c6..0b8c1ed10 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,6 @@ class SetupMenuValFloat: public MenuEntry { const char * _unit; int (*_action)( SetupMenuValFloat *p ); SetupNG * _nvs; + float _dynamic; + bool _roteryPollingChanged; }; From 0fc583b62310bf2d5faf7893050782dffc8071ca Mon Sep 17 00:00:00 2001 From: Axel pauli Date: Tue, 26 Mar 2024 10:23:30 +0100 Subject: [PATCH 5/6] changing of rotary polling period removed --- main/SetupMenuValFloat.cpp | 20 +------------------- main/SetupMenuValFloat.h | 1 - 2 files changed, 1 insertion(+), 20 deletions(-) diff --git a/main/SetupMenuValFloat.cpp b/main/SetupMenuValFloat.cpp index af22f21b1..9658f5af4 100644 --- a/main/SetupMenuValFloat.cpp +++ b/main/SetupMenuValFloat.cpp @@ -12,7 +12,6 @@ #include "Polars.h" #include "sensor.h" #include "ESPAudio.h" -#include "ESPRotary.h" #include @@ -21,8 +20,7 @@ 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 ): - _dynamic(1.0), - _roteryPollingChanged(false) { + _dynamic(1.0) { // ESP_LOGI(FNAME,"SetupMenuValFloat( %s ) ", title.c_str() ); attach(this); _title = title; @@ -137,12 +135,6 @@ void SetupMenuValFloat::down( int count ){ // ESP_LOGI(FNAME,"val down %d times ", count ); _value = _nvs->get(); // float start = _value; - - if( _dynamic > 1.0 && _roteryPollingChanged == false ) { - ESPRotary::setPollPeriod( 100 ); // Increase poll period of rotary - _roteryPollingChanged = true; - } - int _count = std::pow( count, _dynamic ); while( (_value > _min) && _count ) { _value -= step( _step ); @@ -166,12 +158,6 @@ void SetupMenuValFloat::up( int count ){ // ESP_LOGI(FNAME,"val up %d times ", count ); _value = _nvs->get(); // float start = _value; - - if( _dynamic > 1.0 && _roteryPollingChanged == false ) { - ESPRotary::setPollPeriod( 100 ); // Increase poll period of rotary - _roteryPollingChanged = true; - } - int _count = std::pow( count, _dynamic ); while( (_value < _max) && _count ) { _value += step( _step ); @@ -197,10 +183,6 @@ void SetupMenuValFloat::press(){ return; ESP_LOGI(FNAME,"SetupMenuValFloat press %d", pressed ); - if( _roteryPollingChanged ) { - _roteryPollingChanged = false; - ESPRotary::setPollPeriod( ROTARY_POLL_PERIOD ); // reset poll period of rotary to default - } if ( pressed ){ ESP_LOGI(FNAME,"pressed, value: %f", _value ); _nvs->set( _value ); diff --git a/main/SetupMenuValFloat.h b/main/SetupMenuValFloat.h index 0b8c1ed10..7c836473f 100644 --- a/main/SetupMenuValFloat.h +++ b/main/SetupMenuValFloat.h @@ -50,5 +50,4 @@ class SetupMenuValFloat: public MenuEntry { int (*_action)( SetupMenuValFloat *p ); SetupNG * _nvs; float _dynamic; - bool _roteryPollingChanged; }; From 1156eced7e2166a60d29862a0e75348bd0ad10b2 Mon Sep 17 00:00:00 2001 From: Axel pauli Date: Tue, 26 Mar 2024 10:35:30 +0100 Subject: [PATCH 6/6] dynamic handling of poll period removed. Poll period hard coded to 100ms. --- main/ESPRotary.cpp | 9 ++++----- main/ESPRotary.h | 2 -- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/main/ESPRotary.cpp b/main/ESPRotary.cpp index a1091e48b..0999079f1 100644 --- a/main/ESPRotary.cpp +++ b/main/ESPRotary.cpp @@ -24,7 +24,6 @@ pcnt_config_t ESPRotary::enc2; int16_t ESPRotary::r_enc_count = 0; int16_t ESPRotary::r_enc2_count = 0; int ESPRotary::timer = 0; -int16_t ESPRotary::pollPeriod = ROTARY_POLL_PERIOD; bool ESPRotary::released = true; bool ESPRotary::pressed = false; bool ESPRotary::longPressed = false; @@ -178,7 +177,7 @@ void ESPRotary::informObservers( void * args ) { while( 1 ) { if( Flarm::bincom ) { - vTaskDelay(pollPeriod / portTICK_PERIOD_MS); + vTaskDelay(100 / portTICK_PERIOD_MS); continue; } int button = gpio_get_level((gpio_num_t)sw); @@ -186,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(); @@ -198,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(); @@ -243,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(pollPeriod / portTICK_PERIOD_MS); + vTaskDelay(100 / portTICK_PERIOD_MS); } } diff --git a/main/ESPRotary.h b/main/ESPRotary.h index 1c55bab21..2ab47ab9b 100644 --- a/main/ESPRotary.h +++ b/main/ESPRotary.h @@ -17,8 +17,6 @@ #include "esp_system.h" #include "driver/pcnt.h" -#define ROTARY_POLL_PERIOD 20 // default polling period in ms - enum _event { NONE, PRESS, LONG_PRESS, RELEASE, UP, DOWN, ERROR, MAX_EVENT }; class RotaryObserver;