10#ifndef M5_UNIT_UNIFIED_KMETERISO_UNIT_KMETERISO_HPP
11#define M5_UNIT_UNIFIED_KMETERISO_UNIT_KMETERISO_HPP
13#include <M5UnitComponent.hpp>
14#include <m5_utility/container/circular_buffer.hpp>
37 std::array<uint8_t, 4> raw{};
38 inline float temperature()
const
40 return static_cast<int32_t
>(((uint32_t)raw[3] << 24) | ((uint32_t)raw[2] << 16) | ((uint32_t)raw[1] << 8) |
41 ((uint32_t)raw[0] << 0)) *
52class UnitKmeterISO :
public Component,
public PeriodicMeasurementAdapter<UnitKmeterISO, kmeterISO::Data> {
70 : Component(addr), _data{new
m5::container::CircularBuffer<kmeterISO::
Data>(1)}
72 auto ccfg = component_config();
73 ccfg.clock = 100 * 1000U;
74 component_config(ccfg);
76 virtual ~UnitKmeterISO()
80 virtual bool begin()
override;
81 virtual void update(
const bool force =
false)
override;
116 return !empty() ? oldest().temperature() : std::numeric_limits<float>::quiet_NaN();
128 return PeriodicMeasurementAdapter<UnitKmeterISO, kmeterISO::Data>::startPeriodicMeasurement();
139 return PeriodicMeasurementAdapter<UnitKmeterISO, kmeterISO::Data>::startPeriodicMeasurement(interval, munit);
147 return PeriodicMeasurementAdapter<UnitKmeterISO, kmeterISO::Data>::stopPeriodicMeasurement();
184 const uint32_t timeoutMs = 0);
194 const uint32_t timeoutMs = 0);
216 bool start_periodic_measurement();
217 bool start_periodic_measurement(
const uint32_t interval,
219 bool stop_periodic_measurement();
227 std::unique_ptr<m5::container::CircularBuffer<kmeterISO::Data>> _data{};
228 kmeterISO::MeasurementUnit _munit{kmeterISO::MeasurementUnit::Celsius};
236constexpr uint8_t TEMPERATURE_CELSIUS_VAL_REG{0X00};
237constexpr uint8_t TEMPERATURE_FAHRENHEIT_VAL_REG{0X04};
238constexpr uint8_t INTERNAL_TEMPERATURE_CELSIUS_VAL_REG{0X10};
239constexpr uint8_t INTERNAL_TEMPERATURE_FAHRENHEIT_VAL_REG{0X14};
240constexpr uint8_t ERROR_STATUS_REG{0x20};
241constexpr uint8_t TEMPERATURE_CELSIUS_STRING_REG{0x30};
242constexpr uint8_t TEMPERATURE__FAHRENHEIT_STRING_REG{0x40};
243constexpr uint8_t INTERNAL_TEMPERATURE_CELSIUS_STRING_REG{0x50};
244constexpr uint8_t INTERNAL_TEMPERATURE_FAHRENHEIT_STRING_REG{0x60};
245constexpr uint8_t FIRMWARE_VERSION_REG{0xFE};
246constexpr uint8_t I2C_ADDRESS_REG{0xFF};
KMeterISO unitis an integrated K-type thermocouple sensor unit that integrates the functions of "acqu...
Definition unit_KmeterISO.hpp:52
void setMeasurementUnit(const kmeterISO::MeasurementUnit munit)
Definition unit_KmeterISO.hpp:105
bool isReady()
Ready to read data?
Definition unit_KmeterISO.hpp:161
bool readFirmwareVersion(uint8_t &ver)
Read firmware version.
Definition unit_KmeterISO.cpp:117
bool measureSingleshot(kmeterISO::Data &d, kmeterISO::MeasurementUnit munit=kmeterISO::MeasurementUnit::Celsius, const uint32_t timeoutMs=0)
Measure temperature single shot.
Definition unit_KmeterISO.cpp:122
bool readI2CAddress(uint8_t &i2c_address)
Read device I2C address.
Definition unit_KmeterISO.cpp:171
bool stopPeriodicMeasurement()
Stop periodic measurement.
Definition unit_KmeterISO.hpp:145
kmeterISO::MeasurementUnit measurementUnit() const
Definition unit_KmeterISO.hpp:100
bool readStatus(uint8_t &status)
Read status.
Definition unit_KmeterISO.cpp:111
bool startPeriodicMeasurement()
Start periodic measurement in the current settings.
Definition unit_KmeterISO.hpp:126
bool changeI2CAddress(const uint8_t i2c_address)
Change device I2C address.
Definition unit_KmeterISO.cpp:151
config_t config()
Gets the configration.
Definition unit_KmeterISO.hpp:86
void config(const config_t &cfg)
Set the configration.
Definition unit_KmeterISO.hpp:91
bool startPeriodicMeasurement(const uint32_t interval, const kmeterISO::MeasurementUnit munit=kmeterISO::Celsius)
Start periodic measurement.
Definition unit_KmeterISO.hpp:136
bool measureInternalSingleshot(kmeterISO::Data &d, kmeterISO::MeasurementUnit munit=kmeterISO::MeasurementUnit::Celsius, const uint32_t timeoutMs=0)
Measure internal temperature single shot.
Definition unit_KmeterISO.cpp:136
float temperature() const
Oldest temperature.
Definition unit_KmeterISO.hpp:114
Top level namespace of M5stack.
Settings for begin.
Definition unit_KmeterISO.hpp:60
kmeterISO::MeasurementUnit measurement_unit
//!< measurement unit if start on begin
Definition unit_KmeterISO.hpp:66
uint32_t interval
periodic interval(ms) if start on begin
Definition unit_KmeterISO.hpp:64
bool start_periodic
Start periodic measurement on begin?
Definition unit_KmeterISO.hpp:62
Measurement data group.
Definition unit_ADS111x.hpp:204
Measurement data group.
Definition unit_KmeterISO.hpp:36
MeasurementUnit
measurement unit on periodic measurement
Definition unit_KmeterISO.hpp:27
@ Fahrenheit
Temperature is fahrenheit.
Definition unit_KmeterISO.hpp:29
@ Celsius
Temperature is celsius.
Definition unit_KmeterISO.hpp:28