Compare commits

...

3 Commits

12 changed files with 141 additions and 26 deletions

View File

@ -331,6 +331,9 @@ bk_err_t gpio_hal_wakeup_interrupt_clear()
static inline bool is_gpio_for_current_cpu(int gpio_id){
const gpio_default_map_t default_map[] = GPIO_DEFAULT_DEV_CONFIG;
for(int i = 0; i < sizeof(default_map)/sizeof(gpio_default_map_t); i++){
//helloyifa {
if(default_map[i].gpio_id == GPIO_51) continue;
//helloyifa }
if (gpio_id == default_map[i].gpio_id){
return true;
}

View File

@ -171,6 +171,10 @@ static bk_err_t send_audio_msg(void)
int send_audio_data_to_trans(uint8_t *data, unsigned int len)
{
if (!g_connected_flag)
{
return 0;
}
#if CONFIG_USE_OPUS_CODEC
if (ring_buffer_get_free_size(&mic_data_rb) >= len)
{

View File

@ -52,6 +52,10 @@
#define BAT_DETEC_ADC_STEADY_CTRL 7
#define BAT_DETEC_ADC_SAMPLE_RATE 0
#define BATTERY_MAX_VOLTAGE 4200
#define BATTERY_MIN_VOLTAGE 3400
static int batt_percent = 0;
static battery_main_event_callback_t s_battery_main_event_callback = NULL;
int battery_main_event_callback_register(battery_main_event_callback_t callback)
{
@ -165,6 +169,15 @@ static bk_err_t prvStartBatteryAdcOneTime()
uint8_t insert_value = bk_gpio_get_input(GPIO_50);
bk_printf("Charging insert_value %d \n", insert_value);
bk_printf("ADC bat_value: %d mv\r\n", vol);
batt_percent=(vol-BATTERY_MIN_VOLTAGE)*100/(BATTERY_MAX_VOLTAGE-BATTERY_MIN_VOLTAGE);
if(vol < BATTERY_MIN_VOLTAGE){
batt_percent=0;
}
else if(vol > BATTERY_MAX_VOLTAGE){
batt_percent = 100;
}
bk_printf("batt_percent:%d\r\n",batt_percent);
if (vol < 3500)
{
if (s_battery_main_event_callback && insert_value == 0)
@ -173,7 +186,7 @@ static bk_err_t prvStartBatteryAdcOneTime()
s_battery_main_event_callback(EVT_BATTERY_MAIN_LOW_VOLTAGE);
}
}
goto ADC_EXIT;
ADC_EXIT:
if (s_raw_voltage_data)
{
@ -183,7 +196,7 @@ ADC_EXIT:
BK_LOG_ON_ERR(bk_adc_stop());
BK_LOG_ON_ERR(bk_adc_deinit(ADC_15));
BK_LOG_ON_ERR(bk_adc_release());
bk_printf("exit battery check\r\n");
return ret;
}
@ -198,25 +211,24 @@ static void adc_bat_ticks(void *param)
void init_bat_timer()
{
bk_err_t result;
bk_printf("init_bat_timer\n");
result = rtos_init_timer(&g_adc_bat,
60000,
adc_bat_ticks,
(void *)0);
if (result != 0)
{
bk_printf("rtos_init_bat_timer fail\r\n");
}
result = rtos_start_timer(&g_adc_bat);
if (result != 0)
{
bk_printf("rtos_start_bat_timer fail\r\n");
}
prvStartBatteryAdcOneTime();
}
@ -239,7 +251,9 @@ void poweroff_voice()
}
}
int battery_get_percent(){
return batt_percent;
}

View File

@ -11,3 +11,7 @@ int battery_main_event_callback_register(battery_main_event_callback_t callback)
void init_bat_timer();
void poweron_voice();
void poweroff_voice();
/**
*
*/
int battery_get_percent();

View File

@ -27,6 +27,8 @@
#include "spi_led.h"
#include "bk_wifi.h"
#include "../iot/iot_speaker.h"
#include "bat_main.h"
#include "app_event.h"
static ble_boarding_info_t *s_ble_boarding_info = NULL;
static beken_semaphore_t s_ble_sema = NULL;
@ -685,15 +687,18 @@ static int32_t wifi_boarding_gatts_cb(bk_gatts_cb_event_t event, bk_gatt_if_t ga
sscanf((char *)recv, "AT+SLEEP_TIMEOUT=%s", mode);
if (strcmp(mode, "?") == 0)
{
sprintf((char *)str_respone, "%s", "AT+SLEEP_TIMEOUT=10");
int sleep_work_time = sleep_helper_get_work_timeout();
sprintf((char *)str_respone, "AT+SLEEP_TIMEOUT=%d", sleep_work_time);
wifi_boarding_notify(str_respone, strlen((char *)&str_respone));
}
else
{
int v = atoi(mode);
sleep_helper_set_timeout(v);
sprintf((char *)str_respone, "%s", "AT+SLEEP_MODE=OK");
sprintf((char *)str_respone, "%s", "AT+SLEEP_TIMEOUT=OK");
wifi_boarding_notify(str_respone, strlen((char *)&str_respone));
}
wifi_boarding_notify(str_respone, strlen((char *)&str_respone));
}
/*
*11.
@ -734,6 +739,17 @@ static int32_t wifi_boarding_gatts_cb(bk_gatts_cb_event_t event, bk_gatt_if_t ga
sprintf((char *)str_respone, "AT+VERSION=%s", IOT_LAMP_DEVICE_VERSION);
wifi_boarding_notify(str_respone, strlen((char *)&str_respone));
}
else if (NULL != (ptr = strstr((char *)recv, "AT+SETAIURL")))
{
wboard_loge("AT+SETAIURL!!");
uint8_t str_respone[32] = {0};
memset(str_respone, 0, sizeof(str_respone));
sprintf((char *)str_respone, "AT+SETAIURL=%s", IOT_LAMP_DEVICE_VERSION);
wifi_boarding_notify(str_respone, strlen((char *)&str_respone));
}
/**
* APP
@ -757,6 +773,7 @@ static int32_t wifi_boarding_gatts_cb(bk_gatts_cb_event_t event, bk_gatt_if_t ga
C: 0 -100 0
D: 0 - 3 0 1-3
E: 1 - 9 9
F: 0-100
*/
else if (NULL != (ptr = strstr((char *)recv, "AT+STATE")))
{
@ -781,7 +798,8 @@ static int32_t wifi_boarding_gatts_cb(bk_gatts_cb_event_t event, bk_gatt_if_t ga
int sleep_mode = sleep_helper_get_mode();
int sleep_level = sleep_helper_get_level();
int sleep_work_time = sleep_helper_get_work_timeout();
sprintf((char *)str_respone, "AT+STATE=%d,%d,%d,%d,%d,%d", connect_state,device_volme,device_bright,sleep_mode,sleep_level,sleep_work_time);
int battery_p = battery_get_percent();
sprintf((char *)str_respone, "AT+STATE=%d,%d,%d,%d,%d,%d,%d", connect_state,device_volme,device_bright,sleep_mode,sleep_level,sleep_work_time,battery_p);
wifi_boarding_notify(str_respone, strlen((char *)&str_respone));
}
@ -818,8 +836,15 @@ static int32_t wifi_boarding_gatts_cb(bk_gatts_cb_event_t event, bk_gatt_if_t ga
{
wboard_loge("OTA-->%s", ota_url);
wboard_loge("OTA--len >%d", strlen(ota_url));
ws2812_led_start_ota();
lamp_http_ota_start(ota_url);
//ws2812_led_start_ota();
//lamp_http_ota_start(ota_url);
//电量低于25 不允许执行OTA
int battery = battery_get_percent();
if(battery > 25){
iot_lamp_check_ota();
}else{
app_event_send_msg(APP_EVT_LOW_VOLTAGE, 0);
}
free(ota_url);
}
}

View File

@ -13,9 +13,12 @@
#include "bk_genie_comm.h"
#include "iot_lamp.h"
//OTA
#include "audio_transfer.h"
#include "modules/ota.h"
#include "spi_led.h"
#include "thing.h"
#include "bat_main.h"
#include "app_event.h"
#define TAG "iot_lamp"
#define LOGI(...) BK_LOGI(TAG, ##__VA_ARGS__)
@ -27,6 +30,7 @@
#define IOT_LAMP_DEVICE_OTA_CHECK_URL "http://106.52.233.130:8888/ir58/ir58.json"
static int is_ota = 0;
void lamp_init(){
//ws2812_init();
}
@ -52,6 +56,13 @@ cJSON* iot_lamp_get_device_desc(){
cJSON_AddStringToObject(brightness, "type", "number");
//添加brightness属性到properties
cJSON_AddItemToObjectCS(properties,"brightness",brightness);
//定义battery 属性
cJSON *battery = cJSON_CreateObject();
cJSON_AddStringToObject(battery, "description", "当前电量百分比");
cJSON_AddStringToObject(battery, "type", "number");
cJSON_AddItemToObjectCS(properties,IOT_LAMP_DEVICE_PARAM_BATTERY,battery);
//添加properties 到lamp_desc 描述
cJSON_AddItemToObjectCS(lamp_desc,"properties",properties);
@ -128,6 +139,15 @@ void bk_https_start_download(beken_thread_arg_t arg) {
int ret;
char *ota_url = (char*)arg;
BK_LOGE(TAG,"ota_url %s\n",ota_url);
//OTA升级时关闭语音
//audio_tras_deinit();
extern bk_err_t audio_turn_off(void);
audio_turn_off();
audio_tras_deinit();
rtos_delay_milliseconds(500);
//extern bk_err_t beken_rtc_stop(void);
//beken_rtc_stop();
ret = bk_http_ota_download(ota_url);
//ret = bk_https_ota_download("https://xiaozhi.xa-poka.com/xiaozhi/otaMag/download/59cc091e-eaf3-417d-a524-d5e3d95883f4");
if(ret != BK_OK) {
@ -251,8 +271,10 @@ int iot_lamp_check_ota(){
if (!strcmp(version, IOT_LAMP_DEVICE_VERSION) == 0){
BK_LOGE(TAG,"%s do ota!!! \n",version);
is_ota = 1;
ws2812_led_start_ota();
https_ota_start(otafile);
return 1;
}else{
BK_LOGE(TAG,"%s device version is lasted:%s \n",version);
@ -305,6 +327,13 @@ void iot_lamp_parser_invoke(char* cmd,char * paramters_json){
}
else if (strcmp(cmd, IOT_LAMP_DEVICE_OTA) == 0){
LOGE("invoke ota !!\n");
//电量低于25 不允许执行OTA
int battery = battery_get_percent();
if(battery < 25){
LOGE("power low bat:%d ,don't ota !!\n",battery);
app_event_send_msg(APP_EVT_LOW_VOLTAGE, 0);
return ;
}
iot_lamp_check_ota();
//ws2812_led_start_ota();
//https_ota_start();

View File

@ -19,11 +19,18 @@ extern "C" {
#define IOT_LAMP_DEVICE_NAME "lamp"
#define IOT_LAMP_DEVICE_FUNS_SET_BRIGHTNESS "SetBrightness"
#define IOT_LAMP_DEVICE_PARAM_BRIGHTNESS "brightness"
#define IOT_LAMP_DEVICE_PARAM_BATTERY "battery"
#define IOT_LAMP_DEVICE_GET_BATTERY "GetBattery"
#define IOT_LAMP_DEVICE_OTA "ota"
#define IOT_LAMP_DEVICE_VERSION "1.0.8"
/**
* 1.1.1 OTA升级电量限制 25%
*
* OTA时关闭语音
*
*/
#define IOT_LAMP_DEVICE_VERSION "1.1.3"
void lamp_init();
void lamp_http_ota_start(char *url);
@ -36,6 +43,7 @@ int lamp_get_bright();
cJSON * iot_lamp_get_device_desc();
void iot_lamp_parser_invoke(char* cmd,char * paramters_json);
int iot_lamp_check_ota();
#ifdef __cplusplus
}
#endif

View File

@ -90,7 +90,7 @@ int test_ota(){
goto __exit;
}
//webclient_set_tls_session(session);
/* send GET request by default header */
if ((resp_status = webclient_get(session, url)) != 200)
{

View File

@ -160,9 +160,8 @@ static mode_info_t mode_3[49] = {
{-1, 20},
};
//static uint32_t g_mode_level[SLEEP_MODE_LEVEL_NUM] = {65, 60, 55, 50, 45, 40, 35,30,25};
static uint32_t g_mode_level[SLEEP_MODE_LEVEL_NUM] = {35, 40, 45, 50, 60, 70, 80,90,100};
//static uint32_t g_mode_level[SLEEP_MODE_LEVEL_NUM] = { 30, 35, 40, 45, 50, 55};
static uint32_t g_mode_level[SLEEP_MODE_LEVEL_NUM] = {25, 34, 43, 52, 61, 70, 79,88,99};
static int helper_start = 0;
static beken_queue_t sleep_helper_msg_que = NULL;
@ -320,16 +319,28 @@ void sleep_helper_set_level(sleep_model_level level){
//config.period_cycle = 100;
config.period_cycle = s_period;
//config.duty_cycle = g_mode_level[level-1];
config.duty_cycle = s_period*g_mode_level[level-1]/100;
config.duty_cycle = (uint32_t)s_period*(g_mode_level[level-1])/(uint32_t)100;
LOGE("sleep_helper_set_level %d \n",g_mode_level[level-1]);
LOGE("sleep_helper period_cycle s %d duty_cycle %d\n",config.period_cycle,config.duty_cycle);
bk_pwm_set_init_signal_low(pwm_chan);
bk_pwm_set_period_duty(pwm_chan,&config);
//bk_pwm_stop(pwm_chan);
//bk_pwm_deinit(pwm_chan);
//rtos_delay_milliseconds(100);
//bk_pwm_init(pwm_chan, &config);
//bk_pwm_start(pwm_chan);
//LOGE("sleep_helper period_cycle e %d duty_cycle %d\n",config.period_cycle,config.duty_cycle);
thing_report_iot_state_number(IOT_SLEEP_HELPER_DEVICE_NAME,IOT_SLEEP_HELPER_DEVICE_PARAM_LEVEL,level);
}
}
void sleep_helper_open(){
if(current_mode != SLEEP_MODE_OFF){
sleep_helper_close();
}
LOGE("sleep_helper_open\n");
bk_gpio_enable_output(44);
bk_gpio_enable_output(44);
bk_gpio_enable_output(45);
// bk_gpio_enable_pull(GPIO_50);
@ -337,7 +348,7 @@ void sleep_helper_open(){
uint8_t insert_value = bk_gpio_get_input(GPIO_50);
LOGE("sleep_helper insert_valueccc %d \n",insert_value);
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);
@ -349,7 +360,9 @@ void sleep_helper_open(){
config.period_cycle = s_period;
//config.duty_cycle = g_mode_level[0];//默认等级1
config.duty_cycle = s_period*g_mode_level[0]/100;
LOGE("sleep_helper period_cycle %d duty_cycle %d\n",config.period_cycle,config.duty_cycle);
bk_pwm_init(pwm_chan, &config);
bk_pwm_set_init_signal_low(pwm_chan);
bk_pwm_start(pwm_chan);
//默认模式1
sleep_helper_set_mode(SLEEP_MODE_1);
@ -501,7 +514,7 @@ void sleep_helper_init(){
config.duty_cycle = 0;
//config.duty_cycle = g_mode_level[SLEEP_MODEL_LEVEL_1-1];
bk_pwm_init(pwm_chan, &config);
bk_pwm_start(pwm_chan);
helper_start = 1;
bk_err_t ret = BK_OK;

View File

@ -34,7 +34,8 @@
#if (CONFIG_SYS_CPU0)
static uint32_t volume = 7; // volume level, not gain.
static uint32_t g_volume_gain[SPK_VOLUME_LEVEL] = {0, 0x05, 0x18, 0x10, 0x13, 0x15, 0x18, 0x21, 0x22, 0x25, 0x30};
//static uint32_t g_volume_gain[SPK_VOLUME_LEVEL] = {0, 0x05, 0x18, 0x10, 0x13, 0x15, 0x18, 0x21, 0x22, 0x25, 0x30};
static uint32_t g_volume_gain[SPK_VOLUME_LEVEL] = {0, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x30};
void speaker_volume_init(void)
{
int volume_size = bk_config_read("volume", (void *)&volume, 4);

View File

@ -16,6 +16,7 @@
#include "iot_lamp.h"
#include "iot_speaker.h"
#include "iot_sleep_helper.h"
#include "bat_main.h"
#include "beken_rtc.h"
#define TAG "thing"
@ -25,6 +26,7 @@
#define LOGD(...) BK_LOGD(TAG, ##__VA_ARGS__)
extern rtc_session *__get_beken_rtc(void);
extern char *getGlobalSessionId(void);
extern bool g_connected_flag;
static beken_queue_t thing_msg_que = NULL;
static beken_thread_t thing_thread_hdl = NULL;
@ -232,7 +234,14 @@ static void thing_thread_task(void *arg)
// 发送数据到平台
case 0:
{
//没有连接平台的情况下 不允许发送数据
if(!g_connected_flag){
break;
}
rtc_session *beken_rtc = __get_beken_rtc();
if(beken_rtc == NULL){
break;
}
transport bk_rtc_ws = beken_rtc->bk_rtc_client;
websocket_client_send_text(bk_rtc_ws, msg.data, msg.data_len, 10*1000);
os_free(msg.data);
@ -263,6 +272,8 @@ void thing_report_device_state(){
thing_report_iot_state_number(IOT_LAMP_DEVICE_NAME,IOT_LAMP_DEVICE_PARAM_BRIGHTNESS,lamp_get_bright());
//上报当前音量
thing_report_iot_state_number(IOT_SPEAKER_DEVICE_NAME,IOT_SPEAKER_DEVICE_PARAM_VOL,speaker_volume_get_current());
//上报当前电量
thing_report_iot_state_number(IOT_LAMP_DEVICE_NAME,IOT_LAMP_DEVICE_PARAM_BATTERY,battery_get_percent());
//thing_report_iot_state_number(IOT_SPEAKER_DEVICE_NAME,IOT_SPEAKER_DEVICE_PARAM_VOL,volume*10);
}
void thing_init()

View File

@ -632,6 +632,9 @@ static void poka_aud_tras_main(void)
void poka_audio_receive_data_opus(rtc_session *rtc_session, uint8 *data, uint32_t len)
{
// LOGE("poka_audio_receive_data_opus called, rtc_session->opus_buffer: %d", rtc_session->opus_buffer != NULL);
if(!rtc_runing){
return;
}
if (rtc_session->opus_buffer)
{
// LOGE("rtc_session->opus_buffer condition met, trying to allocate memory for opus data");
@ -684,7 +687,7 @@ void sent_abort_msg()
// bk_printf("MEDIA_APP_EVT_ASR_WAKEUP_IND_sent_abort_msg first_abort = %d\n",first_abort);
if (client)
{
bk_printf("rtc_websocket_send_text_BEKEN_RTC_SEND_ABORT_BEKEN_RTC_SEND_STOP_LISTEN_BEKEN_RTC_SEND_START_LISTEN\r\n");
//bk_printf("rtc_websocket_send_text_BEKEN_RTC_SEND_ABORT_BEKEN_RTC_SEND_STOP_LISTEN_BEKEN_RTC_SEND_START_LISTEN\r\n");
rtc_websocket_send_text(client, (void *)(&audio_info), BEKEN_RTC_SEND_ABORT);
rtc_websocket_send_text(client, (void *)(&audio_info), BEKEN_RTC_SEND_START);