interface_task.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #pragma once
  2. #include <AceButton.h>
  3. #include <Arduino.h>
  4. #include "configuration.h"
  5. #include "display_task.h"
  6. #include "logger.h"
  7. #include "motor_task.h"
  8. #include "serial/serial_protocol_plaintext.h"
  9. #include "serial/serial_protocol_protobuf.h"
  10. #include "serial/uart_stream.h"
  11. #include "task.h"
  12. #ifndef SK_FORCE_UART_STREAM
  13. #define SK_FORCE_UART_STREAM 0
  14. #endif
  15. class InterfaceTask : public Task<InterfaceTask>, public Logger {
  16. friend class Task<InterfaceTask>; // Allow base Task to invoke protected run()
  17. public:
  18. InterfaceTask(const uint8_t task_core, MotorTask& motor_task, DisplayTask* display_task);
  19. virtual ~InterfaceTask();
  20. void log(const char* msg) override;
  21. void setConfiguration(Configuration* configuration);
  22. protected:
  23. void run();
  24. private:
  25. #if defined(CONFIG_IDF_TARGET_ESP32S3) && !SK_FORCE_UART_STREAM
  26. HWCDC stream_;
  27. #else
  28. UartStream stream_;
  29. #endif
  30. MotorTask& motor_task_;
  31. DisplayTask* display_task_;
  32. char buf_[128];
  33. SemaphoreHandle_t mutex_;
  34. Configuration* configuration_ = nullptr; // protected by mutex_
  35. PB_PersistentConfiguration configuration_value_;
  36. bool configuration_loaded_ = false;
  37. uint8_t strain_calibration_step_ = 0;
  38. int32_t strain_reading_ = 0;
  39. SerialProtocol* current_protocol_ = nullptr;
  40. bool remote_controlled_ = false;
  41. int current_config_ = 0;
  42. uint8_t press_count_ = 1;
  43. PB_SmartKnobState latest_state_ = {};
  44. PB_SmartKnobConfig latest_config_ = {};
  45. QueueHandle_t log_queue_;
  46. QueueHandle_t knob_state_queue_;
  47. SerialProtocolPlaintext plaintext_protocol_;
  48. SerialProtocolProtobuf proto_protocol_;
  49. void changeConfig(bool next);
  50. void updateHardware();
  51. void publishState();
  52. void applyConfig(PB_SmartKnobConfig& config, bool from_remote);
  53. };