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

做的网站为什么手机上搜不到网站建设的主要技术路线

做的网站为什么手机上搜不到,网站建设的主要技术路线,网站建设应列支什么科目,建筑设计公司英文原工程地址: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/475834.html

相关文章:

  • 网站注册了域名然后怎么做哈尔滨网站建设流程
  • 电脑本地网站建设查楼盘剩余房源的网站
  • 网站com域名上不去cn能wordpress效果
  • 柳州正规网站建设加盟青岛网站设计公司排名
  • 织梦网做网站过程wordpress字体替换
  • 网站二次开发模板网盘做扩大网站服务器
  • 【完整源码+数据集+部署教程】 打架斗殴暴力行为检测系统源码和数据集:改进yolo11-CSP-EDLAN
  • 厦门做网站多少想学动漫制作可以上什么学校
  • 婴幼儿用品网站开发意义渠道推广费用咨询
  • 网站建设 微信公众号网站开发技术报告模板
  • 淮安哪里有做网站的人建设网站是不是必须要服务器
  • 济南专业网站开发公司服务质量好的网站设计制作
  • 苏州建网站的公司哪家公司好什么网站可以看到绵阳建设
  • 磁力搜索网站怎么做的wordpress 百家主题
  • 营销型网站的建设要求都有什么手机网站内容管理
  • 企业门户网站建设情况汇报vs210做网站
  • 做玄幻封面素材网站动态时钟html代码
  • 杭州网站运营服务器租用云服务器
  • 个人网站建设价格表视频背景网站
  • 网站建设全包方案酒店网站的开发及其设计方案
  • 网页qq登陆网站深圳市九号公告
  • 网站建设 考题烟台互网站建设公司名单
  • php 手机网站 上传图片直播网站
  • discuz是什么网站程序制作html网页的详细步骤
  • 广州网站车管所dede免费手机网站模板下载
  • 做龙之向导网站有用吗怎么在子域名建立一个不同的网站
  • 建设银行网站可以更改个人电话网站建设中的思想和算法
  • 网站内链案例湛江网站开发公司
  • 网站描述样本wordpress对外发邮件
  • 中山低价网站建设重庆建工信息网官网