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
136 lines
4.7 KiB
// //
|
|
// // Created by iflyt on 2025/3/17.
|
|
// //
|
|
//
|
|
// #include "timer_key_manager.h"
|
|
//
|
|
// TimerKeyInfo TimerKeyManager::timer_keys_[TIMER_KEY_COUNT] = {
|
|
// {SYSTEM_POWER_PORT, SYSTEM_POWER_PIN, 3000, 500},
|
|
// {E_STOP_PORT, E_STOP_PIN, 3000, 500}
|
|
// };
|
|
//
|
|
//
|
|
// TimerKeyManager::TimerKeyManager() {
|
|
//
|
|
// }
|
|
//
|
|
// TimerKeyManager::~TimerKeyManager() {
|
|
//
|
|
// }
|
|
//
|
|
// void TimerKeyManager::start() {
|
|
// osTimerId_t timer = osTimerNew(timerCallback, osTimerPeriodic, &buttonManager, nullptr);
|
|
// if (timer != nullptr) {
|
|
// osTimerStart(timer, 10); // 每 10ms 轮询一次
|
|
// }
|
|
// }
|
|
//
|
|
// void TimerKeyManager::poll() {
|
|
// uint32_t currentTime = osKernelGetTickCount();
|
|
// for (auto& button : timer_keys_) {
|
|
// bool isPressed = HAL_GPIO_ReadPin(button.port, button.pin) == GPIO_PIN_RESET;
|
|
// switch (button.state) {
|
|
// case ButtonStateExtended::BUTTON_STATE_IDLE:
|
|
// if (isPressed) {
|
|
// button.state = ButtonStateExtended::BUTTON_STATE_PRESSED;
|
|
// button.pressStartTime = currentTime;
|
|
// }
|
|
// break;
|
|
// case ButtonStateExtended::BUTTON_STATE_PRESSED:
|
|
// if (!isPressed) {
|
|
// if (currentTime - button.pressStartTime < button.shortPressTime) {
|
|
// button.state = ButtonStateExtended::BUTTON_STATE_SHORT_PRESSED;
|
|
// if (button.shortPressCallback) {
|
|
// button.shortPressCallback();
|
|
// }
|
|
// }
|
|
// button.state = ButtonStateExtended::BUTTON_STATE_IDLE;
|
|
// } else if (currentTime - button.pressStartTime >= button.longPressTime) {
|
|
// button.state = ButtonStateExtended::BUTTON_STATE_LONG_PRESSED;
|
|
// if (button.longPressCallback) {
|
|
// button.longPressCallback();
|
|
// }
|
|
// button.state = ButtonStateExtended::BUTTON_STATE_IDLE;
|
|
// }
|
|
// break;
|
|
// case ButtonStateExtended::BUTTON_STATE_SHORT_PRESSED:
|
|
// case ButtonStateExtended::BUTTON_STATE_LONG_PRESSED:
|
|
// // 此状态仅为过渡,正常情况下不会进入此分支
|
|
// break;
|
|
// }
|
|
// }
|
|
// }
|
|
//
|
|
// // 定时器回调函数
|
|
// void timerCallback(void* arg) {
|
|
// TimerKeyManager* manager = static_cast<TimerKeyManager*>(arg);
|
|
// manager->poll();
|
|
// }
|
|
|
|
|
|
//
|
|
// case E_STOP_PIN: {
|
|
// // 处理急停按键事件
|
|
// if (isPinStateTriggered(E_STOP_PIN, state)) {
|
|
// ZLOGI(TAG, "E_STOP_PIN Pressed");
|
|
//
|
|
// {
|
|
// CanMessage msg = CanProtocolFactory::createUploadEvent(0xFF, SYSTEM_E_STOP_Pressed);
|
|
// iflytop::AppHardware::ins()->can0Controller.sendMessage(msg);
|
|
// }
|
|
// iflytop::AppHardware::ins()->setE_Stop(true);
|
|
// iflytop::AppHardware::ins()->SystemPowerOff();
|
|
// } else {
|
|
// ZLOGI(TAG, "E_STOP_PIN Released");
|
|
// {
|
|
// CanMessage msg = CanProtocolFactory::createUploadEvent(0xFF, SYSTEM_E_STOP_Released);
|
|
// iflytop::AppHardware::ins()->can0Controller.sendMessage(msg);
|
|
// }
|
|
// iflytop::AppHardware::ins()->setE_Stop(false);
|
|
// bool isLaunched = iflytop::AppHardware::ins()->isLaunched();
|
|
// if(isLaunched) {
|
|
// iflytop::AppHardware::ins()->SystemPowerOn();
|
|
// }
|
|
// }
|
|
//
|
|
// if (pinStates[index] != state) {
|
|
// pinStates[index] = state;
|
|
// }
|
|
// break;
|
|
// }
|
|
//
|
|
//
|
|
// case SYSTEM_POWER_PIN: {
|
|
// // 处理暂停按键事件
|
|
// if(isPinStateTriggered(SYSTEM_POWER_PIN, state)) {
|
|
// ZLOGI(TAG, "SYSTEM_POWER_PIN Pressed");
|
|
//
|
|
// {
|
|
// CanMessage msg = CanProtocolFactory::createUploadEvent(0xFF, SYSTEM_Pause_Pressed);
|
|
// iflytop::AppHardware::ins()->can0Controller.sendMessage(msg);
|
|
// }
|
|
// RK3588_POWER_TOGGLE;
|
|
// LED_KEY_TOGGLE;
|
|
// // bool
|
|
// const bool isLaunched = iflytop::AppHardware::ins()->isLaunched();
|
|
// if(!isLaunched) {
|
|
// iflytop::AppHardware::ins()->SystemPowerOn();
|
|
// }
|
|
// else {
|
|
// iflytop::AppHardware::ins()->SystemPowerOff();
|
|
// }
|
|
// iflytop::AppHardware::ins()->toggleLaunched();
|
|
// }
|
|
// else {
|
|
// {
|
|
// CanMessage msg = CanProtocolFactory::createUploadEvent(0xFF, SYSTEM_Pause_Released);
|
|
// iflytop::AppHardware::ins()->can0Controller.sendMessage(msg);
|
|
// }
|
|
// ZLOGI(TAG, "SYSTEM POWER PIN Released");
|
|
// }
|
|
//
|
|
// if (pinStates[index] != state) {
|
|
// pinStates[index] = state;
|
|
// }
|
|
// break;
|
|
// }
|