Optimize encoder-rest control, Invert back-rest direction
Less unintended menu jumping when controlling rest Less ignored ticks when recently used
This commit is contained in:
		
							parent
							
								
									1559b0abdf
								
							
						
					
					
						commit
						25cc72c5e6
					
				@ -183,7 +183,7 @@ void buttonCommands::action (uint8_t count, bool lastPressLong){
 | 
				
			|||||||
// and takes the corresponding action
 | 
					// and takes the corresponding action
 | 
				
			||||||
// this function has to be started once in a separate task
 | 
					// this function has to be started once in a separate task
 | 
				
			||||||
#define INPUT_TIMEOUT 600 // duration of no button events, after which action is run (implicitly also is 'long-press' time)
 | 
					#define INPUT_TIMEOUT 600 // duration of no button events, after which action is run (implicitly also is 'long-press' time)
 | 
				
			||||||
#define IGNORE_BUTTON_TIME_SINCE_LAST_ROTATE 800 // time that has to be passed since last encoder rotate click for button count command to be accepted (e.g. prevent long press action after PRESS+ROTATE was used)
 | 
					#define IGNORE_BUTTON_TIME_SINCE_LAST_ROTATE 2600 // time that has to be passed since last encoder rotate click for button count command to be accepted (e.g. prevent long press action after PRESS+ROTATE was used)
 | 
				
			||||||
#define IGNORE_ROTATE_COUNT 1 //amount of ignored clicks before action is actually taken (ignore accidental touches)
 | 
					#define IGNORE_ROTATE_COUNT 1 //amount of ignored clicks before action is actually taken (ignore accidental touches)
 | 
				
			||||||
void buttonCommands::startHandleLoop()
 | 
					void buttonCommands::startHandleLoop()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@ -191,7 +191,7 @@ void buttonCommands::startHandleLoop()
 | 
				
			|||||||
    static bool isPressed = false;
 | 
					    static bool isPressed = false;
 | 
				
			||||||
    static rotary_encoder_event_t event; // store event data
 | 
					    static rotary_encoder_event_t event; // store event data
 | 
				
			||||||
    int rotateCount = 0; // temporary count clicks encoder was rotated
 | 
					    int rotateCount = 0; // temporary count clicks encoder was rotated
 | 
				
			||||||
    uint32_t timestampLastRotate = 0;
 | 
					    uint32_t timestampLastAdjustChange = 0;
 | 
				
			||||||
    // int count = 0; (from class)
 | 
					    // int count = 0; (from class)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    while (1)
 | 
					    while (1)
 | 
				
			||||||
@ -225,13 +225,15 @@ void buttonCommands::startHandleLoop()
 | 
				
			|||||||
                isPressed = false; // rest stored state
 | 
					                isPressed = false; // rest stored state
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
            case RE_ET_CHANGED:
 | 
					            case RE_ET_CHANGED:
 | 
				
			||||||
                // ignore first clicks
 | 
					                // ignore first clicks (dont ignore when changed position recently)
 | 
				
			||||||
                if (rotateCount++ < IGNORE_ROTATE_COUNT)
 | 
					                if ((rotateCount++ < IGNORE_ROTATE_COUNT) && ((esp_log_timestamp() - timestampLastAdjustChange) > IGNORE_BUTTON_TIME_SINCE_LAST_ROTATE))
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        buzzer->beep(1, 20, 0);
 | 
					                        buzzer->beep(1, 20, 0);
 | 
				
			||||||
                        break;
 | 
					                        break;
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                timestampLastRotate = esp_log_timestamp();
 | 
					                    else {
 | 
				
			||||||
 | 
					                        timestampLastAdjustChange = esp_log_timestamp();
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
                if (isPressed){
 | 
					                if (isPressed){
 | 
				
			||||||
                    /////### scroll through status pages when PRESSED + ROTATED ###
 | 
					                    /////### scroll through status pages when PRESSED + ROTATED ###
 | 
				
			||||||
                    ///if (event.diff > 0)
 | 
					                    ///if (event.diff > 0)
 | 
				
			||||||
@ -246,7 +248,7 @@ void buttonCommands::startHandleLoop()
 | 
				
			|||||||
                    // show temporary notification on display
 | 
					                    // show temporary notification on display
 | 
				
			||||||
                    char buf[8];
 | 
					                    char buf[8];
 | 
				
			||||||
                    snprintf(buf, 8, "%.0f%%", backRest->getTargetPercent());
 | 
					                    snprintf(buf, 8, "%.0f%%", backRest->getTargetPercent());
 | 
				
			||||||
                    display_showNotification(2500, "moving Rest:", "BACK", buf);
 | 
					                    display_showNotification(IGNORE_BUTTON_TIME_SINCE_LAST_ROTATE, "moving Rest:", "BACK", buf);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                //### adjust leg support when ROTATED ###
 | 
					                //### adjust leg support when ROTATED ###
 | 
				
			||||||
                else
 | 
					                else
 | 
				
			||||||
@ -273,8 +275,11 @@ void buttonCommands::startHandleLoop()
 | 
				
			|||||||
        {
 | 
					        {
 | 
				
			||||||
            rotateCount = 0; // reset rotate count
 | 
					            rotateCount = 0; // reset rotate count
 | 
				
			||||||
            // ignore button click events when "ROTATE+PRESSED" was just used
 | 
					            // ignore button click events when "ROTATE+PRESSED" was just used
 | 
				
			||||||
            if (count > 0 && (esp_log_timestamp() - timestampLastRotate < IGNORE_BUTTON_TIME_SINCE_LAST_ROTATE))
 | 
					            if (count > 0 && (esp_log_timestamp() - timestampLastAdjustChange < IGNORE_BUTTON_TIME_SINCE_LAST_ROTATE))
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
                ESP_LOGW(TAG, "ignoring button count %d because encoder was rotated less than %d ms ago", count, IGNORE_BUTTON_TIME_SINCE_LAST_ROTATE);
 | 
					                ESP_LOGW(TAG, "ignoring button count %d because encoder was rotated less than %d ms ago", count, IGNORE_BUTTON_TIME_SINCE_LAST_ROTATE);
 | 
				
			||||||
 | 
					                count = 0;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
            // encoder was pressed
 | 
					            // encoder was pressed
 | 
				
			||||||
            else if (count > 0)
 | 
					            else if (count > 0)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
 | 
				
			|||||||
@ -163,7 +163,7 @@ void createObjects()
 | 
				
			|||||||
    // create objects for controlling the chair position
 | 
					    // create objects for controlling the chair position
 | 
				
			||||||
    //                       gpio_up, gpio_down, travelDuration, name, defaultPosition
 | 
					    //                       gpio_up, gpio_down, travelDuration, name, defaultPosition
 | 
				
			||||||
    legRest = new cControlledRest(GPIO_NUM_2, GPIO_NUM_15, 11000, "legRest");
 | 
					    legRest = new cControlledRest(GPIO_NUM_2, GPIO_NUM_15, 11000, "legRest");
 | 
				
			||||||
    backRest = new cControlledRest(GPIO_NUM_4, GPIO_NUM_16, 12000, "backRest", 100); //default position "100% up"
 | 
					    backRest = new cControlledRest(GPIO_NUM_16, GPIO_NUM_4, 12000, "backRest", 5); //default position "100% up"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // create control object (control.hpp)
 | 
					    // create control object (control.hpp)
 | 
				
			||||||
    // with configuration from config.cpp
 | 
					    // with configuration from config.cpp
 | 
				
			||||||
 | 
				
			|||||||
@ -399,8 +399,8 @@ void controlChairAdjustment(joystickData_t data, cControlledRest * legRest, cCon
 | 
				
			|||||||
        legRest->requestStateChange(REST_OFF);
 | 
					        legRest->requestStateChange(REST_OFF);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //back rest (y-axis)
 | 
					    //back rest (y-axis)
 | 
				
			||||||
    if (data.y > stickThreshold) backRest->setTargetPercent(100);
 | 
					    if (data.y > stickThreshold) backRest->setTargetPercent(0);
 | 
				
			||||||
    else if (data.y < -stickThreshold) backRest->setTargetPercent(0);
 | 
					    else if (data.y < -stickThreshold) backRest->setTargetPercent(100);
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
        backRest->requestStateChange(REST_OFF);
 | 
					        backRest->requestStateChange(REST_OFF);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user