优化充电状态逻辑,判断温度是否稳定,低电亮灯

This commit is contained in:
hu-jiafeng 2025-06-12 17:14:39 +08:00
parent e06c240191
commit 6b7a65900a
17 changed files with 58477 additions and 51831 deletions

11
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,11 @@
{
"files.associations": {
"typedef.h": "c",
"app_temperature.h": "c",
"tuya_ble_stdlib.h": "c",
"xutility": "c",
"tuya_ble_type.h": "c",
"initializer_list": "c",
"type_traits": "c"
}
}

View File

@ -48,6 +48,8 @@ tuya_ble_status_t tuya_ble_dequeue(tuya_ble_queue_t *q, void *out);
void tuya_ble_queue_decrease(tuya_ble_queue_t *q);
void tuya_ble_queue_flush(tuya_ble_queue_t *q);
uint8_t tuya_ble_get_queue_used(tuya_ble_queue_t *q);
bool tuya_ble_queue_isFull(tuya_ble_queue_t *q);
uint8_t tuya_ble_queue_size(tuya_ble_queue_t* q);
#ifdef __cplusplus
}

View File

@ -25,7 +25,7 @@
#include "tuya_ble_stdlib.h"
#include "tuya_ble_queue.h"
#include "tuya_ble_type.h"
#include "app_temperature.h"
tuya_ble_status_t tuya_ble_queue_init(tuya_ble_queue_t *q, void *buf, uint8_t queue_size, uint8_t elem_size)
{
if (buf == NULL || q == NULL) {
@ -98,3 +98,10 @@ uint8_t tuya_ble_get_queue_used(tuya_ble_queue_t *q)
return q->used;
}
bool tuya_ble_queue_isFull(tuya_ble_queue_t *q) {
return q->used >= q->size;
}
uint8_t tuya_ble_queue_size(tuya_ble_queue_t* q) {
return q->size;
}

View File

@ -9,7 +9,7 @@
#include "asm/charge.h"
#include "app_temperature.h"
#include "typedef.h"
#include "tuya_ble_queue.h"
#include "le_common.h"
#include "cpu.h"
#include "timer.h"
@ -20,8 +20,9 @@
#include "examples/trans_data/ble_trans_profile.h"
//#include "ble_trans_profile.h"
static int led_state = 0;
static u16 temer_temperature_detect = 0;
static u16 temer_sleep = 0;
static u16 timer_temperature_detect = 0;
static u16 timer_sleep = 0;
static u16 timer_work = 0;
app_dev_info_t dev_info;
//struct app_dev_config_t dev_config;
@ -68,13 +69,13 @@ void ble_receive_callback(u8* data,u16 len){
if(strstr(data,"AT^TEMP:") != NULL){
u8 str_get_temp[64] = {0};
memset(str_get_temp,0,sizeof(str_get_temp));
sprintf(str_get_temp,"AT^TEMP:%d,%d,%d", dev_info.temperature_sensor/10, dev_info.temperature_sensor/10, dev_info.temperature_sensor/10);
sprintf(str_get_temp,"AT^TEMP:%d,%d,%d,%d", dev_info.temperature_sensor/10, dev_info.temperature_sensor/10, dev_info.temperature_sensor/10,dev_info.temperature_state);
ble_send_data(&str_get_temp,strlen(str_get_temp));
}
else if(strstr(data,"AT+TEMP=") != NULL){
u8 str_get_temp[64] = {0};
memset(str_get_temp,0,sizeof(str_get_temp));
sprintf(str_get_temp,"AT+TEMP=%d,%d,%d", dev_info.temperature_sensor/10, dev_info.temperature_sensor/10, dev_info.temperature_sensor/10);
sprintf(str_get_temp,"AT+TEMP=%d,%d,%d,%d", dev_info.temperature_sensor/10, dev_info.temperature_sensor/10, dev_info.temperature_sensor/10,dev_info.temperature_state);
ble_send_data(&str_get_temp,strlen(str_get_temp));
}
//BATT 真实电压值
@ -371,7 +372,10 @@ static uint8_t reversal(uint8_t data)
return -4;
}
}
char err_code[4][20] = {"NOT Connected", "No DONE signal", "DAT Recv Err", "CRC Err"};
static tuya_ble_queue_t temp_queue;
u16 buffer[MAX_SIZE];
void nst1002_read_temperatura(void)
{
if(charge_state){
@ -381,7 +385,6 @@ static uint8_t reversal(uint8_t data)
int err, ei;
float dtmp;
int16_t cal;
// NTC VDD
gpio_set_direction(IO_PORTB_05,0);
gpio_direction_output(IO_PORTB_05, 1);
@ -408,15 +411,17 @@ static uint8_t reversal(uint8_t data)
u16 body = (u16)temp_value;
u16 obj = (u16)temp_value;
u16 ntc = (u16)0;
u8 battery = 99;
// u8 battery = 99;
u8 battery = get_vbat_percent();
//batt
battery = get_cur_battery_level() *10;
// battery = get_cur_battery_level() *10;
dev_info.temperature_sensor = body;
dev_info.temperature_ntc = body;
dev_info.batt_percent = battery;
dev_info.batt_val = get_vbat_value();
printf("battery: %d\r\n",battery);
u8 ff_temp_data[7] = {0};
//body
ff_temp_data[0] = (body >> 8) & 0xFF;
@ -442,6 +447,83 @@ static uint8_t reversal(uint8_t data)
trans_client_adv_data_set_ff(ff_temp_data,sizeof(ff_temp_data));
gpio_direction_output(IO_PORTB_05, 0);
//计算温度稳定性
u16 temp_body = dev_info.temperature_sensor;
u16 last_body_temp = 0;
if(temp_body < BLE_TEMPERATURE_LIMIT_MIN || temp_body > BLE_TEMPERATURE_LIMIT_MAX){
printf("error temp_body\r\n");
return;
}
last_body_temp = temp_body;
//添加数据到队列,数量足够后取出所有温度数据 计算方差 如果小于 N N可以趋近于0 暂定小于20 则表示温度稳定
if (tuya_ble_queue_isFull(&temp_queue)) {
tuya_ble_queue_decrease(&temp_queue); // 移除队首元素
}
tuya_ble_enqueue(&temp_queue, &last_body_temp);
uint8_t size = tuya_ble_get_queue_used(&temp_queue);
if (!tuya_ble_queue_isFull(&temp_queue)) {
printf("queue_size -> %d \r\n", size);
}
if (tuya_ble_queue_isFull(&temp_queue)) {
uint8_t i = 0;
u16 t_datas[MAX_SIZE];
uint8_t index = temp_queue.rd_ptr;
for (int i = 0; i < MAX_SIZE; i++) {
t_datas[i] = *(u16*)((uint8_t*)temp_queue.buf + index * temp_queue.offset);
index = (index + 1) % temp_queue.size;
}
// 中值滤波:排序
// for (int i = 0; i < MAX_SIZE - 1; i++) {
// for (int j = i + 1; j < MAX_SIZE; j++) {
// if (t_datas[i] > t_datas[j]) {
// u16 tmp = t_datas[i];
// t_datas[i] = t_datas[j];
// t_datas[j] = tmp;
// }
// }
// }
// // 取中值
// u16 mean_value;
// if (MAX_SIZE % 2 == 1) {
// mean_value = t_datas[MAX_SIZE / 2];
// } else {
// mean_value = (t_datas[MAX_SIZE / 2 - 1] + t_datas[MAX_SIZE / 2]) / 2;
// }
// printf("mean_value:%d \r\n", mean_value);
//计算平均值
u32 sum = 0;
for(i = 0;i < MAX_SIZE; i++){
sum += t_datas[i];
}
u16 mean_value = sum / MAX_SIZE;
printf("mean_value:%d \r\n", mean_value);
//计算方差
double sumOfSquares = 0;
for (int i = 0; i < MAX_SIZE; i++) {
sumOfSquares += (t_datas[i] - mean_value) * (t_datas[i] - mean_value);
}
u16 variance_value = sumOfSquares / MAX_SIZE; // 注意这里是n而不是n-1对于样本方差
printf("variance_value:%d \r\n", variance_value);
//方差小于 20 表示温度稳定
if(variance_value <= 15){
dev_info.temperature_state=1;
}else{
dev_info.temperature_state=0;
}
printf("dev_info.temperature_state:%d\r\n", dev_info.temperature_state);
}
}
/**
@ -492,12 +574,51 @@ void rtc_test_demo()
//read_alarm(&tmp_time); //读修改后alarm时间
//printf("rtc_read_alarm_after: %d-%d-%d %d:%d:%d", tmp_time.year, tmp_time.month, tmp_time.day, tmp_time.hour, tmp_time.min, tmp_time.sec); //打印修改后闹钟时间值
}
static u8 low_battery_led_blinking = 0;
static u16 low_battery_led_timer_id = 0;
void low_battery_led_flash(void *priv)
{
if (charge_state) {
if (low_battery_led_timer_id) {
usr_timer_del(low_battery_led_timer_id);
low_battery_led_timer_id = 0;
}
temperature_work_led(0); // 关闭LED
low_battery_led_blinking = 0;
return;
}
led_state = !led_state;
temperature_work_led(led_state); // 切换LED状态
}
void stop_low_battery_blink(void)
{
if (low_battery_led_timer_id) {
usr_timer_del(low_battery_led_timer_id);
low_battery_led_timer_id = 0;
}
low_battery_led_blinking = 0;
temperature_work_led(0); // 关闭LED
}
void temperature_detect(void)
{
rtc_test_demo();
nst1002_read_temperatura();
u8 battery = get_vbat_percent();
// 低电处理电量小于20%
if (battery < 20 && !charge_state) {
if (!low_battery_led_blinking) {
// 开始闪烁
low_battery_led_blinking = 1;
low_battery_led_timer_id = usr_timer_add(NULL, low_battery_led_flash, 500, 1);
}
} else { // 停止闪烁
if (low_battery_led_blinking) {
stop_low_battery_blink();
}
}
}
#endif
@ -527,11 +648,12 @@ void temperature_poweron_led_timeout(){
temperature_work_led(0);
}
static u8 init_complete = 0;
void temperature_set_soft_poweroff(void)
{
printf("temperature_set_soft_poweroff\n");
temperature_deinit();
syscfg_write(INIT_COMPLETE_FLAG_CONFIG, &init_complete,sizeof(init_complete));
//VCM_DET_EN(0);//关闭VCM复位
//gpio_shortpress_reset_config(0);//1--enable 0--disable
@ -548,17 +670,42 @@ void temperature_set_soft_poweroff(void)
power_set_soft_poweroff();
#endif
}
void timer_sleep_callback(void);
void temperature_charge_state(int state){
switch (state)
{
static u8 charge_inited = 0;//防止充电因电压不稳,重复触发充电状态
printf("init_complete:%d",init_complete);
if ( init_complete == 0 ) { //读取初始化标志,防止休眠重置
syscfg_read(INIT_COMPLETE_FLAG_CONFIG, &init_complete, sizeof(init_complete));
init_complete = (init_complete == 1);
}
if (!init_complete && state == BLE_TEMPERATURE_CHARGE_KEEP_CHARGING ) { //防止开机误判充电状态,并提前亮灯
init_complete = 1;
sys_timer_del(timer_temperature_detect);
temperature_work_led(1);
sys_s_hi_timerout_add(NULL,temperature_poweron_led_timeout,2000);
return;
}
switch (state){
//接入充电
case BLE_TEMPERATURE_CHARGE_STATE_CHARGING :
charge_state = 1;
if (charge_inited) {
printf("vbal instablity!\n");
return;
}
printf("BLE_TEMPERATURE_CHARGE_STATE_CHARGING\n");
//关闭低电提示LED
charge_state = 1;
init_complete = 0;
charge_inited = 1;
syscfg_write(INIT_COMPLETE_FLAG_CONFIG, &init_complete,sizeof(init_complete));
temperature_charge_lowpower(0);
sys_timer_del(temer_temperature_detect);
sys_timer_del(timer_temperature_detect);
//sys_timer_del(timer_sleep);
//体温计指标灯闪烁3次后转灭
for(int i = 0; i< 3 ; i++){
temperature_work_led(1);
@ -572,7 +719,34 @@ void temperature_charge_state(int state){
//spple_power_event_to_user(POWER_EVENT_POWER_SOFTOFF);
//printf("!!!!!!!!!!!!!! CHARGING POWER OFF!!!!!!!!!!!!!!!!\n");
//printf("BLE_TEMPERATURE_CHARGE_STATE_CHARGING 2\n");
break;
//拔出电压0.6左右)< ldoin < vbat
case BLE_TEMPERATURE_CHARGE_KEEP_CHARGING :
if (charge_inited) {
printf("vbal instablity!\n");
return;
}
printf("BLE_TEMPERATURE_CHARGE_KEEP_CHARGING\n");
charge_state = 1;
init_complete = 0;
charge_inited = 1;
syscfg_write(INIT_COMPLETE_FLAG_CONFIG, &init_complete,sizeof(init_complete));
temperature_charge_lowpower(0);
sys_timer_del(timer_temperature_detect);
//sys_timer_del(timer_sleep);
//体温计指标灯闪烁3次后转灭
for(int i = 0; i< 3 ; i++){
temperature_work_led(1);
delay_ms_by_timer0(150);
temperature_work_led(0);
delay_ms_by_timer0(150);
}
//接入充电关闭蓝牙广播
ble_op_adv_enable(0);
ble_module_enable(0);
break;
//充电完成
case BLE_TEMPERATURE_CHARGE_STATE_FULL :
@ -582,12 +756,19 @@ void temperature_charge_state(int state){
//拔出充电
case BLE_TEMPERATURE_CHARGE_STATE_IDLE :
charge_state = 0;
charge_inited = 0;
printf("BLE_TEMPERATURE_CHARGE_STATE_IDLE\n");
temer_temperature_detect = sys_timer_add(NULL, temperature_detect, dev_config.detect_interval);
timer_temperature_detect = sys_timer_add(NULL, temperature_detect, dev_config.detect_interval);
//timer_sleep = sys_timer_add(NULL, timer_sleep_callback,DEVICE_WORK_TIMEOUT);
printf("dev_info.batt_percent:%d\n",dev_info.batt_percent);
//temperature_charge_led(0);
if(init_complete == 0 ){ //如果开机未进入BLE_TEMPERATURE_CHARGE_KEEP_CHARGING则亮灯
temperature_work_led(1);
sys_s_hi_timerout_add(NULL,temperature_poweron_led_timeout,2000);
}
init_complete = 1;
//拔出充电打开蓝牙广播
ble_module_enable(1);
ble_op_adv_enable(1);
@ -616,8 +797,6 @@ void temperature_ble_init(){
char ble_name[12] ={0};
sprintf(ble_name,"iT12_%02X%02X",bt_mac_addr[1],bt_mac_addr[0]);
ble_comm_set_config_name(&ble_name, 0);
}
/**
*
@ -629,7 +808,6 @@ void temperature_config_init(){
int ret = syscfg_read(BLE_TEMPERATURE_VM_DEVICE_CONFIG, &dev_config, sizeof(app_dev_config_t));
if (ret != sizeof(app_dev_config_t)) {
printf("temperature_config_init err:%d", ret);
dev_config.detect_interval = 500;
dev_config.temperature_offset = 0;
syscfg_write(BLE_TEMPERATURE_VM_DEVICE_CONFIG, &dev_config, sizeof(app_dev_config_t));
@ -659,24 +837,33 @@ void timer_sleep_callback(void)
{
//关机开启闹钟
printf(">>>>>>>>>>>>>>>>> timer_sleep_callback ...\n");
//先查明当前连接的conn_handle 如果是蓝牙连接状态 不休眠
//先查明当前连接的conn_handle 如果是蓝牙连接状态或充电状态 不休眠
u16 connection_handle = ble_comm_dev_get_handle(0, GATT_ROLE_SERVER);
if(connection_handle != 0)//
{
printf("ble connected !! connection_handle: %04x\n", connection_handle);
if(connection_handle != 0 || charge_state == 1){
sys_timer_del(timer_sleep);
timer_sleep = sys_timer_add(NULL, timer_sleep_callback, DEVICE_WORK_TIMEOUT);
printf("ble connected or charging !! connection_handle: %04x\n", connection_handle);
return ;
}else{
//printf("connection_handle: %04x\n", connection_handle);
}
if( charge_state == 1){
printf("charging !! do not sleep\n");
return ;
stop_low_battery_blink();
rtc_alarm_set_timer(DEVICE_SLEEP_TIMEOUT);
temperature_set_soft_poweroff();
// sys_timer_del(timer_sleep); // 清除旧定时器
// timer_work = sys_timer_add(NULL, timer_work_callback, 5000);
}
rtc_alarm_set_timer(5);
temperature_set_soft_poweroff();
}
// void timer_work_callback(void){
// printf(">>>>>>>>>>>>>>>>> timer_work_callback ...\n");
// // 重启测温
// timer_temperature_detect = sys_timer_add(NULL, temperature_detect, dev_config.detect_interval);
// // 启动下一轮10秒工作定时器
// sys_timer_del(timer_work);
// timer_sleep = sys_timer_add(NULL, timer_sleep_callback, 10000);
// }
void temperature_init(void)
{
@ -685,7 +872,6 @@ void temperature_init(void)
//extern void alarm_rtc_start(void);
//alarm_rtc_start();
//user_alarm_test();
printf(">>>>>>>>>>>>>>>>> temperature_init ...\n");
delay_us(60);
printf(">>>>>>>>>>>>>>>>> temperature_OTA ...\n");
@ -698,16 +884,21 @@ void temperature_init(void)
temperature_config_init();
//从收纳仓取出时自动开机指示灯亮2S后灭
temperature_work_led(1);
sys_s_hi_timerout_add(NULL,temperature_poweron_led_timeout,2000);
// temperature_work_led(1);
// sys_s_hi_timerout_add(NULL,temperature_poweron_led_timeout,2000);
//sys_s_hi_timer_add(NULL, temperature_blink_led, 200);
//sys_s_hi_timer_add(NULL, temperature_detect, 2000);
//sys_timer_add 方式添加定时任务 任务里边可以使用udelay delay_ms 等延时 sys_s_hi_timer_add 则延时无效
temer_temperature_detect = sys_timer_add(NULL, temperature_detect, dev_config.detect_interval);
//工作10秒关机 关机10s后 RTC重新唤醒
//temer_sleep = sys_timer_add(NULL, timer_sleep_callback,10*1000);
timer_temperature_detect = sys_timer_add(NULL, temperature_detect, dev_config.detect_interval);
//工作10秒关机 关机10s后 RTC重新唤醒
//timer_sleep = sys_timer_add(NULL, timer_sleep_callback,DEVICE_WORK_TIMEOUT);
tuya_ble_queue_init(&temp_queue, buffer, MAX_SIZE, sizeof(u16));
tuya_ble_queue_flush(&temp_queue);
//charge_only = 0;
//HALL PIN 输入
gpio_set_direction(IO_PORTA_00,1);
gpio_set_die(IO_PORTA_00,1);

View File

@ -2,24 +2,9 @@
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Release" />
<File name="..\..\app_temperature.c" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="..\..\..\..\cpu\bd19\adc_api.c" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="10635" topLine="320" />
</Cursor>
</File>
<File name="..\..\..\common\third_party_profile\jieli\gatt_common\le_gatt_server.c" open="1" top="0" tabpos="9" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="27428" topLine="677" />
</Cursor>
</File>
<File name="..\..\examples\trans_data\ble_trans.h" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="553" topLine="0" />
</Cursor>
</File>
<File name="board_config.h" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="518" topLine="0" />
<Cursor1 position="11677" topLine="441" />
</Cursor>
</File>
<File name="..\..\include\app_config.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
@ -29,22 +14,12 @@
</File>
<File name="..\..\modules\power\app_charge.c" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="855" topLine="6" />
<Cursor1 position="1522" topLine="53" />
</Cursor>
</File>
<File name="..\..\examples\trans_data\ble_trans.c" open="1" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="..\..\..\..\cpu\bd19\charge.c" open="1" top="0" tabpos="10" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="26810" topLine="719" />
</Cursor>
</File>
<File name="board_ac6323a_demo_cfg.h" open="1" top="1" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="4367" topLine="216" />
</Cursor>
</File>
<File name="..\..\..\..\cpu\bd19\adc_api.c" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="11677" topLine="441" />
<Cursor1 position="8796" topLine="308" />
</Cursor>
</File>
<File name="..\..\modules\bt\app_comm_edr.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
@ -52,9 +27,39 @@
<Cursor1 position="1154" topLine="18" />
</Cursor>
</File>
<File name="..\..\app_main.c" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="board_ac6323a_demo_cfg.h" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="7571" topLine="261" />
<Cursor1 position="12074" topLine="216" />
</Cursor>
</File>
<File name="..\..\..\common\third_party_profile\jieli\gatt_common\le_gatt_server.c" open="1" top="0" tabpos="9" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="27428" topLine="677" />
</Cursor>
</File>
<File name="board_config.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="518" topLine="0" />
</Cursor>
</File>
<File name="..\..\app_main.c" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="7497" topLine="261" />
</Cursor>
</File>
<File name="..\..\examples\trans_data\ble_trans.c" open="1" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="26810" topLine="719" />
</Cursor>
</File>
<File name="..\..\app_temperature.c" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="16761" topLine="496" />
</Cursor>
</File>
<File name="..\..\examples\trans_data\ble_trans.h" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="553" topLine="0" />
</Cursor>
</File>
</CodeBlocks_layout_file>

View File

@ -24,10 +24,19 @@
#define BLE_TEMPERATURE_CHARGE_STATE_FULL 2
#define BLE_TEMPERATURE_CHARGE_STATE_IDLE 3
#define BLE_TEMPERATURE_CHARGE_STATE_LOWPOWER 4
#define BLE_TEMPERATURE_CHARGE_KEEP_CHARGING 5
//VM用户自定义配置项[1 ~ 49]
#define BLE_TEMPERATURE_VM_DEVICE_CONFIG 2
#define INIT_COMPLETE_FLAG_CONFIG 3
#define DEVICE_SLEEP_TIMEOUT 5 //设备休眠时间
#define DEVICE_WORK_TIMEOUT 15000 //设备工作时间
#define BLE_TEMPERATURE_LIMIT_MIN 2000
#define BLE_TEMPERATURE_LIMIT_MAX 4500
#define MAX_SIZE 30
typedef struct
{
u16 temperature_sensor;
@ -36,6 +45,7 @@ typedef struct
u16 batt_val;
u8 is_bat_charge;
u8 is_bat_full;
u8 temperature_state;
}app_dev_info_t;
typedef struct
@ -59,4 +69,5 @@ void temperature_work_led(u8 on);
void temperature_charge_led(u8 on);
void temperature_charge_state(int state);
void temperature_deinit(void);
#endif //_APP_TEMPERATURE_H_

View File

@ -43,7 +43,7 @@ void ldo5v_keep_deal(void)
#if TCFG_HANDSHAKE_ENABLE
handshake_app_start(2, handshake_complete);
#endif
temperature_charge_state(BLE_TEMPERATURE_CHARGE_STATE_CHARGING);
temperature_charge_state(BLE_TEMPERATURE_CHARGE_KEEP_CHARGING);
}
void charge_full_deal(void)
@ -65,6 +65,7 @@ void charge_close_deal(void)
void charge_ldo5v_in_deal(void)
{
log_info("%s\n", __FUNCTION__);
#if TCFG_HANDSHAKE_ENABLE
handshake_app_start(2, handshake_complete);
#else
@ -73,6 +74,7 @@ void charge_ldo5v_in_deal(void)
temperature_charge_state(BLE_TEMPERATURE_CHARGE_STATE_CHARGING);
}
void charge_ldo5v_off_deal(void)
{
log_info("%s\n", __FUNCTION__);
@ -85,11 +87,14 @@ void charge_ldo5v_off_deal(void)
vbat_check_init();
#endif
temperature_charge_state(BLE_TEMPERATURE_CHARGE_STATE_IDLE);
}
int app_charge_event_handler(struct device_event *dev)
{
log_info("%s\n %d", __FUNCTION__,dev->event);
switch (dev->event) {
case CHARGE_EVENT_CHARGE_START:
charge_start_deal();
@ -112,8 +117,11 @@ int app_charge_event_handler(struct device_event *dev)
default:
break;
}
return 0;
}
#endif

View File

@ -24,7 +24,7 @@ enum {
VBAT_LOWPOWER,
} VBAT_STATUS;
#define VBAT_DETECT_CNT (2*1) //2*N
#define VBAT_DETECT_CNT (2*3) //2*N
#define VBAT_DETECT_ADC_MS (10) //unint:ms
#define VBAT_PERIOD_CHECK_S (30) //unint:s

View File

@ -252,7 +252,6 @@ static void charge_full_detect(void *priv)
static void ldo5v_detect(void *priv)
{
/* log_info("%s\n",__func__); */
static u16 ldo5v_on_cnt = 0;
static u16 ldo5v_keep_cnt = 0;
static u16 ldo5v_off_cnt = 0;
@ -422,7 +421,6 @@ static void charge_config(void)
CHARGE_mA_SEL(CHARGE_mA_20);
}
int charge_init(const struct dev_node *node, void *arg)
{
log_info("%s\n", __func__);
@ -446,6 +444,7 @@ int charge_init(const struct dev_node *node, void *arg)
if (check_charge_state()) {
if (__this->ldo5v_timer == 0) {
__this->ldo5v_timer = usr_timer_add(0, ldo5v_detect, 2, 1);
}
} else {
@ -453,8 +452,8 @@ int charge_init(const struct dev_node *node, void *arg)
power_exit_charge_mode();
}
__this->init_ok = 1;
__this->init_ok = 1;
return 0;
}

