M5Unit-LIGHT 0.0.2 git rev:6d734f0
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 */
14#ifndef M5_UNIT_LIGHT_UNIT_BH1750FVI_DATA_HPP
15#define M5_UNIT_LIGHT_UNIT_BH1750FVI_DATA_HPP
16
17#include <cstdint>
18#include <limits>
19
20namespace m5 {
21namespace unit {
22
27namespace bh1750fvi {
28
33enum class Mode : uint8_t {
35 OneTime,
36};
37
43enum class Resolution : uint8_t {
44 Low,
45 High,
46 High2,
47};
48
50constexpr uint8_t MTREG_MIN{31};
52constexpr uint8_t MTREG_MAX{254};
54constexpr uint8_t MTREG_DEFAULT{69};
55
57constexpr float SENSITIVITY_FACTOR_MIN{0.45f};
59constexpr float SENSITIVITY_FACTOR_MAX{3.68f};
60
65struct Data {
66 uint16_t raw{};
68 Resolution resolution{Resolution::High};
69
73 inline float lux() const
74 {
75 if (mtreg == 0) {
76 return std::numeric_limits<float>::quiet_NaN();
77 }
78 const float base{static_cast<float>(raw) / 1.2f};
79 const float scale{static_cast<float>(MTREG_DEFAULT) / static_cast<float>(mtreg)};
80 float v{base * scale};
81 if (resolution == Resolution::High2) {
82 v *= 0.5f;
83 }
84 return v;
85 }
86};
87
88} // namespace bh1750fvi
89} // namespace unit
90} // namespace m5
91
92#endif
For BH1750FVI.
Top level namespace of M5Stack.
Unit-related namespace.
Measurement data group.
Definition unit_BH1750FVI_data.hpp:65
uint8_t mtreg
MTreg value in effect at the time of measurement.
Definition unit_BH1750FVI_data.hpp:67
Resolution resolution
Resolution in effect at the time of measurement.
Definition unit_BH1750FVI_data.hpp:68
float lux() const
Illuminance in lx.
Definition unit_BH1750FVI_data.hpp:73
uint16_t raw
Raw 16-bit ADC value (MSB first)
Definition unit_BH1750FVI_data.hpp:66
constexpr uint8_t MTREG_DEFAULT
Default value of MTREG.
Definition unit_BH1750FVI_data.hpp:54
constexpr uint8_t MTREG_MIN
Minimum value of MTREG (sensitivity register)
Definition unit_BH1750FVI_data.hpp:50
Resolution
Resolution of the measurement.
Definition unit_BH1750FVI_data.hpp:43
@ 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:52
Mode
Measurement mode.
Definition unit_BH1750FVI_data.hpp:33
@ 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:59
constexpr float SENSITIVITY_FACTOR_MIN
Minimum sensitivity factor (MTREG_MIN / MTREG_DEFAULT)
Definition unit_BH1750FVI_data.hpp:57