新增强制复位功能
This commit is contained in:
@@ -30,7 +30,7 @@ extern "C" {
|
|||||||
|
|
||||||
#define DEVICE_HIVERSION "1.0.0"
|
#define DEVICE_HIVERSION "1.0.0"
|
||||||
/* 设备固件版本号 */
|
/* 设备固件版本号 */
|
||||||
#define FIRMWARE_VER "1.0.8"
|
#define FIRMWARE_VER "1.0.9"
|
||||||
/* 设备硬件版本号 */
|
/* 设备硬件版本号 */
|
||||||
#define HARDWARE_VER "1.0.0"
|
#define HARDWARE_VER "1.0.0"
|
||||||
/* 设备软件版本号 */
|
/* 设备软件版本号 */
|
||||||
|
|||||||
@@ -212,7 +212,7 @@ int32_t wifi_scan_and_check(int32_t rssi_threshold)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
e_printf("WiFi signal strength test. RSSI: expect >= %d, actual %d\n", rssi_threshold, expected_bss.rsv);
|
e_printf("WiFi signal strength test. RSSI: expect >= %d, actual %d\n", rssi_threshold, expected_bss.rsv);
|
||||||
if (expected_bss.rsv !=0 && expected_bss.rsv >= rssi_threshold) {
|
if (expected_bss.rsv !=0 && (int)expected_bss.rsv >= (int)rssi_threshold) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ typedef struct __attribute__((packed, aligned(1))) {
|
|||||||
|
|
||||||
#define INIT_NET_CFG_PWOER_ON_KEEP_TIME (5 * 1000) // 统计进入配网每次打开状态的保持时间
|
#define INIT_NET_CFG_PWOER_ON_KEEP_TIME (5 * 1000) // 统计进入配网每次打开状态的保持时间
|
||||||
|
|
||||||
#define NET_CFG_ENTRY_CNT 6 // 配网进入的上电次数
|
#define NET_CFG_ENTRY_CNT 8 // 配网进入的上电次数
|
||||||
#define NET_CFG_BREATH_DURATION 1*60*1000 // 配网呼吸灯持续时间(ms)
|
#define NET_CFG_BREATH_DURATION 1*60*1000 // 配网呼吸灯持续时间(ms)
|
||||||
#define NET_CFG_TOTAL_TIMEOUT 10*60*1000 // 配网总超时时间(ms)
|
#define NET_CFG_TOTAL_TIMEOUT 10*60*1000 // 配网总超时时间(ms)
|
||||||
|
|
||||||
|
|||||||
@@ -51,6 +51,8 @@ static bool report_task_running = false; // 添加任务运行状态标志
|
|||||||
static uint32_t g_report_mask = 0;
|
static uint32_t g_report_mask = 0;
|
||||||
static osal_semaphore report_sem; // 条件变量,用于唤醒report task
|
static osal_semaphore report_sem; // 条件变量,用于唤醒report task
|
||||||
|
|
||||||
|
bool g_reset_factory_flag = false;
|
||||||
|
|
||||||
// 灯渐变任务相关定义
|
// 灯渐变任务相关定义
|
||||||
#define FADE_TASK_PRIO 80
|
#define FADE_TASK_PRIO 80
|
||||||
#define FADE_TASK_STACK_SIZE 0x1000
|
#define FADE_TASK_STACK_SIZE 0x1000
|
||||||
@@ -885,7 +887,7 @@ int set_light(light_ctrl_source_e source,
|
|||||||
// 如果打开灯,则需要手动将前置状态设置为关闭的样子,这样子后面计算渐变才能正常计算
|
// 如果打开灯,则需要手动将前置状态设置为关闭的样子,这样子后面计算渐变才能正常计算
|
||||||
if (APP_OPEN_LIGHT == source) {
|
if (APP_OPEN_LIGHT == source) {
|
||||||
g_device_control.on = true;
|
g_device_control.on = true;
|
||||||
fade_ctx.current_brightness = 0;
|
// fade_ctx.current_brightness = 0;
|
||||||
brightness_local_target = g_device_control.brightness_local;
|
brightness_local_target = g_device_control.brightness_local;
|
||||||
if (g_device_control.colourMode == COLOUR_MODE_DUAL) {
|
if (g_device_control.colourMode == COLOUR_MODE_DUAL) {
|
||||||
fade_ctx.current_cct = g_device_control.cct_local;
|
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,
|
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.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.fade_time = g_device_control.fade_time;
|
||||||
|
tmp_fade_ctx.is_closing_fade = false;
|
||||||
switch (source) {
|
switch (source) {
|
||||||
case APP_CLOSE_LIGHT:
|
case APP_CLOSE_LIGHT:
|
||||||
// 使用渐变方式关灯:设置目标亮度为0,使用is_closing_fade标志
|
// 使用渐变方式关灯:设置目标亮度为0,使用is_closing_fade标志
|
||||||
@@ -1071,6 +1074,36 @@ void stop_net_config(void) {
|
|||||||
static int handle_network_status(void)
|
static int handle_network_status(void)
|
||||||
{
|
{
|
||||||
uint8_t start_net_cfg = 0;
|
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) {
|
if (g_device_control.is_bound) {
|
||||||
// 如果已经配网,则设置发出ble广播确保如果没法连接路由器可以转为本地蓝牙控制
|
// 如果已经配网,则设置发出ble广播确保如果没法连接路由器可以转为本地蓝牙控制
|
||||||
@@ -1078,18 +1111,7 @@ static int handle_network_status(void)
|
|||||||
return start_net_cfg;
|
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;
|
return start_net_cfg;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1232,7 +1254,7 @@ void handle_device_online(void)
|
|||||||
if (!g_device_control.is_bound) {
|
if (!g_device_control.is_bound) {
|
||||||
e_printf("设备首次上线,记录配网状态\r\n");
|
e_printf("设备首次上线,记录配网状态\r\n");
|
||||||
g_device_control.is_bound = true;
|
g_device_control.is_bound = true;
|
||||||
g_device_control.power_on_cnt = 0; // 重置上电计数
|
// g_device_control.power_on_cnt = 0; // 重置上电计数
|
||||||
stop_breath_timer(); // 停止呼吸灯
|
stop_breath_timer(); // 停止呼吸灯
|
||||||
set_light2net_cfg_done();
|
set_light2net_cfg_done();
|
||||||
req_save_device_data();
|
req_save_device_data();
|
||||||
@@ -1253,7 +1275,7 @@ void handle_device_offline(void)
|
|||||||
device_online = 0;
|
device_online = 0;
|
||||||
e_printf("device offline!\r\n");
|
e_printf("device offline!\r\n");
|
||||||
}
|
}
|
||||||
bool g_reset_factory_flag = false;
|
|
||||||
// 处理设备解绑
|
// 处理设备解绑
|
||||||
void handle_device_unbind(void)
|
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)
|
static void check_net_cfg_power_on_keep_time(void)
|
||||||
{
|
{
|
||||||
if (g_device_control.power_on_cnt <= 0) {
|
if (g_device_control.power_on_cnt <= 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (g_device_control.is_bound) {
|
if (uapi_systick_get_ms() - startup_time > INIT_NET_CFG_PWOER_ON_KEEP_TIME) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (uapi_systick_get_ms() > 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);
|
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;
|
g_device_control.power_on_cnt = 0;
|
||||||
req_save_device_data();
|
req_save_device_data();
|
||||||
@@ -1382,6 +1402,7 @@ static void check_net_cfg_timeout(void)
|
|||||||
// 修改spotlight_main函数
|
// 修改spotlight_main函数
|
||||||
int spotlight_main(void) {
|
int spotlight_main(void) {
|
||||||
uapi_systick_init();
|
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());
|
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();
|
read_device_data();
|
||||||
// 初始化GPIO并将灯关闭
|
// 初始化GPIO并将灯关闭
|
||||||
|
|||||||
BIN
output/SR_light-LPT262_hilink-20250807-1.0.9.fwpkg
Normal file
BIN
output/SR_light-LPT262_hilink-20250807-1.0.9.fwpkg
Normal file
Binary file not shown.
BIN
output/package(SR_light-LPT262_hilink-20250807-1.0.9).zip
Normal file
BIN
output/package(SR_light-LPT262_hilink-20250807-1.0.9).zip
Normal file
Binary file not shown.
Reference in New Issue
Block a user