- complete rework of chairAdjust.cpp/.hpp created a class cControlledRest which is more readable and saves a lot of duplicate code - joystick.cpp: move chair control via joystick to chairAdjust.cpp (prevents dependency loop) - button.cpp: fix bug instant idle when changing to ADJUST_CHAIR Note: briefly tested this state on a breakout board: Mode change and call of new class methods works.
		
			
				
	
	
		
			41 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			41 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
#pragma once
 | 
						|
 | 
						|
#include "joystick.hpp"
 | 
						|
 | 
						|
typedef enum {
 | 
						|
    REST_OFF = 0,
 | 
						|
    REST_DOWN,
 | 
						|
    REST_UP
 | 
						|
} restState_t;
 | 
						|
 | 
						|
extern const char* restStateStr[];
 | 
						|
 | 
						|
 | 
						|
//=====================================
 | 
						|
//======= cControlledRest class =======
 | 
						|
//=====================================
 | 
						|
//class that controls 2 relays powering a motor that moves a rest of the armchair up or down
 | 
						|
//2 instances will be created one for back and one for leg rest
 | 
						|
class cControlledRest {
 | 
						|
    public:
 | 
						|
    cControlledRest(gpio_num_t gpio_up, gpio_num_t gpio_down, const char * name);
 | 
						|
    void setState(restState_t targetState);
 | 
						|
    void stop();
 | 
						|
 | 
						|
    private:
 | 
						|
    void init();
 | 
						|
 | 
						|
    char name[32];
 | 
						|
    gpio_num_t gpio_up;
 | 
						|
    gpio_num_t gpio_down;
 | 
						|
    restState_t state;
 | 
						|
    const uint32_t travelDuration = 5000;
 | 
						|
    uint32_t timestamp_lastChange;
 | 
						|
    float currentPosition = 0;
 | 
						|
};
 | 
						|
 | 
						|
//====================================
 | 
						|
//====== controlChairAdjustment ======
 | 
						|
//====================================
 | 
						|
//function that controls the two rests according to joystick data (applies threshold, defines direction)
 | 
						|
void controlChairAdjustment(joystickData_t data, cControlledRest * legRest, cControlledRest * backRest); |