forked from EmbeddedTeam/app_photomagnetic
feat: Add Kconfig and conditional build for hello world sample
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
#ifndef __THER_COM_HPP__
|
||||
#define __THER_COM_HPP__
|
||||
|
||||
#include <led_strip_indicator/led_strip_indicator.hpp>
|
||||
#include <uart_com/simple_protocal.hpp>
|
||||
#include <zpp/driver.hpp>
|
||||
#include <zpp/error.hpp>
|
||||
namespace ther {
|
||||
|
||||
template <device *kDev> class Com {
|
||||
public:
|
||||
enum Addr : uint8_t { TEMP = 0, GET_ID, RUNNING_STATE };
|
||||
using CbTableValueType =
|
||||
std::pair<const uint8_t, void (*)(uart_com::DataType)>;
|
||||
static auto Init() -> zpp::error {
|
||||
s_proto->SetRxCallbackTable({GET_ID, Cb::GetId},
|
||||
{RUNNING_STATE, Cb::RunningState});
|
||||
return zpp::ok();
|
||||
}
|
||||
|
||||
private:
|
||||
struct Cb {
|
||||
static auto GetId(uart_com::DataType data) -> void {
|
||||
// TODO
|
||||
}
|
||||
static auto RunningState(uart_com::DataType data) -> void {
|
||||
// TODO
|
||||
}
|
||||
};
|
||||
constexpr static uart_com::SimpleProtocal *s_proto =
|
||||
(uart_com::SimpleProtocal *)(kDev);
|
||||
};
|
||||
} // namespace ther
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
#ifndef __THER_HEATING_HPP__
|
||||
#define __THER_HEATING_HPP__
|
||||
#include <zephyr/device.h>
|
||||
|
||||
namespace ther {
|
||||
template <const device *kDev> class HeatingPad {
|
||||
public:
|
||||
};
|
||||
|
||||
} // namespace ther
|
||||
#endif
|
||||
@@ -0,0 +1,49 @@
|
||||
#ifndef __THER_INFRARED_HPP__
|
||||
#define __THER_INFRARED_HPP__
|
||||
#include <zephyr/device.h>
|
||||
#include <zephyr/drivers/sensor.h>
|
||||
#include <zpp/result.hpp>
|
||||
#include <zpp/value.hpp>
|
||||
#include <zpp/work_queue.hpp>
|
||||
namespace ther {
|
||||
|
||||
template <device *kDev> class Infrared {
|
||||
public:
|
||||
static auto Init() -> zpp::error {
|
||||
static sensor_trigger tri{.type = SENSOR_TRIG_DATA_READY,
|
||||
.chan = SENSOR_CHAN_AMBIENT_TEMP};
|
||||
if (auto r = sensor_trigger_set(
|
||||
kDev, &tri,
|
||||
[](const device *dev, const sensor_trigger *trig) {
|
||||
s_is_data_ready = true;
|
||||
});
|
||||
r != 0) {
|
||||
return -ENODEV;
|
||||
};
|
||||
}
|
||||
static auto GetSensorValue()
|
||||
-> zpp::result<zpp::value<zpp::value_type::AMBIENT_TEMP>> {
|
||||
if (!s_is_data_ready) {
|
||||
return zpp::error_code::k_nodata;
|
||||
}
|
||||
|
||||
if (0 != sensor_sample_fetch(kDev)) {
|
||||
return zpp::error_code::k_io;
|
||||
}
|
||||
|
||||
zpp::value<zpp::value_type::AMBIENT_TEMP> val;
|
||||
if (0 != sensor_channel_get(kDev, SENSOR_CHAN_AMBIENT_TEMP, &val)) {
|
||||
return zpp::error_code::k_io;
|
||||
}
|
||||
|
||||
s_is_data_ready = false;
|
||||
return val;
|
||||
}
|
||||
|
||||
private:
|
||||
inline static bool s_is_data_ready{false};
|
||||
};
|
||||
|
||||
} // namespace ther
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,45 @@
|
||||
#ifndef THER_NTC_HPP
|
||||
#define THER_NTC_HPP
|
||||
#include <zephyr/device.h>
|
||||
#include <zephyr/drivers/sensor.h>
|
||||
#include <zpp/result.hpp>
|
||||
#include <zpp/value.hpp>
|
||||
|
||||
namespace ther {
|
||||
|
||||
template <device *...kNtcDev> class Ntc {
|
||||
public:
|
||||
/// Read all NTC sensors, return the maximum temperature value.
|
||||
/// Returns error if every sensor read fails.
|
||||
static auto GetSensorValue()
|
||||
-> zpp::result<zpp::value<zpp::value_type::AMBIENT_TEMP>> {
|
||||
bool found = false;
|
||||
zpp::value<zpp::value_type::AMBIENT_TEMP> max_val;
|
||||
|
||||
for (const auto *dev : s_devices) {
|
||||
if (0 != sensor_sample_fetch(dev))
|
||||
continue;
|
||||
|
||||
zpp::value<zpp::value_type::AMBIENT_TEMP> val;
|
||||
if (0 != sensor_channel_get(dev, SENSOR_CHAN_AMBIENT_TEMP, &val))
|
||||
continue;
|
||||
|
||||
if (!found || val.to_double() > max_val.to_double()) {
|
||||
max_val = val;
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (found)
|
||||
return max_val;
|
||||
|
||||
return zpp::error_code::k_io;
|
||||
}
|
||||
|
||||
private:
|
||||
static constexpr device *s_devices[] = {kNtcDev...};
|
||||
};
|
||||
|
||||
} // namespace ther
|
||||
|
||||
#endif // THER_NTC_HPP
|
||||
Reference in New Issue
Block a user