M5Unit-COLOR 0.2.0 git rev:d6fe6e1
Loading...
Searching...
No Matches
unit_color_utility.hpp File Reference

Utilities for UnitColor. More...

#include "../unit/unit_TCS3472x_data.hpp"
#include <algorithm>
#include <cmath>
#include <tuple>
#include <cassert>
#include <type_traits>

Go to the source code of this file.

Classes

struct  m5::unit::tcs3472x::Calibration
 Raw value to determine black and white. More...
 

Namespaces

namespace  m5
 Top level namespace of M5Stack.
 

Functions

float m5::unit::tcs3472x::atime_to_ms (const uint8_t a)
 ATIME to ms.
 
float m5::unit::tcs3472x::wtime_to_ms (const uint8_t w, const bool wlong)
 WTIME and WLONG to ms.
 
uint8_t m5::unit::tcs3472x::ms_to_atime (const float ms)
 ms to ATIME
 
std::tuple< uint8_t, bool > m5::unit::tcs3472x::ms_to_wtime (const float ms)
 ms to WTIME and WLONG
 
float m5::unit::tcs3472x::calculateLux (const uint16_t rawR, const uint16_t rawG, const uint16_t rawB, const uint16_t rawC, const float atime_ms, const Gain gc, const float dgf=DGF, const float coefR=R_Coef, const float coefG=G_Coef, const float coefB=B_Coef)
 Calculate Lux.
 
float m5::unit::tcs3472x::calculateColorTemperature (const uint16_t rawR, const uint16_t rawG, const uint16_t rawB, const uint16_t rawC, const float coefCT=CT_Coef, const float offsetCT=CT_Offset)
 Calculate color temperature(degrees Kelvin)
 
uint16_t m5::unit::tcs3472x::calculateSaturation (const uint8_t atime)
 Calculate Saturation.
 
uint16_t m5::unit::tcs3472x::calculateSaturation (const float atime_ms)
 Calculate Saturation.
 
template<typename T , typename std::enable_if< std::is_integral< T >::value &&!std::is_same< T, uint8_t >::value, std::nullptr_t >::type = nullptr>
uint16_t m5::unit::tcs3472x::calculateSaturation (const T atime)
 Calculate Saturation.
 
float m5::unit::tcs3472x::calculateCRATIO (const uint16_t rawR, const uint16_t rawG, const uint16_t rawB, const uint16_t rawC)
 Calculate CRATIO.
 
float m5::unit::tcs3472x::calculateCPL (const float atime_ms, const Gain gc, const float dgf=DGF)
 Calculate Counts per Lux (CPL)
 
float m5::unit::tcs3472x::calculateMaxLux (const float atime_ms, const Gain gc, const float dgf=DGF)
 Calculate maximum Lux.
 
template<size_t Size = 256>
M5_UNIT_COLOR_UTILITY_UNIT_COLOR_UTILITY_CONSTEXPR std::array< uint8_t, Size > m5::unit::tcs3472x::make_gamma_table (const float gamma=2.2f)
 Make gamma table.
 

Variables

Coefficients for Lux and CT Equations
constexpr float m5::unit::tcs3472x::GA {1.0f}
 Glass attenuation factor (open air)
 
constexpr float m5::unit::tcs3472x::DF {310.f}
 Device factor.
 
constexpr float m5::unit::tcs3472x::DGF {GA * DF}
 Device and glass factor.
 
constexpr float m5::unit::tcs3472x::R_Coef {0.136f}
 Lux coefficient for the red channel.
 
constexpr float m5::unit::tcs3472x::G_Coef {1.0f}
 Lux coefficient for the green channel.
 
constexpr float m5::unit::tcs3472x::B_Coef {-0.444f}
 Lux coefficient for the blue channel.
 
constexpr float m5::unit::tcs3472x::CT_Coef {3810.f}
 Color temperature coefficient.
 
constexpr float m5::unit::tcs3472x::CT_Offset {1391.f}
 Color temperature offset.
 
For A/WTIME
constexpr float m5::unit::tcs3472x::AT_NORMAL_FACTOR {2.4f}
 ATIME step (ms)
 
constexpr float m5::unit::tcs3472x::AT_NORMAL_MIN {AT_NORMAL_FACTOR}
 Minimum ATIME (2.4 ms)
 
constexpr float m5::unit::tcs3472x::AT_NORMAL_MAX {256 * AT_NORMAL_FACTOR}
 Maximum ATIME (614.4 ms)
 
constexpr float m5::unit::tcs3472x::WT_NORMAL_FACTOR {AT_NORMAL_FACTOR}
 WTIME step (ms)
 
constexpr float m5::unit::tcs3472x::WT_NORMAL_MIN {WT_NORMAL_FACTOR}
 Minimum WTIME (2.4 ms)
 
constexpr float m5::unit::tcs3472x::WT_NORMAL_MAX {256 * WT_NORMAL_FACTOR}
 Maximum WTIME without WLONG (614.4 ms)
 
constexpr float m5::unit::tcs3472x::WT_LONG_FACTOR {2.4f * 12.f}
 WTIME step with WLONG (ms)
 
constexpr float m5::unit::tcs3472x::WT_LONG_MIN {WT_LONG_FACTOR}
 Minimum WTIME with WLONG (28.8 ms)
 
constexpr float m5::unit::tcs3472x::WT_LONG_MAX {256 * WT_LONG_FACTOR}
 Maximum WTIME with WLONG (7372.8 ms)
 

