当前位置: 首页 > news >正文

企业网站推广的形式有哪些福州网站推广排名

企业网站推广的形式有哪些,福州网站推广排名,wordpress虚拟空,自搭建网站原工程地址:https://github.com/candylife9/state_machine_example 视频:C语言之状态机编程_02_状态机使用案例分析_哔哩哔哩_bilibili 我觉得讲的挺好的。 来自豆包封装的通用接口 头文件 /*** file key_state_machine.h* brief 通用按键状态机接口…

原工程地址:https://github.com/candylife9/state_machine_example

视频:C语言之状态机编程_02_状态机使用案例分析_哔哩哔哩_bilibili

我觉得讲的挺好的。

来自豆包封装的通用接口

头文件

/*** @file key_state_machine.h* @brief 通用按键状态机接口*/#ifndef KEY_STATE_MACHINE_H
#define KEY_STATE_MACHINE_H#include <stdint.h>
#include <stdbool.h>/** 按键状态枚举 */
typedef enum {KEY_STATE_IDLE,           // 空闲状态KEY_STATE_PRESS_DEBOUNCE, // 按下消抖状态KEY_STATE_SHORT_PRESS,    // 短按状态KEY_STATE_LONG_PRESS,     // 长按状态KEY_STATE_RELEASE_DEBOUNCE // 释放消抖状态
} KeyState;/** 按键事件回调函数类型 */
typedef void (*KeyEventCallback)(void* context, uint8_t key_id, bool is_long_press);/** 按键配置结构体 */
typedef struct {uint8_t key_id;                  // 按键IDuint32_t debounce_time_ms;       // 消抖时间(ms)uint32_t long_press_threshold_ms; // 长按阈值(ms)uint32_t long_press_interval_ms;  // 长按连续触发间隔(ms)bool active_low;                 // 是否低电平有效bool (*read_pin)(void);          // 读取引脚电平的函数指针KeyEventCallback event_callback; // 事件回调函数void* callback_context;          // 回调函数上下文
} KeyConfig;/** 按键状态机实例结构体 */
typedef struct {const KeyConfig* config;         // 按键配置KeyState state;                  // 当前状态uint8_t debounce_counter;        // 消抖计数器uint32_t check_time;             // 检测时间戳uint32_t old_time;               // 旧时间戳bool press_detected;             // 短按检测标志bool long_press_detected;        // 长按检测标志uint32_t long_press_trigger_time; // 长按触发时间
} KeyStateMachine;/*** @brief 初始化按键状态机* @param key 按键状态机实例指针* @param config 按键配置指针*/
void Key_Init(KeyStateMachine* key, const KeyConfig* config);/*** @brief 按键状态机处理函数,需定期调用* @param key 按键状态机实例指针*/
void Key_Process(KeyStateMachine* key);/*** @brief 获取按键当前状态* @param key 按键状态机实例指针* @return 当前状态*/
KeyState Key_GetState(const KeyStateMachine* key);/*** @brief 检查按键是否被按下(短按或长按)* @param key 按键状态机实例指针* @return true: 按下, false: 未按下*/
bool Key_IsPressed(const KeyStateMachine* key);/*** @brief 检查按键是否处于长按状态* @param key 按键状态机实例指针* @return true: 长按, false: 非长按*/
bool Key_IsLongPressed(const KeyStateMachine* key);#endif // KEY_STATE_MACHINE_H

C文件 

