From 5d9bec21399622df03213f9ec158499c24b01904 Mon Sep 17 00:00:00 2001 From: helloyifa Date: Mon, 19 May 2025 19:00:59 +0800 Subject: [PATCH] =?UTF-8?q?1.=E5=88=9D=E6=AD=A5=E8=B0=83=E8=AF=95=E7=9D=A1?= =?UTF-8?q?=E7=9C=A0=E4=BB=AA=20=E7=9B=AE=E5=89=8D=E6=9C=89=E6=AD=A3?= =?UTF-8?q?=E8=B4=9F=E5=8E=8B=E8=BE=93=E5=87=BA=202.=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E6=89=AC=E5=A3=B0=E5=99=A8=E6=8E=A7=E5=88=B6=20=E7=81=AF?= =?UTF-8?q?=E5=85=89=E6=8E=A7=E5=88=B6=E7=9A=84=E5=86=85=E5=AD=98=E6=B3=84?= =?UTF-8?q?=E9=9C=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../beken_wss_paopao/main/CMakeLists.txt | 1 + .../beken_wss_paopao/main/iot/iot_lamp.c | 1 + .../main/iot/iot_sleep_helper.c | 128 ++++++++++++++++++ .../main/iot/iot_sleep_helper.h | 60 ++++++++ .../beken_wss_paopao/main/iot/iot_speaker.c | 1 + .../beken_wss_paopao/main/iot/thing.c | 8 +- .../main/websocket_rtc_demo.c | 4 +- 7 files changed, 199 insertions(+), 4 deletions(-) create mode 100755 bk_aidk/projects/beken_wss_paopao/main/iot/iot_sleep_helper.h diff --git a/bk_aidk/projects/beken_wss_paopao/main/CMakeLists.txt b/bk_aidk/projects/beken_wss_paopao/main/CMakeLists.txt index 8b3ad45f..8c728e3a 100755 --- a/bk_aidk/projects/beken_wss_paopao/main/CMakeLists.txt +++ b/bk_aidk/projects/beken_wss_paopao/main/CMakeLists.txt @@ -23,6 +23,7 @@ list(APPEND srcs audio_para.c iot/iot_lamp.c iot/iot_speaker.c + iot/iot_sleep_helper.c iot/thing.c ) if (CONFIG_NETWORK_AUTO_RECONNECT) diff --git a/bk_aidk/projects/beken_wss_paopao/main/iot/iot_lamp.c b/bk_aidk/projects/beken_wss_paopao/main/iot/iot_lamp.c index a2aadb19..7bf6016e 100755 --- a/bk_aidk/projects/beken_wss_paopao/main/iot/iot_lamp.c +++ b/bk_aidk/projects/beken_wss_paopao/main/iot/iot_lamp.c @@ -129,6 +129,7 @@ void iot_lamp_parser_invoke(char* cmd,char * paramters_json){ // {"brightness": 60} int brightness = cJSON_GetObjectItem(params, "brightness")->valueint; LOGE("invoke brightness-->%d\n",brightness); + cJSON_Delete(params); } } diff --git a/bk_aidk/projects/beken_wss_paopao/main/iot/iot_sleep_helper.c b/bk_aidk/projects/beken_wss_paopao/main/iot/iot_sleep_helper.c index e69de29b..42320fdb 100755 --- a/bk_aidk/projects/beken_wss_paopao/main/iot/iot_sleep_helper.c +++ b/bk_aidk/projects/beken_wss_paopao/main/iot/iot_sleep_helper.c @@ -0,0 +1,128 @@ +#include +#include +#include +#include +#include +#include +#include "bk_private/bk_init.h" +#include +#include +#include "components/webclient.h" +#include "cJSON.h" +#include "components/bk_uid.h" +#include "bk_genie_comm.h" + +#include +#include +#include "pwm_hal.h" + +#include +#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(){ + +} \ No newline at end of file diff --git a/bk_aidk/projects/beken_wss_paopao/main/iot/iot_sleep_helper.h b/bk_aidk/projects/beken_wss_paopao/main/iot/iot_sleep_helper.h new file mode 100755 index 00000000..0459c6c6 --- /dev/null +++ b/bk_aidk/projects/beken_wss_paopao/main/iot/iot_sleep_helper.h @@ -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__ */ + diff --git a/bk_aidk/projects/beken_wss_paopao/main/iot/iot_speaker.c b/bk_aidk/projects/beken_wss_paopao/main/iot/iot_speaker.c index cf9812eb..1144369d 100755 --- a/bk_aidk/projects/beken_wss_paopao/main/iot/iot_speaker.c +++ b/bk_aidk/projects/beken_wss_paopao/main/iot/iot_speaker.c @@ -218,6 +218,7 @@ void iot_speaker_parser_invoke(char* cmd,char * paramters_json){ LOGE("speaker_setVolume--> volume :%d level:%d\n",volume,level); speaker_volume_set_abs(level,0); } + cJSON_Delete(params); } } \ No newline at end of file diff --git a/bk_aidk/projects/beken_wss_paopao/main/iot/thing.c b/bk_aidk/projects/beken_wss_paopao/main/iot/thing.c index 3c7a4cfb..ab53f05d 100755 --- a/bk_aidk/projects/beken_wss_paopao/main/iot/thing.c +++ b/bk_aidk/projects/beken_wss_paopao/main/iot/thing.c @@ -15,7 +15,7 @@ #include "thing.h" #include "iot_lamp.h" #include "iot_speaker.h" - +#include "iot_sleep_helper.h" #define TAG "thing" #define LOGI(...) BK_LOGI(TAG, ##__VA_ARGS__) #define LOGW(...) BK_LOGW(TAG, ##__VA_ARGS__) @@ -31,7 +31,11 @@ void thing_init() #ifdef IOT_SPEAKER speaker_volume_init(); #endif - + + #ifdef IOT_SLEEP_HELPER + sleep_helper_init(); + sleep_helper_set_mode(SLEEP_MODE_1); + #endif } cJSON* thing_gen_iot_descriptors(char *session_id) diff --git a/bk_aidk/projects/beken_wss_paopao/main/websocket_rtc_demo.c b/bk_aidk/projects/beken_wss_paopao/main/websocket_rtc_demo.c index a0ca1e4c..b51aa0e9 100755 --- a/bk_aidk/projects/beken_wss_paopao/main/websocket_rtc_demo.c +++ b/bk_aidk/projects/beken_wss_paopao/main/websocket_rtc_demo.c @@ -815,8 +815,8 @@ void beken_rtc_main(void) bk_printf("headers = %s\r\n", headers); websocket_cfg.headers = headers; - //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 = "wss://xiaozhi.xa-poka.com/websocket/xiaozhi/v1/"; + //websocket_cfg.uri = "ws://43.139.216.160:8000/xiaozhi/v1/"; 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); if (rtc_session == NULL)