@@ -51,6 +51,8 @@ static bool report_task_running = false; // 添加任务运行状态标志
static uint32_t g_report_mask = 0 ;
static osal_semaphore report_sem ; // 条件变量, 用于唤醒report task
bool g_reset_factory_flag = false ;
// 灯渐变任务相关定义
# define FADE_TASK_PRIO 80
# define FADE_TASK_STACK_SIZE 0x1000
@@ -885,7 +887,7 @@ int set_light(light_ctrl_source_e source,
// 如果打开灯,则需要手动将前置状态设置为关闭的样子,这样子后面计算渐变才能正常计算
if ( APP_OPEN_LIGHT = = source ) {
g_device_control . on = true ;
fade_ctx. current_brightness = 0 ;
// fade_ctx. current_brightness = 0;
brightness_local_target = g_device_control . brightness_local ;
if ( g_device_control . colourMode = = COLOUR_MODE_DUAL ) {
fade_ctx . current_cct = g_device_control . cct_local ;
@@ -916,6 +918,7 @@ int set_light(light_ctrl_source_e source,
source , g_device_control . elightMode , tmp_fade_ctx . current_brightness ,
tmp_fade_ctx . target_brightness , tmp_fade_ctx . current_cct , tmp_fade_ctx . target_cct ) ;
tmp_fade_ctx . fade_time = g_device_control . fade_time ;
tmp_fade_ctx . is_closing_fade = false ;
switch ( source ) {
case APP_CLOSE_LIGHT :
// 使用渐变方式关灯: 设置目标亮度为0, 使用is_closing_fade标志
@@ -1071,6 +1074,36 @@ void stop_net_config(void) {
static int handle_network_status ( void )
{
uint8_t start_net_cfg = 0 ;
// 增加上电计数
g_device_control . power_on_cnt + + ;
e_printf ( " 现在是第 %d 次上电 \r \n " , g_device_control . power_on_cnt ) ;
// 检查是否需要进入配网状态或恢复出厂设置
if ( g_device_control . power_on_cnt > = NET_CFG_ENTRY_CNT ) {
g_device_control . power_on_cnt = 0 ;
if ( g_device_control . is_net_configured ) {
// 已出厂设备: 上下电6次后恢复出厂设置并重启
e_printf ( " 已到达出厂设备上电次,执行恢复出厂设置 \r \n " ) ;
g_reset_factory_flag = true ;
extern int HILINK_RestoreFactorySettings ( void ) ;
while ( ! hf_hilink_main_is_runing ( ) ) {
msleep ( 10 ) ;
}
HILINK_RestoreFactorySettings ( ) ;
return start_net_cfg ;
} else {
// 未出厂设备:进入配网模式
e_printf ( " 未出厂设备上电6次, 进入配网模式 \r \n " ) ;
start_net_config ( ) ;
start_net_cfg = 1 ;
}
} else if ( ! g_device_control . is_net_configured ) {
// 未出厂设备直接进入配网
start_net_config ( ) ;
start_net_cfg = 1 ;
}
// 保存设备状态
req_save_device_data ( ) ;
// 如果已经配网,直接返回
if ( g_device_control . is_bound ) {
// 如果已经配网, 则设置发出ble广播确保如果没法连接路由器可以转为本地蓝牙控制
@@ -1078,18 +1111,7 @@ static int handle_network_status(void)
return start_net_cfg ;
}
// 增加上电计数
g_device_control . power_on_cnt + + ;
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 ) {
start_net_config ( ) ;
start_net_cfg = 1 ;
}
// 保存设备状态
req_save_device_data ( ) ;
return start_net_cfg ;
}
@@ -1232,7 +1254,7 @@ void handle_device_online(void)
if ( ! g_device_control . is_bound ) {
e_printf ( " 设备首次上线,记录配网状态 \r \n " ) ;
g_device_control . is_bound = true ;
g_device_control. power_on_cnt = 0 ; // 重置上电计数
// g_device_control. power_on_cnt = 0; // 重置上电计数
stop_breath_timer ( ) ; // 停止呼吸灯
set_light2net_cfg_done ( ) ;
req_save_device_data ( ) ;
@@ -1253,7 +1275,7 @@ void handle_device_offline(void)
device_online = 0 ;
e_printf ( " device offline! \r \n " ) ;
}
bool g_reset_factory_flag = false ;
// 处理设备解绑
void handle_device_unbind ( void )
{
@@ -1271,15 +1293,13 @@ void handle_device_unbind(void)
}
}
uint64_t startup_time = 0 ;
static void check_net_cfg_power_on_keep_time ( void )
{
if ( g_device_control . power_on_cnt < = 0 ) {
return ;
}
if ( g_device_control . is_bound ) {
return ;
}
if ( uapi_systick_get_ms ( ) > INIT_NET_CFG_PWOER_ON_KEEP_TIME ) {
if ( uapi_systick_get_ms ( ) - startup_time > INIT_NET_CFG_PWOER_ON_KEEP_TIME ) {
e_printf ( " power_on keep time is %llums must < %ds, we will reset cnt \r \n " , uapi_systick_get_ms ( ) , INIT_NET_CFG_PWOER_ON_KEEP_TIME / 1000 ) ;
g_device_control . power_on_cnt = 0 ;
req_save_device_data ( ) ;
@@ -1382,6 +1402,7 @@ static void check_net_cfg_timeout(void)
// 修改spotlight_main函数
int spotlight_main ( void ) {
uapi_systick_init ( ) ;
startup_time = uapi_systick_get_ms ( ) ;
e_printf ( " uapi_timer_get_max_us:%uus, start_time:%uus \r \n " , uapi_timer_get_max_us ( ) , uapi_systick_get_ms ( ) ) ;
read_device_data ( ) ;
// 初始化GPIO并将灯关闭