ADD HC-12 sensor

This commit is contained in:
aixiao 2024-06-07 00:10:17 +08:00
parent 0d9424bf2b
commit c0e3e0addd
6 changed files with 19 additions and 4 deletions

View File

@ -41,6 +41,7 @@ target_Sources(main PRIVATE
${CMAKE_CURRENT_LIST_DIR}/Source/ZC13.cpp ${CMAKE_CURRENT_LIST_DIR}/Source/ZC13.cpp
${CMAKE_CURRENT_LIST_DIR}/Source/ZE07CO.cpp ${CMAKE_CURRENT_LIST_DIR}/Source/ZE07CO.cpp
${CMAKE_CURRENT_LIST_DIR}/Source/MHZ14B.cpp ${CMAKE_CURRENT_LIST_DIR}/Source/MHZ14B.cpp
${CMAKE_CURRENT_LIST_DIR}/Source/HC-12.cpp
) )
target_include_directories(main PRIVATE target_include_directories(main PRIVATE

View File

@ -1,4 +1,5 @@
#include "DS18B20.hpp" #include "DS18B20.hpp"
#include "HC-12.hpp"
#include "common.hpp" #include "common.hpp"
QueueHandle_t xQueue; QueueHandle_t xQueue;
@ -114,13 +115,22 @@ void DS18B20(void *pvParameters)
one_wire.convert_temperature(address, true, false); one_wire.convert_temperature(address, true, false);
TEMPERATURE = one_wire.temperature(address); TEMPERATURE = one_wire.temperature(address);
sleep_ms(300);
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)); 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[256] = { 0 };
sprintf(TEMPERATURE_TEMP, "Temperature: %.3f°C\n", TEMPERATURE);
_HC_12(TEMPERATURE_TEMP);
//TEMPERATURE = -1;
}
// 发送数据到队列 // 发送数据到队列
xQueueSend(xQueue, &TEMPERATURE, portMAX_DELAY); xQueueSend(xQueue, &TEMPERATURE, portMAX_DELAY);
vTaskDelay(pdMS_TO_TICKS(1000)); vTaskDelay(pdMS_TO_TICKS(1000));
//_printTaskStackHighWaterMark("DS18B20"); _printTaskStackHighWaterMark("DS18B20");
watchdog_update(); // 喂狗 watchdog_update(); // 喂狗
vTaskDelay(pdMS_TO_TICKS(3000)); // 非阻塞延时 vTaskDelay(pdMS_TO_TICKS(3000)); // 非阻塞延时
} }

View File

@ -11,7 +11,7 @@ void _HC_12_INIT()
return; return;
} }
void _HC_12(const char *string) void _HC_12(char *string)
{ {
uart_tx_program_puts(HC_12_PIO, HC_12_PIO_SM_TX, string); uart_tx_program_puts(HC_12_PIO, HC_12_PIO_SM_TX, string);
sleep_ms(100); sleep_ms(100);

View File

@ -14,6 +14,6 @@
#define HC_12_PIO_SERIAL_BAUD 9600 #define HC_12_PIO_SERIAL_BAUD 9600
extern void _HC_12_INIT(); extern void _HC_12_INIT();
extern void _HC_12(const char *string); extern void _HC_12(char *string);
#endif #endif

View File

@ -18,6 +18,7 @@
#include "ZC13.hpp" #include "ZC13.hpp"
#include "ZE07CO.hpp" #include "ZE07CO.hpp"
#include "MHZ14B.hpp" #include "MHZ14B.hpp"
#include "HC-12.hpp"
#ifndef PICO_DEFAULT_LED_PIN #ifndef PICO_DEFAULT_LED_PIN
#warning pio/hello_pio example requires a board with a regular LED #warning pio/hello_pio example requires a board with a regular LED
@ -93,6 +94,8 @@ int main(void)
// 创建队列 // 创建队列
xQueue = xQueueCreate(10, sizeof(long)); xQueue = xQueueCreate(10, sizeof(long));
_HC_12_INIT();
// 创建任务 // 创建任务
BaseType_t xReturned; BaseType_t xReturned;
TaskHandle_t CPU_xHandle = NULL; TaskHandle_t CPU_xHandle = NULL;

@ -0,0 +1 @@
Subproject commit 6deababa069269f42343589a5148ea2e16922856