M5Unit-LIGHT 0.1.0 git rev:1ddbe92
Loading...
Searching...
No Matches
unit_BH1750FVI_data.hpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2026 M5Stack Technology CO LTD
3 *
4 * SPDX-License-Identifier: MIT
5 */
12#ifndef M5_UNIT_LIGHT_UNIT_BH1750FVI_DATA_HPP
13#define M5_UNIT_LIGHT_UNIT_BH1750FVI_DATA_HPP
14
15#include <cstdint>
16#include <limits>
17
18namespace m5 {
19namespace unit {
20
25namespace bh1750fvi {
26
31enum class Mode : uint8_t {
33 OneTime,
34};
35
41enum class Resolution : uint8_t {
42 Low,
43 High,
44 High2,
45};
46
48constexpr uint8_t MTREG_MIN{31};
50constexpr uint8_t MTREG_MAX{254};
52constexpr uint8_t MTREG_DEFAULT{69};
53
55constexpr float SENSITIVITY_FACTOR_MIN{0.45f};
57constexpr float SENSITIVITY_FACTOR_MAX{3.68f};
58
63struct Data {
64 uint16_t raw{};
66 Resolution resolution{Resolution::High};
67
71 inline float lux() const
72 {
73 if (mtreg == 0) {
74 return std::numeric_limits<float>::quiet_NaN();
75 }
76 const float base{static_cast<float>(raw) / 1.2f};
77 const float scale{static_cast<float>(MTREG_DEFAULT) / static_cast<float>(mtreg)};
78 float v{base * scale};
79 if (resolution == Resolution::High2) {
80 v *= 0.5f;
81 }
82 return v;
83 }
84};
85
86} // namespace bh1750fvi
87} // namespace unit
88} // namespace m5
89
90#endif
For BH1750FVI.
Top level namespace of M5Stack.
Unit-related namespace.
Measurement data group.
Definition unit_BH1750FVI_data.hpp:63
uint8_t mtreg
MTreg value in effect at the time of measurement.
Definition unit_BH1750FVI_data.hpp:65
Resolution resolution
Resolution in effect at the time of measurement.
Definition unit_BH1750FVI_data.hpp:66
float lux() const
Illuminance in lx.
Definition unit_BH1750FVI_data.hpp:71
uint16_t raw
Raw 16-bit ADC value (MSB first)
Definition unit_BH1750FVI_data.hpp:64
constexpr uint8_t MTREG_DEFAULT
Default value of MTREG.
Definition unit_BH1750FVI_data.hpp:52
constexpr uint8_t MTREG_MIN
Minimum value of MTREG (sensitivity register)
Definition unit_BH1750FVI_data.hpp:48
Resolution
Resolution of the measurement.
Definition unit_BH1750FVI_data.hpp:41
@ Low
4 lx resolution, ~16 ms (max 24 ms) conversion time
@ High2
0.5 lx resolution, ~120 ms (max 180 ms) conversion time
@ High
1 lx resolution, ~120 ms (max 180 ms) conversion time
constexpr uint8_t MTREG_MAX
Maximum value of MTREG.
Definition unit_BH1750FVI_data.hpp:50
Mode
Measurement mode.
Definition unit_BH1750FVI_data.hpp:31
@ Continuous
Continuous measurement. Sensor updates the data register periodically.
@ OneTime
One-time measurement. Sensor enters Power Down after the conversion completes.
constexpr float SENSITIVITY_FACTOR_MAX
Maximum sensitivity factor (MTREG_MAX / MTREG_DEFAULT)
Definition unit_BH1750FVI_data.hpp:57
constexpr float SENSITIVITY_FACTOR_MIN
Minimum sensitivity factor (MTREG_MIN / MTREG_DEFAULT)
Definition unit_BH1750FVI_data.hpp:55