1. 修复频繁上下线问题
2. 修复会bind会有两个设备的问题 3. 其他若干体验问题 4. 增加产测功能
This commit is contained in:
@ -14,6 +14,7 @@
|
||||
// #include "tcxo.h"
|
||||
|
||||
#include "spotlight.h"
|
||||
#include "factory_test.h"
|
||||
|
||||
// 函数前向声明
|
||||
static void init_timer_system(void);
|
||||
@ -30,7 +31,6 @@ static void set_light2net_cfg_done(void);
|
||||
static void start_breath_timer(void);
|
||||
static void report_switch_status(void);
|
||||
void calculate_pwm_duty(void);
|
||||
void update_pwm_output(void);
|
||||
|
||||
// 定义上报函数类型
|
||||
typedef void (*report_func_t)(void);
|
||||
@ -245,7 +245,7 @@ static void *fade_task(const char *arg)
|
||||
g_device_control.brightness_local = fade_ctx.current_brightness;
|
||||
g_device_control.cct_local = fade_ctx.current_cct;
|
||||
calculate_pwm_duty();
|
||||
update_pwm_output();
|
||||
update_pwm_output(g_device_control.on, g_device_control.duty_cw, g_device_control.duty_ww);
|
||||
|
||||
if (fade_ctx.fade_completed) {
|
||||
fade_ctx.fade_completed = false;
|
||||
@ -306,7 +306,7 @@ static void *breath_task(const char *arg)
|
||||
g_device_control.duty_ww = brightness_pwm;
|
||||
g_device_control.duty_cw = PWM_DUTY_RATIO_MAX - brightness_pwm;
|
||||
|
||||
update_pwm_output();
|
||||
update_pwm_output(g_device_control.on, g_device_control.duty_cw, g_device_control.duty_ww);
|
||||
}
|
||||
|
||||
e_printf("[breath_task] Task exited\r\n");
|
||||
@ -424,7 +424,7 @@ static void stop_fade_task(void)
|
||||
}
|
||||
|
||||
// 停止呼吸灯任务
|
||||
static void stop_breath_task(void)
|
||||
void stop_breath_task(void)
|
||||
{
|
||||
if (breath_ctx.task_handle == NULL) {
|
||||
return;
|
||||
@ -438,7 +438,7 @@ static void stop_breath_task(void)
|
||||
breath_ctx.task_handle = NULL;
|
||||
osal_kthread_unlock();
|
||||
|
||||
osal_sem_destroy(&breath_ctx.sem);
|
||||
// osal_sem_destroy(&breath_ctx.sem);
|
||||
|
||||
e_printf("[stop_breath_task] Breath task stopped\n");
|
||||
}
|
||||
@ -446,8 +446,11 @@ static void stop_breath_task(void)
|
||||
// 修改stop_breath_timer函数
|
||||
static void stop_breath_timer(void)
|
||||
{
|
||||
uapi_timer_stop(breath_ctx.timer_handle);
|
||||
uapi_timer_delete(breath_ctx.timer_handle);
|
||||
if (breath_ctx.timer_handle) {
|
||||
uapi_timer_stop(breath_ctx.timer_handle);
|
||||
uapi_timer_delete(breath_ctx.timer_handle);
|
||||
}
|
||||
breath_ctx.timer_handle = NULL;
|
||||
stop_breath_task();
|
||||
}
|
||||
|
||||
@ -465,53 +468,53 @@ void calculate_pwm_duty(void)
|
||||
}
|
||||
|
||||
// 更新PWM输出
|
||||
void update_pwm_output(void)
|
||||
void update_pwm_output(bool on_state, uint16_t duty_cw_val, uint16_t duty_ww_val)
|
||||
{
|
||||
pwm_config_t cfg_repeat = {0};
|
||||
cfg_repeat.repeat = true;
|
||||
if (g_device_control.duty_cw > PWM_DUTY_RATIO_MAX) {
|
||||
g_device_control.duty_cw = PWM_DUTY_RATIO_MAX;
|
||||
|
||||
uint16_t current_duty_cw = duty_cw_val;
|
||||
uint16_t current_duty_ww = duty_ww_val;
|
||||
|
||||
if (current_duty_cw > PWM_DUTY_RATIO_MAX) {
|
||||
current_duty_cw = PWM_DUTY_RATIO_MAX;
|
||||
}
|
||||
if (g_device_control.duty_ww > PWM_DUTY_RATIO_MAX) {
|
||||
g_device_control.duty_ww = PWM_DUTY_RATIO_MAX;
|
||||
if (current_duty_ww > PWM_DUTY_RATIO_MAX) {
|
||||
current_duty_ww = PWM_DUTY_RATIO_MAX;
|
||||
}
|
||||
uint32_t high_cnt_cw = (pwm_period_cnt * g_device_control.duty_cw) / PWM_DUTY_RATIO_MAX;
|
||||
|
||||
uint32_t high_cnt_cw = (pwm_period_cnt * current_duty_cw) / PWM_DUTY_RATIO_MAX;
|
||||
uint32_t low_cnt_cw = pwm_period_cnt - high_cnt_cw;
|
||||
|
||||
uint32_t high_cnt_ww = (pwm_period_cnt * g_device_control.duty_ww) / PWM_DUTY_RATIO_MAX;
|
||||
uint32_t high_cnt_ww = (pwm_period_cnt * current_duty_ww) / PWM_DUTY_RATIO_MAX;
|
||||
uint32_t low_cnt_ww = pwm_period_cnt - high_cnt_ww;
|
||||
|
||||
// uapi_pwm_stop_group(CONFIG_PWM_GROUP_ID);
|
||||
// uapi_pwm_clear_group(CONFIG_PWM_GROUP_ID);
|
||||
if (!g_device_control.on) { // 如果开关关闭,则占空比为0
|
||||
e_printf("spotlight off\r\n");
|
||||
if (!on_state) {
|
||||
high_cnt_cw = 0;
|
||||
low_cnt_cw = 0;
|
||||
low_cnt_cw = pwm_period_cnt; // Ensure low_cnt is full period if off
|
||||
high_cnt_ww = 0;
|
||||
low_cnt_ww = 0;
|
||||
low_cnt_ww = pwm_period_cnt; // Ensure low_cnt is full period if off
|
||||
}
|
||||
|
||||
cfg_repeat.high_time = high_cnt_cw;
|
||||
cfg_repeat.low_time = low_cnt_cw;
|
||||
uapi_pwm_open(channel_id_cw, &cfg_repeat);
|
||||
// 配置第二个通道
|
||||
|
||||
cfg_repeat.high_time = high_cnt_ww;
|
||||
cfg_repeat.low_time = low_cnt_ww;
|
||||
cfg_repeat.offset_time = high_cnt_cw;//配置互补形成相位
|
||||
cfg_repeat.offset_time = high_cnt_cw; // WW PWM starts after CW PWM high time
|
||||
|
||||
uapi_pwm_open(channel_id_ww, &cfg_repeat);
|
||||
// 设置PWM组
|
||||
uint8_t channel_ids[2] = {channel_id_cw, channel_id_ww};
|
||||
// uapi_pwm_set_group(CONFIG_PWM_GROUP_ID, channel_ids, 2);
|
||||
|
||||
// // 更新PWM占空比
|
||||
// uapi_pwm_update_duty_ratio(channel_id_cw, low_cnt_cw, high_cnt_cw);
|
||||
// uapi_pwm_update_duty_ratio(channel_id_ww, low_cnt_ww, high_cnt_ww);
|
||||
|
||||
// 启动PWM组
|
||||
// The line 'uint8_t channel_ids[2] = {channel_id_cw, channel_id_ww};' was present in the original code snippet from the checkpoint
|
||||
// but seems unused before the uapi_pwm_start_group call. Retaining original behavior regarding this line.
|
||||
// If it was indeed unused, it can be removed. For now, assuming it might have a purpose or was for debugging.
|
||||
// uint8_t channel_ids[2] = {channel_id_cw, channel_id_ww}; // This line is commented out as it appears unused in the provided snippet.
|
||||
uapi_pwm_start_group(CONFIG_PWM_GROUP_ID);
|
||||
|
||||
if (should_print(&pwm_limiter)) {
|
||||
e_printf("cw:high:%u, low:%u, duty:%u/1000, ww:high:%u, low:%u, duty:%u/1000, offset_time:%u\r\n",
|
||||
high_cnt_cw, low_cnt_cw, g_device_control.duty_cw, high_cnt_ww, low_cnt_ww, g_device_control.duty_ww, cfg_repeat.offset_time);
|
||||
e_printf("on:%d, cw:high:%u, low:%u, duty:%u/1000, ww:high:%u, low:%u, duty:%u/1000, offset_time:%u\r\n",
|
||||
on_state, high_cnt_cw, low_cnt_cw, current_duty_cw, high_cnt_ww, low_cnt_ww, current_duty_ww, cfg_repeat.offset_time);
|
||||
}
|
||||
}
|
||||
|
||||
@ -883,6 +886,7 @@ int set_light(int32_t brightness_local, int32_t cct_local)
|
||||
// 启动渐变定时器
|
||||
set_switch(true);
|
||||
uapi_timer_start(fade_ctx.timer_handle, fade_ctx.update_interval, fade_timer_callback, 0);
|
||||
fast_report(SVC_ID_LIGHT_MODE);
|
||||
#if 0
|
||||
等待渐变完成
|
||||
while (!fade_ctx.fade_completed) {
|
||||
@ -910,7 +914,7 @@ int set_switch(bool open)
|
||||
cancel_current_light_fade();
|
||||
}
|
||||
calculate_pwm_duty();
|
||||
update_pwm_output();
|
||||
update_pwm_output(g_device_control.on, g_device_control.duty_cw, g_device_control.duty_ww);
|
||||
uapi_gpio_set_val(SWITCH_PIN, open ? OPEN_LIGHT : CLOSE_LIGHT);
|
||||
return 0;
|
||||
}
|
||||
@ -954,6 +958,29 @@ static void pwm_init(pin_t pin, pin_t pin1)
|
||||
e_printf("PWM基础时钟频率: %dHz, 目标时钟频率: %dHz, 周期计数: %d\r\n", frequency, PWM_FREQUENCY, pwm_period_cnt);
|
||||
}
|
||||
|
||||
extern int start_hilink_ble_net_config(int32_t net_cfg_time_s);
|
||||
void start_net_config(void) {
|
||||
e_printf("进入配网状态,上电次数:%d, is_new_device:%d\r\n", g_device_control.power_on_cnt, !g_device_control.is_net_configured);
|
||||
g_device_control.power_on_cnt = 0;//
|
||||
int ret = start_hilink_ble_net_config(NET_CFG_TOTAL_TIMEOUT/1000);
|
||||
if (ret) {
|
||||
// FIXME: 这里简单恢复之前等待配网的灯效即可
|
||||
e_printf("start net_cfg fail:%n\r\n", ret);
|
||||
req_save_device_data();
|
||||
// extern int HILINK_RestoreFactorySettings(void);
|
||||
// HILINK_RestoreFactorySettings();
|
||||
return;
|
||||
}
|
||||
// 初始化呼吸灯控制
|
||||
init_breath_ctx();
|
||||
start_breath_timer();
|
||||
}
|
||||
|
||||
void stop_net_config(void) {
|
||||
stop_breath_timer();
|
||||
start_hilink_ble_net_config(0);
|
||||
}
|
||||
|
||||
// 配网状态管理相关函数
|
||||
static void handle_network_status(void)
|
||||
{
|
||||
@ -967,21 +994,7 @@ static void handle_network_status(void)
|
||||
e_printf("现在是第 %d 次上电\r\n", g_device_control.power_on_cnt);
|
||||
// 检查是否需要进入配网状态
|
||||
if ((!g_device_control.is_net_configured) || g_device_control.power_on_cnt >= NET_CFG_ENTRY_CNT) {
|
||||
e_printf("进入配网状态,上电次数:%d, is_new_device:%d\r\n", g_device_control.power_on_cnt, !g_device_control.is_net_configured);
|
||||
g_device_control.power_on_cnt = 0;//
|
||||
extern int start_hilink_ble_net_config(int32_t net_cfg_time_s);
|
||||
int ret = start_hilink_ble_net_config(NET_CFG_TOTAL_TIMEOUT/1000);
|
||||
if (ret) {
|
||||
// FIXME: 这里简单恢复之前等待配网的灯效即可
|
||||
e_printf("start net_cfg fail:%n\r\n", ret);
|
||||
req_save_device_data();
|
||||
// extern int HILINK_RestoreFactorySettings(void);
|
||||
// HILINK_RestoreFactorySettings();
|
||||
return;
|
||||
}
|
||||
// 初始化呼吸灯控制
|
||||
init_breath_ctx();
|
||||
start_breath_timer();
|
||||
start_net_config();
|
||||
}
|
||||
|
||||
// 保存设备状态
|
||||
@ -1227,7 +1240,9 @@ int spotlight_main(void) {
|
||||
handle_network_status();
|
||||
|
||||
set_switch(g_device_control.on);//按照当前值更新light
|
||||
|
||||
if (!g_device_control.is_networked && !g_device_control.is_net_configured) {
|
||||
try_detect_factory_test();
|
||||
}
|
||||
start_spotlight_main_task();
|
||||
return 0;
|
||||
}
|
||||
@ -1259,7 +1274,7 @@ static void set_light2breathtimeout(void)
|
||||
g_device_control.brightness_local = BRIGHTNESS_REMOTE2LOCAL(NET_CFG_TIMEOUT_BRIGHTNESS);
|
||||
g_device_control.cct_local = CCT_REMOTE2LOCAL(NET_CFG_TIMEOUT_CCT);
|
||||
calculate_pwm_duty();
|
||||
update_pwm_output();
|
||||
update_pwm_output(g_device_control.on, g_device_control.duty_cw, g_device_control.duty_ww);
|
||||
}
|
||||
|
||||
// 设置灯光到配网完成状态
|
||||
@ -1270,7 +1285,7 @@ static void set_light2net_cfg_done(void)
|
||||
g_device_control.cct_local = CCT_REMOTE2LOCAL(NET_CFG_DEFAULT_CCT);
|
||||
g_device_control.fade_time = NET_CFG_DEFAULT_FADE_TIME;
|
||||
calculate_pwm_duty();
|
||||
update_pwm_output();
|
||||
update_pwm_output(g_device_control.on, g_device_control.duty_cw, g_device_control.duty_ww);
|
||||
}
|
||||
|
||||
// 启动呼吸灯
|
||||
|
Reference in New Issue
Block a user