LPT26x-HSF-4MB-Hilink_14.2..../application/ws63/user_main/spotlight/spotlight_ut.c
ekko.bao 5ec8b9380c 1. 解决频繁频繁掉线的问题:原因是因为ble
sdk需要一开始就初始化,配网的时候只是去控制其广播是否开启。不然会导致一直掉线
2025-06-02 21:31:39 +08:00

124 lines
3.4 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "hsf.h"
#include "spotlight.h"
#include "pinctrl.h"
#include "gpio.h"
#include "pinctrl.h"
#include "pwm.h"
#include "timer.h"
#include "soc_osal.h"
#include "systick.h"
extern device_control_t g_device_control;
extern void update_pwm_output(void);
extern void calculate_pwm_duty(void);
// AT指令设置PWM占空比
// 格式AT+PWM=<channel>,<duty>
// channel: 0-冷白LED, 1-暖白LED
// duty: 0-1000
int hf_atcmd_pwm(pat_session_t s, int argc, char *argv[], char *rsp, int len)
{
if (argc != 2) {
e_printf(rsp, "ERROR: Invalid parameters. Usage: AT+PWM=<channel>,<duty>");
return -1;
}
int channel = atoi(argv[0]);
int duty = atoi(argv[1]);
// 参数检查
if (channel < 0 || channel > 1) {
e_printf(rsp, "ERROR: Invalid channel. Must be 0(CW) or 1(WW)");
return -1;
}
if (duty < 0 || duty > PWM_DUTY_RATIO_MAX) {
e_printf(rsp, "ERROR: Invalid duty. Must be 0-%d", PWM_DUTY_RATIO_MAX);
return -1;
}
// 设置PWM占空比
if (channel == 0) {
g_device_control.duty_cw = duty;
} else {
g_device_control.duty_ww = duty;
}
// 更新PWM输出
update_pwm_output();
sprintf(rsp, "OK: Channel %d PWM duty set to %d", channel, duty);
return 0;
}
// AT指令获取当前PWM占空比
// 格式AT+PWM?
int hf_atcmd_pwm_query(pat_session_t s, int argc, char *argv[], char *rsp, int len)
{
sprintf(rsp, "+PWM: CW=%d,WW=%d", g_device_control.duty_cw, g_device_control.duty_ww);
return 0;
}
// AT指令直接设置色温和亮度
// 格式AT+LIGHT=<brightness>,<cct>
// brightness: 0-1000
// cct: 2700-6500
int hf_atcmd_light(pat_session_t s, int argc, char *argv[], char *rsp, int len)
{
if (argc != 2) {
e_printf(rsp, "ERROR: Invalid parameters. Usage: AT+LIGHT=<brightness>,<cct>");
return -1;
}
int brightness = atoi(argv[0]);
int cct = atoi(argv[1]);
// 参数检查
if (brightness < 0 || brightness > BRIGHTNESS_MAX) {
e_printf(rsp, "ERROR: Invalid brightness. Must be 0-%d", BRIGHTNESS_MAX);
return -1;
}
if (cct < CCT_MIN || cct > CCT_MAX) {
e_printf(rsp, "ERROR: Invalid CCT. Must be %d-%d", CCT_MIN, CCT_MAX);
return -1;
}
// 设置亮度和色温
g_device_control.brightness_local = BRIGHTNESS_REMOTE2LOCAL(brightness);
g_device_control.cct_local = CCT_REMOTE2LOCAL(cct);
// 计算PWM占空比并更新输出
calculate_pwm_duty();
update_pwm_output();
sprintf(rsp, "OK: Brightness=%d, CCT=%d, CW=%d%%%%, WW=%d%%%%",
brightness, cct, g_device_control.duty_cw, g_device_control.duty_ww);
return 0;
}
// AT指令获取当前亮度和色温
// 格式AT+LIGHT?
int hf_atcmd_light_query(pat_session_t s, int argc, char *argv[], char *rsp, int len)
{
sprintf(rsp, "+LIGHT: Brightness=%d, CCT=%d, CW=%d, WW=%d",
g_device_control.brightness_local,
g_device_control.cct_local,
g_device_control.duty_cw,
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;
}
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;
}