feat(mode_switch): 添加无效模式枚举值并更新事件处理
添加 MODE_SWITCH_INVALID 枚举值到 mode_switch_mode 中, 用于表示无效的模式状态。同时更新相关的事件处理逻辑, 确保在模式切换时能够正确处理无效模式的情况。 refactor(mode_policy): 简化模块上下文结构并优化模式策略 将模块上下文中的 ble_adv_suspended 和 usb_enabled 标志位 替换为 active_mode 枚举值,简化了数据结构。重新设计了 模式策略应用逻辑,使其更清晰易懂,并改进了BLE和USB设备 的启用/暂停控制流程。 refactor(usb_device): 重构USB设备生命周期管理 移除了 USB_STACK_DISABLED 状态,简化了USB栈的状态管理。 改进了USB设备的启动和停止逻辑,更好地与模块生命周期 集成。现在USB状态事件仅在模块初始化后提交,避免了 不必要的事件发布。 feat(logging): 增加详细的状态转换日志记录 为BLE NUS模块添加了业务状态转换的日志记录功能, 增加了详细的错误和警告日志,包括生命周期状态、 业务状态和连接信息,便于调试和问题排查。 refactor(mode_switch): 优化模式检测和报告机制 修改了模式切换采样的判断逻辑,移除了force_report和 mode_valid标志位,改用last_mode状态来决定是否提交 模式切换事件,使代码更简洁且易于理解。
This commit is contained in:
@@ -31,8 +31,6 @@ struct mode_switch_module_ctx {
|
||||
struct module_lifecycle_ctx lc;
|
||||
const struct device *mode_switch_adc_dev;
|
||||
struct k_work_delayable mode_switch_sample_work;
|
||||
bool force_report;
|
||||
bool mode_valid;
|
||||
enum mode_switch_mode last_mode;
|
||||
};
|
||||
|
||||
@@ -115,12 +113,10 @@ static void mode_switch_sample_fn(struct k_work *work)
|
||||
uint16_t sample_mv = (uint16_t)((voltage.val1 * 1000) + (voltage.val2 / 1000));
|
||||
enum mode_switch_mode mode = detect_mode(sample_mv);
|
||||
|
||||
if (ctx.force_report || !ctx.mode_valid || (mode != ctx.last_mode)) {
|
||||
if ((ctx.last_mode == MODE_SWITCH_INVALID) || (mode != ctx.last_mode)) {
|
||||
submit_mode_switch_event(mode, sample_mv);
|
||||
|
||||
ctx.last_mode = mode;
|
||||
ctx.mode_valid = true;
|
||||
ctx.force_report = false;
|
||||
}
|
||||
|
||||
reschedule:
|
||||
@@ -138,8 +134,7 @@ static int do_init(void)
|
||||
}
|
||||
|
||||
k_work_init_delayable(&ctx.mode_switch_sample_work, mode_switch_sample_fn);
|
||||
ctx.mode_valid = false;
|
||||
ctx.force_report = false;
|
||||
ctx.last_mode = MODE_SWITCH_INVALID;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -157,7 +152,6 @@ static int do_start(void)
|
||||
return err;
|
||||
}
|
||||
|
||||
ctx.force_report = true;
|
||||
k_work_reschedule(&ctx.mode_switch_sample_work, K_NO_WAIT);
|
||||
|
||||
return 0;
|
||||
@@ -182,6 +176,15 @@ static bool app_event_handler(const struct app_event_header *aeh)
|
||||
|
||||
if (check_state(event, MODULE_ID(main), MODULE_STATE_READY)) {
|
||||
(void)module_set_lifecycle(&ctx.lc, LC_RUNNING);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (check_state(event, MODULE_ID(mode_policy_module),
|
||||
MODULE_STATE_READY)) {
|
||||
if (ctx.last_mode != MODE_SWITCH_INVALID) {
|
||||
submit_mode_switch_event(ctx.last_mode, 0U);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user