增加了修改温度校准的协议

This commit is contained in:
haped 2025-07-17 15:20:30 +08:00
parent f5db5fb7b1
commit 88b4122a95
5 changed files with 75 additions and 26 deletions

View File

@ -21,7 +21,8 @@
//#include "ble_trans_profile.h" //#include "ble_trans_profile.h"
static int led_state = 0; static int led_state = 0;
static u16 timer_temperature_detect = 0; static u16 timer_temperature_detect = 0;
static int16_t ADJ_temp = 0; static int16_t ADJ_obj_temp = 0;
static int16_t ADJ_body_temp = 0;
app_dev_info_t dev_info; app_dev_info_t dev_info;
//struct app_dev_config_t dev_config; //struct app_dev_config_t dev_config;
@ -127,21 +128,52 @@ void ble_receive_callback(u8* data,u16 len){
ble_send_data(&str_adj,strlen(str_adj)); ble_send_data(&str_adj,strlen(str_adj));
u16 temp = dev_info.init_sensor; u16 temp = dev_info.init_sensor;
ADJ_temp = temp - BLE_ADJUST_TEMP_37 ; ADJ_obj_temp = temp - BLE_ADJUST_TEMP_37 ;
if (ADJ_temp > 3000 || ADJ_temp < -3000) { if (ADJ_obj_temp > 3000 || ADJ_obj_temp < -3000) {
ADJ_temp = 0; ADJ_obj_temp = 0;
} }
syscfg_write(ADJ_TEMP_CONFIG, &ADJ_temp,sizeof(ADJ_temp)); syscfg_write(ADJ_OBJ_TEMP_CONFIG, &ADJ_obj_temp,sizeof(ADJ_obj_temp));
} }
//物温偏差+1度
else if(strstr(data,"AT+ADJOBJ=") != NULL){
u8 str_adj[64] = {0};
char *end;
long value = strtol(data + strlen("AT+ADJOBJ="), &end, 10);
ADJ_obj_temp -= (int16_t)value;
memset(str_adj,0,sizeof(str_adj));
sprintf(str_adj,"AT+ADJOBJ=%d",-ADJ_obj_temp);
ble_send_data(&str_adj,strlen(str_adj));
syscfg_write(ADJ_OBJ_TEMP_CONFIG, &ADJ_obj_temp,sizeof(ADJ_obj_temp));
}
//体温偏差+1度
else if(strstr(data,"AT+ADJBODY=") != NULL){
u8 str_adj[64] = {0};
char *end;
long value = strtol(data + strlen("AT+ADJBODY="), &end, 10);
ADJ_body_temp -= (int16_t)value;
memset(str_adj,0,sizeof(str_adj));
sprintf(str_adj,"AT+ADJBODY=%d",-ADJ_body_temp);
ble_send_data(&str_adj,strlen(str_adj));
syscfg_write(ADJ_BODY_TEMP_CONFIG, &ADJ_body_temp,sizeof(ADJ_body_temp));
}
else if(strstr(data,"AT+RESET=") != NULL){ else if(strstr(data,"AT+RESET=") != NULL){
u8 str_res[64] = {0}; u8 str_res[64] = {0};
memset(str_res,0,sizeof(str_res)); memset(str_res,0,sizeof(str_res));
sprintf(str_res,"AT+RESET=OK"); sprintf(str_res,"AT+RESET=OK");
ble_send_data(&str_res,strlen(str_res)); ble_send_data(&str_res,strlen(str_res));
ADJ_temp = 0; ADJ_obj_temp = 0;
syscfg_write(ADJ_TEMP_CONFIG, &ADJ_temp,sizeof(ADJ_temp)); ADJ_body_temp = 0;
syscfg_write(ADJ_OBJ_TEMP_CONFIG, &ADJ_obj_temp,sizeof(ADJ_obj_temp));
syscfg_write(ADJ_BODY_TEMP_CONFIG, &ADJ_body_temp,sizeof(ADJ_body_temp));
} }
else{ else{
printf("unknow cmd\n"); printf("unknow cmd\n");
@ -322,11 +354,12 @@ u16 buffer[MAX_SIZE];
} }
int temp_value = t_body; int temp_value = t_body;
int Tobj_value = t_ntc;
printf("Temp: %d\r\n\r\n", temp_value); printf("Temp: %d\r\n\r\n", temp_value);
//BBOOEEb 2字节体温 2字节物温 2字节环温 1字节电量 //BBOOEEb 2字节体温 2字节物温 2字节环温 1字节电量
u16 body = (u16)temp_value; u16 body = (u16)temp_value;
u16 obj = (u16)temp_value; u16 obj = (u16)Tobj_value;
u16 ntc = (u16)t_ntc; u16 ntc = (u16)t_ntc;
u8 battery = get_vbat_percent(); u8 battery = get_vbat_percent();
u16 batt_val = 0; u16 batt_val = 0;
@ -339,16 +372,16 @@ u16 buffer[MAX_SIZE];
dev_info.init_sensor = body; //原始温度 dev_info.init_sensor = body; //原始温度
if (ADJ_temp != 0) { if (ADJ_obj_temp != 0) {
int16_t temp_body = (int16_t)body;
int16_t temp_obj = (int16_t)obj; int16_t temp_obj = (int16_t)obj;
temp_obj -= ADJ_obj_temp;
temp_body -= ADJ_temp;
temp_obj -= ADJ_temp;
body = (temp_body > 0) ? (u16)temp_body : 0;
obj = (temp_obj > 0) ? (u16)temp_obj : 0; obj = (temp_obj > 0) ? (u16)temp_obj : 0;
} }
if (ADJ_body_temp != 0) {
int16_t temp_body = (int16_t)body;
temp_body -= ADJ_body_temp;
body = (temp_body > 0) ? (u16)temp_body : 0;
}
if(body == 0 && obj == 0 ){ if(body == 0 && obj == 0 ){
printf("error data ...\r\n"); printf("error data ...\r\n");
@ -791,10 +824,13 @@ void temperature_init(void)
tuya_ble_queue_init(&temp_queue, buffer, MAX_SIZE, sizeof(u16)); tuya_ble_queue_init(&temp_queue, buffer, MAX_SIZE, sizeof(u16));
tuya_ble_queue_flush(&temp_queue); tuya_ble_queue_flush(&temp_queue);
if (syscfg_read(ADJ_TEMP_CONFIG, &ADJ_temp, sizeof(ADJ_temp)) != sizeof(ADJ_temp)) { if (syscfg_read(ADJ_OBJ_TEMP_CONFIG, &ADJ_obj_temp, sizeof(ADJ_obj_temp)) != sizeof(ADJ_obj_temp)) {
ADJ_temp = 0; ADJ_obj_temp = 0;
} }
printf("ADJ_temp:%d\r\n", ADJ_temp); if (syscfg_read(ADJ_BODY_TEMP_CONFIG, &ADJ_body_temp, sizeof(ADJ_body_temp)) != sizeof(ADJ_body_temp)) {
ADJ_body_temp = 0;
}
printf("ADJ_obj_temp:%d ADJ_body_temp:%d\r\n", ADJ_obj_temp,ADJ_body_temp);
dev_info.batt_percent = get_vbat_percent(); dev_info.batt_percent = get_vbat_percent();

View File

@ -21,7 +21,8 @@ typedef unsigned int uint32_t;
// output: // output:
// int16_t tax10 // Ten times the ambient temperature, degree centigrade // int16_t tax10 // Ten times the ambient temperature, degree centigrade
// int16_t tox10 // Ten times the target temperature, degree centigrade // int16_t tox10 // Ten times the target temperature, degree centigrade
void Cal_get_temp(int32_t tmp_ad, int32_t corr_k1, int32_t tob_ad, int32_t corr_k2, int16_t *tax10, int16_t *tox10); // uint16_t tbx10 // Ten times the body temperature, degree centigrade
void Cal_get_temp(int32_t tmp_ad, int32_t corr_k1, int32_t tob_ad, int32_t corr_k2, int16_t *tax10, int16_t *tox10, uint16_t *tbx10);
#endif #endif

View File

@ -28,7 +28,13 @@
//VM用户自定义配置项[1 ~ 49] //VM用户自定义配置项[1 ~ 49]
#define BLE_TEMPERATURE_VM_DEVICE_CONFIG 2 #define BLE_TEMPERATURE_VM_DEVICE_CONFIG 2
<<<<<<< Updated upstream
#define ADJ_TEMP_CONFIG 4 #define ADJ_TEMP_CONFIG 4
=======
#define ADJ_BODY_TEMP_CONFIG 4
#define ADJ_OBJ_TEMP_CONFIG 6
#define HELL_WAKEUP 5
>>>>>>> Stashed changes
#define DEVICE_SLEEP_TIMEOUT 10 //设备休眠时间 #define DEVICE_SLEEP_TIMEOUT 10 //设备休眠时间
#define DEVICE_WORK_TIMEOUT 15000 //设备工作时间 #define DEVICE_WORK_TIMEOUT 15000 //设备工作时间

View File

@ -23,6 +23,7 @@
#include "asm/iic_soft.h" #include "asm/iic_soft.h"
#include "trs55d.h" #include "trs55d.h"
#define IIC_CHANNEL_1 0 #define IIC_CHANNEL_1 0
const struct soft_iic_config soft_iic_cfg[] = { const struct soft_iic_config soft_iic_cfg[] = {
//iic0 data //iic0 data
@ -294,8 +295,11 @@ uu32_t obj,tmp_3, vtp_cor;
float tamb_temp ,vtp_cor_uv ,Tobj_temp ; float tamb_temp ,vtp_cor_uv ,Tobj_temp ;
//#include "FW_TRS_CAL.h" //#include "FW_TRS_CAL.h"
uint16_t t_objx10_u16; //uint16_t t_objx10_u16;
int16_t Tambx10_u16; //int16_t Tambx10_u16;
int16_t tax10;
int16_t tox10;
uint16_t tbx10;
uint16_t Trs_Read(uint16_t *t_body, uint16_t *t_ntc) uint16_t Trs_Read(uint16_t *t_body, uint16_t *t_ntc)
{ {
@ -403,14 +407,16 @@ uint16_t Trs_Read(uint16_t *t_body, uint16_t *t_ntc)
//printf("tmp_3.i32: %d obj.i32: %d \r\n", tmp_3.i32, obj.i32); //printf("tmp_3.i32: %d obj.i32: %d \r\n", tmp_3.i32, obj.i32);
Cal_get_temp(tmp_3.i32, 1000, obj.i32, 1000, &Tambx10_u16, &t_objx10_u16); //Cal_get_temp(tmp_3.i32, 1000, obj.i32, 1000, &Tambx10_u16, &t_objx10_u16);
Tobj_temp = (float)t_objx10_u16 / 10; Cal_get_temp(tmp_3.i32, 1000, obj.i32, 1000, &tax10, &tox10, &tbx10);
tamb_temp = (float)Tambx10_u16 / 10; Tobj_temp = (float)tox10 / 10;
tamb_temp = (float)tbx10 / 10;
printf("tox10: %d tbx10: %d \r\n", tox10,tbx10);
*t_body = (uint16_t)(Tobj_temp * 100); *t_body = (uint16_t)(tamb_temp * 100);
*t_ntc = (uint16_t)(tamb_temp * 100); *t_ntc = (uint16_t)(Tobj_temp * 100);
return 1; return 1;