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

35 lines
987 B
C++

#include "DS18B20.hpp"
#include "common.hpp"
QueueHandle_t xQueue;
// 温度传感器
void DS18B20(void *pvParameters)
{
float TEMPERATURE = -1;
One_wire one_wire(DS18B20_PIN);
one_wire.init();
rom_address_t address {
};
_printTaskStackHighWaterMark("DS18B20");
while (1) {
one_wire.single_device_read_rom(address);
one_wire.convert_temperature(address, true, false);
TEMPERATURE = one_wire.temperature(address);
printf("Device Address: %02x%02x%02x%02x%02x%02x%02x%02x 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));
// 发送数据到队列
xQueueSend(xQueue, &TEMPERATURE, portMAX_DELAY);
vTaskDelay(pdMS_TO_TICKS(1000));
//_printTaskStackHighWaterMark("DS18B20");
vTaskDelay(pdMS_TO_TICKS(3000)); // 非阻塞延时
}
return;
}