Danger-alarm/SOFTWARE-FreeRTOS/Source/DS18B20.cpp
aixiao f4bd30a4dc 这次提交基于FreeRTOS能正常运行。
还存在微小问题,由于CO2传感器必须通过看门狗重启一次后才能正常,这个问题还没解决。(喂狗只在CO2函数内,保证能重启RP2040)
2024-08-11 22:11:50 +08:00

53 lines
1.4 KiB
C++

#include "DS18B20.hpp"
#include "HC-12.hpp"
#include "common.hpp"
QueueHandle_t xQueue;
// 温度传感器
void DS18B20(void *pvParameters)
{
// One_wire 第三方库方法
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);
sleep_ms(1000);
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));
if (TEMPERATURE != 85) {
char TEMPERATURE_TEMP[BUFER] = { 0 };
sprintf(TEMPERATURE_TEMP, "Temperature: %.3f°C\n", TEMPERATURE);
_HC_12(TEMPERATURE_TEMP);
TEMPERATURE = -1;
}
/*
// 发送数据到队列
xQueueSend(xQueue, &TEMPERATURE, portMAX_DELAY);
vTaskDelay(pdMS_TO_TICKS(1000));
*/
//_printTaskStackHighWaterMark("DS18B20");
//watchdog_update(); // 喂狗
vTaskDelay(pdMS_TO_TICKS(3000)); // 非阻塞延时
}
return ;
}