修复一下问题:

A用户绑定IPC和门夹弹力绳,分享给B用户;
A用户先进入门夹弹力绳页面,已唤醒玩具,B用户再进入页面
A用户退出页面下发休眠指令,B用户操作玩具,未提示操作成功/失败
This commit is contained in:
2026-09-10 11:43:33 +08:00
parent 026d6d5da7
commit 5875d2a339
5 changed files with 155 additions and 45 deletions
+40 -9
View File
@@ -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");
}
/**
+11 -3
View File
@@ -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);
+19
View File
@@ -69,6 +69,9 @@ void userHandle(void)
* ════════════════════════════════════════════════════════════════ */
int8_t jbEventProcess(jb_event_info_t *info, jb_data_point_t *ctrl)
{
uint8_t other_cmd = 0;
uint8_t got_power_off = 0;
if (!info || !ctrl)
{
return -1;
@@ -89,6 +92,7 @@ int8_t jbEventProcess(jb_event_info_t *info, jb_data_point_t *ctrl)
else
{
gDevData.power = 0;
got_power_off = 1;
// TODO: 关 — 执行动作
}
break;
@@ -96,6 +100,7 @@ int8_t jbEventProcess(jb_event_info_t *info, jb_data_point_t *ctrl)
/* ── DP1 自动模式 (enum) ── */
case DP_ID_PLAY_MODE:
gDevData.play_mode = ctrl->play_mode;
other_cmd = 1;
switch (ctrl->play_mode)
{
case PLAY_MODE_0: /* 停止复位 */
@@ -127,6 +132,7 @@ int8_t jbEventProcess(jb_event_info_t *info, jb_data_point_t *ctrl)
/* ── DP2 手动模式 (raw) ── */
case DP_ID_HAND_MODE:
memcpy(gDevData.hand_mode, ctrl->hand_mode, 2);
other_cmd = 1;
/* 薄适配:通知业务层;03=停,00=空闲 */
{
extern void usr_dp_hand_write(uint8_t cmd);
@@ -136,6 +142,7 @@ int8_t jbEventProcess(jb_event_info_t *info, jb_data_point_t *ctrl)
/* ── DP3 绳索校准 (bool) ── */
case DP_ID_CALIBRATION:
other_cmd = 1;
if (ctrl->calibration)
{
gDevData.calibration = 1;
@@ -151,30 +158,35 @@ int8_t jbEventProcess(jb_event_info_t *info, jb_data_point_t *ctrl)
/* ── DP4 绳索圈数 (uint8) ── */
case DP_ID_NUMBERTURNS:
gDevData.numberturns = ctrl->numberturns;
other_cmd = 1;
// TODO: 根据 ctrl->numberturns 执行动作
break;
/* ── DP8 勿扰模式开关 (raw) ── */
case DP_ID_NO_DISTURB_ENABLE:
memcpy(gDevData.no_disturb_enable, ctrl->no_disturb_enable, 13);
other_cmd = 1;
// TODO: 根据 gDevData.no_disturb_enable 执行动作 (长度 13 字节)
break;
/* ── DP9 预留DP1 (uint32) ── */
case DP_ID_RESERVA_DP1:
gDevData.reserva_dp1 = ctrl->reserva_dp1;
other_cmd = 1;
// TODO: 根据 ctrl->reserva_dp1 执行动作
break;
/* ── DP10 预留DP2 (uint32) ── */
case DP_ID_RESERVA_DP2:
gDevData.reserva_dp2 = ctrl->reserva_dp2;
other_cmd = 1;
// TODO: 根据 ctrl->reserva_dp2 执行动作
break;
/* ── DP11 预留DP3 (uint32) ── */
case DP_ID_RESERVA_DP3:
gDevData.reserva_dp3 = ctrl->reserva_dp3;
other_cmd = 1;
// TODO: 根据 ctrl->reserva_dp3 执行动作
break;
@@ -182,6 +194,13 @@ int8_t jbEventProcess(jb_event_info_t *info, jb_data_point_t *ctrl)
break;
}
}
/* 软关后其它控制 DP 可唤醒;与关机 DP 同帧则关机优先,避免关完立刻被拉开 */
if (other_cmd && !got_power_off)
{
extern void usr_dp_app_cmd(void);
usr_dp_app_cmd();
}
return 0;
}
+9
View File
@@ -306,6 +306,15 @@ void usr_dp_hand_write(uint8_t cmd)
app_function_dp_hand_write(cmd);
}
/**
* @brief APP 下发了非关机控制 DPjb_product 薄适配)
* @return 无
*/
void usr_dp_app_cmd(void)
{
app_function_on_app_cmd();
}
/**
* @brief BLE 收到见宝载荷,送入协议环形缓冲
* @param data 载荷指针