1. 解决频繁频繁掉线的问题:原因是因为ble
sdk需要一开始就初始化,配网的时候只是去控制其广播是否开启。不然会导致一直掉线
This commit is contained in:
@ -57,11 +57,7 @@ typedef struct _HFUART
|
||||
}HFUART,*PHFUART;
|
||||
|
||||
|
||||
#if defined(DEBUG_LOG_ENABLE)
|
||||
#define HF_Debug( debug_level, format, ...) printf(format, ##__VA_ARGS__)
|
||||
#else
|
||||
void HSF_API HF_Debug(int debug_level, const char *format, ...);
|
||||
#endif
|
||||
void HSF_API HF_Debug(int debug_level, const char *format , ... );
|
||||
|
||||
#define hfdbg_error(...) HF_Debug(DEBUG_ERROR,"[ %d error %s %d]",hfsys_get_time(),__FUNCTION__,__LINE__); \
|
||||
HF_Debug(DEBUG_ERROR,__VA_ARGS__)
|
||||
|
@ -11,7 +11,6 @@
|
||||
#ifdef HF_MCU_OTA
|
||||
#include "mcu_update.h"
|
||||
#endif
|
||||
|
||||
int g_module_id = HFM_TYPE_LPT262;
|
||||
const int hf_lpt_262_gpio_fid_to_pid_map_table[HFM_MAX_FUNC_CODE]=
|
||||
{
|
||||
@ -198,28 +197,26 @@ int hf_atcmd_appver(pat_session_t s,int argc,char *argv[],char *rsp,int len)
|
||||
}
|
||||
return -3;
|
||||
}
|
||||
int hf_atcmd_reset(pat_session_t s,int argc,char *argv[],char *rsp,int len)
|
||||
{
|
||||
extern int HILINK_RestoreFactorySettings(void);
|
||||
HILINK_RestoreFactorySettings();
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_SPOTLIGHT_UT
|
||||
extern int hf_atcmd_pwm(pat_session_t s, int argc, char *argv[], char *rsp, int len);
|
||||
extern int hf_atcmd_pwm_query(pat_session_t s, int argc, char *argv[], char *rsp, int len);
|
||||
extern int hf_atcmd_light(pat_session_t s, int argc, char *argv[], char *rsp, int len);
|
||||
extern int hf_atcmd_light_query(pat_session_t s, int argc, char *argv[], char *rsp, int len);
|
||||
extern int hf_atcmd_reset(pat_session_t s, int argc, char *argv[], char *rsp, int len);
|
||||
extern int hf_atcmd_reset_factory(pat_session_t s, int argc, char *argv[], char *rsp, int len);
|
||||
#endif
|
||||
const hfat_cmd_t user_define_at_cmds_table[]=
|
||||
{
|
||||
{"APPVER", hf_atcmd_appver, "AT+APPVER: get version. \r\n",NULL},
|
||||
{"RESET", hf_atcmd_reset, "AT+RESET: reset. \r\n",NULL},
|
||||
#ifdef HF_MCU_OTA
|
||||
{"MCUOTA", hf_atcmd_mcu, "AT+MCUOTA: start mcu ota. \r\n",NULL},
|
||||
{"MCUVER", hf_atcmd_mcuver, "AT+MCUVER: get mcu version. \r\n",NULL},
|
||||
{"OTAWAITTIME", hf_atcmd_ota_wait_time, "AT+OTAWAITTIME: set/get uart send mcu ota time\r\n", NULL},
|
||||
#endif
|
||||
#ifdef CONFIG_SPOTLIGHT_UT
|
||||
{"RESET", hf_atcmd_reset, "AT+RESET: reset. \r\n",NULL},
|
||||
{"FACTORY", hf_atcmd_reset_factory, "AT+FACTORY: factory. \r\n",NULL},
|
||||
{"UTPWM", hf_atcmd_pwm, "AT+PWM=<channel>,<duty>: Set PWM duty cycle (0-1000)\r\n", NULL},
|
||||
{"UTLIGHT", hf_atcmd_light, "AT+LIGHT=<brightness>,<cct>: Set brightness(0-1000) and CCT(2700-6000)\r\n", NULL},
|
||||
{"UTPWMQ", NULL, "AT+PWMQ=<channel>,<duty>: Set PWM duty cycle (0-1000)\r\n", hf_atcmd_pwm_query},
|
||||
@ -240,7 +237,7 @@ int USER_FUNC user_app_main(void)
|
||||
HF_Debug(DEBUG_WARN,"init mcu ota fail!\r\n");
|
||||
#endif
|
||||
//See Wi-Fi Config tools APP for detailed usage of this thread, only debug mode open
|
||||
if(0 && hfdbg_get_level())
|
||||
if(hfdbg_get_level())
|
||||
{
|
||||
while(!hfnet_wifi_is_active())
|
||||
{
|
||||
@ -251,8 +248,7 @@ int USER_FUNC user_app_main(void)
|
||||
HF_Debug(DEBUG_WARN,"start assis fail\r\n");
|
||||
}
|
||||
}
|
||||
e_printf("start assis success!\r\n");
|
||||
// hfgpio_pwm_enable(HFGPIO_F_SPI_CLK, 1000, 50);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -1,17 +1,6 @@
|
||||
#include "spotlight.h"
|
||||
#include "cJSON.h"
|
||||
// 服务处理函数定义
|
||||
typedef int (*handle_put_func)(const char* svc_id, const char* payload, unsigned int len);
|
||||
typedef int (*handle_get_func)(const char* svc_id, const char* in, unsigned int in_len, char** out, unsigned int* out_len);
|
||||
// 服务注册信息定义
|
||||
typedef struct{
|
||||
// service id
|
||||
char* sid;
|
||||
// HILINK_PutCharState cmd function
|
||||
handle_put_func putFunc;
|
||||
// handle HILINK_GetCharState cmd function
|
||||
handle_get_func getFunc;
|
||||
} HANDLE_SVC_INFO;
|
||||
#include "hilink_device.h"
|
||||
|
||||
#define CHECK_JSON_ITEM(condition) if(condition) { \
|
||||
goto lab_end; \
|
||||
@ -38,7 +27,7 @@ static const scene_preset_t scene_presets[] = {
|
||||
#define SCENE_MODE_COUNT (sizeof(scene_presets) / sizeof(scene_presets[0]))
|
||||
|
||||
// 处理亮度控制
|
||||
static int handle_put_brightness(const char* svc_id, const char* payload, unsigned int len)
|
||||
int myhandle_put_brightness(const char* svc_id, const char* payload, unsigned int len)
|
||||
{
|
||||
int ret = -1;
|
||||
cJSON *json = cJSON_Parse(payload);
|
||||
@ -65,7 +54,7 @@ static int handle_put_brightness(const char* svc_id, const char* payload, unsign
|
||||
}
|
||||
|
||||
// 处理色温控制
|
||||
static int handle_put_cct(const char* svc_id, const char* payload, unsigned int len)
|
||||
int myhandle_put_cct(const char* svc_id, const char* payload, unsigned int len)
|
||||
{
|
||||
int ret = -1;
|
||||
cJSON *json = cJSON_Parse(payload);
|
||||
@ -92,7 +81,7 @@ static int handle_put_cct(const char* svc_id, const char* payload, unsigned int
|
||||
}
|
||||
|
||||
// 处理场景模式控制
|
||||
static int handle_put_lightMode(const char* svc_id, const char* payload, unsigned int len)
|
||||
int myhandle_put_lightMode(const char* svc_id, const char* payload, unsigned int len)
|
||||
{
|
||||
int ret = -1;
|
||||
cJSON *json = cJSON_Parse(payload);
|
||||
@ -119,7 +108,7 @@ static int handle_put_lightMode(const char* svc_id, const char* payload, unsigne
|
||||
}
|
||||
|
||||
// 处理开关控制
|
||||
static int handle_put_switch(const char* svc_id, const char* payload, unsigned int len)
|
||||
int myhandle_put_switch(const char* svc_id, const char* payload, unsigned int len)
|
||||
{
|
||||
int ret = -1;
|
||||
cJSON *json = cJSON_Parse(payload);
|
||||
@ -142,7 +131,7 @@ static int handle_put_switch(const char* svc_id, const char* payload, unsigned i
|
||||
}
|
||||
|
||||
// 获取亮度状态
|
||||
static int handle_get_brightness(const char* svc_id, const char* in, unsigned int in_len, char** out, unsigned int* out_len)
|
||||
int myhandle_get_brightness(const char* svc_id, const char* in, unsigned int in_len, char** out, unsigned int* out_len)
|
||||
{
|
||||
*out_len = 32;
|
||||
*out = (char*)malloc(*out_len);
|
||||
@ -154,7 +143,7 @@ static int handle_get_brightness(const char* svc_id, const char* in, unsigned in
|
||||
}
|
||||
|
||||
// 获取色温状态
|
||||
static int handle_get_cct(const char* svc_id, const char* in, unsigned int in_len, char** out, unsigned int* out_len)
|
||||
int myhandle_get_cct(const char* svc_id, const char* in, unsigned int in_len, char** out, unsigned int* out_len)
|
||||
{
|
||||
*out_len = 32;
|
||||
*out = (char*)malloc(*out_len);
|
||||
@ -166,7 +155,7 @@ static int handle_get_cct(const char* svc_id, const char* in, unsigned int in_le
|
||||
}
|
||||
|
||||
// 获取场景模式状态
|
||||
static int handle_get_lightMode(const char* svc_id, const char* in, unsigned int in_len, char** out, unsigned int* out_len)
|
||||
int myhandle_get_lightMode(const char* svc_id, const char* in, unsigned int in_len, char** out, unsigned int* out_len)
|
||||
{
|
||||
*out_len = 32;
|
||||
*out = (char*)malloc(*out_len);
|
||||
@ -178,7 +167,7 @@ static int handle_get_lightMode(const char* svc_id, const char* in, unsigned int
|
||||
}
|
||||
|
||||
// 获取开关状态
|
||||
static int handle_get_switch(const char* svc_id, const char* in, unsigned int in_len, char** out, unsigned int* out_len)
|
||||
int myhandle_get_switch(const char* svc_id, const char* in, unsigned int in_len, char** out, unsigned int* out_len)
|
||||
{
|
||||
*out_len = 32;
|
||||
*out = (char*)malloc(*out_len);
|
||||
@ -190,107 +179,41 @@ static int handle_get_switch(const char* svc_id, const char* in, unsigned int in
|
||||
}
|
||||
|
||||
// 处理渐变时长控制
|
||||
static int handle_put_smooth_time(const char* svc_id, const char* payload, unsigned int len)
|
||||
int myhandle_put_progressSwitch(const char* svc_id, const char* payload, unsigned int len)
|
||||
{
|
||||
int ret = -1;
|
||||
e_printf("[handle_put_smooth_time] Received smooth time setting request: %s\n", payload);
|
||||
|
||||
|
||||
cJSON *json = cJSON_Parse(payload);
|
||||
if (json == NULL) {
|
||||
e_printf("[handle_put_smooth_time] JSON parsing failed\n");
|
||||
e_printf("JSON parsing failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
cJSON *item = cJSON_GetObjectItem(json, JSON_FIELD_FADE_TIME);
|
||||
if (item == NULL || !cJSON_IsNumber(item)) {
|
||||
e_printf("[handle_put_smooth_time] Invalid smooth time parameter\n");
|
||||
e_printf("Invalid progressSwitch parameter\n");
|
||||
cJSON_Delete(json);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int smooth_time = item->valueint;
|
||||
e_printf("[handle_put_smooth_time] Setting smooth time: %d s\n", smooth_time);
|
||||
ret = set_smooth_time(smooth_time);
|
||||
|
||||
cJSON_Delete(json);
|
||||
// e_printf("[handle_put_smooth_time] Smooth time setting completed\n");
|
||||
// e_printf("Smooth time setting completed\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
// 获取渐变时长状态
|
||||
static int handle_get_smooth_time(const char* svc_id, const char* in, unsigned int in_len, char** out, unsigned int* out_len)
|
||||
int myhandle_get_progressSwitch(const char* svc_id, const char* in, unsigned int in_len, char** out, unsigned int* out_len)
|
||||
{
|
||||
*out_len = 32;
|
||||
*out = (char*)malloc(*out_len);
|
||||
if (NULL == *out) {
|
||||
e_printf("[handle_get_smooth_time] Memory allocation failed\n");
|
||||
e_printf("Memory allocation failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
*out_len = sprintf_s(*out, *out_len, "{\"%s\":%d}", JSON_FIELD_FADE_TIME, g_device_control.fade_time);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 服务处理信息注册
|
||||
HANDLE_SVC_INFO g_device_profile[] = {
|
||||
{SVC_ID_SWITCH, handle_put_switch, handle_get_switch},
|
||||
{SVC_ID_BRIGHTNESS, handle_put_brightness, handle_get_brightness},
|
||||
{SVC_ID_CCT, handle_put_cct, handle_get_cct},
|
||||
{SVC_ID_LIGHT_MODE, handle_put_lightMode, handle_get_lightMode},
|
||||
{SVC_ID_FADE_TIME, handle_put_smooth_time, handle_get_smooth_time},
|
||||
};
|
||||
|
||||
// 服务总数量
|
||||
int g_device_profile_count = sizeof(g_device_profile) / sizeof(HANDLE_SVC_INFO);
|
||||
|
||||
// 辅助函数,用于查找服务注册信息
|
||||
static HANDLE_SVC_INFO* find_handle(const char* svc_id)
|
||||
{
|
||||
for(int i = 0; i < g_device_profile_count; i++) {
|
||||
HANDLE_SVC_INFO handle = g_device_profile[i];
|
||||
if(strcmp(handle.sid, svc_id) == 0) {
|
||||
return &g_device_profile[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// 分发设备控制指令
|
||||
int device_module_control(const char* svc_id, const char* payload, unsigned int len)
|
||||
{
|
||||
e_printf("[device_module_control] Received control command: svc_id=%s, payload=%s\n", svc_id, payload);
|
||||
|
||||
HANDLE_SVC_INFO* handle = find_handle(svc_id);
|
||||
if(handle == NULL) {
|
||||
e_printf("[device_module_control] No service handler found\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
handle_put_func function = handle->putFunc;
|
||||
if(function == NULL) {
|
||||
e_printf("[device_module_control] Service handler function is NULL\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ret = function(svc_id, payload, len);
|
||||
e_printf("[device_module_control] Control command processing completed, return value: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// 分发获取状态指令
|
||||
int device_module_get_state(const char* svc_id, const char* in, unsigned int in_len, char** out, unsigned int* out_len)
|
||||
{
|
||||
HANDLE_SVC_INFO* handle = find_handle(svc_id);
|
||||
if(handle == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
handle_get_func function = handle->getFunc;
|
||||
if(function == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return function(svc_id, in, in_len, out, out_len);
|
||||
}
|
||||
|
||||
|
||||
|
@ -27,6 +27,7 @@ typedef enum {
|
||||
#define SVC_ID_CCT "cct" // 色温控制
|
||||
#define SVC_ID_LIGHT_MODE "lightMode" // 场景模式控制
|
||||
#define SVC_ID_FADE_TIME "progressSwitch" // 渐变时长的控制
|
||||
#define SVC_ID_NET_INFO "netInfo" // 配网信息
|
||||
|
||||
// JSON字段名定义
|
||||
#define JSON_FIELD_ON "on" // 开关状态字段
|
||||
@ -37,20 +38,21 @@ typedef enum {
|
||||
|
||||
|
||||
// 当前亮度和色温状态
|
||||
typedef struct {
|
||||
typedef struct __attribute__((packed, aligned(1))) {
|
||||
// 物模型同步需要 持久化维持
|
||||
bool on; // 开关状态
|
||||
uint8_t on; // 开关状态
|
||||
lightMode_e elightMode;
|
||||
uint16_t brightness_local; // 当前亮度 (0-1000)
|
||||
uint16_t fade_time; // s
|
||||
uint16_t cct_local; // 当前色温 (2700-6500)
|
||||
// 持久化维持
|
||||
int32_t power_on_cnt; // 上电次数计数
|
||||
bool is_networked; // 是否已配网
|
||||
uint8_t is_networked; // 是否已配网
|
||||
uint8_t is_net_configured; // 设备是否曾经配网成功过
|
||||
//运行时的数据
|
||||
bool read_done; // 读取数据done
|
||||
uint16_t duty_cw; // 冷白LED占空比
|
||||
uint16_t duty_ww; // 暖白LED占空比
|
||||
uint8_t read_done; // 读取数据done
|
||||
} device_control_t;
|
||||
|
||||
// 色温范围定义
|
||||
@ -122,11 +124,11 @@ typedef struct {
|
||||
#define DEVICE_DATA_FLASH_SIZE 0x001000 // 使用一个页的大小
|
||||
|
||||
// 设备数据结构
|
||||
typedef struct {
|
||||
uint32_t checksum; // 校验和
|
||||
uint32_t magic; // 魔数,用于验证数据有效性
|
||||
uint32_t version; // 数据版本号
|
||||
device_control_t control; // 设备控制状态
|
||||
typedef struct __attribute__((packed, aligned(1))) {
|
||||
uint8_t checksum; // 校验和
|
||||
uint32_t magic; // 魔数,用于验证数据有效性
|
||||
uint32_t version; // 数据版本号
|
||||
device_control_t control; // 设备控制状态
|
||||
} device_data_t;
|
||||
|
||||
#define DEVICE_DATA_MAGIC 0x4C505426 // "LPT&"的ASCII码
|
||||
@ -159,6 +161,7 @@ typedef enum {
|
||||
.brightness_local = BRIGHTNESS_REMOTE2LOCAL(INIT_STA__BRIGHTNESS), \
|
||||
.fade_time = NET_CFG_DEFAULT_FADE_TIME, \
|
||||
.is_networked = false, \
|
||||
.is_net_configured = false, \
|
||||
.duty_cw = 0, \
|
||||
.duty_ww = 0, \
|
||||
};
|
||||
|
@ -28,6 +28,7 @@ static void check_net_cfg_power_on_keep_time(void);
|
||||
static void set_light2breathtimeout(void);
|
||||
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);
|
||||
|
||||
@ -35,7 +36,7 @@ void update_pwm_output(void);
|
||||
typedef void (*report_func_t)(void);
|
||||
static void start_report_task(report_func_t report_func);
|
||||
static void report_fade_complete_status(void);
|
||||
static uint32_t calculate_checksum(const device_data_t* data);
|
||||
static uint8_t calculate_checksum(const device_data_t* data);
|
||||
static bool write_device_data_to_addr(uint32_t addr, const device_data_t* data);;
|
||||
static void report_device_online_status(void);
|
||||
|
||||
@ -101,7 +102,7 @@ typedef struct {
|
||||
} print_limiter_t;
|
||||
|
||||
// 渐变控制相关变量
|
||||
static struct {
|
||||
static struct fade_ctx_t {
|
||||
// 渐变控制参数
|
||||
int32_t target_brightness;
|
||||
int32_t target_cct;
|
||||
@ -588,13 +589,13 @@ static void cancel_current_light_fade(void)
|
||||
}
|
||||
|
||||
// 计算校验和
|
||||
static uint32_t calculate_checksum(const device_data_t* data)
|
||||
static uint8_t calculate_checksum(const device_data_t* data)
|
||||
{
|
||||
uint32_t sum = 0;
|
||||
const uint32_t* ptr = (const uint32_t*)(((char*)data) + sizeof(data->checksum));
|
||||
uint8_t sum = 0;
|
||||
const uint8_t* ptr = (const uint8_t*)(((char*)data) + sizeof(data->checksum));
|
||||
size_t len = sizeof(device_data_t) - sizeof(data->checksum); // 减去checksum字段的大小
|
||||
|
||||
for (size_t i = 0; i < len / 4; i++) {
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
sum ^= ptr[i];
|
||||
}
|
||||
return sum;
|
||||
@ -613,7 +614,7 @@ static bool verify_device_data(const device_data_t* data)
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t checksum = calculate_checksum(data);
|
||||
uint8_t checksum = calculate_checksum(data);
|
||||
if (checksum != data->checksum) {
|
||||
e_printf("check sum error:%x\n", data->version);
|
||||
return false;
|
||||
@ -678,9 +679,9 @@ void read_device_data(void)
|
||||
} else if (!main_valid && !backup_valid) { // 如果两个区域都无效,使用默认值
|
||||
e_printf("主数据和备份数据都无效,使用默认值\r\n");
|
||||
// 只打印g_device_control的当前值,不打印data.control
|
||||
// e_printf("读取完成状态: %d\r\n", g_device_control.read_done);
|
||||
e_printf("上电次数: %d\r\n", g_device_control.power_on_cnt);
|
||||
e_printf("配网状态: %d\r\n", g_device_control.is_networked);
|
||||
e_printf("是否是新设备: %d\r\n", !g_device_control.is_net_configured);
|
||||
e_printf("开关状态: %d\r\n", g_device_control.on);
|
||||
e_printf("灯光模式: %d\r\n", g_device_control.elightMode);
|
||||
e_printf("亮度: %d\r\n", g_device_control.brightness_local);
|
||||
@ -692,9 +693,9 @@ void read_device_data(void)
|
||||
}
|
||||
// 更新设备控制状态
|
||||
e_printf("设备状态恢复:\r\n");
|
||||
// e_printf("读取完成状态: %d => %d\r\n", g_device_control.read_done, data.control.read_done);
|
||||
e_printf("上电次数: %d => %d\r\n", g_device_control.power_on_cnt, data.control.power_on_cnt);
|
||||
e_printf("配网状态: %d => %d\r\n", g_device_control.is_networked, data.control.is_networked);
|
||||
e_printf("是否是新设备: %d => %d\r\n", !g_device_control.is_net_configured, !data.control.is_net_configured);
|
||||
e_printf("开关状态: %d => %d\r\n", g_device_control.on, data.control.on);
|
||||
e_printf("灯光模式: %d => %d\r\n", g_device_control.elightMode, data.control.elightMode);
|
||||
e_printf("亮度: %d => %d\r\n", g_device_control.brightness_local, data.control.brightness_local);
|
||||
@ -703,6 +704,7 @@ void read_device_data(void)
|
||||
e_printf("暖白LED: %d => %d\r\n", g_device_control.duty_ww, data.control.duty_ww);
|
||||
e_printf("渐变时间: %d => %d\r\n", g_device_control.fade_time, data.control.fade_time);
|
||||
|
||||
data.control.read_done = false;
|
||||
g_device_control = data.control;
|
||||
lab_exit:
|
||||
#endif
|
||||
@ -725,7 +727,8 @@ void save_device_data(void)
|
||||
last_control.fade_time != g_device_control.fade_time ||
|
||||
last_control.cct_local != g_device_control.cct_local ||
|
||||
last_control.power_on_cnt != g_device_control.power_on_cnt ||
|
||||
last_control.is_networked != g_device_control.is_networked;
|
||||
last_control.is_networked != g_device_control.is_networked ||
|
||||
last_control.is_net_configured != g_device_control.is_net_configured;
|
||||
|
||||
if (!need_save) {
|
||||
e_printf("No changes detected, skip saving\n");
|
||||
@ -834,20 +837,20 @@ static void stop_save_task(void)
|
||||
// 设置灯光状态(统一控制函数)
|
||||
int set_light(int32_t brightness_local, int32_t cct_local)
|
||||
{
|
||||
struct fade_ctx_t tmp_fade_ctx = fade_ctx;
|
||||
// 如果任一参数大于等于0,则更新对应值
|
||||
e_printf("ligMode:%d, local brightness: curr:%d, target:%d, local cct: curr:%d, target:%d\r\n",
|
||||
g_device_control.elightMode, g_device_control.brightness_local, brightness_local, g_device_control.cct_local, cct_local);
|
||||
|
||||
fade_ctx.current_brightness = g_device_control.brightness_local;
|
||||
fade_ctx.current_cct = g_device_control.cct_local;
|
||||
fade_ctx.target_brightness = fade_ctx.current_brightness ;
|
||||
fade_ctx.target_cct = fade_ctx.current_cct;
|
||||
tmp_fade_ctx.current_brightness = g_device_control.brightness_local;
|
||||
tmp_fade_ctx.current_cct = g_device_control.cct_local;
|
||||
tmp_fade_ctx.target_brightness = tmp_fade_ctx.current_brightness ;
|
||||
tmp_fade_ctx.target_cct = tmp_fade_ctx.current_cct;
|
||||
|
||||
if (brightness_local >= 0) {
|
||||
BRIGHTNESS_LITME_RANGE(brightness_local);
|
||||
|
||||
if (g_device_control.elightMode == LIGHT_MODE_CUSTOMER) {
|
||||
fade_ctx.target_brightness = brightness_local;
|
||||
tmp_fade_ctx.target_brightness = brightness_local;
|
||||
} else {
|
||||
g_device_control.brightness_local = brightness_local;
|
||||
}
|
||||
@ -857,7 +860,7 @@ int set_light(int32_t brightness_local, int32_t cct_local)
|
||||
CCT_LITME_RANGE(cct_local);
|
||||
|
||||
if (g_device_control.elightMode == LIGHT_MODE_CUSTOMER) {
|
||||
fade_ctx.target_cct = cct_local;
|
||||
tmp_fade_ctx.target_cct = cct_local;
|
||||
} else {
|
||||
g_device_control.cct_local = cct_local;
|
||||
}
|
||||
@ -867,8 +870,13 @@ int set_light(int32_t brightness_local, int32_t cct_local)
|
||||
{
|
||||
case LIGHT_MODE_CUSTOMER:
|
||||
if (g_device_control.fade_time) {
|
||||
fade_ctx.is_fading = true;
|
||||
fade_ctx.fade_completed = false;
|
||||
tmp_fade_ctx.is_fading = true;
|
||||
tmp_fade_ctx.fade_completed = false;
|
||||
// if(fade_ctx.is_fading) {
|
||||
// e_printf("fade is running, skip set_light\r\n");
|
||||
// return -111;
|
||||
// }
|
||||
fade_ctx = tmp_fade_ctx;
|
||||
// 计算渐变步长
|
||||
calculate_fade_steps();
|
||||
e_printf("start fade\r\n");
|
||||
@ -904,9 +912,6 @@ int set_switch(bool open)
|
||||
calculate_pwm_duty();
|
||||
update_pwm_output();
|
||||
uapi_gpio_set_val(SWITCH_PIN, open ? OPEN_LIGHT : CLOSE_LIGHT);
|
||||
|
||||
// 保存设备状态
|
||||
req_save_device_data();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -937,6 +942,7 @@ static void pwm_init(pin_t pin, pin_t pin1)
|
||||
// uint32_t pwm_base_period_ns = 1000 * 1000 * 1000 / (80 * 1000 * 1000);// 80MHZ
|
||||
// uint32_t pwm_target_period_ns = 1000 * 1000 * 1000 / PWM_FREQUENCY;
|
||||
pwm_period_cnt = ((80 * 1000 * 1000) / PWM_FREQUENCY);
|
||||
cfg_repeat.low_time = pwm_period_cnt;
|
||||
// 设置PWM组
|
||||
channel_id_cw = pin%8;
|
||||
channel_id_ww = pin1%8;
|
||||
@ -960,8 +966,8 @@ static void handle_network_status(void)
|
||||
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) {
|
||||
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);
|
||||
@ -986,24 +992,31 @@ static void handle_network_status(void)
|
||||
// 设备上线时的状态上报
|
||||
static void report_device_online_status(void)
|
||||
{
|
||||
e_printf("[report_task] Starting to report all service status\r\n");
|
||||
e_printf("Starting to report all service status\r\n");
|
||||
fast_report(SVC_ID_SWITCH);
|
||||
fast_report(SVC_ID_BRIGHTNESS);
|
||||
fast_report(SVC_ID_CCT);
|
||||
fast_report(SVC_ID_LIGHT_MODE);
|
||||
fast_report(SVC_ID_FADE_TIME);
|
||||
e_printf("[report_task] Status report completed\r\n");
|
||||
// fast_report(SVC_ID_NET_INFO);
|
||||
e_printf("Status report completed\r\n");
|
||||
}
|
||||
|
||||
// 渐变结束时的状态上报
|
||||
static void report_fade_complete_status(void)
|
||||
{
|
||||
req_save_device_data();
|
||||
e_printf("[report_task] Reporting fade complete status\r\n");
|
||||
e_printf("Reporting fade complete status\r\n");
|
||||
fast_report(SVC_ID_LIGHT_MODE);
|
||||
fast_report(SVC_ID_BRIGHTNESS);
|
||||
fast_report(SVC_ID_CCT);
|
||||
e_printf("[report_task] Fade status report completed\r\n");
|
||||
e_printf("Fade status report completed\r\n");
|
||||
}
|
||||
// 渐变结束时的状态上报
|
||||
static void report_switch_status(void)
|
||||
{
|
||||
req_save_device_data();
|
||||
fast_report(SVC_ID_SWITCH);
|
||||
}
|
||||
|
||||
// 状态上报任务函数
|
||||
@ -1032,6 +1045,7 @@ static void start_report_task(report_func_t report_func)
|
||||
e_printf("[report_task] Previous task is still running, skip this report\r\n");
|
||||
return;
|
||||
}
|
||||
report_task_running = true; // 设置任务运行标志
|
||||
if (report_task_handle) {
|
||||
osal_kthread_destroy(report_task_handle, 0);
|
||||
report_task_handle = NULL;
|
||||
@ -1042,7 +1056,6 @@ static void start_report_task(report_func_t report_func)
|
||||
report_task_handle = osal_kthread_create((osal_kthread_handler)report_task, (void*)report_func, "ReportStaTask",
|
||||
REPORT_TASK_STACK_SIZE);
|
||||
if (report_task_handle != NULL) {
|
||||
report_task_running = true; // 设置任务运行标志
|
||||
osal_kthread_set_priority(report_task_handle, REPORT_TASK_PRIO);
|
||||
}
|
||||
osal_kthread_unlock();
|
||||
@ -1057,6 +1070,7 @@ void handle_device_online(void)
|
||||
return;
|
||||
}
|
||||
e_printf("device online!\r\n");
|
||||
g_device_control.is_net_configured = true;//设备上线后,认为设备已经配网成功,就取消标记为新设备,终生只存在这一次标记
|
||||
if (!g_device_control.is_networked) {
|
||||
e_printf("设备首次上线,记录配网状态\r\n");
|
||||
g_device_control.is_networked = true;
|
||||
@ -1081,6 +1095,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)
|
||||
{
|
||||
@ -1090,6 +1105,9 @@ void handle_device_unbind(void)
|
||||
g_device_control.power_on_cnt = 0; // 重置上电计数
|
||||
stop_spotlight_main_task();
|
||||
device_control_t tmp = DEFAULT_DEVICE_DATA;//恢复默认
|
||||
if (!g_reset_factory_flag) {
|
||||
tmp.is_net_configured = g_device_control.is_net_configured;
|
||||
}
|
||||
g_device_control = tmp;
|
||||
save_device_data();
|
||||
}
|
||||
|
@ -108,9 +108,17 @@ int hf_atcmd_light_query(pat_session_t s, int argc, char *argv[], char *rsp, int
|
||||
g_device_control.duty_ww);
|
||||
return 0;
|
||||
}
|
||||
extern int HILINK_RestoreFactorySettings(void);
|
||||
int hf_atcmd_reset(pat_session_t s,int argc,char *argv[],char *rsp,int len)
|
||||
{
|
||||
HILINK_RestoreFactorySettings();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 注册AT指令
|
||||
const hfat_cmd_t spotlight_ut_cmds_table[] = {
|
||||
|
||||
{NULL, NULL, NULL, NULL}
|
||||
};
|
||||
extern bool g_reset_factory_flag;
|
||||
int hf_atcmd_reset_factory(pat_session_t s,int argc,char *argv[],char *rsp,int len)
|
||||
{
|
||||
g_reset_factory_flag = true;
|
||||
HILINK_RestoreFactorySettings();
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user