基质喷涂
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
902 B

  1. //
  2. // Created by iflyt on 2025/3/17.
  3. //
  4. #ifndef TIMER_KEY_MANAGER_H
  5. #define TIMER_KEY_MANAGER_H
  6. #include <cmsis_os2.h>
  7. #include <stm32f4xx_hal.h>
  8. // 按键和传感器引脚定义
  9. #define SYSTEM_POWER_PIN GPIO_PIN_0
  10. #define SYSTEM_POWER_PORT GPIOA
  11. #define E_STOP_PIN GPIO_PIN_12
  12. #define E_STOP_PORT GPIOF
  13. #define TIMER_KEY_COUNT 2
  14. /**
  15. *
  16. */
  17. enum class ButtonStateExtended {
  18. BUTTON_STATE_IDLE,
  19. BUTTON_STATE_PRESSED,
  20. BUTTON_STATE_LONG_PRESSED,
  21. BUTTON_STATE_LONG_RELEASED
  22. };
  23. struct TimerKeyInfo {
  24. GPIO_TypeDef* port;
  25. uint16_t pin;
  26. uint32_t longPressTime;
  27. uint32_t pressStartTime;
  28. ButtonStateExtended state;
  29. };
  30. class TimerKeyManager {
  31. public:
  32. TimerKeyManager();
  33. ~TimerKeyManager();
  34. void start();
  35. void poll();
  36. private:
  37. static TimerKeyInfo timer_keys_[TIMER_KEY_COUNT];
  38. osTimerId_t timer_;
  39. };
  40. #endif //TIMER_KEY_MANAGER_H