M5Unit-LIGHT 0.0.2 git rev:6d734f0
Loading...
Searching...
No Matches
unit_Light_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_LIGHT_DATA_HPP
15#define M5_UNIT_LIGHT_UNIT_LIGHT_DATA_HPP
16
17#include <cstdint>
18#include <limits>
19
20namespace m5 {
21namespace unit {
22
27namespace light {
28
33struct Data {
34 uint16_t analog_raw{};
35 bool digital{};
36 uint16_t dark{0};
37 uint16_t bright{4095};
38
47 inline float normalized() const
48 {
49 if (dark == bright) {
50 return std::numeric_limits<float>::quiet_NaN();
51 }
52 const float span{static_cast<float>(bright) - static_cast<float>(dark)};
53 float v{(static_cast<float>(analog_raw) - static_cast<float>(dark)) * 100.0f / span};
54 if (v < 0.0f) v = 0.0f;
55 if (v > 100.0f) v = 100.0f;
56 return v;
57 }
58};
59
60} // namespace light
61} // namespace unit
62} // namespace m5
63
64#endif
For UnitLight (U021)
Top level namespace of M5Stack.
Unit-related namespace.
Measurement data group.
Definition unit_Light_data.hpp:33
bool digital
Comparator threshold output (active level is board-specific; verify with calibration)
Definition unit_Light_data.hpp:35
float normalized() const
Normalized brightness in 0..100 (%), where 0% = dark reference and 100% = bright reference.
Definition unit_Light_data.hpp:47
uint16_t bright
ADC reading captured when the sensor was lit (bright reference)
Definition unit_Light_data.hpp:37
uint16_t dark
ADC reading captured when the sensor was covered (dark reference)
Definition unit_Light_data.hpp:36
uint16_t analog_raw
Raw ADC value from the photoresistor path.
Definition unit_Light_data.hpp:34