Rework/simplify chairAdjust - now using a class
- 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.
This commit is contained in:
@@ -77,8 +77,10 @@ void buttonCommands::action (uint8_t count, bool lastPressLong){
|
||||
}
|
||||
|
||||
//toggle idle when 2x pressed
|
||||
else {
|
||||
ESP_LOGW(TAG, "cmd %d: toggle IDLE", count);
|
||||
control->toggleIdle(); //toggle between idle and previous/default mode
|
||||
}
|
||||
break;
|
||||
|
||||
case 3:
|
||||
|
||||
@@ -195,5 +195,9 @@ controlledArmchair control(configControl, &buzzer, &motorLeft, &motorRight, &joy
|
||||
//create global automatedArmchair object (for auto-mode) (auto.hpp)
|
||||
automatedArmchair armchair;
|
||||
|
||||
//create global objects for controlling the chair position
|
||||
// gpio_up, gpio_down, name
|
||||
cControlledRest legRest(GPIO_NUM_4, GPIO_NUM_16, "legRest");
|
||||
cControlledRest backRest(GPIO_NUM_2, GPIO_NUM_15, "backRest");
|
||||
|
||||
|
||||
|
||||
@@ -11,11 +11,12 @@
|
||||
#include "http.hpp"
|
||||
#include "auto.hpp"
|
||||
#include "speedsensor.hpp"
|
||||
#include "chairAdjust.hpp"
|
||||
|
||||
|
||||
//in IDLE mode: set loglevel for evaluatedJoystick to DEBUG
|
||||
//and repeatedly read joystick e.g. for manually calibrating / testing joystick
|
||||
#define JOYSTICK_LOG_IN_IDLE
|
||||
//#define JOYSTICK_LOG_IN_IDLE
|
||||
|
||||
|
||||
//TODO outsource global variables to e.g. global.cpp and only config options here?
|
||||
@@ -49,3 +50,7 @@ extern fan_config_t configCooling;
|
||||
extern speedSensor speedLeft;
|
||||
extern speedSensor speedRight;
|
||||
|
||||
//create global objects for controlling the chair position
|
||||
extern cControlledRest legRest;
|
||||
extern cControlledRest backRest;
|
||||
|
||||
|
||||
@@ -179,7 +179,7 @@ void controlledArmchair::startHandleLoop() {
|
||||
motorRight->setTarget(commands.right.state, commands.right.duty);
|
||||
motorLeft->setTarget(commands.left.state, commands.left.duty);
|
||||
//--- control armchair position with joystick input ---
|
||||
joystick_ControlChairAdjustment(stickData, 0);
|
||||
controlChairAdjustment(joystick_l->getData(), &legRest, &backRest);
|
||||
break;
|
||||
|
||||
|
||||
@@ -386,8 +386,8 @@ void controlledArmchair::changeMode(controlMode_t modeNew) {
|
||||
case controlMode_t::ADJUST_CHAIR:
|
||||
ESP_LOGW(TAG, "switching from ADJUST_CHAIR mode => turning off adjustment motors...");
|
||||
//prevent motors from being always on in case of mode switch while joystick is not in center thus motors currently moving
|
||||
setLegrestOff();
|
||||
setBackrestOff();
|
||||
legRest.setState(REST_OFF);
|
||||
backRest.setState(REST_OFF);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
@@ -154,6 +154,7 @@ void setLoglevels(void){
|
||||
esp_log_level_set("display", ESP_LOG_INFO);
|
||||
//esp_log_level_set("current-sensors", ESP_LOG_INFO);
|
||||
//esp_log_level_set("speedSensor", ESP_LOG_INFO);
|
||||
esp_log_level_set("chair-adjustment", ESP_LOG_INFO);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user