View File

@ -2113,6 +2113,8 @@ obj/Release/apps/common/third_party_profile/tuya_protocol/sdk/src/tuya_ble_queue
-r=obj/Release/apps/common/third_party_profile/tuya_protocol/sdk/src/tuya_ble_queue.o,tuya_ble_queue_decrease,pl
-r=obj/Release/apps/common/third_party_profile/tuya_protocol/sdk/src/tuya_ble_queue.o,tuya_ble_queue_flush,pl
-r=obj/Release/apps/common/third_party_profile/tuya_protocol/sdk/src/tuya_ble_queue.o,tuya_ble_get_queue_used,pl
-r=obj/Release/apps/common/third_party_profile/tuya_protocol/sdk/src/tuya_ble_queue.o,tuya_ble_queue_isFull,pl
-r=obj/Release/apps/common/third_party_profile/tuya_protocol/sdk/src/tuya_ble_queue.o,tuya_ble_queue_size,pl
obj/Release/apps/common/third_party_profile/tuya_protocol/sdk/src/tuya_ble_storage.o
-r=obj/Release/apps/common/third_party_profile/tuya_protocol/sdk/src/tuya_ble_storage.o,tuya_ble_storage_load_settings,pl
-r=obj/Release/apps/common/third_party_profile/tuya_protocol/sdk/src/tuya_ble_storage.o,tuya_ble_malloc,l
@ -2270,7 +2272,6 @@ obj/Release/apps/spp_and_le/app_main.o
-r=obj/Release/apps/spp_and_le/app_main.o,usr_timer_del,l
-r=obj/Release/apps/spp_and_le/app_main.o,alarm_rtc_start,l
-r=obj/Release/apps/spp_and_le/app_main.o,user_alarm_test,l
-r=obj/Release/apps/spp_and_le/app_main.o,alarm_isr_user_cbfun,pl
-r=obj/Release/apps/spp_and_le/app_main.o,user_main,pl
-r=obj/Release/apps/spp_and_le/app_main.o,temperature_init,l
-r=obj/Release/apps/spp_and_le/app_main.o,app_main,pl
@ -2297,12 +2298,15 @@ obj/Release/apps/spp_and_le/app_temperature.o
-r=obj/Release/apps/spp_and_le/app_temperature.o,ble_comm_dev_get_handle,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,ble_comm_att_check_send,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,ble_gatt_server_characteristic_ccc_get,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,printf,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,ble_comm_att_send_data,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,ble_receive_callback,pl
-r=obj/Release/apps/spp_and_le/app_temperature.o,printf,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,strstr,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,memset,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,sprintf,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,strlen,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,ble_on_connect_change,pl
-r=obj/Release/apps/spp_and_le/app_temperature.o,temperature_work_led,pl
-r=obj/Release/apps/spp_and_le/app_temperature.o,delay_us_by_timer0,pl
-r=obj/Release/apps/spp_and_le/app_temperature.o,clk_get,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,delay_us_by_timer0_irq,pl
@ -2314,38 +2318,57 @@ obj/Release/apps/spp_and_le/app_temperature.o
-r=obj/Release/apps/spp_and_le/app_temperature.o,gpio_set_die,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,gpio_read,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,nst1002_read_temperatura,pl
-r=obj/Release/apps/spp_and_le/app_temperature.o,get_cur_battery_level,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,get_vbat_percent,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,get_vbat_value,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,trans_client_adv_data_set_ff,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,tuya_ble_queue_isFull,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,tuya_ble_queue_decrease,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,tuya_ble_enqueue,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,tuya_ble_get_queue_used,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,temperature_update_adv_ff,pl
-r=obj/Release/apps/spp_and_le/app_temperature.o,get_cur_battery_level,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,rtc_test_demo,pl
-r=obj/Release/apps/spp_and_le/app_temperature.o,read_sys_time,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,low_battery_led_flash,pl
-r=obj/Release/apps/spp_and_le/app_temperature.o,usr_timer_del,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,stop_low_battery_blink,pl
-r=obj/Release/apps/spp_and_le/app_temperature.o,temperature_detect,pl
-r=obj/Release/apps/spp_and_le/app_temperature.o,usr_timer_add,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,temperature_charge_lowpower,pl
-r=obj/Release/apps/spp_and_le/app_temperature.o,sys_timer_del,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,sys_timer_add,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,temperature_work_led,pl
-r=obj/Release/apps/spp_and_le/app_temperature.o,temperature_poweron_led_timeout,pl
-r=obj/Release/apps/spp_and_le/app_temperature.o,temperature_set_soft_poweroff,pl
-r=obj/Release/apps/spp_and_le/app_temperature.o,temperature_deinit,pl
-r=obj/Release/apps/spp_and_le/app_temperature.o,syscfg_write,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,gpio_longpress_pin0_reset_config,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,btstack_ble_exit,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,sys_timeout_add,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,power_set_soft_poweroff,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,temperature_charge_state,pl
-r=obj/Release/apps/spp_and_le/app_temperature.o,syscfg_read,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,usr_timeout_add,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,ble_user_cmd_prepare,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,ble_module_enable,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,usr_timeout_add,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,temperature_ble_init,pl
-r=obj/Release/apps/spp_and_le/app_temperature.o,bt_get_vm_mac_addr,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,le_controller_set_mac,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,ble_comm_set_config_name,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,temperature_config_init,pl
-r=obj/Release/apps/spp_and_le/app_temperature.o,syscfg_read,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,syscfg_write,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,alarm_isr_user_cbfun,pl
-r=obj/Release/apps/spp_and_le/app_temperature.o,timer_sleep_callback,pl
-r=obj/Release/apps/spp_and_le/app_temperature.o,rtc_alarm_set_timer,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,temperature_init,pl
-r=obj/Release/apps/spp_and_le/app_temperature.o,get_vbat_trim,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,get_vbg_trim,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,temperature_deinit,pl
-r=obj/Release/apps/spp_and_le/app_temperature.o,tuya_ble_queue_init,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,tuya_ble_queue_flush,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,gpio_set_pull_up,l
-r=obj/Release/apps/spp_and_le/app_temperature.o,dev_info,pl
-r=obj/Release/apps/spp_and_le/app_temperature.o,err_code,pl
-r=obj/Release/apps/spp_and_le/app_temperature.o,charge_led_hander,pl
-r=obj/Release/apps/spp_and_le/app_temperature.o,dev_config,pl
-r=obj/Release/apps/spp_and_le/app_temperature.o,buffer,pl
obj/Release/apps/spp_and_le/config/lib_btctrler_config.o
-r=obj/Release/apps/spp_and_le/config/lib_btctrler_config.o,config_btctler_modules,pl
-r=obj/Release/apps/spp_and_le/config/lib_btctrler_config.o,CONFIG_TWS_RUN_SLOT,pl
@ -3262,6 +3285,7 @@ obj/Release/apps/spp_and_le/examples/trans_data/ble_trans.o
-r=obj/Release/apps/spp_and_le/examples/trans_data/ble_trans.o,get_remote_test_flag,l
-r=obj/Release/apps/spp_and_le/examples/trans_data/ble_trans.o,little_endian_read_16,l
-r=obj/Release/apps/spp_and_le/examples/trans_data/ble_trans.o,ble_vendor_get_peer_rssi,l
-r=obj/Release/apps/spp_and_le/examples/trans_data/ble_trans.o,ble_on_connect_change,l
-r=obj/Release/apps/spp_and_le/examples/trans_data/ble_trans.o,little_endian_read_32,l
-r=obj/Release/apps/spp_and_le/examples/trans_data/ble_trans.o,ble_gatt_server_characteristic_ccc_set,l
-r=obj/Release/apps/spp_and_le/examples/trans_data/ble_trans.o,ble_gatt_server_connetion_update_request,l

File diff suppressed because it is too large Load Diff