1.初步调试睡眠仪 目前有正负压输出 2.优化扬声器控制 灯光控制的内存泄露

This commit is contained in:
helloyifa 2025-05-19 19:00:59 +08:00
parent 15611c3a2d
commit 5d9bec2139
7 changed files with 199 additions and 4 deletions

View File

@ -23,6 +23,7 @@ list(APPEND srcs
audio_para.c audio_para.c
iot/iot_lamp.c iot/iot_lamp.c
iot/iot_speaker.c iot/iot_speaker.c
iot/iot_sleep_helper.c
iot/thing.c iot/thing.c
) )
if (CONFIG_NETWORK_AUTO_RECONNECT) if (CONFIG_NETWORK_AUTO_RECONNECT)

View File

@ -129,6 +129,7 @@ void iot_lamp_parser_invoke(char* cmd,char * paramters_json){
// {"brightness": 60} // {"brightness": 60}
int brightness = cJSON_GetObjectItem(params, "brightness")->valueint; int brightness = cJSON_GetObjectItem(params, "brightness")->valueint;
LOGE("invoke brightness-->%d\n",brightness); LOGE("invoke brightness-->%d\n",brightness);
cJSON_Delete(params);
} }
} }

View File

@ -0,0 +1,128 @@
#include <common/sys_config.h>
#include <components/log.h>
#include <modules/wifi.h>
#include <components/netif.h>
#include <components/event.h>
#include <string.h>
#include "bk_private/bk_init.h"
#include <components/system.h>
#include <os/os.h>
#include "components/webclient.h"
#include "cJSON.h"
#include "components/bk_uid.h"
#include "bk_genie_comm.h"
#include <os/os.h>
#include <driver/pwm.h>
#include "pwm_hal.h"
#include <driver/gpio.h>
#include "gpio_driver.h"
#include "iot_sleep_helper.h"
#define TAG "sleep_helper"
#define LOGI(...) BK_LOGI(TAG, ##__VA_ARGS__)
#define LOGW(...) BK_LOGW(TAG, ##__VA_ARGS__)
#define LOGE(...) BK_LOGE(TAG, ##__VA_ARGS__)
#define LOGD(...) BK_LOGD(TAG, ##__VA_ARGS__)
/*
*PWM
*/
static uint32_t pwm_chan = 1;
/**
* 1
*/
static mode_info_t model_1[7] = {
{0, 2000},
{1, 2000},
{0, 2000},
{-1, 2000},
{1, 2000},
{0, 2000},
{-1, 2000},
};
static int helper_start = 0;
//static beken_queue_t sleep_helper_msg_que = NULL;
static beken_thread_t sleep_helper_thread_hdl = NULL;
typedef struct
{
sleep_mode model;
sleep_model_level level;
} sleep_msg_t;
static void sleep_helper_thread(void *arg)
{
while (helper_start)
{
LOGE("doing...\n");
for (int i = 0; i < 7; i++)
{
int dir = model_1[i].dir;
int delay = model_1[i].delay_ms;
LOGE("dir:%d delay:%d\n", dir, delay);
//设置方向
switch(dir){
case 1:
bk_gpio_set_output_high(GPIO_44);
bk_gpio_set_output_low(GPIO_45);
break;
case 0:
bk_gpio_set_output_low(GPIO_44);
bk_gpio_set_output_low(GPIO_45);
break;
case -1:
bk_gpio_set_output_low(GPIO_44);
bk_gpio_set_output_high(GPIO_45);
break;
}
rtos_delay_milliseconds(delay);
}
}
}
void sleep_helper_init(){
bk_pwm_driver_init();
//GPIO
gpio_dev_unmap(GPIO_44);
gpio_dev_unmap(GPIO_45);
bk_gpio_enable_output(44);
bk_gpio_enable_output(45);
pwm_init_config_t config = {0};
config.period_cycle = 200;
config.duty_cycle = 100;
bk_pwm_init(pwm_chan, &config);
bk_pwm_start(pwm_chan);
}
void sleep_helper_set_mode(sleep_mode mode){
//model 1
helper_start = 1;
bk_err_t ret = BK_OK;
ret = rtos_create_thread(&sleep_helper_thread_hdl,
9,
"sleep_helper",
(beken_thread_function_t)sleep_helper_thread,
20 * 1024,
NULL);
if (ret != kNoErr)
{
sleep_helper_thread_hdl = NULL;
}
}
void sleep_helper_set_level(sleep_model_level level){
}
void sleep_helper_deinit(){
}

