generated from Template/H563ZI-HAL-CMake-Template
新增 Hc05 类,支持 HC-05 蓝牙模块的串口通信,增加串口设置波特率函数
All checks were successful
Build and Upload Artifact / build and upload-artifact (push) Successful in 19m59s
All checks were successful
Build and Upload Artifact / build and upload-artifact (push) Successful in 19m59s
This commit is contained in:
31
Core/App/Common/key.hpp
Normal file
31
Core/App/Common/key.hpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include "../Helper/delay_helper.h"
|
||||
#include "stm32h5xx_hal_gpio.h"
|
||||
#include <cstdint>
|
||||
|
||||
#include "../Helper/gpio_helper.hpp"
|
||||
|
||||
class Key {
|
||||
private:
|
||||
static constexpr uint32_t kDebounceDelay = 20;
|
||||
GpioHelper::Gpio gpio;
|
||||
GPIO_PinState normalStatus;
|
||||
|
||||
public:
|
||||
explicit Key(GpioHelper::Gpio gpio, GPIO_PinState normalStatus) : gpio(gpio), normalStatus(normalStatus) {
|
||||
GpioHelper::GpioInit(gpio, GPIO_MODE_INPUT, normalStatus ? GPIO_PULLUP : GPIO_PULLDOWN);
|
||||
}
|
||||
|
||||
bool IsPressed() {
|
||||
auto reading = gpio.Read();
|
||||
if (reading != normalStatus) {
|
||||
DelayMs(kDebounceDelay);
|
||||
reading = gpio.Read();
|
||||
if (reading != normalStatus) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user