/*** @file key_state_machine.c* @brief 通用按键状态机实现*/#include "key_state_machine.h"
#include "stm32fxxx_hal.h" // 假设使用STM32系列,需要包含HAL库头文件/*** @brief 判断引脚电平是否为有效电平* @param key 按键状态机实例指针* @return true: 有效电平, false: 无效电平*/
static bool IsKeyLevelActive(const KeyStateMachine* key) {bool pin_state = key->config->read_pin();return (key->config->active_low) ? (pin_state == false) : (pin_state == true);
}void Key_Init(KeyStateMachine* key, const KeyConfig* config) {if (!key || !config) return;key->config = config;key->state = KEY_STATE_IDLE;key->debounce_counter = 0;key->check_time = HAL_GetTick();key->old_time = HAL_GetTick();key->press_detected = false;key->long_press_detected = false;key->long_press_trigger_time = 0;
}void Key_Process(KeyStateMachine* key) {if (!key || !key->config) return;uint32_t current_time = HAL_GetTick();switch (key->state) {case KEY_STATE_IDLE:if (current_time - key->old_time > 1000) {// 空闲时,每间隔1秒输出等待按键提示信息(可通过回调函数实现)if (key->config->event_callback) {key->config->event_callback(key->config->callback_context, key->config->key_id, false);}key->old_time = current_time;}if (IsKeyLevelActive(key)) {// 检测到有效电平,开始消抖key->check_time = current_time;key->debounce_counter = 5; // 默认5次检测key->state = KEY_STATE_PRESS_DEBOUNCE;}break;case KEY_STATE_PRESS_DEBOUNCE:if (key->debounce_counter > 0) {if (current_time - key->check_time > key->config->debounce_time_ms) {if (!IsKeyLevelActive(key)) {// 检测到无效电平,抖动,返回空闲状态key->old_time = current_time;key->state = KEY_STATE_IDLE;} else {// 仍然是有效电平,继续消抖key->check_time = current_time;key->debounce_counter--;}}} else {// 消抖完成,确认按下key->press_detected = true;key->old_time = current_time;key->long_press_trigger_time = current_time;key->state = KEY_STATE_SHORT_PRESS;// 触发短按事件回调if (key->config->event_callback) {key->config->event_callback(key->config->callback_context, key->config->key_id, false);}}break;case KEY_STATE_SHORT_PRESS:key->press_detected = false; // 重置短按标志if (current_time - key->old_time > key->config->long_press_threshold_ms) {// 达到长按阈值,进入长按状态key->long_press_detected = true;key->old_time = current_time;key->state = KEY_STATE_LONG_PRESS;// 触发长按事件回调if (key->config->event_callback) {key->config->event_callback(key->config->callback_context, key->config->key_id, true);}} else if (!IsKeyLevelActive(key)) {// 短按状态下检测到释放,开始释放消抖key->check_time = current_time;key->debounce_counter = 5;key->state = KEY_STATE_RELEASE_DEBOUNCE;}break;case KEY_STATE_LONG_PRESS:if (current_time - key->old_time > key->config->long_press_interval_ms) {// 长按连续触发key->old_time = current_time;// 触发长按连续事件回调if (key->config->event_callback) {key->config->event_callback(key->config->callback_context, key->config->key_id, true);}}if (!IsKeyLevelActive(key)) {// 长按状态下检测到释放,开始释放消抖key->check_time = current_time;key->debounce_counter = 5;key->state = KEY_STATE_RELEASE_DEBOUNCE;}break;case KEY_STATE_RELEASE_DEBOUNCE:if (key->debounce_counter > 0) {if (current_time - key->check_time > key->config->debounce_time_ms) {if (IsKeyLevelActive(key)) {// 检测到有效电平,抖动,返回之前的状态key->state = (key->long_press_detected) ? KEY_STATE_LONG_PRESS : KEY_STATE_SHORT_PRESS;} else {// 仍然是无效电平,继续消抖key->check_time = current_time;key->debounce_counter--;}}} else {// 消抖完成,确认释放key->long_press_detected = false;key->old_time = current_time;key->state = KEY_STATE_IDLE;}break;default:key->state = KEY_STATE_IDLE;break;}
}KeyState Key_GetState(const KeyStateMachine* key) {return (key) ? key->state : KEY_STATE_IDLE;
}bool Key_IsPressed(const KeyStateMachine* key) {if (!key) return false;KeyState state = key->state;return (state == KEY_STATE_SHORT_PRESS || state == KEY_STATE_LONG_PRESS);
}bool Key_IsLongPressed(const KeyStateMachine* key) {return (key && key->state == KEY_STATE_LONG_PRESS);
}

http://www.dtcms.com/a/490660.html

相关文章:

  • 关键词优化网站排名群英云服务器
  • nano-GPT:最小可复现的GPT实操
  • 网站建设公众号wordpress中文模板下载地址
  • 菜单及库(Num28)
  • super()核心作用是调用父类的属性/方法
  • 【Win32 多线程程序设计基础第三章笔记】
  • CentOS 7 FTP安装与配置详细介绍
  • 网页设计跟网站建设的区别淘宝店铺运营推广
  • 机器学习使用GPU
  • 做网站分为哪些功能的网站找工作网
  • 湖南粒界教育科技有限公司:专注影视技能培养,AI辅助教学提升学员就业竞争力
  • 【系统分析师】写作框架:静态测试方法及其应用
  • React useEffect组件渲染执行操作 组件生命周期 监视器 副作用
  • 在哪些场景下适合使用 v-model 机制?
  • 长沙申请域名网站备案查域名服务商
  • 游标卡尺 东莞网站建设大连建设工程信息网去哪里找
  • 华为USG防火墙之开局上网配置
  • 【第五章:计算机视觉-计算机视觉在医学领域中应用】1.生物细胞检测实战-(3)基于YOLO的细胞检测实战:数据读取、模型搭建、训练与测试
  • 【MFC实用技巧】对话框“边框”属性四大选项:None、Thin、Resizing、对话框外框,到底怎么选?
  • 网站备案 备注关联性天津网站建设内容
  • 所有网站收录入口济南市住监局官网
  • frida android quickstart
  • 作为测试工程师,我们该如何应用 AI?
  • 【Flutter】Flutter项目整体架构
  • 电子电气架构 --- 未来汽车软件架构
  • 怎么优化网站关键词辽宁省住房建设厅网站科技中心
  • 电力自动化新突破:Modbus如何变身Profinet?智能仪表连接的终极解决方案
  • cGVHD患者的血常规指标 生化指标 动态监测
  • 重庆网站建设师网站顶部布局
  • 【算法与数据结构】二叉树后序遍历非递归算法:保姆级教程(附具体实例+可运行代码)