基质喷涂
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.

136 lines
4.7 KiB

  1. // //
  2. // // Created by iflyt on 2025/3/17.
  3. // //
  4. //
  5. // #include "timer_key_manager.h"
  6. //
  7. // TimerKeyInfo TimerKeyManager::timer_keys_[TIMER_KEY_COUNT] = {
  8. // {SYSTEM_POWER_PORT, SYSTEM_POWER_PIN, 3000, 500},
  9. // {E_STOP_PORT, E_STOP_PIN, 3000, 500}
  10. // };
  11. //
  12. //
  13. // TimerKeyManager::TimerKeyManager() {
  14. //
  15. // }
  16. //
  17. // TimerKeyManager::~TimerKeyManager() {
  18. //
  19. // }
  20. //
  21. // void TimerKeyManager::start() {
  22. // osTimerId_t timer = osTimerNew(timerCallback, osTimerPeriodic, &buttonManager, nullptr);
  23. // if (timer != nullptr) {
  24. // osTimerStart(timer, 10); // 每 10ms 轮询一次
  25. // }
  26. // }
  27. //
  28. // void TimerKeyManager::poll() {
  29. // uint32_t currentTime = osKernelGetTickCount();
  30. // for (auto& button : timer_keys_) {
  31. // bool isPressed = HAL_GPIO_ReadPin(button.port, button.pin) == GPIO_PIN_RESET;
  32. // switch (button.state) {
  33. // case ButtonStateExtended::BUTTON_STATE_IDLE:
  34. // if (isPressed) {
  35. // button.state = ButtonStateExtended::BUTTON_STATE_PRESSED;
  36. // button.pressStartTime = currentTime;
  37. // }
  38. // break;
  39. // case ButtonStateExtended::BUTTON_STATE_PRESSED:
  40. // if (!isPressed) {
  41. // if (currentTime - button.pressStartTime < button.shortPressTime) {
  42. // button.state = ButtonStateExtended::BUTTON_STATE_SHORT_PRESSED;
  43. // if (button.shortPressCallback) {
  44. // button.shortPressCallback();
  45. // }
  46. // }
  47. // button.state = ButtonStateExtended::BUTTON_STATE_IDLE;
  48. // } else if (currentTime - button.pressStartTime >= button.longPressTime) {
  49. // button.state = ButtonStateExtended::BUTTON_STATE_LONG_PRESSED;
  50. // if (button.longPressCallback) {
  51. // button.longPressCallback();
  52. // }
  53. // button.state = ButtonStateExtended::BUTTON_STATE_IDLE;
  54. // }
  55. // break;
  56. // case ButtonStateExtended::BUTTON_STATE_SHORT_PRESSED:
  57. // case ButtonStateExtended::BUTTON_STATE_LONG_PRESSED:
  58. // // 此状态仅为过渡,正常情况下不会进入此分支
  59. // break;
  60. // }
  61. // }
  62. // }
  63. //
  64. // // 定时器回调函数
  65. // void timerCallback(void* arg) {
  66. // TimerKeyManager* manager = static_cast<TimerKeyManager*>(arg);
  67. // manager->poll();
  68. // }
  69. //
  70. // case E_STOP_PIN: {
  71. // // 处理急停按键事件
  72. // if (isPinStateTriggered(E_STOP_PIN, state)) {
  73. // ZLOGI(TAG, "E_STOP_PIN Pressed");
  74. //
  75. // {
  76. // CanMessage msg = CanProtocolFactory::createUploadEvent(0xFF, SYSTEM_E_STOP_Pressed);
  77. // iflytop::AppHardware::ins()->can0Controller.sendMessage(msg);
  78. // }
  79. // iflytop::AppHardware::ins()->setE_Stop(true);
  80. // iflytop::AppHardware::ins()->SystemPowerOff();
  81. // } else {
  82. // ZLOGI(TAG, "E_STOP_PIN Released");
  83. // {
  84. // CanMessage msg = CanProtocolFactory::createUploadEvent(0xFF, SYSTEM_E_STOP_Released);
  85. // iflytop::AppHardware::ins()->can0Controller.sendMessage(msg);
  86. // }
  87. // iflytop::AppHardware::ins()->setE_Stop(false);
  88. // bool isLaunched = iflytop::AppHardware::ins()->isLaunched();
  89. // if(isLaunched) {
  90. // iflytop::AppHardware::ins()->SystemPowerOn();
  91. // }
  92. // }
  93. //
  94. // if (pinStates[index] != state) {
  95. // pinStates[index] = state;
  96. // }
  97. // break;
  98. // }
  99. //
  100. //
  101. // case SYSTEM_POWER_PIN: {
  102. // // 处理暂停按键事件
  103. // if(isPinStateTriggered(SYSTEM_POWER_PIN, state)) {
  104. // ZLOGI(TAG, "SYSTEM_POWER_PIN Pressed");
  105. //
  106. // {
  107. // CanMessage msg = CanProtocolFactory::createUploadEvent(0xFF, SYSTEM_Pause_Pressed);
  108. // iflytop::AppHardware::ins()->can0Controller.sendMessage(msg);
  109. // }
  110. // RK3588_POWER_TOGGLE;
  111. // LED_KEY_TOGGLE;
  112. // // bool
  113. // const bool isLaunched = iflytop::AppHardware::ins()->isLaunched();
  114. // if(!isLaunched) {
  115. // iflytop::AppHardware::ins()->SystemPowerOn();
  116. // }
  117. // else {
  118. // iflytop::AppHardware::ins()->SystemPowerOff();
  119. // }
  120. // iflytop::AppHardware::ins()->toggleLaunched();
  121. // }
  122. // else {
  123. // {
  124. // CanMessage msg = CanProtocolFactory::createUploadEvent(0xFF, SYSTEM_Pause_Released);
  125. // iflytop::AppHardware::ins()->can0Controller.sendMessage(msg);
  126. // }
  127. // ZLOGI(TAG, "SYSTEM POWER PIN Released");
  128. // }
  129. //
  130. // if (pinStates[index] != state) {
  131. // pinStates[index] = state;
  132. // }
  133. // break;
  134. // }