armchair_fw/main/button.hpp
jonny_ji7 adb517c7ed Create 'control.hpp/cpp', Create 'button.hpp/cpp'
Add control.hpp and control.cpp
 - task that repeatedly generates motor commands depending on the current mode
 - function to change to a specified control mode

Add button.hpp and button.cpp
  - class which runs commands depending on the count a button was pressed

Update main.cpp
  - create button task
  - create control task
  - comment out previous testing code
  - remove unnecessary includes (already included in config.hpp)

Add control.cpp and button.cpp to CMakeLists

Notes: Tested this state on the armchair: All currently implemented features
work. You can switch between IDLE and JOYSTICK by pressing the button 2
or 3 times. Also driving works well (limited to 60% duty, with no fans
yet).
2022-06-10 23:09:23 +02:00

41 lines
1.0 KiB
C++

#pragma once
#include "gpio_evaluateSwitch.hpp"
#include "buzzer.hpp"
//===================================
//====== buttonCommands class =======
//===================================
//class which runs commands depending on the count a button was pressed
class buttonCommands {
public:
//--- constructor ---
buttonCommands (
gpio_evaluatedSwitch * button_f,
buzzer_t * buzzer_f
);
//--- functions ---
//the following function has to be started once in a separate task.
//repeatedly evaluates and processes button events then takes the corresponding action
void startHandleLoop();
private:
//--- functions ---
void action(uint8_t count);
//--- objects ---
gpio_evaluatedSwitch* button;
buzzer_t* buzzer;
//--- variables ---
uint8_t count = 0;
uint32_t timestamp_lastAction = 0;
enum class inputState_t {IDLE, WAIT_FOR_INPUT};
inputState_t state = inputState_t::IDLE;
};