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

@@ -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];