motor_task.h 863 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #pragma once
  2. #include <Arduino.h>
  3. #include <vector>
  4. #include "knob_data.h"
  5. #include "task.h"
  6. enum class CommandType {
  7. CONFIG,
  8. HAPTIC,
  9. };
  10. struct HapticData {
  11. bool press;
  12. };
  13. struct Command {
  14. CommandType command_type;
  15. union CommandData {
  16. KnobConfig config;
  17. HapticData haptic;
  18. };
  19. CommandData data;
  20. };
  21. class MotorTask : public Task<MotorTask> {
  22. friend class Task<MotorTask>; // Allow base Task to invoke protected run()
  23. public:
  24. MotorTask(const uint8_t task_core);
  25. ~MotorTask();
  26. void setConfig(const KnobConfig& config);
  27. void playHaptic(bool press);
  28. void addListener(QueueHandle_t queue);
  29. protected:
  30. void run();
  31. private:
  32. QueueHandle_t queue_;
  33. std::vector<QueueHandle_t> listeners_;
  34. void publish(const KnobState& state);
  35. };