- Move all separately declared functions in control.hpp to a new class 'controlledArmchair' - now passing other objects only one time with constructor instead of accessing them globally - Create control instance in config.hpp, and passing objects in config.cpp - Add functions to new control class - toggleIdle(): toggle between last mode and idle - toggleModes(mode1, mode2): toggle between two modes - Add commands to button.cpp - 2x button press: call toggleIdle() - 6x button press: toggleModes MASSAGE -> JOYSTICK - Define control task in main.cpp - Adjust button files and main.cpp to use the new command object instead of the previus functions
61 lines
1.9 KiB
C++
61 lines
1.9 KiB
C++
#pragma once
|
|
|
|
#include "motordrivers.hpp"
|
|
#include "motorctl.hpp"
|
|
#include "buzzer.hpp"
|
|
|
|
|
|
//enum that decides how the motors get controlled
|
|
enum class controlMode_t {IDLE, JOYSTICK, MASSAGE, MQTT, BLUETOOTH, AUTO};
|
|
//extern controlMode_t mode;
|
|
extern const char* controlModeStr[6];
|
|
|
|
|
|
|
|
//==================================
|
|
//========= control class ==========
|
|
//==================================
|
|
//controls the mode the armchair operates
|
|
//repeatedly generates the motor commands corresponding to current mode and sends those to motorcontrol
|
|
class controlledArmchair {
|
|
public:
|
|
//--- constructor ---
|
|
controlledArmchair (
|
|
buzzer_t* buzzer_f,
|
|
controlledMotor* motorLeft_f,
|
|
controlledMotor* motorRight_f
|
|
);
|
|
|
|
//--- functions ---
|
|
//task that repeatedly generates motor commands depending on the current mode
|
|
void startHandleLoop();
|
|
|
|
//function that changes to a specified control mode
|
|
void changeMode(controlMode_t modeNew);
|
|
|
|
//function that toggle between IDLE and previous active mode (or default if not switched to certain mode yet)
|
|
void toggleIdle();
|
|
|
|
//function that toggles between two modes, but prefers first argument if entirely different mode is currently active
|
|
void toggleModes(controlMode_t modePrimary, controlMode_t modeSecondary);
|
|
|
|
private:
|
|
|
|
//--- objects ---
|
|
buzzer_t* buzzer;
|
|
controlledMotor* motorLeft;
|
|
controlledMotor* motorRight;
|
|
|
|
//---variables ---
|
|
//struct for motor commands returned by generate functions of each mode
|
|
motorCommands_t commands;
|
|
|
|
//definition of mode enum
|
|
controlMode_t mode = controlMode_t::IDLE;
|
|
|
|
//variable to store mode when toggling IDLE mode
|
|
controlMode_t modePrevious = controlMode_t::JOYSTICK; //default mode
|
|
};
|
|
|
|
|