基质喷涂
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.9 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. //
  71. // //
  72. // // case E_STOP_PIN: {
  73. // // // 处理急停按键事件
  74. // // if (isPinStateTriggered(E_STOP_PIN, state)) {
  75. // // ZLOGI(TAG, "E_STOP_PIN Pressed");
  76. // //
  77. // // {
  78. // // CanMessage msg = CanProtocolFactory::createUploadEvent(0xFF, SYSTEM_E_STOP_Pressed);
  79. // // iflytop::AppHardware::ins()->can0Controller.sendMessage(msg);
  80. // // }
  81. // // iflytop::AppHardware::ins()->setE_Stop(true);
  82. // // iflytop::AppHardware::ins()->SystemPowerOff();
  83. // // } else {
  84. // // ZLOGI(TAG, "E_STOP_PIN Released");
  85. // // {
  86. // // CanMessage msg = CanProtocolFactory::createUploadEvent(0xFF, SYSTEM_E_STOP_Released);
  87. // // iflytop::AppHardware::ins()->can0Controller.sendMessage(msg);
  88. // // }
  89. // // iflytop::AppHardware::ins()->setE_Stop(false);
  90. // // bool isLaunched = iflytop::AppHardware::ins()->isLaunched();
  91. // // if(isLaunched) {
  92. // // iflytop::AppHardware::ins()->SystemPowerOn();
  93. // // }
  94. // // }
  95. // //
  96. // // if (pinStates[index] != state) {
  97. // // pinStates[index] = state;
  98. // // }
  99. // // break;
  100. // // }
  101. // //
  102. // //
  103. // // case SYSTEM_POWER_PIN: {
  104. // // // 处理暂停按键事件
  105. // // if(isPinStateTriggered(SYSTEM_POWER_PIN, state)) {
  106. // // ZLOGI(TAG, "SYSTEM_POWER_PIN Pressed");
  107. // //
  108. // // {
  109. // // CanMessage msg = CanProtocolFactory::createUploadEvent(0xFF, SYSTEM_Pause_Pressed);
  110. // // iflytop::AppHardware::ins()->can0Controller.sendMessage(msg);
  111. // // }
  112. // // RK3588_POWER_TOGGLE;
  113. // // LED_KEY_TOGGLE;
  114. // // // bool
  115. // // const bool isLaunched = iflytop::AppHardware::ins()->isLaunched();
  116. // // if(!isLaunched) {
  117. // // iflytop::AppHardware::ins()->SystemPowerOn();
  118. // // }
  119. // // else {
  120. // // iflytop::AppHardware::ins()->SystemPowerOff();
  121. // // }
  122. // // iflytop::AppHardware::ins()->toggleLaunched();
  123. // // }
  124. // // else {
  125. // // {
  126. // // CanMessage msg = CanProtocolFactory::createUploadEvent(0xFF, SYSTEM_Pause_Released);
  127. // // iflytop::AppHardware::ins()->can0Controller.sendMessage(msg);
  128. // // }
  129. // // ZLOGI(TAG, "SYSTEM POWER PIN Released");
  130. // // }
  131. // //
  132. // // if (pinStates[index] != state) {
  133. // // pinStates[index] = state;
  134. // // }
  135. // // break;
  136. // // }