Add chairAdjust task, pos tracking, move with encoder

This commit is contained in:
jonny
2024-09-04 18:27:24 +02:00
parent 70df86f70c
commit 2a2678b734
5 changed files with 195 additions and 35 deletions

View File

@@ -23,7 +23,7 @@ void task_button(void *task_button_parameters)
task_button_parameters_t *objects = (task_button_parameters_t *)task_button_parameters;
ESP_LOGI(TAG, "Initializing command-button and starting handle loop");
// create button instance
buttonCommands commandButton(objects->control, objects->joystick, objects->encoderQueue, objects->motorLeft, objects->motorRight, objects->buzzer);
buttonCommands commandButton(objects->control, objects->joystick, objects->encoderQueue, objects->motorLeft, objects->motorRight, objects->legRest, objects->backRest, objects->buzzer);
// start handle loop
commandButton.startHandleLoop();
}
@@ -35,8 +35,10 @@ buttonCommands::buttonCommands(
controlledArmchair *control_f,
evaluatedJoystick *joystick_f,
QueueHandle_t encoderQueue_f,
controlledMotor *motorLeft_f,
controlledMotor * motorLeft_f,
controlledMotor *motorRight_f,
cControlledRest *legRest_f,
cControlledRest *backRest_f,
buzzer_t *buzzer_f)
{
// copy object pointers
@@ -46,6 +48,8 @@ buttonCommands::buttonCommands(
motorLeft = motorLeft_f;
motorRight = motorRight_f;
buzzer = buzzer_f;
legRest = legRest_f;
backRest = backRest_f;
// TODO declare / configure evaluatedSwitch here instead of config (unnecessary that button object is globally available - only used here)?
}
@@ -141,6 +145,12 @@ void buttonCommands::action (uint8_t count, bool lastPressLong){
control->changeMode(controlMode_t::MASSAGE); //switch to MASSAGE mode
break;
case 7:
legRest->setTargetPercent(100);
backRest->setTargetPercent(0);
ESP_LOGW(TAG, "7x TESTING: set leg/back rest to 100/0");
break;
case 8:
// ## toggle "sport-mode" ##
//toggle deceleration fading between on and off
@@ -212,18 +222,25 @@ void buttonCommands::startHandleLoop()
isPressed = false; // rest stored state
break;
case RE_ET_CHANGED: // scroll through status pages when simply rotating encoder
rotateCount++;
if (rotateCount >= 2) // at least two rotate-clicks necessary for one page switch
{
if (event.diff > 0)
display_rotateStatusPage(true, true); // select NEXT status screen, stay at last element (dont rotate to first)
else
display_rotateStatusPage(false, true); // select PREVIOUS status screen, stay at first element (dont rotate to last)
rotateCount = 0;
buzzer->beep(1, 90, 0);
}
if (event.diff > 0)
legRest->setTargetPercent(legRest->getTargetPercent() + 10);
else
buzzer->beep(1, 65, 0);
legRest->setTargetPercent(legRest->getTargetPercent() - 10);
//## switch status page with rotate - disabled
///rotateCount++;
///if (rotateCount >= 2) // at least two rotate-clicks necessary for one page switch
///{
/// if (event.diff > 0)
/// display_rotateStatusPage(true, true); // select NEXT status screen, stay at last element (dont rotate to first)
/// else
/// display_rotateStatusPage(false, true); // select PREVIOUS status screen, stay at first element (dont rotate to last)
/// rotateCount = 0;
/// buzzer->beep(1, 90, 0);
///}
///else
/// buzzer->beep(1, 65, 0);
break;
case RE_ET_BTN_LONG_PRESSED:
case RE_ET_BTN_CLICKED:
@@ -233,14 +250,15 @@ void buttonCommands::startHandleLoop()
}
else // timeout (no event received within TIMEOUT)
{
//## switch status page with rotate - disabled
// switch back to default status screen in case less than 2 rotate-clicks received
if (rotateCount != 0)
{
rotateCount = 0;
display_selectStatusPage(STATUS_SCREEN_OVERVIEW);
//TODO only change/beep if not already at STATUS_SCREEN_OVERVIEW
//buzzer->beep(1, 100, 0);
}
///if (rotateCount != 0)
///{
/// rotateCount = 0;
/// display_selectStatusPage(STATUS_SCREEN_OVERVIEW);
/// //TODO only change/beep if not already at STATUS_SCREEN_OVERVIEW
/// //buzzer->beep(1, 100, 0);
///}
// encoder was pressed
if (count > 0)

View File

@@ -6,6 +6,7 @@
#include "motorctl.hpp"
#include "auto.hpp"
#include "joystick.hpp"
#include "chairAdjust.hpp"
@@ -22,6 +23,8 @@ class buttonCommands {
QueueHandle_t encoderQueue_f,
controlledMotor * motorLeft_f,
controlledMotor *motorRight_f,
cControlledRest *legRest_f,
cControlledRest *backRest_f,
buzzer_t *buzzer_f);
//--- functions ---
@@ -40,6 +43,8 @@ class buttonCommands {
controlledMotor * motorRight;
buzzer_t* buzzer;
QueueHandle_t encoderQueue;
cControlledRest *legRest;
cControlledRest *backRest;
//--- variables ---
uint8_t count = 0;
@@ -62,6 +67,8 @@ typedef struct task_button_parameters_t
QueueHandle_t encoderQueue;
controlledMotor *motorLeft;
controlledMotor *motorRight;
cControlledRest *legRest;
cControlledRest *backRest;
buzzer_t *buzzer;
} task_button_parameters_t;

View File

@@ -162,8 +162,8 @@ void createObjects()
// create objects for controlling the chair position
// gpio_up, gpio_down, name
legRest = new cControlledRest(GPIO_NUM_2, GPIO_NUM_15, "legRest");
backRest = new cControlledRest(GPIO_NUM_16, GPIO_NUM_4, "backRest");
legRest = new cControlledRest(GPIO_NUM_2, GPIO_NUM_15, 14000, "legRest");
backRest = new cControlledRest(GPIO_NUM_16, GPIO_NUM_4, 12000, "backRest");
// create control object (control.hpp)
// with configuration from config.cpp
@@ -266,7 +266,7 @@ extern "C" void app_main(void) {
//--- create task for button ---
//------------------------------
//task that handles button/encoder events in any mode except 'MENU_SETTINGS' and 'MENU_MODE_SELECT' (e.g. switch modes by pressing certain count)
task_button_parameters_t button_param = {control, joystick, encoderQueue, motorLeft, motorRight, buzzer};
task_button_parameters_t button_param = {control, joystick, encoderQueue, motorLeft, motorRight, legRest, backRest, buzzer};
xTaskCreate(&task_button, "task_button", 4096, &button_param, 3, NULL);
//-----------------------------------
@@ -282,6 +282,13 @@ extern "C" void app_main(void) {
//task that handles the display (show stats, handle menu in 'MENU_SETTINGS' and 'MENU_MODE_SELECT' mode)
display_task_parameters_t display_param = {display_config, control, joystick, encoderQueue, motorLeft, motorRight, speedLeft, speedRight, buzzer, &nvsHandle};
xTaskCreate(&display_task, "display_task", 3*2048, &display_param, 3, NULL);
//-------------------------------------
//-- create task for chairAdjustment --
//-------------------------------------
//task that stops chair-rest motors when they reach target
chairAdjust_task_parameters_t chairAdjust_param = {legRest, backRest};
xTaskCreate(&chairAdjust_task, "chairAdjust_task", 2048, &chairAdjust_param, 1, NULL);
vTaskDelay(200 / portTICK_PERIOD_MS); //wait for all tasks to finish initializing
printf("\n");