forked from EmbeddedTeam/app_photomagnetic
feat: Complete the optical magnetic small board to obtain temperature and id and receive and send data
This commit is contained in:
commit
62205e1377
13
CMakeLists.txt
Normal file
13
CMakeLists.txt
Normal file
@ -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
|
||||
)
|
||||
11
prj.conf
Normal file
11
prj.conf
Normal file
@ -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
|
||||
37
src/main.cpp
Normal file
37
src/main.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
#include <zephyr/device.h>
|
||||
#include <zephyr/drivers/sensor.h>
|
||||
|
||||
#include <zpp/device.hpp>
|
||||
|
||||
#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;
|
||||
}
|
||||
0
testcase.yaml
Normal file
0
testcase.yaml
Normal file
Loading…
x
Reference in New Issue
Block a user