Detailed Description

Utilities for UnitColor.

Function Documentation

◆ atime_to_ms()

float m5::unit::tcs3472x::atime_to_ms ( const uint8_t a)
inline

ATIME to ms.

Parameters
aATIME raw value
Returns
Integration time (ms)

◆ calculateColorTemperature()

float m5::unit::tcs3472x::calculateColorTemperature ( const uint16_t rawR,
const uint16_t rawG,
const uint16_t rawB,
const uint16_t rawC,
const float coefCT = CT_Coef,
const float offsetCT = CT_Offset )

Calculate color temperature(degrees Kelvin)

Parameters
rawRRaw red value
rawGRaw green value
rawBRaw blue value
rawCRaw clear value
coefCTCoefficient for the color temperature
offsetCTOffset for the color temperature
Returns
Color temperature(degrees Kelvin)

◆ calculateCPL()

float m5::unit::tcs3472x::calculateCPL ( const float atime_ms,
const Gain gc,
const float dgf = DGF )

Calculate Counts per Lux (CPL)

Parameters
atime_msintegration time(ms)
gcGain
dgfDevice and Glass Factor
Returns
CPL

◆ calculateCRATIO()

float m5::unit::tcs3472x::calculateCRATIO ( const uint16_t rawR,
const uint16_t rawG,
const uint16_t rawB,
const uint16_t rawC )

Calculate CRATIO.

Parameters
rawRraw red value
rawGraw green value
rawBraw blue value
rawCraw clear value
Returns
CRATIO (0.0f - 1.0f)

Guidelines for CRATIO and Light Source Correspondence

Compare Description
CRATIO < 0.1 LED or fluorescent light
0.1 <= CRATIO < 0.25 Sunlight
0.25 <= CRATIO Incandescent light

◆ calculateLux()

float m5::unit::tcs3472x::calculateLux ( const uint16_t rawR,
const uint16_t rawG,
const uint16_t rawB,
const uint16_t rawC,
const float atime_ms,
const Gain gc,
const float dgf = DGF,
const float coefR = R_Coef,
const float coefG = G_Coef,
const float coefB = B_Coef )

Calculate Lux.

Parameters
rawRRaw red value
rawGRaw green value
rawBRaw blue value
rawCRaw clear value
atime_msIntegration time(ms)
gcGain
dgfDevice and Glass Factor
coefRCoefficient for the R channel
coefGCoefficient for the G channel
coefBCoefficient for the B channel
Returns
Lux (lx)

◆ calculateMaxLux()

float m5::unit::tcs3472x::calculateMaxLux ( const float atime_ms,
const Gain gc,
const float dgf = DGF )
inline

Calculate maximum Lux.

Parameters
atime_msintegration time(ms)
gcGain
dgfDevice and Glass Factor
Returns
Lux(lx)

◆ calculateSaturation() [1/3]

uint16_t m5::unit::tcs3472x::calculateSaturation ( const float atime_ms)
inline

Calculate Saturation.

Parameters
atime_msATIME ms value
Returns
Saturation value
Note
Ripple saturation is also considered (in Analog)

◆ calculateSaturation() [2/3]

template<typename T , typename std::enable_if< std::is_integral< T >::value &&!std::is_same< T, uint8_t >::value, std::nullptr_t >::type = nullptr>
uint16_t m5::unit::tcs3472x::calculateSaturation ( const T atime)
inline

Calculate Saturation.

Parameters
atimeATIME raw value (integer types other than uint8_t are treated as raw values too)
Returns
Saturation value

◆ calculateSaturation() [3/3]

uint16_t m5::unit::tcs3472x::calculateSaturation ( const uint8_t atime)

Calculate Saturation.

Parameters
atimeATIME raw value
Returns
Saturation value
Note
Ripple saturation is also considered (in Analog)

◆ make_gamma_table()

template<size_t Size = 256>
M5_UNIT_COLOR_UTILITY_UNIT_COLOR_UTILITY_CONSTEXPR std::array< uint8_t, Size > m5::unit::tcs3472x::make_gamma_table ( const float gamma = 2.2f)

Make gamma table.

Template Parameters
SizeTable size
Parameters
gammaGamma value. Each entry is (index / 255)^gamma * 255 (rounded)
Returns
std::array<uint8_t, Size> gamma table
Note
Make on compile time if it can
The sensor values are linear in light. Use 1/2.2 to show them on a display (sRGB-like encoding), and 2.2 - 2.8 to drive an LED by PWM so that it looks right to the eye

◆ ms_to_atime()

uint8_t m5::unit::tcs3472x::ms_to_atime ( const float ms)
inline

ms to ATIME

Parameters
msIntegration time (ms)
Returns
ATIME raw value (clamped)

◆ ms_to_wtime()

std::tuple< uint8_t, bool > m5::unit::tcs3472x::ms_to_wtime ( const float ms)

ms to WTIME and WLONG

Parameters
msWait time (ms), clamped to 2.4 - 7372.8
Returns
Tuple of (WTIME raw value, WLONG)

◆ wtime_to_ms()

float m5::unit::tcs3472x::wtime_to_ms ( const uint8_t w,
const bool wlong )
inline

WTIME and WLONG to ms.

Parameters
wWTIME raw value
wlongTrue if WLONG is set (x12)
Returns
Wait time (ms)