From 62205e13771c61a4c1a5935fa1010a729cf1b12e Mon Sep 17 00:00:00 2001 From: chenanchun Date: Tue, 27 Jan 2026 22:02:25 +0800 Subject: [PATCH] feat: Complete the optical magnetic small board to obtain temperature and id and receive and send data --- CMakeLists.txt | 13 +++++++++++++ README.md | 0 prj.conf | 11 +++++++++++ src/main.cpp | 37 +++++++++++++++++++++++++++++++++++++ testcase.yaml | 0 5 files changed, 61 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 README.md create mode 100644 prj.conf create mode 100644 src/main.cpp create mode 100644 testcase.yaml diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..2f70cd3 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,13 @@ +# SPDX-License-Identifier: Apache-2.0 +cmake_minimum_required(VERSION 3.20.0) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(app_photomagnetic) + +target_sources(app PRIVATE src/main.cpp) + +set(ZEPHYR_EXTRA_MODULES "${CMAKE_SOURCE_DIR}/../../modules/godtek_temp") +set(ZEPHYR_EXTRA_MODULES "${CMAKE_SOURCE_DIR}/../../modules/photomagnetic_com") + +target_include_directories(app PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/../../modules/photomagnetic_com/include +) \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/prj.conf b/prj.conf new file mode 100644 index 0000000..2ad4d3d --- /dev/null +++ b/prj.conf @@ -0,0 +1,11 @@ +CONFIG_STDOUT_CONSOLE=y +CONFIG_CBPRINTF_FP_SUPPORT=y +CONFIG_STD_CPP20=y +CONFIG_CPP=y +CONFIG_REQUIRES_FULL_LIBCPP=y + +CONFIG_CONSOLE=y +CONFIG_SERIAL=y +CONFIG_UART_INTERRUPT_DRIVEN=y +CONFIG_PMC_COM=y +CONFIG_HWINFO=y \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..a8b1e97 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,37 @@ +#include +#include + +#include + +#include "internal/photomagnetic_com/photomagnetic_com_device.hpp" +using namespace pmc; + +auto sensor = DEVICE_DT_GET(DT_NODELABEL(godtek)); + +volatile bool flag{false}; + +auto main(void) -> int { + auto &dev = ZPP_DEVICE_GET_BY_NODE(PmcComDevice, pmc_com); + sensor_trigger tri{.type = SENSOR_TRIG_DATA_READY, + .chan = SENSOR_CHAN_AMBIENT_TEMP}; + if (auto r = sensor_trigger_set( + sensor, &tri, + [](const device *dev, const sensor_trigger *trig) { flag = true; }); + r != 0) { + return -ENODEV; + }; + + while (1) { + if (flag) { + sensor_value val{0, 0}; + if (sensor_sample_fetch_chan(sensor, SENSOR_CHAN_AMBIENT_TEMP) == 0) { + sensor_channel_get(sensor, SENSOR_CHAN_AMBIENT_TEMP, &val); + dev.UpdateTemperature(&val); + } + + dev.SendTemperature(&val); + flag = false; + } + } + return 0; +} \ No newline at end of file diff --git a/testcase.yaml b/testcase.yaml new file mode 100644 index 0000000..e69de29