修复一下问题:
A用户绑定IPC和门夹弹力绳,分享给B用户; A用户先进入门夹弹力绳页面,已唤醒玩具,B用户再进入页面 A用户退出页面下发休眠指令,B用户操作玩具,未提示操作成功/失败
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
* @file app_function.c
|
||||
* @brief 设备功能开关 + 自动玩法 + 手动点动 + 按键动作实现
|
||||
* @author cyWu <1917507415@qq.com>
|
||||
* @date 2026.08.26
|
||||
* @version V1.1.0
|
||||
* @date 2026.09.10
|
||||
* @version V1.2.0
|
||||
* @history
|
||||
* - V1.0.0, 2026.08.25, cyWu, 首次发布,实现 DP0 开关、自动玩法、手动点动与按键动作
|
||||
* - V1.1.0, 2026.08.26, cyWu, 切模式闪灯改到 function_play_mode_apply 统一
|
||||
@@ -11,6 +11,8 @@
|
||||
* 启动也补上闪灯;DP2 停转(cmd=3)改边沿触发,
|
||||
* 避免残留的 03 一直把刚启动的自动模式打断;
|
||||
* 自动模式新增单次最长运行时长,到点回待机
|
||||
* - V1.2.0, 2026.09.10, cyWu, 软关后 APP 下发其它控制指令也可唤醒,
|
||||
* 唤醒后本拍继续执行该指令(玩法/点动)
|
||||
******************************************************************************/
|
||||
|
||||
#include "app_function.h"
|
||||
@@ -39,11 +41,13 @@ typedef struct {
|
||||
uint16_t hand_ms;
|
||||
volatile uint8_t hand_write_pending; /**< DP2 刚写入(03 停转要靠事件) */
|
||||
volatile uint8_t hand_write_cmd;
|
||||
volatile uint8_t app_cmd_wake; /**< 软关后收到其它 APP 控制 DP */
|
||||
} AppFunctionCtx_t;
|
||||
|
||||
static AppFunctionCtx_t s_func;
|
||||
|
||||
static void function_hand_stop(void);
|
||||
static void function_app_power_on(const char *reason);
|
||||
static void function_play_mode_apply(uint8_t mode);
|
||||
static void function_play_mode_poll(void);
|
||||
static void function_play_mode_timeout(uint16_t dt);
|
||||
@@ -70,18 +74,45 @@ void app_function_dp_hand_write(uint8_t cmd)
|
||||
s_func.hand_write_pending = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief APP 下发了非关机控制 DP,软关时下一拍唤醒
|
||||
* @return 无
|
||||
*/
|
||||
void app_function_on_app_cmd(void)
|
||||
{
|
||||
s_func.app_cmd_wake = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief APP 侧开机:功能开、同步 DP0、挂开机绿灯
|
||||
* @param reason 日志原因(英文)
|
||||
* @return 无
|
||||
*/
|
||||
static void function_app_power_on(const char *reason)
|
||||
{
|
||||
s_func.app_power = 1;
|
||||
gDevData.power = 1;
|
||||
app_led_hint_power_on();
|
||||
log_info("%s\n", reason);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 跟随 APP 下发的 DP0/DP1,并处理 DP2 手动点动
|
||||
* @return 无
|
||||
*/
|
||||
void app_function_poll(void)
|
||||
{
|
||||
/* DP0:APP 下发开关。充电中 / 正在关机时不跟,避免和 USB 软关抢状态 */
|
||||
uint8_t cmd_wake = s_func.app_cmd_wake;
|
||||
|
||||
s_func.app_cmd_wake = 0;
|
||||
|
||||
/* DP0:APP 下发开关。充电中 / 正在关机时不跟,避免和 USB 软关抢状态。
|
||||
* 已软关时,后续其它控制 DP 也当开机,本拍接着跑玩法/点动。 */
|
||||
if (!app_power_usb_online() && !app_power_poweroff_pending()) {
|
||||
if (gDevData.power && !s_func.app_power) {
|
||||
s_func.app_power = 1;
|
||||
app_led_hint_power_on();
|
||||
log_info("APP power on\n");
|
||||
if (!s_func.app_power && cmd_wake) {
|
||||
function_app_power_on("APP cmd wake from soft off");
|
||||
} else if (gDevData.power && !s_func.app_power) {
|
||||
function_app_power_on("APP power on");
|
||||
} else if (!gDevData.power && s_func.app_power) {
|
||||
app_function_soft_off();
|
||||
}
|
||||
@@ -133,7 +164,7 @@ void app_function_stop_all(void)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 软关:电机停、DP0=0,等 APP/短按再开。不断 BLE
|
||||
* @brief 软关:电机停、DP0=0,等 APP 开机/其它指令/短按再开。不断 BLE
|
||||
* @return 无
|
||||
*/
|
||||
void app_function_soft_off(void)
|
||||
@@ -145,7 +176,7 @@ void app_function_soft_off(void)
|
||||
gDevData.play_mode = 0;
|
||||
app_mode_stop();
|
||||
function_hand_stop();
|
||||
log_info("soft off, wait APP power on\n");
|
||||
log_info("soft off, wait APP cmd or key\n");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,10 +2,11 @@
|
||||
* @file app_function.h
|
||||
* @brief 设备功能开关(DP0)+ 自动玩法(DP1)+ 手动点动(DP2)+ 按键动作
|
||||
* @author cyWu <1917507415@qq.com>
|
||||
* @date 2026.08.25
|
||||
* @version V1.0.0
|
||||
* @date 2026.09.10
|
||||
* @version V1.2.0
|
||||
* @history
|
||||
* - V1.0.0, 2026.08.25, cyWu, 首次发布,实现 DP0 开关、自动玩法、手动点动与按键动作
|
||||
* - V1.2.0, 2026.09.10, cyWu, 软关后 APP 下发其它控制 DP 也可唤醒功能
|
||||
*
|
||||
* @note 本模块决定“电机现在该不该转、转哪种”,会读 app_power/app_pair 的
|
||||
* 状态作为阻塞条件(充电中/深睡中/配对中都不能转),也会触发
|
||||
@@ -30,6 +31,13 @@ void app_function_init(void);
|
||||
*/
|
||||
void app_function_dp_hand_write(uint8_t cmd);
|
||||
|
||||
/**
|
||||
* @brief APP 下发了非关机控制 DP(玩法/点动等),软关时下一拍唤醒功能
|
||||
* @note 与关机 DP 同一帧到达时不要调用,避免关完立刻被同包其它 DP 拉开
|
||||
* @return 无
|
||||
*/
|
||||
void app_function_on_app_cmd(void);
|
||||
|
||||
/**
|
||||
* @brief 跟随 APP 下发的 DP0/DP1,并处理 DP2 手动点动,每个业务 tick 调用一次
|
||||
* @return 无
|
||||
@@ -50,7 +58,7 @@ void app_function_tick_1ms(uint16_t dt);
|
||||
void app_function_stop_all(void);
|
||||
|
||||
/**
|
||||
* @brief 软关:电机停、DP0=0,等 APP/短按再开(USB 拔出 / APP 关时用)
|
||||
* @brief 软关:电机停、DP0=0,等 APP 开机/其它指令/短按再开(USB 拔出 / APP 关时用)
|
||||
* @return 无
|
||||
*/
|
||||
void app_function_soft_off(void);
|
||||
|
||||
Reference in New Issue
Block a user