upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
Public Member Functions
BH1792 Class Reference

Public Member Functions

 BH1792 (int bus=0, int addr=0x5b)
 Init the sensor with specific bus and address. Before starting measurement, one of (EnableSyncMode, EnableNonSyncMode, or EnableSingleMode) has to be called. More...
 
virtual ~BH1792 ()
 Close and free sensor.
 
void CheckWhoAmI ()
 Check "who am I" register value to identify the sensor. More...
 
bool IsEnabled ()
 Checks if the measuremnt on sensor is enabled. More...
 
void SoftReset ()
 Initiates a software reset to the sensor. All register values will be written to their defaults, thus intended operation mode need to be enabled. More...
 
float GetMeasurementTimeMS ()
 Gets the value of measurement time is milli-seconds. More...
 
void SetGreenLedsCurrent (uint16_t current)
 Sets the green LED Current value. More...
 
int GetGreenLedsCurrent ()
 Gets the green LED current value. More...
 
void SetIrLedCurrent (uint16_t current)
 Sets the IR LED Current value. More...
 
int GetIrLedCurrent ()
 Gets the green LED current value. More...
 
void SetIrThreshold (uint16_t threshold)
 Sets interrupt IR threshold value for non-synchronized mode. More...
 
int GetIrThreshold ()
 Gets interrupt IR threshold value. More...
 
int GetFifoSize ()
 Gets the current size of built-in FIFO. More...
 
void DisableInterrupt ()
 Disables interrupt function. Interrupt is enabled by default on all operation modes, so this have to be called after enabling a specific operation mode. More...
 
void ClearInterrupt ()
 Clears the interrupt flag allowing more interrupts to be raised. More...
 
void StartMeasurement ()
 Starts the measuremnt on sensor or enable the sensor. More...
 
void StopMeasurement ()
 
void RestartMeasurement ()
 Restart the measurement, This function stops measurement, then re-writes the configuration registers again and start measurement with same configuration. More...
 
std::vector< std::vector< int > > GetFifoData ()
 Gets the fifo data of 32 entries and resets the WATERMARK interrupt flag. More...
 
void DiscardFifoData ()
 Reads and discard the 32 FIFO entries to reset the WATERMARK interrupt flag. More...
 
std::vector< int > GetGreenData ()
 Gets the values from using green LED light. More...
 
std::vector< int > GetIrData ()
 Gets the values from using IR LED light. More...
 
void EnableSyncMode (uint16_t measFreq, uint16_t green_current)
 Enables and configures the sensor to use synchronized mode. This will use the built-in FIFO and raises a WATERMARK interrupt when FIFO size reaches 32 entries. To clear that interrupt flag FIFO must be read or discarded. This mode uses only green LED. More...
 
void EnableNonSyncMode (uint16_t ir_current, uint16_t threshold)
 Enabled and configures the sensor to use non-synchronized mode. This mode uses IR_THRESHOLD interrupt, it will raise an interrupt if IR LED ON value is equal or greater than the threshold value. Interrupt must be cleared before receiving new interrupts. This mode uses only IR LED. More...
 
void EnableSingleMode (LED_TYPES led_type, uint16_t current)
 Enables and configures the sensor to use single mode. This sets the sensor to take only one measurement and raise an interrupt after measurement is finished. Interrupt flags has to be cleared to recieved new interrupts. This mode uses both green and IR LEDs. More...
 
void InstallISR (mraa_gpio_edge_t edge, int pin, void(*isr)(void *), void *isr_args)
 Installs the ISR to a given GPIO pin. More...
 
void InstallISR (int pin, void(*isr)(void *), void *isr_args)
 Installs the ISR to a given GPIO pin. More...
 
void RemoveISR ()
 Removes the ISR if it is installed.
 
std::string RegistersDump ()
 Gets a dump of configuration registers as a string. More...
 

Constructor & Destructor Documentation

BH1792 ( int  bus = 0,
int  addr = 0x5b 
)
Parameters
busI2C bus number
addrI2C sensor address
Exceptions
std::runtime_erroron initialization failure

Member Function Documentation

void CheckWhoAmI ( )
Exceptions
std::runtime_errorif this value is incorrect

Here is the call graph for this function:

bool IsEnabled ( )
Returns
True if measurement is enabled, or false otherwise

Here is the call graph for this function:

void SoftReset ( )
Exceptions
std::runtime_errorif software reset fails

Here is the call graph for this function:

float GetMeasurementTimeMS ( )
Returns
measurement time float in milli-seconds
Exceptions
std::runtime_errorif reading measurement time fails

Here is the call graph for this function:

void SetGreenLedsCurrent ( uint16_t  current)
Parameters
currentThe current value, accepted values are between 0-63
Exceptions
std::runtime_errorif setting current fails
std::range_errorif current value out of range

Here is the call graph for this function:

int GetGreenLedsCurrent ( )
Returns
Green LED used current
Exceptions
std::runtime_errorif reading current fails

Here is the call graph for this function:

void SetIrLedCurrent ( uint16_t  current)
Parameters
currentThe current value, accepted values are between 0-63
Exceptions
std::runtime_errorif setting current fails
std::range_errorif current value out of range

Here is the call graph for this function:

int GetIrLedCurrent ( )
Returns
Green LED used current
Exceptions
std::runtime_errorif reading current fails

Here is the call graph for this function:

void SetIrThreshold ( uint16_t  threshold)
Parameters
thresholdValue to be written, range 0-65536
Exceptions
std::runtime_errorif setting threshold fails

Here is the call graph for this function:

int GetIrThreshold ( )
Returns
Green LED used current
Exceptions
std::runtime_errorif reading current fails

Here is the call graph for this function:

int GetFifoSize ( )
Returns
Number of entries store in FIFO
Exceptions
std::runtime_errorif reading size fails

Here is the call graph for this function:

void DisableInterrupt ( )
Exceptions
std::runtime_errorif setting interrupt disable bits fails

Here is the call graph for this function:

void ClearInterrupt ( )
Exceptions
std::runtime_errorif clearing interrupt fails

Here is the call graph for this function:

void StartMeasurement ( )
Exceptions
std::runtime_errorif starting measurement fails

Here is the call graph for this function:

void StopMeasurement ( )

Stops the measurement by setting the software reset bit. This function will reset all config registers. To resume from previous configuration call RestartMeasurement().

Exceptions
std::runtime_errorif disabling measurement fails

Here is the call graph for this function:

void RestartMeasurement ( )
Exceptions
std::runtime_errorif restarting measurement fails

Here is the call graph for this function:

std::vector< std::vector< int > > GetFifoData ( )
Returns
vector of values of the retrieved FIFO values, which are vectors containing 2 values each (led off, led_on)
Exceptions
std::runtime_errorif reading FIFO data fails

Here is the call graph for this function:

void DiscardFifoData ( )
Exceptions
std::runtime_errorif reading FIFO data fails

Here is the call graph for this function:

std::vector< int > GetGreenData ( )
Returns
vector of values (led off, led on) of green led values
Exceptions
std::runtime_errorif reading green data fails

Here is the call graph for this function:

std::vector< int > GetIrData ( )
Returns
vector of values (led off, led on) of IR led values
Exceptions
std::runtime_errorif reading IR data fails

Here is the call graph for this function:

void EnableSyncMode ( uint16_t  measFreq,
uint16_t  green_current 
)

You need to call StartMeasurement() after this.

Parameters
measFreqMeasurement frequncy mode, valid values 32, 64, 128, 256, 1024
green_currentGreen LED current value
Exceptions
std::runtime_errorif enabling synchronized mode fails
std::invalid_argumentif measurement frequency is invalid

Here is the call graph for this function:

void EnableNonSyncMode ( uint16_t  ir_current,
uint16_t  threshold 
)

You need to call StartMeasurement() after this.

Parameters
ir_currentThe IR LED current value
thresholdThe IR LED interrupt threshold value
Exceptions
std::runtime_errorif enabling non-synchronized mode fails

Here is the call graph for this function:

void EnableSingleMode ( LED_TYPES  led_type,
uint16_t  current 
)

You need to call StartMeasurement() after this. If you need to get continuous values, clear interrupt and StartMeasurement() continuously.

Parameters
led_typeLED light type to use, takes GREEN or IR (0 or 1)
currentThe chosen led_type current value
Exceptions
std::runtime_errorif enabling single mode fails

Here is the call graph for this function:

void InstallISR ( mraa_gpio_edge_t  edge,
int  pin,
void(*)(void *)  isr,
void *  isr_args 
)
Parameters
edgeEdge type to raise ISR with, of type mraa_gpio_edge_t
pinGPIO pin number
isrPointer to ISR function
isr_argsArguments to pass the ISR function
Exceptions
std::runtime_errorif installing ISR fails

Here is the call graph for this function:

void InstallISR ( int  pin,
void(*)(void *)  isr,
void *  isr_args 
)
Parameters
pinGPIO pin number
isrPointer to ISR function
isr_argsArguments to pass the ISR function
Exceptions
std::runtime_errorif installing ISR fails

Here is the call graph for this function:

std::string RegistersDump ( )
Returns
string of dumped registers
Exceptions
std::runtime_errorif reading one of the registers fails

Here is the call graph for this function:


The documentation for this class was generated from the following files: