M5Unit-COLOR 0.2.0 git rev:d6fe6e1
Loading...
Searching...
No Matches
m5::unit::UnitTCS3472x Class Reference

Color recognition unit. More...

#include <unit_TCS3472x.hpp>

Inheritance diagram for m5::unit::UnitTCS3472x:
m5::unit::UnitTCS34725 m5::unit::UnitTCS34727

Classes

struct  config_t
 Settings for begin. More...
 

Public Member Functions

 UnitTCS3472x (const uint8_t addr=DEFAULT_ADDRESS)
 Constructor.
 
virtual ~UnitTCS3472x ()
 Destructor.
 
virtual bool begin () override
 Begin communication with the sensor.
 
virtual void update (const bool force=false) override
 Update periodic measurement data.
 
bool readStatus (uint8_t &status)
 Read the status register.
 
Settings for begin
config_t config () const
 Gets the configuration.
 
void config (const config_t &cfg)
 Set the configuration.
 
Measurement data by periodic
uint8_t R8 () const
 Oldest measured Red.
 
uint8_t G8 () const
 Oldest measured Green.
 
uint8_t B8 () const
 Oldest measured Blue.
 
uint16_t RGB565 () const
 Oldest measured RGB565.
 
Settings
bool readPersistence (tcs3472x::Persistence &pers)
 Read the persistence.
 
bool writePersistence (const tcs3472x::Persistence pers)
 Write the persistence.
 
bool readGain (tcs3472x::Gain &gc)
 Read the gain control.
 
bool writeGain (const tcs3472x::Gain gc)
 Write the gain control.
 
bool readAtime (uint8_t &raw)
 Read the RGBC integration time (ATIME)
 
bool readAtime (float &ms)
 Read the RGBC integration time (ATIME)
 
template<typename T , typename std::enable_if< std::is_integral< T >::value, std::nullptr_t >::type = nullptr>
bool writeAtime (const T raw)
 Write the RGBC integration time (ATIME)
 
bool writeAtime (const float ms)
 Write the RGBC integration time (ATIME)
 
bool readWtime (uint8_t &raw, bool &wlong)
 Read the wait time (WTIME)
 
bool readWtime (float &ms)
 Read the wait time (WTIME)
 
bool writeWtime (const uint8_t raw, const bool wlong)
 Write the wait time (WTIME)
 
bool writeWtime (const float ms)
 Write the wait time (WTIME)
 
Periodic measurement
bool startPeriodicMeasurement (const tcs3472x::Gain gc, const float atime, const float wtime)
 Start periodic measurement.
 
bool startPeriodicMeasurement ()
 Start periodic measurement using current settings.
 
bool stopPeriodicMeasurement (const bool power_off=true)
 Stop periodic measurement.
 
Single shot measurement
bool measureSingleshot (tcs3472x::Data &d, const tcs3472x::Gain gc, const float atime)
 Measurement single shot.
 
bool measureSingleshot (tcs3472x::Data &d)
 Measurement single shot using current settings.
 
Interrupt
bool readInterrupt (bool &enable)
 Read the interrupt status.
 
bool writeInterrupt (const bool enable)
 Write the interrupt status.
 
bool readInterruptThreshold (uint16_t &low, uint16_t &high)
 Read the interrupt thresholds for clear channel.
 
bool writeInterruptThreshold (const uint16_t low, const uint16_t high)
 Write the interrupt thresholds for clear channel.
 
bool clearInterrupt ()
 Clear interrupt.
 

Protected Member Functions

virtual bool is_valid_id (const uint8_t) const
 
bool read_register8 (const uint8_t reg, uint8_t &val)
 
bool write_register8 (const uint8_t reg, const uint8_t val)
 
bool read_register (const uint8_t reg, uint8_t *buf, const uint32_t len)
 
bool write_register (const uint8_t reg, const uint8_t *buf, const uint32_t len)
 
bool start_periodic_measurement (const tcs3472x::Gain gc, const float atime, const float wtime)
 
bool start_periodic_measurement ()
 
bool stop_periodic_measurement (const bool power_off)
 
bool is_data_ready ()
 
bool read_measurement (tcs3472x::Data &d)
 
bool write_atime (const uint8_t raw)
 
 M5_UNIT_COMPONENT_PERIODIC_MEASUREMENT_ADAPTER_HPP_BUILDER (UnitTCS3472x, tcs3472x::Data)
 

Detailed Description

Color recognition unit.

Base class for TCS34725/7

Constructor & Destructor Documentation

◆ UnitTCS3472x()

m5::unit::UnitTCS3472x::UnitTCS3472x ( const uint8_t addr = DEFAULT_ADDRESS)
inlineexplicit

Constructor.

Parameters
addrI2C address

Member Function Documentation

◆ begin()

bool m5::unit::UnitTCS3472x::begin ( )
overridevirtual

Begin communication with the sensor.

Returns
True if initialization succeeded

◆ clearInterrupt()

bool m5::unit::UnitTCS3472x::clearInterrupt ( )

Clear interrupt.

Returns
True if successful

◆ measureSingleshot() [1/2]

bool m5::unit::UnitTCS3472x::measureSingleshot ( tcs3472x::Data & d)

Measurement single shot using current settings.

Parameters
[out]dMeasured data
Returns
True if successful
Warning
During periodic measurement, an error is returned

◆ measureSingleshot() [2/2]

bool m5::unit::UnitTCS3472x::measureSingleshot ( tcs3472x::Data & d,
const tcs3472x::Gain gc,
const float atime )

Measurement single shot.

Parameters
[out]dMeasured data
gcGain
atimeIntegration time(ms)
Returns
True if successful
Warning
During periodic measurement, an error is returned
Each setting is overwritten

◆ readAtime() [1/2]

bool m5::unit::UnitTCS3472x::readAtime ( float & ms)

Read the RGBC integration time (ATIME)

Parameters
[out]msATIME in ms
Returns
True if successful

◆ readAtime() [2/2]

bool m5::unit::UnitTCS3472x::readAtime ( uint8_t & raw)

Read the RGBC integration time (ATIME)

Parameters
[out]rawRaw ATIME value
Returns
True if successful

◆ readGain()

bool m5::unit::UnitTCS3472x::readGain ( tcs3472x::Gain & gc)

Read the gain control.

Parameters
[out]gcGain control
Returns
True if successful

◆ readInterrupt()

bool m5::unit::UnitTCS3472x::readInterrupt ( bool & enable)

Read the interrupt status.

Parameters
[out]enabletrue if interrupt is enabled
Returns
True if successful

◆ readInterruptThreshold()

bool m5::unit::UnitTCS3472x::readInterruptThreshold ( uint16_t & low,
uint16_t & high )

Read the interrupt thresholds for clear channel.

Parameters
[out]lowLow threshold value
[out]highHigh threshold value
Returns
True if successful

◆ readPersistence()

bool m5::unit::UnitTCS3472x::readPersistence ( tcs3472x::Persistence & pers)

Read the persistence.

Parameters
[out]persPersistence
Returns
True if successful

◆ readStatus()

bool m5::unit::UnitTCS3472x::readStatus ( uint8_t & status)

Read the status register.

Parameters
[out]statusStatus register value
Returns
True if successful

◆ readWtime() [1/2]

bool m5::unit::UnitTCS3472x::readWtime ( float & ms)

Read the wait time (WTIME)

Parameters
[out]msWTIME in ms
Returns
True if successful

◆ readWtime() [2/2]

bool m5::unit::UnitTCS3472x::readWtime ( uint8_t & raw,
bool & wlong )

Read the wait time (WTIME)

Parameters
[out]rawRaw WTIME value
[out]wlongx12 longer?
Returns
True if successful

◆ startPeriodicMeasurement() [1/2]

bool m5::unit::UnitTCS3472x::startPeriodicMeasurement ( )
inline

Start periodic measurement using current settings.

Returns
True if successful

◆ startPeriodicMeasurement() [2/2]

bool m5::unit::UnitTCS3472x::startPeriodicMeasurement ( const tcs3472x::Gain gc,
const float atime,
const float wtime )
inline

Start periodic measurement.

Parameters
gcGain
atimeIntegration time(ms)
wtimeWait time(ms)
Returns
True if successful

◆ stopPeriodicMeasurement()

bool m5::unit::UnitTCS3472x::stopPeriodicMeasurement ( const bool power_off = true)
inline

Stop periodic measurement.

Parameters
power_offTo power off if true
Returns
True if successful

◆ update()

void m5::unit::UnitTCS3472x::update ( const bool force = false)
overridevirtual

Update periodic measurement data.

Parameters
forceIf true, update immediately without waiting for the configured interval

◆ writeAtime() [1/2]

bool m5::unit::UnitTCS3472x::writeAtime ( const float ms)

Write the RGBC integration time (ATIME)

Parameters
msATIME in ms
Returns
True if successful, false if ms is out of range or writing fails
Note
Converted to approximate raw values and set
Warning
Valid range 2.4 - 614.4

◆ writeAtime() [2/2]

template<typename T , typename std::enable_if< std::is_integral< T >::value, std::nullptr_t >::type = nullptr>
bool m5::unit::UnitTCS3472x::writeAtime ( const T raw)
inline

Write the RGBC integration time (ATIME)

Parameters
rawRaw ATIME value
Returns
True if successful

◆ writeGain()

bool m5::unit::UnitTCS3472x::writeGain ( const tcs3472x::Gain gc)

Write the gain control.

Parameters
gcGain control
Returns
True if successful

◆ writeInterrupt()

bool m5::unit::UnitTCS3472x::writeInterrupt ( const bool enable)

Write the interrupt status.

Parameters
enabletrue if interrupt is to be enabled
Returns
True if successful

◆ writeInterruptThreshold()

bool m5::unit::UnitTCS3472x::writeInterruptThreshold ( const uint16_t low,
const uint16_t high )

Write the interrupt thresholds for clear channel.

Parameters
lowLow threshold value
highHigh threshold value
Returns
True if successful

◆ writePersistence()

bool m5::unit::UnitTCS3472x::writePersistence ( const tcs3472x::Persistence pers)

Write the persistence.

Parameters
persPersistence
Returns
True if successful

◆ writeWtime() [1/2]

bool m5::unit::UnitTCS3472x::writeWtime ( const float ms)

Write the wait time (WTIME)

Parameters
msWTIME in ms
Returns
True if successful, false if ms is out of range or writing fails
Note
Converted to approximate raw values and set
Warning
Valid range 2.4 - 7372.8

◆ writeWtime() [2/2]

bool m5::unit::UnitTCS3472x::writeWtime ( const uint8_t raw,
const bool wlong )

Write the wait time (WTIME)

Parameters
rawRaw WTIME value
wlongx12 longer?
Returns
True if successful