upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
Data Structures | Functions | Typedefs | Enumerations
Include dependency graph for bh1749.h:

API Description

/*
* The MIT License (MIT)
*
* Author: Assam Boudjelthia
* Copyright (c) 2018 Rohm Semiconductor.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdio.h>
#include <signal.h>
#include "bh1749.h"
#include "upm_utilities.h"
bool isStopped;
#define SENSOR_ADDR 0x39
#define I2C_BUS 0
void signal_int_handler(int signo)
{
if (signo == SIGINT)
isStopped = true;
}
void print_data(void *dev)
{
uint16_t result[5];
printf("R: %d, G: %d, B: %d, IR: %d, G2: %d\n", result[0],
result[1], result[2], result[3], result[4]);
}
int main(int argc, char **argv)
{
signal(SIGINT, signal_int_handler);
bh1749_context dev = bh1749_init(I2C_BUS, SENSOR_ADDR);
if (!dev) {
printf("bh1749_init() failed.\n");
return -1;
}
bh1749_sensor_init(dev, INT_JUDGE_1, MEAS_240MS, RGB_GAIN_1X, IR_GAIN_1X, RED);
printf("Installing ISR\n");
bh1749_install_isr(dev, MRAA_GPIO_EDGE_FALLING, 33, &print_data, (void *)dev);
while(!isStopped) {
upm_delay_ms(1000);
}
return 0;
}

Go to the source code of this file.

Data Structures

struct  _bh1749_context
 The full sensor context. More...
 

Functions

upm_result_t bh1749_check_who_am_i (bh1749_context dev)
 Check "who am I" register value to identify the sensor. More...
 
bh1749_context bh1749_init (int bus, int addr)
 Init the sensor with specific bus and address. This function calls the sensor_init() function to set default values for operating mode, gains, measurement time, interrupt source and then sets threshold high to 511. More...
 
void bh1749_close (bh1749_context dev)
 Close and free sensor context. More...
 
upm_result_t bh1749_enable (bh1749_context dev)
 Enables RGB color measurement on the sensor. More...
 
upm_result_t bh1749_disable (bh1749_context dev)
 Disables RGB color measurement on the sensor. More...
 
upm_result_t bh1749_sensor_init (bh1749_context dev, OPERATING_MODES opMode, MEAS_TIMES measTime, RGB_GAINS rgbGain, IR_GAINS irGain, INT_SOURCES intSource)
 Initializes (writes) configuration values to sensor. More...
 
upm_result_t bh1749_set_operating_mode (bh1749_context dev, OPERATING_MODES opMode)
 Sets operating mode (interrupt persistance) More...
 
upm_result_t bh1749_get_operating_mode (bh1749_context dev, uint8_t *opMode)
 Gets operating mode (interrupt persistance) value. More...
 
upm_result_t bh1749_set_measurement_time (bh1749_context dev, MEAS_TIMES measTime)
 Sets measurement time (ODR) More...
 
upm_result_t bh1749_get_measurement_time (bh1749_context dev, uint8_t *meas_time)
 Sets measurement time (ODR) More...
 
upm_result_t bh1749_set_rgb_gain (bh1749_context dev, RGB_GAINS rgbGain)
 Sets RGB gain values. More...
 
upm_result_t bh1749_get_rgb_gain (bh1749_context dev, uint8_t *gain)
 Gets RGB gain value. More...
 
upm_result_t bh1749_set_ir_gain (bh1749_context dev, IR_GAINS irGain)
 Sets IR gain values. More...
 
upm_result_t bh1749_get_ir_gain (bh1749_context dev, uint8_t *gain)
 Gets IR gain value. More...
 
upm_result_t bh1749_set_int_source (bh1749_context dev, INT_SOURCES intSource)
 Sets interrupt source value. More...
 
char bh1749_get_interrupt_source_char (bh1749_context dev)
 Gets interrupt source value. More...
 
upm_result_t bh1749_enable_interrupt (bh1749_context dev)
 Enables interrupt mode and resets the interrupt status (clear) More...
 
upm_result_t bh1749_disable_interrupt (bh1749_context dev)
 Disables interrupt mode. More...
 
upm_result_t bh1749_reset_interrupt (bh1749_context dev)
 Resets interrupt status (clear) to allow new interrupts. More...
 
bool bh1749_is_interrupted (bh1749_context dev)
 Checks the status of the interrupt. More...
 
bool bh1749_is_interrupt_enabled (bh1749_context dev)
 Checks whether interrupt mode is enabled. More...
 
upm_result_t bh1749_soft_reset (bh1749_context dev)
 Initiates a software reset to the sensor. All register values will be written to their defaults, thus sensor_init() must be called after this, and thresholds also needs to be set. More...
 
upm_result_t bh1749_set_threshold_high (bh1749_context dev, uint16_t threshold)
 Sets interrupt threshold high value. More...
 
upm_result_t bh1749_get_threshold_high (bh1749_context dev, uint16_t *threshold)
 Gets interrupt threshold high value. More...
 
upm_result_t bh1749_set_threshold_low (bh1749_context dev, uint16_t threshold)
 Sets interrupt threshold low value. More...
 
upm_result_t bh1749_get_threshold_low (bh1749_context dev, uint16_t *threshold)
 Gets interrupt threshold low value. More...
 
upm_result_t bh1749_get_red (bh1749_context dev, uint16_t *red)
 Gets value of Red color channel. More...
 
upm_result_t bh1749_get_green (bh1749_context dev, uint16_t *green)
 Gets value of Green color channel. More...
 
upm_result_t bh1749_get_blue (bh1749_context dev, uint16_t *blue)
 Gets value of Blue color channel. More...
 
upm_result_t bh1749_get_ir (bh1749_context dev, uint16_t *ir)
 Gets value of IR color channel. More...
 
upm_result_t bh1749_get_green2 (bh1749_context dev, uint16_t *green2)
 Gets value of Green2 color channel. More...
 
upm_result_t bh1749_get_measurements (bh1749_context dev, uint16_t *result)
 Gets all channels measurements values. More...
 
upm_result_t bh1749_install_isr (bh1749_context dev, mraa_gpio_edge_t edge, int pin, void(*isr)(void *), void *isr_args)
 Installs the ISR to a given GPIO pin. More...
 
void bh1749_remove_isr (bh1749_context dev)
 Removes the ISR if it is installed. More...
 
upm_result_t bh1749_registers_dump (bh1749_context dev, char *dump)
 Gets a dump of configuration registers as a string. More...
 

Typedefs

typedef struct _bh1749_contextbh1749_context
 The full sensor context.
 

Enumerations

enum  OPERATING_MODES { INT_JUDGE_0 = BH1749_PERSISTENCE_MODE_STATUS_ACTIVE_AFTER_MEASUREMENT, INT_JUDGE_1 = BH1749_PERSISTENCE_MODE_STATUS_UPDATE_AFTER_MEASUREMENT, INT_JUDGE_4 = BH1749_PERSISTENCE_MODE_STATUS_UPDATE_AFTER_4_SAME, INT_JUDGE_8 = BH1749_PERSISTENCE_MODE_STATUS_UPDATE_AFTER_8_SAME }
 Operation modes enum for interrupt modes (persistance)
 
enum  MEAS_TIMES { MEAS_35MS = BH1749_MODE_CONTROL1_ODR_28P6, MEAS_120MS = BH1749_MODE_CONTROL1_ODR_8P333, MEAS_240MS = BH1749_MODE_CONTROL1_ODR_4P167 }
 Measuremnt time choices.
 
enum  RGB_GAINS { RGB_GAIN_1X = BH1749_MODE_CONTROL1_RGB_GAIN_1X, RGB_GAIN_32X = BH1749_MODE_CONTROL1_RGB_GAIN_32X }
 RGB gain choices.
 
enum  IR_GAINS { IR_GAIN_1X = BH1749_MODE_CONTROL1_IR_GAIN_1X, IR_GAIN_32X = BH1749_MODE_CONTROL1_IR_GAIN_32X }
 IR gain choices.
 
enum  INT_SOURCES { RED = BH1749_INTERRUPT_SOURCE_SELECT_RED, GREEN = BH1749_INTERRUPT_SOURCE_SELECT_GREEN, BLUE = BH1749_INTERRUPT_SOURCE_SELECT_BLUE }
 Interrupt source choices.
 

Function Documentation

upm_result_t bh1749_check_who_am_i ( bh1749_context  dev)
Parameters
devSensor context
Returns
UPM result

Here is the caller graph for this function:

bh1749_context bh1749_init ( int  bus,
int  addr 
)
Parameters
busI2C bus number
addrI2C sensor address
Returns
context of initialized sensor

Here is the call graph for this function:

void bh1749_close ( bh1749_context  dev)
Parameters
devSensor context

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t bh1749_enable ( bh1749_context  dev)
Parameters
devSensor context
Returns
UPM result

Here is the caller graph for this function:

upm_result_t bh1749_disable ( bh1749_context  dev)
Parameters
devSensor context
Returns
UPM result

Here is the caller graph for this function:

upm_result_t bh1749_sensor_init ( bh1749_context  dev,
OPERATING_MODES  opMode,
MEAS_TIMES  measTime,
RGB_GAINS  rgbGain,
IR_GAINS  irGain,
INT_SOURCES  intSource 
)
Parameters
devSensor context
opModeOperating mode choice, a value of OPERATING_MODES enum
measTimeMeasurement time choice, a value of MEAS_TIMES enum
rgbGainRGB gain choice, a value of RGB_GAINS enum
irGainIR gain choice, a value of IR_GAINS enum
intSourceinterrupt source choice, a value of INT_SOURCES enum
Returns
UPM result

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t bh1749_set_operating_mode ( bh1749_context  dev,
OPERATING_MODES  opMode 
)
Parameters
devSensor context
opModeOperating mode choice, a value of OPERATING_MODES enum
Returns
UPM result

Here is the caller graph for this function:

upm_result_t bh1749_get_operating_mode ( bh1749_context  dev,
uint8_t *  opMode 
)
Parameters
devSensor context
opModepointer (uint8_t) to save value
Returns
UPM result

Here is the caller graph for this function:

upm_result_t bh1749_set_measurement_time ( bh1749_context  dev,
MEAS_TIMES  measTime 
)
Parameters
devSensor context
measTimemeasurement time choice, a value of MEAS_TIMES enum
Returns
UPM result

Here is the caller graph for this function:

upm_result_t bh1749_get_measurement_time ( bh1749_context  dev,
uint8_t *  meas_time 
)
Parameters
devSensor context
meas_timepointer (uint8_t) to save value
Returns
UPM result

Here is the caller graph for this function:

upm_result_t bh1749_set_rgb_gain ( bh1749_context  dev,
RGB_GAINS  rgbGain 
)
Parameters
devSensor context
rgbGainRGB gain choice, a value of RGB_GAINS enum
Returns
UPM result

Here is the caller graph for this function:

upm_result_t bh1749_get_rgb_gain ( bh1749_context  dev,
uint8_t *  gain 
)
Parameters
devSensor context
gainpointer (uint8_t) to save value
Returns
UPM result

Here is the caller graph for this function:

upm_result_t bh1749_set_ir_gain ( bh1749_context  dev,
IR_GAINS  irGain 
)
Parameters
devSensor context
irGainIR gain choice, a value of IR_GAINS enum
Returns
UPM result

Here is the caller graph for this function:

upm_result_t bh1749_get_ir_gain ( bh1749_context  dev,
uint8_t *  gain 
)
Parameters
devSensor context
gainpointer (uint8_t) to save value
Returns
UPM result

Here is the caller graph for this function:

upm_result_t bh1749_set_int_source ( bh1749_context  dev,
INT_SOURCES  intSource 
)
Parameters
devSensor context
intSourceinterrupt source choice, a value of INT_SOURCES enum
Returns
UPM result

Here is the caller graph for this function:

char bh1749_get_interrupt_source_char ( bh1749_context  dev)
Parameters
devSensor context
Returns
character of interrupt source

Here is the caller graph for this function:

upm_result_t bh1749_enable_interrupt ( bh1749_context  dev)
Parameters
devSensor context
Returns
UPM result

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t bh1749_disable_interrupt ( bh1749_context  dev)
Parameters
devSensor context
Returns
UPM result

Here is the caller graph for this function:

upm_result_t bh1749_reset_interrupt ( bh1749_context  dev)
Parameters
devSensor context
Returns
UPM result

Here is the caller graph for this function:

bool bh1749_is_interrupted ( bh1749_context  dev)
Parameters
devSensor context
Returns
true if there is interrupt, otherwise false

Here is the caller graph for this function:

bool bh1749_is_interrupt_enabled ( bh1749_context  dev)
Parameters
devSensor context
Returns
true if interrupt is enabled, otherwise false

Here is the caller graph for this function:

upm_result_t bh1749_soft_reset ( bh1749_context  dev)
Parameters
devSensor context
Returns
UPM result

Here is the caller graph for this function:

upm_result_t bh1749_set_threshold_high ( bh1749_context  dev,
uint16_t  threshold 
)
Parameters
devSensor context
thresholdValue to be written, range 0-65536
Returns
UPM result

Here is the caller graph for this function:

upm_result_t bh1749_get_threshold_high ( bh1749_context  dev,
uint16_t *  threshold 
)
Parameters
devSensor context
thresholdPointer (uint16_t) to write value
Returns
UPM result

Here is the caller graph for this function:

upm_result_t bh1749_set_threshold_low ( bh1749_context  dev,
uint16_t  threshold 
)
Parameters
devSensor context
thresholdValue to be written, range 0-65536
Returns
UPM result

Here is the caller graph for this function:

upm_result_t bh1749_get_threshold_low ( bh1749_context  dev,
uint16_t *  threshold 
)
Parameters
devSensor context
thresholdPointer (uint16_t) to write value
Returns
UPM result

Here is the caller graph for this function:

upm_result_t bh1749_get_red ( bh1749_context  dev,
uint16_t *  red 
)
Parameters
devSensor context
redPointer (uint16_t) to write value
Returns
UPM result

Here is the caller graph for this function:

upm_result_t bh1749_get_green ( bh1749_context  dev,
uint16_t *  green 
)
Parameters
devSensor context
greenPointer (uint16_t) to write value
Returns
UPM result

Here is the caller graph for this function:

upm_result_t bh1749_get_blue ( bh1749_context  dev,
uint16_t *  blue 
)
Parameters
devSensor context
bluePointer (uint16_t) to write value
Returns
UPM result

Here is the caller graph for this function:

upm_result_t bh1749_get_ir ( bh1749_context  dev,
uint16_t *  ir 
)
Parameters
devSensor context
irPointer (uint16_t) to write value
Returns
UPM result

Here is the caller graph for this function:

upm_result_t bh1749_get_green2 ( bh1749_context  dev,
uint16_t *  green2 
)
Parameters
devSensor context
greenPointer (uint16_t) to write value
Returns
UPM result

Here is the caller graph for this function:

upm_result_t bh1749_get_measurements ( bh1749_context  dev,
uint16_t *  result 
)
Parameters
devSensor context
resultPointer of uint16_t to write all values ordered as: Red, Green, Blue, IR, Green2
Returns
UPM result

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t bh1749_install_isr ( bh1749_context  dev,
mraa_gpio_edge_t  edge,
int  pin,
void(*)(void *)  isr,
void *  isr_args 
)
Parameters
devSensor context
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
Returns
UPM result

Here is the call graph for this function:

Here is the caller graph for this function:

void bh1749_remove_isr ( bh1749_context  dev)
Parameters
devSensor context

Here is the caller graph for this function:

upm_result_t bh1749_registers_dump ( bh1749_context  dev,
char *  dump 
)
Parameters
devSensor context
dumpPointer of char to save dump string
Returns
UPM result

Here is the caller graph for this function: