优化助眠仪及灯光

This commit is contained in:
helloyifa 2025-05-28 09:03:46 +08:00
parent 7d81c0f348
commit 410018accb
7 changed files with 124 additions and 30 deletions

View File

@ -24,4 +24,4 @@ set(EXTRA_COMPONENTS_DIRS
) )
include($ENV{ARMINO_PATH}/tools/build_tools/cmake/project.cmake) include($ENV{ARMINO_PATH}/tools/build_tools/cmake/project.cmake)
project(beken_wss) project(beken_wss_paopao)

View File

@ -84,3 +84,5 @@ CONFIG_LWIP_PPP_SUPPORT=y
CONFIG_SYS_CPU1_OFFSET=0x22b0000 CONFIG_SYS_CPU1_OFFSET=0x22b0000
CONFIG_WEBSOCKET=y CONFIG_WEBSOCKET=y
CONFIG_WEBSOCKET_TLS=y CONFIG_WEBSOCKET_TLS=y
CONFIG_HTTPS=y
CONFIG_OTA_HTTPS=y

View File

@ -101,7 +101,7 @@ CONFIG_FATFS=y
CONFIG_LCD_FONT_BLEND=n CONFIG_LCD_FONT_BLEND=n
CONFIG_LCD_DMA2D_BLEND=n CONFIG_LCD_DMA2D_BLEND=n
CONFIG_AUD_TRAS_DAC_PA_CTRL=y CONFIG_AUD_TRAS_DAC_PA_CTRL=y
CONFIG_AUD_DAC_PA_CTRL_GPIO=50 CONFIG_AUD_DAC_PA_CTRL_GPIO=0
CONFIG_BT_REUSE_MEDIA_MEMORY=y CONFIG_BT_REUSE_MEDIA_MEMORY=y
CONFIG_BT_REUSE_MEDIA_MEM_SIZE=0x1B000 CONFIG_BT_REUSE_MEDIA_MEM_SIZE=0x1B000
CONFIG_DEBUG_DUMP=y CONFIG_DEBUG_DUMP=y

View File

@ -371,7 +371,7 @@ static void handle_system_event(key_event_t event)
ws2812_led_wifi_disconnect(); ws2812_led_wifi_disconnect();
// bk_gpio_enable_output(0); // bk_gpio_enable_output(0);
bk_gpio_set_output_high(0); //bk_gpio_set_output_high(0);
#endif #endif
} }
break; break;
@ -656,6 +656,7 @@ static void handle_system_event(key_event_t event)
ws2812_init(); ws2812_init();
thing_init(); thing_init();
// spi_led_init(); // spi_led_init();
bk_printf("VER:1.0.3 2025.05.27\r\n");
#endif #endif
#endif #endif

View File

@ -151,7 +151,8 @@ static mode_info_t mode_3[49] = {
{-1, 20}, {-1, 20},
}; };
static uint32_t g_mode_level[SLEEP_MODE_LEVEL_NUM] = {50, 55, 60, 65, 70, 75, 80, 85, 90}; static uint32_t g_mode_level[SLEEP_MODE_LEVEL_NUM] = {25, 30, 35, 40, 45, 50, 55,60,60};
//static uint32_t g_mode_level[SLEEP_MODE_LEVEL_NUM] = { 30, 35, 40, 45, 50, 55};
static int helper_start = 0; static int helper_start = 0;
static beken_queue_t sleep_helper_msg_que = NULL; static beken_queue_t sleep_helper_msg_que = NULL;
@ -160,6 +161,9 @@ static beken_thread_t sleep_helper_thread_hdl = NULL;
static sleep_mode current_mode = SLEEP_MODE_OFF; static sleep_mode current_mode = SLEEP_MODE_OFF;
static sleep_model_level current_level = SLEEP_MODEL_LEVEL_1; static sleep_model_level current_level = SLEEP_MODEL_LEVEL_1;
static int socket_insert = 0;
typedef struct typedef struct
{ {
sleep_mode mode; sleep_mode mode;
@ -254,6 +258,11 @@ void sleep_helper_init(){
bk_gpio_enable_output(44); bk_gpio_enable_output(44);
bk_gpio_enable_output(45); bk_gpio_enable_output(45);
gpio_dev_unmap(GPIO_50);
bk_gpio_enable_input(GPIO_50);
bk_gpio_enable_pull(GPIO_50);
bk_gpio_pull_up(GPIO_50);
pwm_init_config_t config = {0}; pwm_init_config_t config = {0};
config.period_cycle = 100; config.period_cycle = 100;
//默认初始化不输出波形 //默认初始化不输出波形
@ -293,17 +302,31 @@ void sleep_helper_set_mode(sleep_mode mode){
bk_gpio_set_output_low(GPIO_44); bk_gpio_set_output_low(GPIO_44);
bk_gpio_set_output_low(GPIO_45); bk_gpio_set_output_low(GPIO_45);
} }
/*
uint8_t insert_value = bk_gpio_get_input(GPIO_50);
LOGE("sleep_helper insert_value %d \n",insert_value);
socket_insert = insert_value;
if(socket_insert == 1){
LOGE("sleep_helper open fail!! cable not insert %d \n",insert_value);
return ;
}
if (sleep_helper_msg_que) if (sleep_helper_msg_que)
{ {
sleep_msg_t msg; sleep_msg_t msg;
msg.mode = mode; msg.mode = mode;
rtos_push_to_queue(&sleep_helper_msg_que, &msg, BEKEN_NO_WAIT); rtos_push_to_queue(&sleep_helper_msg_que, &msg, BEKEN_NO_WAIT);
}*/ }
} }
void sleep_helper_set_level(sleep_model_level level){ void sleep_helper_set_level(sleep_model_level level){
if(current_mode == SLEEP_MODE_OFF){
pwm_init_config_t config = {0};
config.period_cycle = 100;
config.duty_cycle = g_mode_level[0];
bk_pwm_init(pwm_chan, &config);
bk_pwm_start(pwm_chan);
}
if(level>0 && level< 10){ if(level>0 && level< 10){
current_level = level; current_level = level;
pwm_period_duty_config_t config = {0}; pwm_period_duty_config_t config = {0};
@ -339,7 +362,7 @@ cJSON* iot_sleep_helper_get_device_desc()
cJSON *parameters = cJSON_CreateObject(); cJSON *parameters = cJSON_CreateObject();
cJSON *p_mode = cJSON_CreateObject(); cJSON *p_mode = cJSON_CreateObject();
cJSON_AddStringToObject(p_mode, "type", "number"); cJSON_AddStringToObject(p_mode, "type", "number");
cJSON_AddStringToObject(p_mode, "description", "0到3之间的整数 0代表关闭"); cJSON_AddStringToObject(p_mode, "description", "0到3之间的整数 0代表关闭助眠仪");
cJSON_AddItemToObjectCS(parameters,"mode",p_mode); cJSON_AddItemToObjectCS(parameters,"mode",p_mode);
cJSON_AddItemToObjectCS(setMode,"parameters",parameters); cJSON_AddItemToObjectCS(setMode,"parameters",parameters);
cJSON_AddItemToObjectCS(methods,IOT_SLEEP_HELPER_DEVICE_FUNS_SET_MODE,setMode); cJSON_AddItemToObjectCS(methods,IOT_SLEEP_HELPER_DEVICE_FUNS_SET_MODE,setMode);

View File

@ -65,6 +65,44 @@ const int TEST_7 = 0xFFFFFF;
static uint8_t led_data[WS2812_LED_NUM *24*sizeof(uint8_t)]; static uint8_t led_data[WS2812_LED_NUM *24*sizeof(uint8_t)];
static int ws2812_start = 0; static int ws2812_start = 0;
//static beken_timer_t timer_led_ota_handle;
static int ota_led_state = 0;
static beken_thread_t ota_led_thread_hdl = NULL;
static void ws2812_led_ota_task(void *arg){
while(ws2812_start){
if(ota_led_state){
ota_led_state = 0;
ws2812_set_all_led(WHITE,0);
}else{
ota_led_state = 1;
ws2812_set_all_led(WHITE,100);
}
rtos_delay_milliseconds(100);
}
}
void ws2812_led_start_ota(){
bk_err_t ret = BK_OK;
ret = rtos_create_thread(&ota_led_thread_hdl,
4,
"ota_led",
(beken_thread_function_t)ws2812_led_ota_task,
5 * 1024,
NULL);
if (ret != kNoErr)
{
ota_led_thread_hdl = NULL;
}
}
void ws2812_led_stop_ota(){
//rtos_stop_timer(&timer_led_ota_handle);
}
typedef struct typedef struct
{ {
beken_thread_t handle; beken_thread_t handle;
@ -88,8 +126,8 @@ static spi_data_test_config_t s_spi_test;
static int colorIndex = 0; static int colorIndex = 0;
static int colors[] = {RED, GREEN, WHITE}; static int colors[] = {RED, GREEN, WHITE};
static int current_color = RED;
static float current_brightness = 100;
static beken_queue_t spi_led_msg_que = NULL; static beken_queue_t spi_led_msg_que = NULL;
static beken_thread_t spi_led_thread_hdl = NULL; static beken_thread_t spi_led_thread_hdl = NULL;
//static beken_thread_t spi_led_thread_hdl_gsensor = NULL; //static beken_thread_t spi_led_thread_hdl_gsensor = NULL;
@ -129,17 +167,19 @@ static void spi_led_task(void *arg)
switch(msg.type){ switch(msg.type){
//唤醒词 灯效果 //唤醒词 灯效果
case TYPE_WAKEUP: case TYPE_WAKEUP:
ws2812_set_all_led(0xFFFFFF,0); ws2812_set_all_led(current_color,0);
ws2812_set_all_led(0xFFFFFF,1); ws2812_set_all_led(current_color,current_brightness);
rtos_delay_milliseconds(50); rtos_delay_milliseconds(100);
ws2812_set_all_led(0xFFFFFF,0); ws2812_set_all_led(current_color,0);
rtos_delay_milliseconds(50); rtos_delay_milliseconds(100);
ws2812_set_all_led(0xFFFFFF,1); ws2812_set_all_led(current_color,current_brightness);
rtos_delay_milliseconds(50); rtos_delay_milliseconds(100);
ws2812_set_all_led(0xFFFFFF,0); ws2812_set_all_led(current_color,0);
rtos_delay_milliseconds(100);
ws2812_set_all_led(current_color,current_brightness);
break; break;
case TYPE_OFF: case TYPE_OFF:
ws2812_set_all_led(0xFFFFFF,0); ws2812_set_all_led(current_color,0);
break; break;
case TYPE_CHANGE_COLOR: case TYPE_CHANGE_COLOR:
@ -168,9 +208,16 @@ static void spi_led_task(void *arg)
void ws2812_set_all_led(int color,int brightness){ void ws2812_set_all_led(int color,int brightness){
bk_printf("ws2812_set_all_led\n"); bk_printf("ws2812_set_all_led\n");
if(!ws2812_start){
bk_printf("ws2812 is not init\n");
return;
}
current_color = color;
current_brightness = brightness;
memset(led_data,0x0C,sizeof(led_data)); memset(led_data,0x0C,sizeof(led_data));
// 对颜色进行亮度调整 // 对颜色进行亮度调整
int adjustedColor = adjustColorBrightness(color, brightness); float br = (float)brightness/100;
int adjustedColor = adjustColorBrightness(color, br);
int index = 0; int index = 0;
// 为灯填充数据 // 为灯填充数据
for (int j = 0; j < WS2812_LED_NUM; j++) for (int j = 0; j < WS2812_LED_NUM; j++)
@ -253,30 +300,49 @@ void ws2812_deinit(){
void ws2812_led_wifi_disconnect(){ void ws2812_led_wifi_disconnect(){
//bk_printf("hi ws2812_led_wifi_disconnect777777\n"); //bk_printf("hi ws2812_led_wifi_disconnect777777\n");
//open_dmaspi(RED, 1); //open_dmaspi(RED, 1);
ws2812_set_all_led(RED,1); ws2812_set_all_led(RED,current_brightness);
} }
void ws2812_led_wifi_connected(){ void ws2812_led_wifi_connected(){
//bk_printf("hi ws2812_led_wifi_connected22\n"); //bk_printf("hi ws2812_led_wifi_connected22\n");
//open_dmaspi(WHITE, 1); //open_dmaspi(WHITE, 1);
ws2812_set_all_led(WHITE,1); ws2812_set_all_led(WHITE,current_brightness);
} }
void ws2812_led_asr_wakeup(){ void ws2812_led_asr_wakeup(){
if (spi_led_msg_que != NULL) if (spi_led_msg_que != NULL)
{ {
ws2812_msg_t msg; //ws2812_msg_t msg;
msg.type = TYPE_WAKEUP; //msg.type = TYPE_WAKEUP;
rtos_push_to_queue(&spi_led_msg_que, &msg, BEKEN_NO_WAIT); //rtos_push_to_queue(&spi_led_msg_que, &msg, BEKEN_NO_WAIT);
} }
} }
void ws2812_set_all_led_brightness(int brightness){
if(brightness<0 || brightness>100){
return;
}
bk_printf("ws2812_set_all_led_brightness br:%d\n",brightness);
if(current_color ==0x000000 && brightness > 0){
ws2812_set_all_led(WHITE, brightness);
}else{
ws2812_set_all_led(current_color, brightness);
}
}
void ws2812_set_all_led_color(int color){
ws2812_set_all_led(color, current_brightness);
}
void spi_led_init_gsensor() void spi_led_init_gsensor()
{ {
int currentColor = colors[colorIndex];
// 调用设置颜色的函数
ws2812_set_all_led(currentColor, 1);
// 更新颜色索引,实现循环
colorIndex = (colorIndex + 1) % 3; colorIndex = (colorIndex + 1) % 3;
//int colorIndex = colors[colorIndex];
// 调用设置颜色的函数
ws2812_set_all_led(colors[colorIndex], current_brightness);
// 更新颜色索引,实现循环
//current_color = colorIndex;
} }
void ws2812_led_change_color(){ void ws2812_led_change_color(){
@ -288,6 +354,6 @@ void ws2812_led_change_color(){
void ws2812_led_clear_all(){ void ws2812_led_clear_all(){
//bk_printf("hi ws2812_led_clear_all8888\n"); //bk_printf("hi ws2812_led_clear_all8888\n");
//clearallled(); //clearallled();
ws2812_set_all_led(0x000000,1); ws2812_set_all_led(0x000000,0);
} }

View File

@ -33,8 +33,10 @@ uint8_t get_binary_data_status();
void ws2812_init(); void ws2812_init();
void ws2812_deinit(); void ws2812_deinit();
void ws2812_set_all_led(int color,int brightness); void ws2812_set_all_led(int color,int brightness);
void ws2812_set_all_led_brightness(int brightness);
void ws2812_led_asr_wakeup(); void ws2812_led_asr_wakeup();
void ws2812_led_change_color(); void ws2812_led_change_color();
void ws2812_led_start_ota();
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif