Fix crash in ADJUST_CHAIR mode, Fix Rest not stopping

While testing the ADJUST_CHAIR mode on actual hardware fixed the
following issues:

- main.cpp: Uninitialized pointer for leg/back-rest were passed to
  control task thus as when a method was called the controller crashed

- chairAdjust.cpp: the state was never reset to REST_OFF when below
  stick threshold
This commit is contained in:
jonny_l480 2024-02-20 09:34:33 +01:00
parent 26761f4a80
commit 8de4dbbe27
3 changed files with 15 additions and 10 deletions

View File

@ -134,12 +134,12 @@ void createObjects()
//sabertoothDriver = new sabertooth2x60a(sabertoothConfig);
// create controlled motor instances (motorctl.hpp)
// with configurations above
// with configurations from config.cpp
motorLeft = new controlledMotor(setLeftFunc, configMotorControlLeft);
motorRight = new controlledMotor(setRightFunc, configMotorControlRight);
// create speedsensor instances
// with configurations above
// with configurations from config.cpp
speedLeft = new speedSensor(speedLeft_config);
speedRight = new speedSensor(speedRight_config);
@ -153,17 +153,18 @@ void createObjects()
// create buzzer object on pin 12 with gap between queued events of 100ms
buzzer = new buzzer_t(GPIO_NUM_12, 100);
// create objects for controlling the chair position
// gpio_up, gpio_down, name
legRest = new cControlledRest(GPIO_NUM_4, GPIO_NUM_16, "legRest");
backRest = new cControlledRest(GPIO_NUM_2, GPIO_NUM_15, "backRest");
// create control object (control.hpp)
// with configuration above
// with configuration from config.cpp
control = new controlledArmchair(configControl, buzzer, motorLeft, motorRight, joystick, httpJoystickMain, automatedArmchair, legRest, backRest);
// create automatedArmchair_c object (for auto-mode) (auto.hpp)
automatedArmchair = new automatedArmchair_c(motorLeft, motorRight);
// create objects for controlling the chair position
// gpio_up, gpio_down, name
legRest = new cControlledRest(GPIO_NUM_4, GPIO_NUM_16, "legRest");
backRest = new cControlledRest(GPIO_NUM_2, GPIO_NUM_15, "backRest");
}

View File

@ -48,6 +48,7 @@ void cControlledRest::init()
// both relays off initially
gpio_set_level(gpio_down, 0);
gpio_set_level(gpio_up, 0);
state = REST_OFF;
}
@ -105,7 +106,10 @@ void controlChairAdjustment(joystickData_t data, cControlledRest * legRest, cCon
//leg rest (x-axis)
if (data.x > stickThreshold) legRest->setState(REST_UP);
else if (data.x < -stickThreshold) legRest->setState(REST_DOWN);
else legRest->setState(REST_OFF);
//back rest (y-axis)
if (data.y > stickThreshold) backRest->setState(REST_UP);
else if (data.y < -stickThreshold) backRest->setState(REST_DOWN);
else backRest->setState(REST_OFF);
}

View File

@ -17,12 +17,12 @@ extern const char* restStateStr[];
//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);
public:
cControlledRest(gpio_num_t gpio_up, gpio_num_t gpio_down, const char *name);
void setState(restState_t targetState);
void stop();
private:
private:
void init();
char name[32];