This commit is contained in:
2026-06-09 16:49:10 +08:00
parent 9014267de0
commit 3276dc5981
16 changed files with 1113 additions and 441 deletions

View File

@ -17,34 +17,34 @@ DallasTemperature DS18b20(&oneWire);
int temp_number;
uint8_t *p[8] = {sensoraddr[0],sensoraddr[1],sensoraddr[2],sensoraddr[3],sensoraddr[4],sensoraddr[5],sensoraddr[6],sensoraddr[7]};
// uint8_t *p[8] = {sensoraddr[0],sensoraddr[1],sensoraddr[2],sensoraddr[3],sensoraddr[4],sensoraddr[5],sensoraddr[6],sensoraddr[7]};
//冒泡排序 将温度地址 DeviceAddress sensoraddr[30]; 从小到大排序
void bubble_sort(DeviceAddress *addr,int n)
{
uint64_t a1 ,a2;
for (int i = 0; i < n; i++)
{
for(uint8_t b = 0 ; b<8;b++)
{
a1 += addr[i][b];
}
// void bubble_sort(DeviceAddress *addr,int n)
// {
// uint64_t a1 ,a2;
// for (int i = 0; i < n; i++)
// {
// for(uint8_t b = 0 ; b<8;b++)
// {
// a1 += addr[i][b];
// }
for (int j = 0; j < n-i-1; j++)
{
for(uint8_t c = 0 ; c<8;c++)
{
a2 += addr[j][c];
}
if (a1 > a2)
{
uint8_t *temp = p[i];
p[i] = p[j];
p[j] = temp;
}
}
}
}
// for (int j = 0; j < n-i-1; j++)
// {
// for(uint8_t c = 0 ; c<8;c++)
// {
// a2 += addr[j][c];
// }
// if (a1 > a2)
// {
// uint8_t *temp = p[i];
// p[i] = p[j];
// p[j] = temp;
// }
// }
// }
// }
uint8_t DS18b20_init()
@ -65,17 +65,18 @@ uint8_t DS18b20_init()
}
i++;
}
write_log(log_path,"ds18b20 has" + String(temp_number),10);
write_log(log_path,"ds18b20 has" + String(temp_number),20);
for(size_t i = 0; i < temp_number; i++)
{
DS18b20.getAddress(sensoraddr[i],i);
}
bubble_sort(sensoraddr,temp_number);
// bubble_sort(sensoraddr,temp_number);
return temp_number;
}
//温度监测
float temp_last[8] = {25,25,25,25,25,25,25,25};
void getall_temp(float *temp)
{
DS18b20.requestTemperatures(); // Send the command to get temperatures
@ -83,7 +84,7 @@ void getall_temp(float *temp)
for(int8_t i =0 ;i<temp_number;i++)
{
temp[i] = DS18b20.getTempC(p[i]);
temp[i] = DS18b20.getTempC(sensoraddr[i]);
uint32_t n = 0;
while(temp[i] < -110)
{
@ -91,15 +92,25 @@ void getall_temp(float *temp)
// temp[i] = DS18b20.getTempC(p[i]);
temp[i] = getone_temp(i);
n++;
if (n>40)
if (n>5)
{
write_log(log_path,"ds18b20 get temperature failed",10);
// return;
break;
}
}
if (temp[i] < -110)
{
temp[i] = temp_last[i];
write_log(log_path,"ds18b20 get temperature failed, use last temperature",10);
}
else
{
temp_last[i] = temp[i];
}
}
// write_log(log_path,"get temperatures ok",10);
}
@ -107,7 +118,7 @@ float getone_temp(uint8_t address)
{
float temp;
DS18b20.requestTemperatures(); // Send the command to get temperatures
temp = DS18b20.getTempC(p[address]);
temp = DS18b20.getTempC(sensoraddr[address]);
return temp;
}