Danger-alarm/SOFTWARE-FreeRTOS/Source/DS18B20.cpp

59 lines
1.6 KiB
C++
Raw Permalink Normal View History

2024-06-03 18:59:42 +08:00
#include "DS18B20.hpp"
2024-06-07 00:10:17 +08:00
#include "HC-12.hpp"
2024-06-03 18:59:42 +08:00
#include "common.hpp"
QueueHandle_t xQueue;
2024-06-03 18:59:42 +08:00
// 温度传感器
void DS18B20(void *pvParameters)
{
// One_wire 第三方库方法
2024-06-03 18:59:42 +08:00
float TEMPERATURE = -1;
2024-08-23 08:08:37 +08:00
char TEMPERATURE_TEMP[BUFER] = { 0 };
2024-06-03 18:59:42 +08:00
One_wire one_wire(DS18B20_PIN);
one_wire.init();
rom_address_t address {
2024-06-03 18:59:42 +08:00
};
2024-06-04 09:54:09 +08:00
2024-06-03 18:59:42 +08:00
_printTaskStackHighWaterMark("DS18B20");
2024-06-04 09:54:09 +08:00
while (1) {
2024-06-03 18:59:42 +08:00
one_wire.single_device_read_rom(address);
2024-08-23 08:08:37 +08:00
int delay_time = one_wire.convert_temperature(address, true, false);
//printf("Conversion delay time: %d ms\n", delay_time);
2024-06-03 18:59:42 +08:00
TEMPERATURE = one_wire.temperature(address);
printf("Device Address: %02x%02x%02x%02x%02x%02x%02x%02x DS18B20 Temperature: %3.1f°C\n", \
address.rom[0], address.rom[1], address.rom[2], address.rom[3], address.rom[4], \
address.rom[5], address.rom[6], address.rom[7], one_wire.temperature(address));
2024-08-23 08:08:37 +08:00
if (TEMPERATURE == -1000) {
continue;
}
2024-06-07 00:10:17 +08:00
if (TEMPERATURE != 85) {
2024-08-23 08:08:37 +08:00
2024-06-07 00:10:17 +08:00
sprintf(TEMPERATURE_TEMP, "Temperature: %.3f°C\n", TEMPERATURE);
_HC_12(TEMPERATURE_TEMP);
2024-08-23 08:08:37 +08:00
memset(TEMPERATURE_TEMP, 0, BUFER);
TEMPERATURE = -1;
2024-06-07 00:10:17 +08:00
}
/*
2024-06-03 18:59:42 +08:00
// 发送数据到队列
xQueueSend(xQueue, &TEMPERATURE, portMAX_DELAY);
vTaskDelay(pdMS_TO_TICKS(1000));
*/
//_printTaskStackHighWaterMark("DS18B20");
//watchdog_update(); // 喂狗
2024-08-23 08:08:37 +08:00
vTaskDelay(pdMS_TO_TICKS(5000)); // 非阻塞延时
2024-06-03 18:59:42 +08:00
}
return ;
2024-06-03 18:59:42 +08:00
}