View File

@ -0,0 +1,60 @@
/*************************************************************
*
* Copyright (C) POKA
* All rights reserved.
*
*************************************************************/
#ifndef __IOT_SLEEP_HELPER_H__
#define __IOT_SLEEP_HELPER_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "cJSON.h"
/**
* 3
*/
typedef enum sleep_mode
{
SLEEP_MODE_1 = 1,
SLEEP_MODE_2,
SLEEP_MODE_3,
} sleep_mode;
/**
* 9
*/
typedef enum sleep_level
{
SLEEP_MODEL_LEVEL_1 = 1,
SLEEP_MODEL_LEVEL_2,
SLEEP_MODEL_LEVEL_3,
} sleep_model_level;
typedef struct
{
/**
* 1 0 -1
*/
int dir; //1,0,-1
/**
* ms
*/
int delay_ms;
} mode_info_t;
void sleep_helper_init();
void sleep_helper_set_mode(sleep_mode mode);
void sleep_helper_set_level(sleep_model_level level);
void sleep_helper_deinit();
cJSON * iot_sleep_helper_get_device_desc();
void iot_lamp_parser_invoke(char* cmd,char * paramters_json);
#ifdef __cplusplus
}
#endif
#endif /* __IOT_SLEEP_HELPER_H__ */

View File

@ -218,6 +218,7 @@ void iot_speaker_parser_invoke(char* cmd,char * paramters_json){
LOGE("speaker_setVolume--> volume :%d level:%d\n",volume,level); LOGE("speaker_setVolume--> volume :%d level:%d\n",volume,level);
speaker_volume_set_abs(level,0); speaker_volume_set_abs(level,0);
} }
cJSON_Delete(params);
} }
} }

View File

@ -15,7 +15,7 @@
#include "thing.h" #include "thing.h"
#include "iot_lamp.h" #include "iot_lamp.h"
#include "iot_speaker.h" #include "iot_speaker.h"
#include "iot_sleep_helper.h"
#define TAG "thing" #define TAG "thing"
#define LOGI(...) BK_LOGI(TAG, ##__VA_ARGS__) #define LOGI(...) BK_LOGI(TAG, ##__VA_ARGS__)
#define LOGW(...) BK_LOGW(TAG, ##__VA_ARGS__) #define LOGW(...) BK_LOGW(TAG, ##__VA_ARGS__)
@ -32,6 +32,10 @@ void thing_init()
speaker_volume_init(); speaker_volume_init();
#endif #endif
#ifdef IOT_SLEEP_HELPER
sleep_helper_init();
sleep_helper_set_mode(SLEEP_MODE_1);
#endif
} }
cJSON* thing_gen_iot_descriptors(char *session_id) cJSON* thing_gen_iot_descriptors(char *session_id)

View File

@ -815,8 +815,8 @@ void beken_rtc_main(void)
bk_printf("headers = %s\r\n", headers); bk_printf("headers = %s\r\n", headers);
websocket_cfg.headers = headers; websocket_cfg.headers = headers;
//websocket_cfg.uri = "wss://xiaozhi.xa-poka.com/websocket/xiaozhi/v1/"; websocket_cfg.uri = "wss://xiaozhi.xa-poka.com/websocket/xiaozhi/v1/";
websocket_cfg.uri = "ws://43.139.216.160:8000/xiaozhi/v1/"; //websocket_cfg.uri = "ws://43.139.216.160:8000/xiaozhi/v1/";
websocket_cfg.ws_event_handler = rtc_websocket_event_handler; websocket_cfg.ws_event_handler = rtc_websocket_event_handler;
rtc_session *rtc_session = rtc_websocket_create(&websocket_cfg, rtc_user_audio_rx_data_handle, &audio_info); rtc_session *rtc_session = rtc_websocket_create(&websocket_cfg, rtc_user_audio_rx_data_handle, &audio_info);
if (rtc_session == NULL) if (rtc_session == NULL)