bh17xx: minor documentation and formatting updates, added rohm to vendor groups

Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
Mihai Tudor Panu 2018-08-09 16:11:51 -07:00
parent 4935a16530
commit 89e2ec870a
18 changed files with 1843 additions and 1839 deletions

View File

@ -3,6 +3,9 @@ a110x.cxx A110X_Example.java a110x.js a110x.py
a110x-intr.cxx A110X_intr_Example.java a110x-intr.js a110x-intr.py
adc121c021.cxx ADC121C021_Example.java adc121c021.js adc121c021.py
adxl345.cxx Adxl345_Example.java adxl345.js adxl345.py
bh1749.cxx BH1749_Example.java bh1749.js bh1749.py
bh1750.cxx BH1750_Example.java bh1750.js bh1750.py
bh1792.cxx BH1792_Example.java bh1792.js bh1792.py
biss0001.cxx BISS0001_Example.java biss0001.js biss0001.py
bmpx8x.cxx BMPX8X_Example.java bmpx8x.js bmpx8x.py
bno055.cxx BNO055_Example.java bno055.js bno055.py

View File

@ -39,31 +39,33 @@ void signal_int_handler(int signo)
isStopped = true;
}
//! [Interesting]
void PrintData(void *args)
{
std::vector<uint16_t> result = dev.GetMeasurements();
std::cout << "R: " << result.at(0) <<
", G: " << result.at(1) <<
", B: " << result.at(2) <<
", IR: " << result.at(3) <<
", G2: " << result.at(4) << std::endl;
dev.ResetInterrupt();
std::vector<uint16_t> result = dev.GetMeasurements();
std::cout << "R: " << result.at(0) <<
", G: " << result.at(1) <<
", B: " << result.at(2) <<
", IR: " << result.at(3) <<
", G2: " << result.at(4) << std::endl;
dev.ResetInterrupt();
}
int main(int argc, char **argv)
{
signal(SIGINT, signal_int_handler);
dev.SoftReset();
dev.SensorInit(INT_JUDGE_1, MEAS_240MS, RGB_GAIN_1X, IR_GAIN_1X, RED);
dev.SetThresholdHigh(511);
std::cout << "Installing ISR" << std::endl;
dev.InstallISR(MRAA_GPIO_EDGE_FALLING, 33, &PrintData, NULL);
dev.EnableInterrupt();
dev.Enable();
signal(SIGINT, signal_int_handler);
dev.SoftReset();
dev.SensorInit(INT_JUDGE_1, MEAS_240MS, RGB_GAIN_1X, IR_GAIN_1X, RED);
dev.SetThresholdHigh(511);
std::cout << "Installing ISR" << std::endl;
dev.InstallISR(MRAA_GPIO_EDGE_FALLING, 33, &PrintData, NULL);
dev.EnableInterrupt();
dev.Enable();
while(!isStopped) {
upm_delay_ms(1000);
}
while(!isStopped) {
upm_delay_ms(1000);
}
return 0;
}
return 0;
}
//! [Interesting]

View File

@ -37,43 +37,45 @@ void signal_int_handler(int signo)
isStopped = true;
}
//! [Interesting]
void PrintData(void *args)
{
std::vector<std::vector<int>> fifo;
struct timespec now;
std::vector<std::vector<int>> fifo;
struct timespec now;
clock_gettime(CLOCK_MONOTONIC_RAW, &now);
try {
fifo = dev.GetFifoData();
clock_gettime(CLOCK_MONOTONIC_RAW, &now);
try {
fifo = dev.GetFifoData();
std::cout << "\nHeart beat sensor FIFO data:" << std::endl;
for(int i = 0; i < 32; i++)
std::cout << i << ": off: " << fifo.at(i).at(0) << ", on: " <<
fifo.at(i).at(1) << std::endl;
std::cout << "\nHeart beat sensor FIFO data:" << std::endl;
for(int i = 0; i < 32; i++)
std::cout << i << ": off: " << fifo.at(i).at(0) << ", on: " <<
fifo.at(i).at(1) << std::endl;
std::cout << "timestamp " << now.tv_sec << " sec, " << now.tv_nsec <<
" nsec" << std::endl;
} catch (std::exception& e) {
std::cout << "Failed to read FIFO data" << std::endl;
throw;
}
std::cout << "timestamp " << now.tv_sec << " sec, " << now.tv_nsec <<
" nsec" << std::endl;
} catch (std::exception& e) {
std::cout << "Failed to read FIFO data" << std::endl;
throw;
}
}
int main(int argc, char **argv)
{
float measTime;
float measTime;
signal(SIGINT, signal_int_handler);
dev.SoftReset();
dev.EnableSyncMode(256, 32);
std::cout << "Installing ISR" << std::endl;
dev.InstallISR(MRAA_GPIO_EDGE_FALLING, 33, &PrintData, NULL);
measTime = dev.GetMeasurementTimeMS();
dev.StartMeasurement();
signal(SIGINT, signal_int_handler);
dev.SoftReset();
dev.EnableSyncMode(256, 32);
std::cout << "Installing ISR" << std::endl;
dev.InstallISR(MRAA_GPIO_EDGE_FALLING, 33, &PrintData, NULL);
measTime = dev.GetMeasurementTimeMS();
dev.StartMeasurement();
while(!isStopped) {
usleep(measTime * 1000);
}
while(!isStopped) {
usleep(measTime * 1000);
}
return 0;
}
return 0;
}
//! [Interesting]

View File

@ -25,27 +25,29 @@
public class BH1749_Example {
public static void main(String[] args) throws InterruptedException {
int sampleCounter = 10;
long waitTime;
upm_bh1749.BH1749 bh1749;
upm_bh1749.uint16Vector result;
bh1749 = new upm_bh1749.BH1749();
bh1749.SensorInit(upm_bh1749.OPERATING_MODES.INT_JUDGE_1,
upm_bh1749.MEAS_TIMES.MEAS_240MS, upm_bh1749.RGB_GAINS.RGB_GAIN_1X,
upm_bh1749.IR_GAINS.IR_GAIN_1X, upm_bh1749.INT_SOURCES.RED);
bh1749.SetThresholdHigh(511);
bh1749.Enable();
//! [Interesting]
int sampleCounter = 10;
long waitTime;
upm_bh1749.BH1749 bh1749;
upm_bh1749.uint16Vector result;
bh1749 = new upm_bh1749.BH1749();
bh1749.SensorInit(upm_bh1749.OPERATING_MODES.INT_JUDGE_1,
upm_bh1749.MEAS_TIMES.MEAS_240MS, upm_bh1749.RGB_GAINS.RGB_GAIN_1X,
upm_bh1749.IR_GAINS.IR_GAIN_1X, upm_bh1749.INT_SOURCES.RED);
bh1749.SetThresholdHigh(511);
bh1749.Enable();
waitTime = bh1749.GetMeasurementTime();
System.out.println("Color readings");
System.out.println("Color readings");
while (sampleCounter-- > 0) {
result = bh1749.GetMeasurements();
System.out.println("R: " + result.get(0) + ", G: " + result.get(1) +
", B: " + result.get(2) + ", IR: " + result.get(3) +
", G2: " + result.get(4));
System.out.println("R: " + result.get(0) + ", G: " + result.get(1) +
", B: " + result.get(2) + ", IR: " + result.get(3) +
", G2: " + result.get(4));
Thread.sleep((long) waitTime);
}
//! [Interesting]
}
}

View File

@ -22,6 +22,7 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
//! [Interesting]
public class BH1792_Example {
public static void main(String[] args) throws InterruptedException {
@ -31,12 +32,12 @@ public class BH1792_Example {
bh1792 = new upm_bh1792.BH1792();
BH1792ISR callback = new BH1792ISR(bh1792);
bh1792.SoftReset();
bh1792.EnableSyncMode(256, 32);
bh1792.InstallISR(33, callback);
waitTime = bh1792.GetMeasurementTimeMS();
bh1792.StartMeasurement();
@ -48,15 +49,15 @@ public class BH1792_Example {
}
class BH1792ISR implements Runnable {
upm_bh1792.intVector2D result;
upm_bh1792.BH1792 bh1792;
public BH1792ISR(upm_bh1792.BH1792 bh1792) {
super();
this.bh1792 = bh1792;
}
public void run() {
result = this.bh1792.GetFifoData();
for(int i = 0; i < 32; i++)
@ -64,4 +65,5 @@ class BH1792ISR implements Runnable {
", on: " + result.get(i).get(1));
System.out.println("Timestamp: " + System.nanoTime() + " nsec\n");
}
}
}
//! [Interesting]

View File

@ -34,7 +34,7 @@
/**
* @brief Reads the value of a register
*
*
* @param dev The sensor context
* @param reg Register address
* @param data Pointer of uint8_t to save register value
@ -42,19 +42,19 @@
*/
static upm_result_t bh1749_read_register(bh1749_context dev, uint8_t reg, uint8_t *data)
{
uint8_t value = mraa_i2c_read_byte_data(dev->i2c, reg);
if(value < 0) {
printf("%s: mraa_i2c_read_byte_data() failed\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
uint8_t value = mraa_i2c_read_byte_data(dev->i2c, reg);
if(value < 0) {
printf("%s: mraa_i2c_read_byte_data() failed\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
*data = value;
return UPM_SUCCESS;
*data = value;
return UPM_SUCCESS;
}
/**
* @brief Reads the values of a set of registers
*
*
* @param dev The sensor context
* @param reg Register address
* @param data Pointer of uint8_t to save registers values
@ -62,22 +62,22 @@ static upm_result_t bh1749_read_register(bh1749_context dev, uint8_t reg, uint8_
*/
static upm_result_t bh1749_read_registers(bh1749_context dev, uint8_t reg, uint8_t *data, uint8_t len)
{
uint8_t value;
uint8_t value;
for(int i = 0; i < len; i++) {
if(bh1749_read_register(dev, reg + i, &value) != UPM_SUCCESS) {
return UPM_ERROR_OPERATION_FAILED;
}
for(int i = 0; i < len; i++) {
if(bh1749_read_register(dev, reg + i, &value) != UPM_SUCCESS) {
return UPM_ERROR_OPERATION_FAILED;
}
*(data + i) = value;
}
*(data + i) = value;
}
return UPM_SUCCESS;
}
/**
* @brief Writes a value to a register
*
*
* @param dev The sensor context
* @param value Value to write
* @param reg Register address
@ -85,17 +85,17 @@ static upm_result_t bh1749_read_registers(bh1749_context dev, uint8_t reg, uint8
*/
static upm_result_t bh1749_write_register(bh1749_context dev, uint8_t value, uint8_t reg)
{
if (mraa_i2c_write_byte_data(dev->i2c, value, reg) != MRAA_SUCCESS) {
printf("%s: mraa_i2c_write_byte_data() failed\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
if (mraa_i2c_write_byte_data(dev->i2c, value, reg) != MRAA_SUCCESS) {
printf("%s: mraa_i2c_write_byte_data() failed\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
return UPM_SUCCESS;
return UPM_SUCCESS;
}
/**
* @brief Sets a bit on in a register with a bit mask
*
*
* @param dev The sensor context
* @param reg Register address
* @param bit_mask Mask to use
@ -103,14 +103,14 @@ static upm_result_t bh1749_write_register(bh1749_context dev, uint8_t value, uin
*/
static upm_result_t bh1749_set_bit_on(bh1749_context dev, uint8_t reg, uint8_t bit_mask)
{
uint8_t reg_value;
int status;
uint8_t reg_value;
int status;
status = bh1749_read_register(dev, reg, &reg_value);
if(status < 0) {
printf("%s: Failed to read register 0x%2X\n", __FUNCTION__, reg);
return UPM_ERROR_OPERATION_FAILED;
}
status = bh1749_read_register(dev, reg, &reg_value);
if(status < 0) {
printf("%s: Failed to read register 0x%2X\n", __FUNCTION__, reg);
return UPM_ERROR_OPERATION_FAILED;
}
reg_value |= bit_mask;
return bh1749_write_register(dev, reg_value, reg);
@ -118,7 +118,7 @@ static upm_result_t bh1749_set_bit_on(bh1749_context dev, uint8_t reg, uint8_t b
/**
* @brief Sets a bit off in a register with a bit mask
*
*
* @param dev The sensor context
* @param reg Register address
* @param bit_mask Mask to use
@ -126,14 +126,14 @@ static upm_result_t bh1749_set_bit_on(bh1749_context dev, uint8_t reg, uint8_t b
*/
static upm_result_t bh1749_set_bit_off(bh1749_context dev, uint8_t reg, uint8_t bit_mask)
{
uint8_t reg_value;
int status;
uint8_t reg_value;
int status;
status = bh1749_read_register(dev, reg, &reg_value);
if(status < 0) {
printf("%s: Failed to read register 0x%2X\n", __FUNCTION__, reg);
return UPM_ERROR_OPERATION_FAILED;
}
status = bh1749_read_register(dev, reg, &reg_value);
if(status < 0) {
printf("%s: Failed to read register 0x%2X\n", __FUNCTION__, reg);
return UPM_ERROR_OPERATION_FAILED;
}
reg_value &= ~bit_mask;
return bh1749_write_register(dev, reg_value, reg);
@ -141,7 +141,7 @@ static upm_result_t bh1749_set_bit_off(bh1749_context dev, uint8_t reg, uint8_t
/**
* @brief Sets the value of a register as a given pattern with a bit mask
*
*
* @param dev The sensor context
* @param reg Register address
* @param value Value to write
@ -150,45 +150,45 @@ static upm_result_t bh1749_set_bit_off(bh1749_context dev, uint8_t reg, uint8_t
*/
static upm_result_t bh1749_set_bits_with_mask(bh1749_context dev, uint8_t reg, uint8_t value, uint8_t bit_mask)
{
uint8_t reg_value;
int status;
uint8_t reg_value;
int status;
status = bh1749_read_register(dev, reg, &reg_value);
if(status < 0) {
printf("%s: Failed to read register 0x%2X\n", __FUNCTION__, reg);
return UPM_ERROR_OPERATION_FAILED;
}
status = bh1749_read_register(dev, reg, &reg_value);
if(status < 0) {
printf("%s: Failed to read register 0x%2X\n", __FUNCTION__, reg);
return UPM_ERROR_OPERATION_FAILED;
}
reg_value &= ~bit_mask;
reg_value |= value;
return bh1749_write_register(dev, reg_value, reg);
reg_value |= value;
return bh1749_write_register(dev, reg_value, reg);
}
upm_result_t bh1749_check_who_am_i(bh1749_context dev)
{
uint8_t partId;
if(bh1749_read_register(dev, BH1749_SYSTEM_CONTROL, &partId) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
uint8_t partId;
if(bh1749_read_register(dev, BH1749_SYSTEM_CONTROL, &partId) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
partId &= BH1749_SYSTEM_CONTROL_PART_MASK;
if(partId != BH1749_SYSTEM_CONTROL_PART_ID) {
printf("%s: wrong manufacturer ID\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
partId &= BH1749_SYSTEM_CONTROL_PART_MASK;
if(partId != BH1749_SYSTEM_CONTROL_PART_ID) {
printf("%s: wrong manufacturer ID\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
return UPM_SUCCESS;
return UPM_SUCCESS;
}
bh1749_context bh1749_init(int bus, int addr)
{
bh1749_context dev = (bh1749_context)malloc(sizeof(struct _bh1749_context));
if (!dev)
bh1749_context dev = (bh1749_context)malloc(sizeof(struct _bh1749_context));
if (!dev)
return NULL;
dev->i2c = NULL;
dev->i2c = NULL;
dev->interrupt = NULL;
if (mraa_init() != MRAA_SUCCESS) {
if (mraa_init() != MRAA_SUCCESS) {
printf("%s: mraa_init() failed.\n", __FUNCTION__);
bh1749_close(dev);
return NULL;
@ -206,452 +206,452 @@ bh1749_context bh1749_init(int bus, int addr)
return NULL;
}
if(bh1749_check_who_am_i(dev) != UPM_SUCCESS)
return NULL;
if(bh1749_check_who_am_i(dev) != UPM_SUCCESS)
return NULL;
dev->enabled = false;
dev->isrEnabled = false;
if(bh1749_sensor_init(dev, DEFAULT_OP_MODE, DEFAULT_MEAS_TIME,
DEFAULT_RGB_GAIN, DEFAULT_IR_GAIN, DEFAULT_INT_SOURCE) != UPM_SUCCESS)
return NULL;
bh1749_set_threshold_high(dev, DEFUALT_THRESHOLD_HIGH);
dev->enabled = false;
dev->isrEnabled = false;
if(bh1749_sensor_init(dev, DEFAULT_OP_MODE, DEFAULT_MEAS_TIME,
DEFAULT_RGB_GAIN, DEFAULT_IR_GAIN, DEFAULT_INT_SOURCE) != UPM_SUCCESS)
return NULL;
bh1749_set_threshold_high(dev, DEFUALT_THRESHOLD_HIGH);
return dev;
return dev;
}
void bh1749_close(bh1749_context dev)
{
if(dev->isrEnabled)
bh1749_remove_isr(dev);
if(dev->isrEnabled)
bh1749_remove_isr(dev);
if (dev->i2c)
mraa_i2c_stop(dev->i2c);
free(dev);
free(dev);
}
upm_result_t bh1749_enable(bh1749_context dev)
{
int status;
int status;
status = bh1749_set_bit_on(dev, BH1749_MODE_CONTROL2,
BH1749_MODE_CONTROL2_RGB_MEASUREMENT_MASK);
if(status != UPM_SUCCESS) {
printf("%s: Failed to bh1749_enable RGB measurement\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
dev->enabled = true;
status = bh1749_set_bit_on(dev, BH1749_MODE_CONTROL2,
BH1749_MODE_CONTROL2_RGB_MEASUREMENT_MASK);
if(status != UPM_SUCCESS) {
printf("%s: Failed to bh1749_enable RGB measurement\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
dev->enabled = true;
return UPM_SUCCESS;
return UPM_SUCCESS;
}
upm_result_t bh1749_disable(bh1749_context dev)
{
int status;
int status;
status = bh1749_set_bit_off(dev, BH1749_MODE_CONTROL2,
BH1749_MODE_CONTROL2_RGB_MEASUREMENT_MASK);
if(status != UPM_SUCCESS) {
printf("%s: Failed to bh1749_disable RGB measurement\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
dev->enabled = false;
status = bh1749_set_bit_off(dev, BH1749_MODE_CONTROL2,
BH1749_MODE_CONTROL2_RGB_MEASUREMENT_MASK);
if(status != UPM_SUCCESS) {
printf("%s: Failed to bh1749_disable RGB measurement\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
dev->enabled = false;
return UPM_SUCCESS;
return UPM_SUCCESS;
}
upm_result_t bh1749_sensor_init(bh1749_context dev, OPERATING_MODES opMode,
MEAS_TIMES measTime,
RGB_GAINS rgbGain,
IR_GAINS irGain,
INT_SOURCES intSource)
MEAS_TIMES measTime,
RGB_GAINS rgbGain,
IR_GAINS irGain,
INT_SOURCES intSource)
{
if(bh1749_set_operating_mode(dev, opMode) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
if(bh1749_set_measurement_time(dev, measTime) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
if(bh1749_set_rgb_gain(dev, rgbGain) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
if(bh1749_set_ir_gain(dev, irGain) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
return bh1749_set_int_source(dev, intSource);
if(bh1749_set_operating_mode(dev, opMode) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
if(bh1749_set_measurement_time(dev, measTime) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
if(bh1749_set_rgb_gain(dev, rgbGain) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
if(bh1749_set_ir_gain(dev, irGain) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
return bh1749_set_int_source(dev, intSource);
}
upm_result_t bh1749_set_operating_mode(bh1749_context dev, OPERATING_MODES opMode)
{
if(bh1749_write_register(dev, opMode, BH1749_PERSISTENCE) != UPM_SUCCESS) {
printf("%s: Setting operating mode failed\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
dev->operating_mode = opMode;
if(bh1749_write_register(dev, opMode, BH1749_PERSISTENCE) != UPM_SUCCESS) {
printf("%s: Setting operating mode failed\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
dev->operating_mode = opMode;
return UPM_SUCCESS;
return UPM_SUCCESS;
}
upm_result_t bh1749_get_operating_mode(bh1749_context dev, uint8_t *opMode)
{
uint8_t value;
uint8_t value;
if(bh1749_read_register(dev, BH1749_PERSISTENCE, &value) != UPM_SUCCESS) {
printf("%s: Failed to read operating mode\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
if(bh1749_read_register(dev, BH1749_PERSISTENCE, &value) != UPM_SUCCESS) {
printf("%s: Failed to read operating mode\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
value &= BH1749_PERSISTENCE_MODE_MASK;
if(value != INT_JUDGE_0 && value != INT_JUDGE_1 &&
value != INT_JUDGE_4 && value != INT_JUDGE_4) {
printf("%s: Returned invalid mode\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
value &= BH1749_PERSISTENCE_MODE_MASK;
if(value != INT_JUDGE_0 && value != INT_JUDGE_1 &&
value != INT_JUDGE_4 && value != INT_JUDGE_4) {
printf("%s: Returned invalid mode\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
*opMode = value;
*opMode = value;
return UPM_SUCCESS;
return UPM_SUCCESS;
}
upm_result_t bh1749_set_measurement_time(bh1749_context dev, MEAS_TIMES measTime)
{
if(bh1749_set_bits_with_mask(dev, BH1749_MODE_CONTROL1, measTime,
BH1749_MODE_CONTROL1_ODR_MASK) != UPM_SUCCESS) {
printf("%s: Failed setting measurement time\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
dev->meas_time = measTime;
if(bh1749_set_bits_with_mask(dev, BH1749_MODE_CONTROL1, measTime,
BH1749_MODE_CONTROL1_ODR_MASK) != UPM_SUCCESS) {
printf("%s: Failed setting measurement time\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
dev->meas_time = measTime;
return UPM_SUCCESS;
return UPM_SUCCESS;
}
upm_result_t bh1749_get_measurement_time(bh1749_context dev, uint8_t *meas_time)
{
uint8_t time_reg;
uint8_t time_reg;
if(bh1749_read_register(dev, BH1749_MODE_CONTROL1, &time_reg) != UPM_SUCCESS) {
printf("%s: Failed to read measurement time\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
if(bh1749_read_register(dev, BH1749_MODE_CONTROL1, &time_reg) != UPM_SUCCESS) {
printf("%s: Failed to read measurement time\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
time_reg &= BH1749_MODE_CONTROL1_ODR_MASK;
if(time_reg == MEAS_35MS)
*meas_time = 35;
else if(time_reg == MEAS_120MS)
*meas_time = 120;
else if(time_reg == MEAS_240MS)
*meas_time = 240;
else {
printf("%s: Returned invalid time\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
time_reg &= BH1749_MODE_CONTROL1_ODR_MASK;
if(time_reg == MEAS_35MS)
*meas_time = 35;
else if(time_reg == MEAS_120MS)
*meas_time = 120;
else if(time_reg == MEAS_240MS)
*meas_time = 240;
else {
printf("%s: Returned invalid time\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
return UPM_SUCCESS;
return UPM_SUCCESS;
}
upm_result_t bh1749_set_rgb_gain(bh1749_context dev, RGB_GAINS rgbGain)
{
if(bh1749_set_bits_with_mask(dev, BH1749_MODE_CONTROL1, rgbGain,
BH1749_MODE_CONTROL1_RGB_GAIN_MASK) != UPM_SUCCESS) {
printf("%s: Failed setting RGB gain\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
dev->rgb_gain = rgbGain;
if(bh1749_set_bits_with_mask(dev, BH1749_MODE_CONTROL1, rgbGain,
BH1749_MODE_CONTROL1_RGB_GAIN_MASK) != UPM_SUCCESS) {
printf("%s: Failed setting RGB gain\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
dev->rgb_gain = rgbGain;
return UPM_SUCCESS;
return UPM_SUCCESS;
}
upm_result_t bh1749_get_rgb_gain(bh1749_context dev, uint8_t *gain)
{
uint8_t rgb_gain;
uint8_t rgb_gain;
if(bh1749_read_register(dev, BH1749_MODE_CONTROL1, &rgb_gain) != UPM_SUCCESS) {
printf("%s: Failed to read rgb gain\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
if(bh1749_read_register(dev, BH1749_MODE_CONTROL1, &rgb_gain) != UPM_SUCCESS) {
printf("%s: Failed to read rgb gain\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
rgb_gain &= BH1749_MODE_CONTROL1_RGB_GAIN_MASK;
if(rgb_gain == RGB_GAIN_1X)
*gain = 1;
else if(rgb_gain == RGB_GAIN_32X)
*gain = 32;
else {
printf("%s: Returned invalid gain\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
rgb_gain &= BH1749_MODE_CONTROL1_RGB_GAIN_MASK;
if(rgb_gain == RGB_GAIN_1X)
*gain = 1;
else if(rgb_gain == RGB_GAIN_32X)
*gain = 32;
else {
printf("%s: Returned invalid gain\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
return UPM_SUCCESS;
return UPM_SUCCESS;
}
upm_result_t bh1749_set_ir_gain(bh1749_context dev, IR_GAINS irGain)
{
if(bh1749_set_bits_with_mask(dev, BH1749_MODE_CONTROL1, irGain,
BH1749_MODE_CONTROL1_IR_GAIN_MASK) != UPM_SUCCESS) {
printf("%s: Failed setting IR gain\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
dev->ir_gain = irGain;
if(bh1749_set_bits_with_mask(dev, BH1749_MODE_CONTROL1, irGain,
BH1749_MODE_CONTROL1_IR_GAIN_MASK) != UPM_SUCCESS) {
printf("%s: Failed setting IR gain\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
dev->ir_gain = irGain;
return UPM_SUCCESS;
return UPM_SUCCESS;
}
upm_result_t bh1749_get_ir_gain(bh1749_context dev, uint8_t *gain)
{
uint8_t ir_gain;
uint8_t ir_gain;
if(bh1749_read_register(dev, BH1749_MODE_CONTROL1, &ir_gain) != UPM_SUCCESS) {
printf("%s: Failed to read rgb gain\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
if(bh1749_read_register(dev, BH1749_MODE_CONTROL1, &ir_gain) != UPM_SUCCESS) {
printf("%s: Failed to read rgb gain\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
ir_gain &= BH1749_MODE_CONTROL1_IR_GAIN_MASK;
if(ir_gain == IR_GAIN_1X)
*gain = 1;
else if(ir_gain == IR_GAIN_32X)
*gain = 32;
else {
printf("%s: Returned invalid gain\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
ir_gain &= BH1749_MODE_CONTROL1_IR_GAIN_MASK;
if(ir_gain == IR_GAIN_1X)
*gain = 1;
else if(ir_gain == IR_GAIN_32X)
*gain = 32;
else {
printf("%s: Returned invalid gain\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
return UPM_SUCCESS;
return UPM_SUCCESS;
}
upm_result_t bh1749_set_int_source(bh1749_context dev, INT_SOURCES intSource)
{
if(bh1749_set_bits_with_mask(dev, BH1749_INTERRUPT, intSource,
BH1749_INTERRUPT_SOURCE_MASK) != UPM_SUCCESS) {
printf("%s: Failed setting interrupt source gain\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
dev->int_src = intSource;
if(bh1749_set_bits_with_mask(dev, BH1749_INTERRUPT, intSource,
BH1749_INTERRUPT_SOURCE_MASK) != UPM_SUCCESS) {
printf("%s: Failed setting interrupt source gain\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
dev->int_src = intSource;
return UPM_SUCCESS;
return UPM_SUCCESS;
}
char bh1749_get_interrupt_source_char(bh1749_context dev)
{
char intSourceChar = ' ';
uint8_t intSource;
if(bh1749_read_register(dev, BH1749_INTERRUPT, &intSource) != UPM_SUCCESS) {
printf("%s: Failed to read interrupt source\n", __FUNCTION__);
return intSourceChar;
}
intSource &= BH1749_INTERRUPT_SOURCE_MASK;
if(intSource == RED)
intSourceChar = 'r';
else if(intSource == GREEN)
intSourceChar = 'g';
else if(intSource == BLUE)
intSourceChar = 'b';
else {
printf("%s: Returned invalid interrupt source\n", __FUNCTION__);
return intSourceChar;
}
char intSourceChar = ' ';
uint8_t intSource;
return intSourceChar;
if(bh1749_read_register(dev, BH1749_INTERRUPT, &intSource) != UPM_SUCCESS) {
printf("%s: Failed to read interrupt source\n", __FUNCTION__);
return intSourceChar;
}
intSource &= BH1749_INTERRUPT_SOURCE_MASK;
if(intSource == RED)
intSourceChar = 'r';
else if(intSource == GREEN)
intSourceChar = 'g';
else if(intSource == BLUE)
intSourceChar = 'b';
else {
printf("%s: Returned invalid interrupt source\n", __FUNCTION__);
return intSourceChar;
}
return intSourceChar;
}
upm_result_t bh1749_enable_interrupt(bh1749_context dev)
{
if(bh1749_set_bit_on(dev, BH1749_INTERRUPT, BH1749_INTERRUPT_EN_MASK) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
return bh1749_reset_interrupt(dev);
if(bh1749_set_bit_on(dev, BH1749_INTERRUPT, BH1749_INTERRUPT_EN_MASK) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
return bh1749_reset_interrupt(dev);
}
upm_result_t bh1749_disable_interrupt(bh1749_context dev)
{
return bh1749_set_bit_off(dev, BH1749_INTERRUPT, BH1749_INTERRUPT_EN_MASK);
return bh1749_set_bit_off(dev, BH1749_INTERRUPT, BH1749_INTERRUPT_EN_MASK);
}
upm_result_t bh1749_reset_interrupt(bh1749_context dev)
{
return bh1749_set_bit_on(dev, BH1749_SYSTEM_CONTROL, BH1749_SYSTEM_CONTROL_INT_RESET);
return bh1749_set_bit_on(dev, BH1749_SYSTEM_CONTROL, BH1749_SYSTEM_CONTROL_INT_RESET);
}
bool bh1749_is_interrupted(bh1749_context dev)
{
uint8_t intStatus;
uint8_t intStatus;
if(bh1749_read_register(dev, BH1749_INTERRUPT, &intStatus) != UPM_SUCCESS) {
printf("%s: Failed to read interrupt status\n", __FUNCTION__);
return false;
}
if(bh1749_read_register(dev, BH1749_INTERRUPT, &intStatus) != UPM_SUCCESS) {
printf("%s: Failed to read interrupt status\n", __FUNCTION__);
return false;
}
intStatus &= BH1749_INTERRUPT_STATUS_MASK;
if(intStatus != BH1749_INTERRUPT_STATUS_ACTIVE)
return false;
intStatus &= BH1749_INTERRUPT_STATUS_MASK;
if(intStatus != BH1749_INTERRUPT_STATUS_ACTIVE)
return false;
return true;
return true;
}
bool bh1749_is_interrupt_enabled(bh1749_context dev)
{
uint8_t intStatus;
uint8_t intStatus;
if(bh1749_read_register(dev, BH1749_INTERRUPT, &intStatus) != UPM_SUCCESS) {
printf("%s: Failed to read interrupt enabled\n", __FUNCTION__);
return false;
}
if(bh1749_read_register(dev, BH1749_INTERRUPT, &intStatus) != UPM_SUCCESS) {
printf("%s: Failed to read interrupt enabled\n", __FUNCTION__);
return false;
}
intStatus &= BH1749_INTERRUPT_EN_MASK;
if(intStatus != BH1749_INTERRUPT_EN_ENABLE)
return false;
intStatus &= BH1749_INTERRUPT_EN_MASK;
if(intStatus != BH1749_INTERRUPT_EN_ENABLE)
return false;
return true;
return true;
}
upm_result_t bh1749_soft_reset(bh1749_context dev)
{
return bh1749_set_bit_on(dev, BH1749_SYSTEM_CONTROL, BH1749_SYSTEM_CONTROL_SW_RESET_MASK);
return bh1749_set_bit_on(dev, BH1749_SYSTEM_CONTROL, BH1749_SYSTEM_CONTROL_SW_RESET_MASK);
}
upm_result_t bh1749_set_threshold_high(bh1749_context dev, uint16_t threshold)
{
if(bh1749_write_register(dev, threshold, BH1749_TH_LSBS) != UPM_SUCCESS ||
bh1749_write_register(dev, threshold >> 8, BH1749_TH_MSBS) != UPM_SUCCESS) {
printf("%s: Failed to write high threshold\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
dev->int_thh = threshold;
if(bh1749_write_register(dev, threshold, BH1749_TH_LSBS) != UPM_SUCCESS ||
bh1749_write_register(dev, threshold >> 8, BH1749_TH_MSBS) != UPM_SUCCESS) {
printf("%s: Failed to write high threshold\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
dev->int_thh = threshold;
return UPM_SUCCESS;
return UPM_SUCCESS;
}
upm_result_t bh1749_get_threshold_high(bh1749_context dev, uint16_t *threshold)
{
uint8_t data[2];
uint8_t data[2];
if(bh1749_read_register(dev, BH1749_TH_MSBS, &data[0]) ||
bh1749_read_register(dev, BH1749_TH_LSBS, &data[1]) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
if(bh1749_read_register(dev, BH1749_TH_MSBS, &data[0]) ||
bh1749_read_register(dev, BH1749_TH_LSBS, &data[1]) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
*threshold = data[0] << 8 | data[1];
return UPM_SUCCESS;
*threshold = data[0] << 8 | data[1];
return UPM_SUCCESS;
}
upm_result_t bh1749_set_threshold_low(bh1749_context dev, uint16_t threshold)
{
if(bh1749_write_register(dev, threshold, BH1749_TL_LSBS) != UPM_SUCCESS ||
bh1749_write_register(dev, threshold >> 8, BH1749_TL_MSBS) != UPM_SUCCESS) {
printf("%s: Failed to write low threshold\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
dev->int_thl = threshold;
if(bh1749_write_register(dev, threshold, BH1749_TL_LSBS) != UPM_SUCCESS ||
bh1749_write_register(dev, threshold >> 8, BH1749_TL_MSBS) != UPM_SUCCESS) {
printf("%s: Failed to write low threshold\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
dev->int_thl = threshold;
return UPM_SUCCESS;
return UPM_SUCCESS;
}
upm_result_t bh1749_get_threshold_low(bh1749_context dev, uint16_t *threshold)
{
uint8_t data[2];
uint8_t data[2];
if(bh1749_read_register(dev, BH1749_TL_MSBS, &data[0]) ||
bh1749_read_register(dev, BH1749_TL_LSBS, &data[1]) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
if(bh1749_read_register(dev, BH1749_TL_MSBS, &data[0]) ||
bh1749_read_register(dev, BH1749_TL_LSBS, &data[1]) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
*threshold = data[0] << 8 | data[1];
return UPM_SUCCESS;
*threshold = data[0] << 8 | data[1];
return UPM_SUCCESS;
}
upm_result_t bh1749_get_red(bh1749_context dev, uint16_t *red)
{
uint8_t data[2];
uint8_t data[2];
if(bh1749_read_register(dev, BH1749_RED_DATA_MSBS, &data[0]) != UPM_SUCCESS ||
bh1749_read_register(dev, BH1749_RED_DATA_LSBS, &data[1]) != UPM_SUCCESS)
return -UPM_ERROR_OPERATION_FAILED;
if(bh1749_read_register(dev, BH1749_RED_DATA_MSBS, &data[0]) != UPM_SUCCESS ||
bh1749_read_register(dev, BH1749_RED_DATA_LSBS, &data[1]) != UPM_SUCCESS)
return -UPM_ERROR_OPERATION_FAILED;
*red = data[0] << 8 | data[1];
*red = data[0] << 8 | data[1];
return UPM_SUCCESS;
return UPM_SUCCESS;
}
upm_result_t bh1749_get_green(bh1749_context dev, uint16_t *green)
{
uint8_t data[2];
uint8_t data[2];
if(bh1749_read_register(dev, BH1749_GREEN_DATA_MSBS, &data[0]) != UPM_SUCCESS ||
bh1749_read_register(dev, BH1749_GREEN_DATA_LSBS, &data[1]) != UPM_SUCCESS)
return -UPM_ERROR_OPERATION_FAILED;
if(bh1749_read_register(dev, BH1749_GREEN_DATA_MSBS, &data[0]) != UPM_SUCCESS ||
bh1749_read_register(dev, BH1749_GREEN_DATA_LSBS, &data[1]) != UPM_SUCCESS)
return -UPM_ERROR_OPERATION_FAILED;
*green = data[0] << 8 | data[1];
*green = data[0] << 8 | data[1];
return UPM_SUCCESS;
return UPM_SUCCESS;
}
upm_result_t bh1749_get_blue(bh1749_context dev, uint16_t *blue)
{
uint8_t data[2];
uint8_t data[2];
if(bh1749_read_register(dev, BH1749_BLUE_DATA_MSBS, &data[0]) != UPM_SUCCESS ||
bh1749_read_register(dev, BH1749_BLUE_DATA_LSBS, &data[1]) != UPM_SUCCESS)
return -UPM_ERROR_OPERATION_FAILED;
if(bh1749_read_register(dev, BH1749_BLUE_DATA_MSBS, &data[0]) != UPM_SUCCESS ||
bh1749_read_register(dev, BH1749_BLUE_DATA_LSBS, &data[1]) != UPM_SUCCESS)
return -UPM_ERROR_OPERATION_FAILED;
*blue = data[0] << 8 | data[1];
*blue = data[0] << 8 | data[1];
return UPM_SUCCESS;
return UPM_SUCCESS;
}
upm_result_t bh1749_get_ir(bh1749_context dev, uint16_t *ir)
{
uint8_t data[2];
uint8_t data[2];
if(bh1749_read_register(dev, BH1749_IR_DATA_MSBS, &data[0]) != UPM_SUCCESS ||
bh1749_read_register(dev, BH1749_IR_DATA_LSBS, &data[1]) != UPM_SUCCESS)
return -UPM_ERROR_OPERATION_FAILED;
if(bh1749_read_register(dev, BH1749_IR_DATA_MSBS, &data[0]) != UPM_SUCCESS ||
bh1749_read_register(dev, BH1749_IR_DATA_LSBS, &data[1]) != UPM_SUCCESS)
return -UPM_ERROR_OPERATION_FAILED;
*ir = data[0] << 8 | data[1];
*ir = data[0] << 8 | data[1];
return UPM_SUCCESS;
return UPM_SUCCESS;
}
upm_result_t bh1749_get_green2(bh1749_context dev, uint16_t *green2)
{
uint8_t data[2];
uint8_t data[2];
if(bh1749_read_register(dev, BH1749_GREEN2_DATA_MSBS, &data[0]) != UPM_SUCCESS ||
bh1749_read_register(dev, BH1749_GREEN2_DATA_LSBS, &data[1]) != UPM_SUCCESS)
return -UPM_ERROR_OPERATION_FAILED;
if(bh1749_read_register(dev, BH1749_GREEN2_DATA_MSBS, &data[0]) != UPM_SUCCESS ||
bh1749_read_register(dev, BH1749_GREEN2_DATA_LSBS, &data[1]) != UPM_SUCCESS)
return -UPM_ERROR_OPERATION_FAILED;
*green2 = data[0] << 8 | data[1];
*green2 = data[0] << 8 | data[1];
return UPM_SUCCESS;
return UPM_SUCCESS;
}
upm_result_t bh1749_get_measurements(bh1749_context dev, uint16_t *result)
{
uint16_t value;
int step = 0;
uint16_t value;
int step = 0;
if(bh1749_get_red(dev, &value) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
*(result + step++) = value;
if(bh1749_get_green(dev, &value) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
*(result + step++) = value;
if(bh1749_get_blue(dev, &value) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
*(result + step++) = value;
if(bh1749_get_ir(dev, &value) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
*(result + step++) = value;
if(bh1749_get_green2(dev, &value) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
*(result + step++) = value;
if(bh1749_get_red(dev, &value) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
*(result + step++) = value;
if(bh1749_get_green(dev, &value) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
*(result + step++) = value;
if(bh1749_get_blue(dev, &value) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
*(result + step++) = value;
if(bh1749_get_ir(dev, &value) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
*(result + step++) = value;
if(bh1749_get_green2(dev, &value) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
*(result + step++) = value;
return UPM_SUCCESS;
return UPM_SUCCESS;
}
upm_result_t bh1749_install_isr(bh1749_context dev, mraa_gpio_edge_t edge, int pin,
void (*isr)(void *), void *isr_args)
void (*isr)(void *), void *isr_args)
{
if(dev->isrEnabled)
bh1749_remove_isr(dev);
if(dev->isrEnabled)
bh1749_remove_isr(dev);
mraa_gpio_context isr_gpio = NULL;
mraa_gpio_context isr_gpio = NULL;
if (!(isr_gpio = mraa_gpio_init(pin))) {
if (!(isr_gpio = mraa_gpio_init(pin))) {
printf("%s: mraa_gpio_init() failed.\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED;
}
@ -664,39 +664,39 @@ upm_result_t bh1749_install_isr(bh1749_context dev, mraa_gpio_edge_t edge, int p
return UPM_ERROR_OPERATION_FAILED;
}
dev->interrupt = isr_gpio;
dev->isrEnabled = true;
dev->interrupt = isr_gpio;
dev->isrEnabled = true;
return UPM_SUCCESS;
return UPM_SUCCESS;
}
void bh1749_remove_isr(bh1749_context dev)
{
mraa_gpio_isr_exit(dev->interrupt);
mraa_gpio_isr_exit(dev->interrupt);
mraa_gpio_close(dev->interrupt);
dev->interrupt = NULL;
dev->isrEnabled = false;
dev->interrupt = NULL;
dev->isrEnabled = false;
}
upm_result_t bh1749_registers_dump(bh1749_context dev, char *dump)
{
uint8_t reg_values[10];
int count = 0;
int len = 3;
uint8_t reg_values[10];
int count = 0;
int len = 3;
if(bh1749_read_registers(dev, BH1749_SYSTEM_CONTROL, reg_values, len) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
count += sprintf(dump, "0x40 ");
for(int i = 0; i < len; i++)
count += sprintf(dump + count, "%02X ", reg_values[i]);
sprintf(dump + count - 1, "\n");
if(bh1749_read_registers(dev, BH1749_SYSTEM_CONTROL, reg_values, len) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
count += sprintf(dump, "0x40 ");
for(int i = 0; i < len; i++)
count += sprintf(dump + count, "%02X ", reg_values[i]);
sprintf(dump + count - 1, "\n");
len = 6;
if(bh1749_read_registers(dev, BH1749_INTERRUPT, reg_values, len) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
count += sprintf(dump + count, "0x60 ");
for(int i = 0; i < len; i++)
count += sprintf(dump + count, "%02X ", reg_values[i]);
len = 6;
if(bh1749_read_registers(dev, BH1749_INTERRUPT, reg_values, len) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED;
count += sprintf(dump + count, "0x60 ");
for(int i = 0; i < len; i++)
count += sprintf(dump + count, "%02X ", reg_values[i]);
return UPM_SUCCESS;
return UPM_SUCCESS;
}

View File

@ -31,274 +31,274 @@ using namespace upm;
void BH1749::CheckWhoAmI()
{
if(bh1749_check_who_am_i(m_bh1749) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_check_who_am_i() failed");
if(bh1749_check_who_am_i(m_bh1749) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_check_who_am_i() failed");
}
BH1749::BH1749(int bus, int addr) : m_bh1749(bh1749_init(bus, addr))
{
if(!m_bh1749)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_init() failed");
if(!m_bh1749)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_init() failed");
}
BH1749::~BH1749()
{
bh1749_close(m_bh1749);
bh1749_close(m_bh1749);
}
void BH1749::Enable()
{
if(bh1749_enable(m_bh1749) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_enable() failed");
if(bh1749_enable(m_bh1749) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_enable() failed");
}
void BH1749::Disable()
{
if(bh1749_disable(m_bh1749) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_disable() failed");
if(bh1749_disable(m_bh1749) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_disable() failed");
}
void BH1749::SensorInit(OPERATING_MODES opMode,
MEAS_TIMES measTime,
RGB_GAINS rgbGain,
IR_GAINS irGain,
INT_SOURCES intSource)
MEAS_TIMES measTime,
RGB_GAINS rgbGain,
IR_GAINS irGain,
INT_SOURCES intSource)
{
if(bh1749_sensor_init(m_bh1749, opMode, measTime, rgbGain, irGain, intSource) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_sensor_init() failed");
if(bh1749_sensor_init(m_bh1749, opMode, measTime, rgbGain, irGain, intSource) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_sensor_init() failed");
}
void BH1749::SetOperatingMode(OPERATING_MODES opMode)
{
if(bh1749_set_operating_mode(m_bh1749, opMode) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_set_operating_mode() failed");
if(bh1749_set_operating_mode(m_bh1749, opMode) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_set_operating_mode() failed");
}
int BH1749::GetOperatingMode()
{
uint8_t opMode;
if(bh1749_get_operating_mode(m_bh1749, &opMode) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_get_operating_mode() failed");
return opMode;
uint8_t opMode;
if(bh1749_get_operating_mode(m_bh1749, &opMode) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_get_operating_mode() failed");
return opMode;
}
void BH1749::SetMeasurementTime(MEAS_TIMES measTime)
{
if(bh1749_set_measurement_time(m_bh1749, measTime) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_set_measurement_time() failed");
if(bh1749_set_measurement_time(m_bh1749, measTime) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_set_measurement_time() failed");
}
int BH1749::GetMeasurementTime()
{
uint8_t measTime;
if(bh1749_get_measurement_time(m_bh1749, &measTime) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_get_measurement_time() failed");
return measTime;
uint8_t measTime;
if(bh1749_get_measurement_time(m_bh1749, &measTime) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_get_measurement_time() failed");
return measTime;
}
void BH1749::SetRgbGain(RGB_GAINS rgbGain)
{
if(bh1749_set_rgb_gain(m_bh1749, rgbGain) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_set_rgb_gain() failed");
if(bh1749_set_rgb_gain(m_bh1749, rgbGain) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_set_rgb_gain() failed");
}
int BH1749::GetRgbGain()
{
uint8_t rgbGain;
if(bh1749_get_rgb_gain(m_bh1749, &rgbGain) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_get_rgb_gain() failed");
return rgbGain;
uint8_t rgbGain;
if(bh1749_get_rgb_gain(m_bh1749, &rgbGain) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_get_rgb_gain() failed");
return rgbGain;
}
void BH1749::SetIrGain(IR_GAINS irGain)
{
if(bh1749_set_ir_gain(m_bh1749, irGain) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_set_ir_gain() failed");
if(bh1749_set_ir_gain(m_bh1749, irGain) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_set_ir_gain() failed");
}
int BH1749::GetIrGain()
{
uint8_t irGain;
if(bh1749_get_ir_gain(m_bh1749, &irGain) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_get_ir_gain() failed");
return irGain;
uint8_t irGain;
if(bh1749_get_ir_gain(m_bh1749, &irGain) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_get_ir_gain() failed");
return irGain;
}
void BH1749::SetIntSource(INT_SOURCES intSource)
{
if(bh1749_set_int_source(m_bh1749, intSource) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_set_int_source() failed");
if(bh1749_set_int_source(m_bh1749, intSource) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_set_int_source() failed");
}
char BH1749::GetInterruptSourceChar()
{
char intSource = bh1749_get_interrupt_source_char(m_bh1749);
if( intSource == ' ')
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_get_interrupt_source_char() failed");
return intSource;
char intSource = bh1749_get_interrupt_source_char(m_bh1749);
if( intSource == ' ')
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_get_interrupt_source_char() failed");
return intSource;
}
void BH1749::EnableInterrupt()
{
if(bh1749_enable_interrupt(m_bh1749) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_enable_interrupt() failed");
if(bh1749_enable_interrupt(m_bh1749) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_enable_interrupt() failed");
}
void BH1749::DisableInterrupt()
{
if(bh1749_disable_interrupt(m_bh1749) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_disable_interrupt() failed");
if(bh1749_disable_interrupt(m_bh1749) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_disable_interrupt() failed");
}
void BH1749::ResetInterrupt()
{
if(bh1749_reset_interrupt(m_bh1749) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_reset_interrupt() failed");
if(bh1749_reset_interrupt(m_bh1749) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_reset_interrupt() failed");
}
bool BH1749::IsInterrupted()
{
return bh1749_is_interrupted(m_bh1749);
return bh1749_is_interrupted(m_bh1749);
}
bool BH1749::IsInterruptEnabled()
{
return bh1749_is_interrupt_enabled(m_bh1749);
return bh1749_is_interrupt_enabled(m_bh1749);
}
void BH1749::SoftReset()
{
if(bh1749_soft_reset(m_bh1749) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_soft_reset() failed");
if(bh1749_soft_reset(m_bh1749) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_soft_reset() failed");
}
void BH1749::SetThresholdHigh(uint16_t threshold)
{
if(bh1749_set_threshold_high(m_bh1749, threshold) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_set_threshold_high() failed");
if(bh1749_set_threshold_high(m_bh1749, threshold) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_set_threshold_high() failed");
}
int BH1749::GetThresholdHigh()
{
uint16_t threhold;
if(bh1749_get_threshold_high(m_bh1749, &threhold) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_get_threshold_high() failed");
return threhold;
uint16_t threhold;
if(bh1749_get_threshold_high(m_bh1749, &threhold) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_get_threshold_high() failed");
return threhold;
}
void BH1749::SetThresholdLow(uint16_t threshold)
{
if(bh1749_set_threshold_low(m_bh1749, threshold) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_set_threshold_low() failed");
if(bh1749_set_threshold_low(m_bh1749, threshold) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_set_threshold_low() failed");
}
int BH1749::GetThresholdLow()
{
uint16_t threhold;
if(bh1749_get_threshold_low(m_bh1749, &threhold) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_get_threshold_low() failed");
return threhold;
uint16_t threhold;
if(bh1749_get_threshold_low(m_bh1749, &threhold) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_get_threshold_low() failed");
return threhold;
}
uint16_t BH1749::GetRed()
{
uint16_t red;
if(bh1749_get_red(m_bh1749, &red) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_get_red() failed");
return red;
uint16_t red;
if(bh1749_get_red(m_bh1749, &red) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_get_red() failed");
return red;
}
uint16_t BH1749::GetGreen()
{
uint16_t green;
if(bh1749_get_green(m_bh1749, &green) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_get_green() failed");
return green;
uint16_t green;
if(bh1749_get_green(m_bh1749, &green) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_get_green() failed");
return green;
}
uint16_t BH1749::GetBlue()
{
uint16_t blue;
if(bh1749_get_blue(m_bh1749, &blue) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_get_blue() failed");
return blue;
uint16_t blue;
if(bh1749_get_blue(m_bh1749, &blue) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_get_blue() failed");
return blue;
}
uint16_t BH1749::GetIr()
{
uint16_t ir;
if(bh1749_get_ir(m_bh1749, &ir) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_get_ir() failed");
return ir;
uint16_t ir;
if(bh1749_get_ir(m_bh1749, &ir) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_get_ir() failed");
return ir;
}
uint16_t BH1749::GetGeen2()
{
uint16_t green2;
if(bh1749_get_green2(m_bh1749, &green2) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_get_green2() failed");
return green2;
uint16_t green2;
if(bh1749_get_green2(m_bh1749, &green2) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_get_green2() failed");
return green2;
}
std::vector<uint16_t> BH1749::GetMeasurements()
{
uint16_t res[5];
if(bh1749_get_measurements(m_bh1749, res) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_get_measurements() failed");
uint16_t res[5];
if(bh1749_get_measurements(m_bh1749, res) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_get_measurements() failed");
std::vector<uint16_t> result(res, res + sizeof res / sizeof res[0]);
return result;
std::vector<uint16_t> result(res, res + sizeof res / sizeof res[0]);
return result;
}
void BH1749::InstallISR(mraa_gpio_edge_t edge, int pin, void (*isr)(void *), void *isr_args)
{
if(bh1749_install_isr(m_bh1749, edge, pin, isr, isr_args) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_install_isr() failed");
if(bh1749_install_isr(m_bh1749, edge, pin, isr, isr_args) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_install_isr() failed");
}
void BH1749::RemoveISR()
{
bh1749_remove_isr(m_bh1749);
bh1749_remove_isr(m_bh1749);
}
std::string BH1749::RegistersDump()
{
char dump[255];
std::string dumpStr;
char dump[255];
std::string dumpStr;
if(bh1749_registers_dump(m_bh1749, dump) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_registers_dump() failed");
dumpStr = dump;
return dumpStr;
if(bh1749_registers_dump(m_bh1749, dump) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_registers_dump() failed");
dumpStr = dump;
return dumpStr;
}

View File

@ -36,63 +36,55 @@ extern "C"
#include "bh1749_registers.h"
/**
* @brief C API for the bh1749 color sensor driver
* @defgroup bh1749 libupm-bh1749
* @ingroup ROHM i2c color
*/
/**
* @file bh1749.h
* @library bh1749
* @sensor bh1749
* @comname ROHM Color Sensor
* @type color
* @man ROHM
* @con i2c
*
* @brief C API for the bh1749 driver
*
* @include bh1749.c
*/
/**
* @brief Operation modes enum for interrupt modes (persistance)
*/
typedef enum {
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,
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,
} OPERATING_MODES;
/**
* @brief Measuremnt time choices
*/
typedef enum {
MEAS_35MS = BH1749_MODE_CONTROL1_ODR_28P6,
MEAS_120MS = BH1749_MODE_CONTROL1_ODR_8P333,
MEAS_240MS = BH1749_MODE_CONTROL1_ODR_4P167
MEAS_35MS = BH1749_MODE_CONTROL1_ODR_28P6,
MEAS_120MS = BH1749_MODE_CONTROL1_ODR_8P333,
MEAS_240MS = BH1749_MODE_CONTROL1_ODR_4P167
} MEAS_TIMES;
/**
* @brief RGB gain choices
*/
typedef enum {
RGB_GAIN_1X = BH1749_MODE_CONTROL1_RGB_GAIN_1X,
RGB_GAIN_32X = BH1749_MODE_CONTROL1_RGB_GAIN_32X
RGB_GAIN_1X = BH1749_MODE_CONTROL1_RGB_GAIN_1X,
RGB_GAIN_32X = BH1749_MODE_CONTROL1_RGB_GAIN_32X
} RGB_GAINS;
/**
* @brief IR gain choices
*/
typedef enum {
IR_GAIN_1X = BH1749_MODE_CONTROL1_IR_GAIN_1X,
IR_GAIN_32X = BH1749_MODE_CONTROL1_IR_GAIN_32X
IR_GAIN_1X = BH1749_MODE_CONTROL1_IR_GAIN_1X,
IR_GAIN_32X = BH1749_MODE_CONTROL1_IR_GAIN_32X
} IR_GAINS;
/**
* @brief Interrupt source choices
*/
typedef enum {
RED = BH1749_INTERRUPT_SOURCE_SELECT_RED,
GREEN = BH1749_INTERRUPT_SOURCE_SELECT_GREEN,
BLUE = BH1749_INTERRUPT_SOURCE_SELECT_BLUE
RED = BH1749_INTERRUPT_SOURCE_SELECT_RED,
GREEN = BH1749_INTERRUPT_SOURCE_SELECT_GREEN,
BLUE = BH1749_INTERRUPT_SOURCE_SELECT_BLUE
} INT_SOURCES;
/**
@ -100,32 +92,32 @@ typedef enum {
*/
typedef struct _bh1749_context
{
mraa_i2c_context i2c;
mraa_gpio_context interrupt;
bool enabled;
bool isrEnabled;
uint16_t int_thh;
uint16_t int_thl;
INT_SOURCES int_src;
IR_GAINS ir_gain;
RGB_GAINS rgb_gain;
MEAS_TIMES meas_time;
OPERATING_MODES operating_mode;
mraa_i2c_context i2c;
mraa_gpio_context interrupt;
bool enabled;
bool isrEnabled;
uint16_t int_thh;
uint16_t int_thl;
INT_SOURCES int_src;
IR_GAINS ir_gain;
RGB_GAINS rgb_gain;
MEAS_TIMES meas_time;
OPERATING_MODES operating_mode;
} *bh1749_context;
/**
* @brief Check "who am I" register value to identify the sensor
*
*
* @param dev Sensor context
* @return UPM result
*/
upm_result_t bh1749_check_who_am_i(bh1749_context dev);
/**
* @brief Init the sensor with specific bus and address. This function calls
* @brief 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.
*
*
* @param bus I2C bus number
* @param addr I2C sensor address
* @return context of initialized sensor
@ -134,14 +126,14 @@ bh1749_context bh1749_init(int bus, int addr);
/**
* @brief Close and free sensor context
*
*
* @param dev Sensor context
*/
void bh1749_close(bh1749_context dev);
/**
* @brief Enables RGB color measurement on the sensor
*
*
* @param dev Sensor context
* @return UPM result
*/
@ -149,7 +141,7 @@ upm_result_t bh1749_enable(bh1749_context dev);
/**
* @brief Disables RGB color measurement on the sensor
*
*
* @param dev Sensor context
* @return UPM result
*/
@ -157,7 +149,7 @@ upm_result_t bh1749_disable(bh1749_context dev);
/**
* @brief Initializes (writes) configuration values to sensor
*
*
* @param dev Sensor context
* @param opMode Operating mode choice, a value of OPERATING_MODES enum
* @param measTime Measurement time choice, a value of MEAS_TIMES enum
@ -167,14 +159,14 @@ upm_result_t bh1749_disable(bh1749_context dev);
* @return UPM result
*/
upm_result_t bh1749_sensor_init(bh1749_context dev, OPERATING_MODES opMode,
MEAS_TIMES measTime,
RGB_GAINS rgbGain,
IR_GAINS irGain,
INT_SOURCES intSource);
MEAS_TIMES measTime,
RGB_GAINS rgbGain,
IR_GAINS irGain,
INT_SOURCES intSource);
/**
* @brief Sets operating mode (interrupt persistance)
*
*
* @param dev Sensor context
* @param opMode Operating mode choice, a value of OPERATING_MODES enum
* @return UPM result
@ -183,7 +175,7 @@ upm_result_t bh1749_set_operating_mode(bh1749_context dev, OPERATING_MODES opMod
/**
* @brief Gets operating mode (interrupt persistance) value
*
*
* @param dev Sensor context
* @param opMode pointer (uint8_t) to save value
* @return UPM result
@ -192,7 +184,7 @@ upm_result_t bh1749_get_operating_mode(bh1749_context dev, uint8_t *opMode);
/**
* @brief Sets measurement time (ODR)
*
*
* @param dev Sensor context
* @param measTime measurement time choice, a value of MEAS_TIMES enum
* @return UPM result
@ -201,7 +193,7 @@ upm_result_t bh1749_set_measurement_time(bh1749_context dev, MEAS_TIMES measTime
/**
* @brief Sets measurement time (ODR)
*
*
* @param dev Sensor context
* @param meas_time pointer (uint8_t) to save value
* @return UPM result
@ -210,7 +202,7 @@ upm_result_t bh1749_get_measurement_time(bh1749_context dev, uint8_t *meas_time)
/**
* @brief Sets RGB gain values
*
*
* @param dev Sensor context
* @param rgbGain RGB gain choice, a value of RGB_GAINS enum
* @return UPM result
@ -219,7 +211,7 @@ upm_result_t bh1749_set_rgb_gain(bh1749_context dev, RGB_GAINS rgbGain);
/**
* @brief Gets RGB gain value
*
*
* @param dev Sensor context
* @param gain pointer (uint8_t) to save value
* @return UPM result
@ -228,7 +220,7 @@ upm_result_t bh1749_get_rgb_gain(bh1749_context dev, uint8_t *gain);
/**
* @brief Sets IR gain values
*
*
* @param dev Sensor context
* @param irGain IR gain choice, a value of IR_GAINS enum
* @return UPM result
@ -237,7 +229,7 @@ upm_result_t bh1749_set_ir_gain(bh1749_context dev, IR_GAINS irGain);
/**
* @brief Gets IR gain value
*
*
* @param dev Sensor context
* @param gain pointer (uint8_t) to save value
* @return UPM result
@ -246,7 +238,7 @@ upm_result_t bh1749_get_ir_gain(bh1749_context dev, uint8_t *gain);
/**
* @brief Sets interrupt source value
*
*
* @param dev Sensor context
* @param intSource interrupt source choice, a value of INT_SOURCES enum
* @return UPM result
@ -255,7 +247,7 @@ upm_result_t bh1749_set_int_source(bh1749_context dev, INT_SOURCES intSource);
/**
* @brief Gets interrupt source value
*
*
* @param dev Sensor context
* @return character of interrupt source
*/
@ -263,7 +255,7 @@ char bh1749_get_interrupt_source_char(bh1749_context dev);
/**
* @brief Enables interrupt mode and resets the interrupt status (clear)
*
*
* @param dev Sensor context
* @return UPM result
*/
@ -271,7 +263,7 @@ upm_result_t bh1749_enable_interrupt(bh1749_context dev);
/**
* @brief Disables interrupt mode
*
*
* @param dev Sensor context
* @return UPM result
*/
@ -279,7 +271,7 @@ upm_result_t bh1749_disable_interrupt(bh1749_context dev);
/**
* @brief Resets interrupt status (clear) to allow new interrupts
*
*
* @param dev Sensor context
* @return UPM result
*/
@ -287,7 +279,7 @@ upm_result_t bh1749_reset_interrupt(bh1749_context dev);
/**
* @brief Checks the status of the interrupt
*
*
* @param dev Sensor context
* @return true if there is interrupt, otherwise false
*/
@ -295,7 +287,7 @@ bool bh1749_is_interrupted(bh1749_context dev);
/**
* @brief Checks whether interrupt mode is enabled
*
*
* @param dev Sensor context
* @return true if interrupt is enabled, otherwise false
*/
@ -305,7 +297,7 @@ bool bh1749_is_interrupt_enabled(bh1749_context dev);
* @brief 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.
*
*
* @param dev Sensor context
* @return UPM result
*/
@ -313,7 +305,7 @@ upm_result_t bh1749_soft_reset(bh1749_context dev);
/**
* @brief Sets interrupt threshold high value
*
*
* @param dev Sensor context
* @param threshold Value to be written, range 0-65536
* @return UPM result
@ -322,7 +314,7 @@ upm_result_t bh1749_set_threshold_high(bh1749_context dev, uint16_t threshold);
/**
* @brief Gets interrupt threshold high value
*
*
* @param dev Sensor context
* @param threshold Pointer (uint16_t) to write value
* @return UPM result
@ -331,7 +323,7 @@ upm_result_t bh1749_get_threshold_high(bh1749_context dev, uint16_t *threshold);
/**
* @brief Sets interrupt threshold low value
*
*
* @param dev Sensor context
* @param threshold Value to be written, range 0-65536
* @return UPM result
@ -340,7 +332,7 @@ upm_result_t bh1749_set_threshold_low(bh1749_context dev, uint16_t threshold);
/**
* @brief Gets interrupt threshold low value
*
*
* @param dev Sensor context
* @param threshold Pointer (uint16_t) to write value
* @return UPM result
@ -349,7 +341,7 @@ upm_result_t bh1749_get_threshold_low(bh1749_context dev, uint16_t *threshold);
/**
* @brief Gets value of Red color channel
*
*
* @param dev Sensor context
* @param red Pointer (uint16_t) to write value
* @return UPM result
@ -358,7 +350,7 @@ upm_result_t bh1749_get_red(bh1749_context dev, uint16_t *red);
/**
* @brief Gets value of Green color channel
*
*
* @param dev Sensor context
* @param green Pointer (uint16_t) to write value
* @return UPM result
@ -367,7 +359,7 @@ upm_result_t bh1749_get_green(bh1749_context dev, uint16_t *green);
/**
* @brief Gets value of Blue color channel
*
*
* @param dev Sensor context
* @param blue Pointer (uint16_t) to write value
* @return UPM result
@ -376,7 +368,7 @@ upm_result_t bh1749_get_blue(bh1749_context dev, uint16_t *blue);
/**
* @brief Gets value of IR color channel
*
*
* @param dev Sensor context
* @param ir Pointer (uint16_t) to write value
* @return UPM result
@ -385,7 +377,7 @@ upm_result_t bh1749_get_ir(bh1749_context dev, uint16_t *ir);
/**
* @brief Gets value of Green2 color channel
*
*
* @param dev Sensor context
* @param green Pointer (uint16_t) to write value
* @return UPM result
@ -394,18 +386,18 @@ upm_result_t bh1749_get_green2(bh1749_context dev, uint16_t *green2);
/**
* @brief Gets all channels measurements values
*
*
* @param dev Sensor context
* @param result Pointer of uint16_t to write all values ordered as:
* @param result Pointer of uint16_t to write all values ordered as:
* Red, Green, Blue, IR, Green2
*
*
* @return UPM result
*/
upm_result_t bh1749_get_measurements(bh1749_context dev, uint16_t *result);
/**
* @brief Installs the ISR to a given GPIO pin
*
*
* @param dev Sensor context
* @param edge Edge type to raise ISR with, of type mraa_gpio_edge_t
* @param pin GPIO pin number
@ -414,18 +406,18 @@ upm_result_t bh1749_get_measurements(bh1749_context dev, uint16_t *result);
* @return UPM result
*/
upm_result_t bh1749_install_isr(bh1749_context dev, mraa_gpio_edge_t edge, int pin,
void (*isr)(void *), void *isr_args);
void (*isr)(void *), void *isr_args);
/**
* @brief Removes the ISR if it is installed
*
*
* @param dev Sensor context
*/
void bh1749_remove_isr(bh1749_context dev);
/**
* @brief Gets a dump of configuration registers as a string
*
*
* @param dev Sensor context
* @param dump Pointer of char to save dump string
* @return UPM result

View File

@ -28,315 +28,318 @@
#include "bh1749.h"
/**
* @brief C++ API wrapper for the bh1749 color sensor driver
* @brief BH1749 Color Sensor
* @defgroup bh1749 libupm-bh1749
* @ingroup ROHM i2c color
* @ingroup rohm i2c color
*/
/**
* @library bh1749
* @sensor bh1749
* @comname Color Sensor
* @type color sensor
* @man ROHM
* @man rohm
* @con i2c
*
* @brief C++ API wrapper for the bh1749 driver
*
* @snippet bh1749.cxx Interesting
*/
namespace upm {
class BH1749 {
public:
/**
* @brief Initialize a sensor instance with bus and address.
*
* This calls SensorInit() to set default values for operating mode,
* gains, measurement time, interrupt source and then sets threshold
* high to 511.
*
* @param bus I2C bus number
* @param addr I2C sensor address
* @throws std::runtime_error on initialization failure
*/
BH1749(int bus = 0, int addr = 0x39);
class BH1749 {
public:
/**
* @brief Initialize a sensor instance with bus and address.
*
* This calls SensorInit() to set default values for operating mode,
* gains, measurement time, interrupt source and then sets threshold
* high to 511.
*
* @param bus I2C bus number
* @param addr I2C sensor address
* @throws std::runtime_error on initialization failure
*/
BH1749(int bus = 0, int addr = 0x39);
/**
* @brief Close and free sensor
*/
virtual ~BH1749();
/**
* @brief Close and free sensor
*/
virtual ~BH1749();
/**
* @brief Enables RGB color measurement on the sensor
*
* @throws std::runtime_error if bh1749_enable() fails
*/
void Enable();
/**
* @brief Enables RGB color measurement on the sensor
*
* @throws std::runtime_error if bh1749_enable() fails
*/
void Enable();
/**
* @brief Disables RGB color measurement on the sensor
*
* @throws std::runtime_error if bh1749_disable() fails
*/
void Disable();
/**
* @brief Disables RGB color measurement on the sensor
*
* @throws std::runtime_error if bh1749_disable() fails
*/
void Disable();
/**
* @brief Check "who am I" register value to identify the sensor
*
* @throws std::runtime_error if this value is incorrect
*/
void CheckWhoAmI();
/**
* @brief Check "who am I" register value to identify the sensor
*
* @throws std::runtime_error if this value is incorrect
*/
void CheckWhoAmI();
/**
* @brief Initializes (writes) configuration values to sensor
*
* @param opMode Operating mode choice, a value of OPERATING_MODES enum
* @param measTime Measurement time choice, a value of MEAS_TIMES enum
* @param rgbGain RGB gain choice, a value of RGB_GAINS enum
* @param irGain IR gain choice, a value of IR_GAINS enum
* @param intSource interrupt source choice, a value of INT_SOURCES enum
*
* @throws std::runtime_error if one of values setting fails
*/
void SensorInit(OPERATING_MODES opMode,
MEAS_TIMES measTime,
RGB_GAINS rgbGain,
IR_GAINS irGain,
INT_SOURCES intSource);
/**
* @brief Initializes (writes) configuration values to sensor
*
* @param opMode Operating mode choice, a value of OPERATING_MODES enum
* @param measTime Measurement time choice, a value of MEAS_TIMES enum
* @param rgbGain RGB gain choice, a value of RGB_GAINS enum
* @param irGain IR gain choice, a value of IR_GAINS enum
* @param intSource interrupt source choice, a value of INT_SOURCES enum
*
* @throws std::runtime_error if one of values setting fails
*/
void SensorInit(OPERATING_MODES opMode,
MEAS_TIMES measTime,
RGB_GAINS rgbGain,
IR_GAINS irGain,
INT_SOURCES intSource);
/**
* @brief Sets operating mode (interrupt persistance)
*
* @param opMode Operating mode choice, a value of OPERATING_MODES enum
* @throws std::runtime_error if writing value fails
*/
void SetOperatingMode(OPERATING_MODES opMode);
/**
* @brief Sets operating mode (interrupt persistance)
*
* @param opMode Operating mode choice, a value of OPERATING_MODES enum
* @throws std::runtime_error if writing value fails
*/
void SetOperatingMode(OPERATING_MODES opMode);
/**
* @brief Gets operating mode (interrupt persistance) value
*
* @param opMode pointer (uint8_t) to save value
* @return operating mode value
* @throws std::runtime_error if reading the value fails
*/
int GetOperatingMode();
/**
* @brief Gets operating mode (interrupt persistance) value
*
* @param opMode pointer (uint8_t) to save value
* @return operating mode value
* @throws std::runtime_error if reading the value fails
*/
int GetOperatingMode();
/**
* @brief Sets measurement time (ODR)
*
* @param measTime measurement time choice, a value of MEAS_TIMES enum
* @throws std::runtime_error if writing value fails
*/
void SetMeasurementTime(MEAS_TIMES measTime);
/**
* @brief Sets measurement time (ODR)
*
* @param measTime measurement time choice, a value of MEAS_TIMES enum
* @throws std::runtime_error if writing value fails
*/
void SetMeasurementTime(MEAS_TIMES measTime);
/**
* @brief Gets measurement time (ODR) value
*
* @return measurement time value
* @throws std::runtime_error if reading the value fails
*/
int GetMeasurementTime();
/**
* @brief Gets measurement time (ODR) value
*
* @return measurement time value
* @throws std::runtime_error if reading the value fails
*/
int GetMeasurementTime();
/**
* @brief Sets RGB gain value
*
* @param rgbGain RGB gain choice, a value of RGB_GAINS enum
* @throws std::runtime_error if writing value fails
*/
void SetRgbGain(RGB_GAINS rgbGain);
/**
* @brief Sets RGB gain value
*
* @param rgbGain RGB gain choice, a value of RGB_GAINS enum
* @throws std::runtime_error if writing value fails
*/
void SetRgbGain(RGB_GAINS rgbGain);
/**
* @brief Gets RGB gain value
*
* @return RGB gain value value
* @throws std::runtime_error if reading the value fails
*/
int GetRgbGain();
/**
* @brief Gets RGB gain value
*
* @return RGB gain value value
* @throws std::runtime_error if reading the value fails
*/
int GetRgbGain();
/**
* @brief Sets IR gain value
*
* @param irGain IR gain choice, a value of IR_GAINS enum
* @throws std::runtime_error if writing value fails
*/
void SetIrGain(IR_GAINS irGain);
/**
* @brief Sets IR gain value
*
* @param irGain IR gain choice, a value of IR_GAINS enum
* @throws std::runtime_error if writing value fails
*/
void SetIrGain(IR_GAINS irGain);
/**
* @brief Gets IR gain value
*
* @return IR gain value value
* @throws std::runtime_error if reading the value fails
*/
int GetIrGain();
/**
* @brief Gets IR gain value
*
* @return IR gain value value
* @throws std::runtime_error if reading the value fails
*/
int GetIrGain();
/**
* @brief Sets interrupt source value
*
* @param intSource interrupt source choice, a value of INT_SOURCES enum
* @throws std::runtime_error if writing value fails
*/
void SetIntSource(INT_SOURCES intSource);
/**
* @brief Sets interrupt source value
*
* @param intSource interrupt source choice, a value of INT_SOURCES enum
* @throws std::runtime_error if writing value fails
*/
void SetIntSource(INT_SOURCES intSource);
/**
* @brief Gets interrupt source value
*
* @return interrupt source value
* @throws std::runtime_error if reading the value fails
*/
char GetInterruptSourceChar();
/**
* @brief Gets interrupt source value
*
* @return interrupt source value
* @throws std::runtime_error if reading the value fails
*/
char GetInterruptSourceChar();
/**
* @brief Enables interrupt mode
*
* @throws std::runtime_error if writing enable bit fails
*/
void EnableInterrupt();
/**
* @brief Enables interrupt mode
*
* @throws std::runtime_error if writing enable bit fails
*/
void EnableInterrupt();
/**
* @brief Disables interrupt mode
*
* @throws std::runtime_error if writing disable bit fails
*/
void DisableInterrupt();
/**
* @brief Disables interrupt mode
*
* @throws std::runtime_error if writing disable bit fails
*/
void DisableInterrupt();
/**
* @brief Resets interrupt status (clear) to allow new interrupt reads
*
* @throws std::runtime_error if writing reset bit fails
*/
void ResetInterrupt();
/**
* @brief Resets interrupt status (clear) to allow new interrupt reads
*
* @throws std::runtime_error if writing reset bit fails
*/
void ResetInterrupt();
/**
* @brief Gets interrupt status, whether interrupt is raised or not
*
* @return true if interrupt is raised, otherwise false
*/
bool IsInterrupted();
/**
* @brief Gets interrupt status, whether interrupt is raised or not
*
* @return true if interrupt is raised, otherwise false
*/
bool IsInterrupted();
/**
* @brief Gets interrupt mode status
*
* @return true if interrupt is enabled, otherwise false
*/
bool IsInterruptEnabled();
/**
* @brief Gets interrupt mode status
*
* @return true if interrupt is enabled, otherwise false
*/
bool IsInterruptEnabled();
/**
* @brief 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.
*
* @throws std::runtime_error if writing reset bit fails
*/
void SoftReset();
/**
* @brief 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.
*
* @throws std::runtime_error if writing reset bit fails
*/
void SoftReset();
/**
* @brief Sets threshold high value
*
* @param threshold interrupt threshold high value, range 0-65536
* @throws std::runtime_error if writing value fails
*/
void SetThresholdHigh(uint16_t threshold);
/**
* @brief Sets threshold high value
*
* @param threshold interrupt threshold high value, range 0-65536
* @throws std::runtime_error if writing value fails
*/
void SetThresholdHigh(uint16_t threshold);
/**
* @brief Gets threshold high value
*
* @return threshold high value
* @throws std::runtime_error if reading the value fails
*/
int GetThresholdHigh();
/**
* @brief Gets threshold high value
*
* @return threshold high value
* @throws std::runtime_error if reading the value fails
*/
int GetThresholdHigh();
/**
* @brief Sets threshold low value
*
* @param threshold interrupt threshold low value, range 0-65536
* @throws std::runtime_error if writing value fails
*/
void SetThresholdLow(uint16_t threshold);
/**
* @brief Sets threshold low value
*
* @param threshold interrupt threshold low value, range 0-65536
* @throws std::runtime_error if writing value fails
*/
void SetThresholdLow(uint16_t threshold);
/**
* @brief Gets threshold low value
*
* @return threshold low value
* @throws std::runtime_error if reading the value fails
*/
int GetThresholdLow();
/**
* @brief Gets threshold low value
*
* @return threshold low value
* @throws std::runtime_error if reading the value fails
*/
int GetThresholdLow();
/**
* @brief Gets value of Red color channel
*
* @return red channel value
* @throws std::runtime_error if reading the value fails
*/
uint16_t GetRed();
/**
* @brief Gets value of Red color channel
*
* @return red channel value
* @throws std::runtime_error if reading the value fails
*/
uint16_t GetRed();
/**
* @brief Gets value of Green color channel
*
* @return green channel value
* @throws std::runtime_error if reading the value fails
*/
uint16_t GetGreen();
/**
* @brief Gets value of Green color channel
*
* @return green channel value
* @throws std::runtime_error if reading the value fails
*/
uint16_t GetGreen();
/**
* @brief Gets value of Blue color channel
*
* @return blue channel value
* @throws std::runtime_error if reading the value fails
*/
uint16_t GetBlue();
/**
* @brief Gets value of Blue color channel
*
* @return blue channel value
* @throws std::runtime_error if reading the value fails
*/
uint16_t GetBlue();
/**
* @brief Gets value of IR color channel
*
* @return ir channel value
* @throws std::runtime_error if reading the value fails
*/
uint16_t GetIr();
/**
* @brief Gets value of IR color channel
*
* @return ir channel value
* @throws std::runtime_error if reading the value fails
*/
uint16_t GetIr();
/**
* @brief Gets value of Green2 color channel
*
* @return green2 channel value
* @throws std::runtime_error if reading the value fails
*/
uint16_t GetGeen2();
/**
* @brief Gets value of Green2 color channel
*
* @return green2 channel value
* @throws std::runtime_error if reading the value fails
*/
uint16_t GetGeen2();
/**
* @brief Gets all channels measurements values
*
* @return vector with all channels values ordered as:
* Red, Green, Blue, IR, Green2
* @throws std::runtime_error if reading one of the values fails
*/
std::vector<uint16_t> GetMeasurements();
/**
* @brief Gets all channels measurements values
*
* @return vector with all channels values ordered as:
* Red, Green, Blue, IR, Green2
* @throws std::runtime_error if reading one of the values fails
*/
std::vector<uint16_t> GetMeasurements();
/**
* @brief Installs the ISR to a given GPIO pin
*
* @param edge Edge type to raise ISR with, of type mraa_gpio_edge_t
* @param pin GPIO pin number
* @param isr Pointer to ISR function
* @param isr_args Arguments to pass the ISR function
* @throws std::runtime_error if installing ISR fails
*/
void InstallISR(mraa_gpio_edge_t edge, int pin, void (*isr)(void *), void *isr_args);
/**
* @brief Removes the ISR if it is installed
*/
void RemoveISR();
/**
* @brief Installs the ISR to a given GPIO pin
*
* @param edge Edge type to raise ISR with, of type mraa_gpio_edge_t
* @param pin GPIO pin number
* @param isr Pointer to ISR function
* @param isr_args Arguments to pass the ISR function
* @throws std::runtime_error if installing ISR fails
*/
void InstallISR(mraa_gpio_edge_t edge, int pin, void (*isr)(void *), void *isr_args);
/**
* @brief Gets a dump of configuration registers as a string
*
* @return string of dumped registers
* @throws std::runtime_error if reading one of the registers fails
*/
std::string RegistersDump();
/**
* @brief Removes the ISR if it is installed
*/
void RemoveISR();
private:
bh1749_context m_bh1749;
/**
* @brief Gets a dump of configuration registers as a string
*
* @return string of dumped registers
* @throws std::runtime_error if reading one of the registers fails
*/
std::string RegistersDump();
/* Disable implicit copy and assignment operators */
BH1749(const BH1749 &) = delete;
BH1749 &operator=(const BH1749 &) = delete;
};
private:
bh1749_context m_bh1749;
/* Disable implicit copy and assignment operators */
BH1749(const BH1749 &) = delete;
BH1749 &operator=(const BH1749 &) = delete;
};
}

View File

@ -32,9 +32,9 @@
"min": -40,
"max": 85
}, "Illumination Detection": {
"unit" : "klx",
"value": 80
}
"unit" : "klx",
"value": 80
}
},
"Urls": {
"Product Pages": [

View File

@ -139,7 +139,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#define BH1749_MODE_CONTROL1_IR_GAIN_MASK 0x60
#define BH1749_MODE_CONTROL1_RGB_GAIN_MASK 0x18
#define BH1749_MODE_CONTROL1_ODR_MASK 0x07
// Measurement data update flag. Sets to 0 if MODE_CONTROL1/2 reg,
// Measurement data update flag. Sets to 0 if MODE_CONTROL1/2 reg,
// MODE_CONTROL2, INTERRUPT, T(H/L)_(LSB/MSB) is written or
// MODE_CONTROL2 read. In specification named as VALID.
#define BH1749_MODE_CONTROL2_VALID_MASK 0x80

View File

@ -36,7 +36,7 @@ namespace upm {
/**
* @brief BH1750 Light Sensor
* @defgroup bh1750 libupm-bh1750
* @ingroup dfrobot i2c
* @ingroup rohm dfrobot i2c
*/
/**
@ -44,7 +44,7 @@ namespace upm {
* @sensor bh1750
* @comname Digital Light Sensor
* @type light
* @man dfrobot
* @man rohm dfrobot
* @con i2c
* @web http://www.dfrobot.com/index.php?route=product/product&product_id=531
*
@ -63,7 +63,7 @@ namespace upm {
/**
* BH1750 object constructor (Analog mode)
*
* @param bus The I2C bus to use
* @param bus The I2C bus to use
* @param addr The I2C address of the device
* @param mode The mode to start operation under. One of the
* BH1750_OPMODES_T values. The default is the highest precision,

File diff suppressed because it is too large Load Diff

View File

@ -30,276 +30,276 @@ using namespace upm;
BH1792::BH1792(int bus, int addr) : m_bh1792(bh1792_init(bus, addr))
{
if(!m_bh1792)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_init() failed");
if(!m_bh1792)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_init() failed");
}
BH1792::~BH1792()
{
bh1792_close(m_bh1792);
bh1792_close(m_bh1792);
}
void BH1792::CheckWhoAmI()
{
if(bh1792_check_who_am_i(m_bh1792) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_check_who_am_i() failed");
if(bh1792_check_who_am_i(m_bh1792) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_check_who_am_i() failed");
}
bool BH1792::IsEnabled()
{
return bh1792_is_enabled(m_bh1792);
return bh1792_is_enabled(m_bh1792);
}
void BH1792::SoftReset()
{
if(bh1792_soft_reset(m_bh1792) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_soft_reset() failed");
if(bh1792_soft_reset(m_bh1792) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_soft_reset() failed");
}
float BH1792::GetMeasurementTimeMS()
{
float meas_time;
float meas_time;
if(bh1792_get_meas_time_ms(m_bh1792, &meas_time) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_get_meas_time_ms() failed");
if(bh1792_get_meas_time_ms(m_bh1792, &meas_time) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_get_meas_time_ms() failed");
return meas_time;
return meas_time;
}
void BH1792::SetGreenLedsCurrent(uint16_t current)
{
uint8_t status;
uint8_t status;
status = bh1792_set_green_leds_current(m_bh1792, current);
if(status == UPM_ERROR_OUT_OF_RANGE) {
throw std::range_error(std::string(__FUNCTION__) +
"bh1792_set_green_leds_current() failed, current not in range");
} else if(status != UPM_SUCCESS) {
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_set_green_leds_current() failed");
}
status = bh1792_set_green_leds_current(m_bh1792, current);
if(status == UPM_ERROR_OUT_OF_RANGE) {
throw std::range_error(std::string(__FUNCTION__) +
"bh1792_set_green_leds_current() failed, current not in range");
} else if(status != UPM_SUCCESS) {
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_set_green_leds_current() failed");
}
}
int BH1792::GetGreenLedsCurrent()
{
uint8_t current;
uint8_t current;
if(bh1792_get_green_leds_current(m_bh1792, &current) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_get_green_leds_current() failed");
if(bh1792_get_green_leds_current(m_bh1792, &current) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_get_green_leds_current() failed");
return (int)current;
return (int)current;
}
void BH1792::SetIrLedCurrent(uint16_t current)
{
uint8_t status;
uint8_t status;
status = bh1792_set_ir_led_current(m_bh1792, current);
if(status == UPM_ERROR_OUT_OF_RANGE) {
throw std::range_error(std::string(__FUNCTION__) +
"bh1792_set_ir_led_current() failed, current not in range");
} else if(status != UPM_SUCCESS) {
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_set_ir_led_current() failed");
}
status = bh1792_set_ir_led_current(m_bh1792, current);
if(status == UPM_ERROR_OUT_OF_RANGE) {
throw std::range_error(std::string(__FUNCTION__) +
"bh1792_set_ir_led_current() failed, current not in range");
} else if(status != UPM_SUCCESS) {
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_set_ir_led_current() failed");
}
}
int BH1792::GetIrLedCurrent()
{
uint8_t current;
uint8_t current;
if(bh1792_get_ir_led_current(m_bh1792, &current) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_get_ir_led_current() failed");
if(bh1792_get_ir_led_current(m_bh1792, &current) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_get_ir_led_current() failed");
return (int)current;
return (int)current;
}
void BH1792::SetIrThreshold(uint16_t threshold)
{
if(bh1792_set_ir_threshold(m_bh1792, threshold) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_set_ir_threshold() failed");
if(bh1792_set_ir_threshold(m_bh1792, threshold) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_set_ir_threshold() failed");
}
int BH1792::GetIrThreshold()
{
uint16_t threshold;
uint16_t threshold;
if(bh1792_get_ir_threshold(m_bh1792, &threshold) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_get_ir_threshold() failed");
if(bh1792_get_ir_threshold(m_bh1792, &threshold) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_get_ir_threshold() failed");
return (int)threshold;
return (int)threshold;
}
int BH1792::GetFifoSize()
{
uint8_t size;
uint8_t size;
if(bh1792_get_fifo_size(m_bh1792, &size) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_get_fifo_size() failed");
if(bh1792_get_fifo_size(m_bh1792, &size) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_get_fifo_size() failed");
return (int)size;
return (int)size;
}
void BH1792::DisableInterrupt()
{
if(bh1792_disable_interrupt(m_bh1792) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_disable_interrupt() failed");
if(bh1792_disable_interrupt(m_bh1792) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_disable_interrupt() failed");
}
void BH1792::ClearInterrupt()
{
if(bh1792_clear_interrupt(m_bh1792) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_clear_interrupt() failed");
if(bh1792_clear_interrupt(m_bh1792) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_clear_interrupt() failed");
}
void BH1792::StartMeasurement()
{
if(bh1792_start_measurement(m_bh1792) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_start_measurement() failed");
if(bh1792_start_measurement(m_bh1792) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_start_measurement() failed");
}
void BH1792::StopMeasurement()
{
if(bh1792_stop_measurement(m_bh1792) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_stop_measurement() failed");
if(bh1792_stop_measurement(m_bh1792) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_stop_measurement() failed");
}
void BH1792::RestartMeasurement()
{
if(bh1792_restart_measurement(m_bh1792) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_restart_measurement() failed");
if(bh1792_restart_measurement(m_bh1792) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_restart_measurement() failed");
}
std::vector<std::vector<int>> BH1792::GetFifoData()
{
uint16_t fifo_off[FIFO_WATERMARK], fifo_on[FIFO_WATERMARK];
uint16_t fifo_off[FIFO_WATERMARK], fifo_on[FIFO_WATERMARK];
if(bh1792_get_fifo_data(m_bh1792, fifo_off, fifo_on) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_get_fifo_data() failed");
std::vector<int> item;
std::vector<std::vector<int>> result;
item.reserve(2);
result.reserve(FIFO_WATERMARK);
for(int i = 0; i < FIFO_WATERMARK; i++) {
item.clear();
item.push_back(fifo_off[i]);
item.push_back(fifo_on[i]);
result.push_back(item);
}
if(bh1792_get_fifo_data(m_bh1792, fifo_off, fifo_on) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_get_fifo_data() failed");
return result;
std::vector<int> item;
std::vector<std::vector<int>> result;
item.reserve(2);
result.reserve(FIFO_WATERMARK);
for(int i = 0; i < FIFO_WATERMARK; i++) {
item.clear();
item.push_back(fifo_off[i]);
item.push_back(fifo_on[i]);
result.push_back(item);
}
return result;
}
void BH1792::DiscardFifoData()
{
if(bh1792_discard_fifo_data(m_bh1792) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_discard_fifo_data() failed");
if(bh1792_discard_fifo_data(m_bh1792) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_discard_fifo_data() failed");
}
std::vector<int> BH1792::GetGreenData()
{
uint16_t green_off, green_on;
uint16_t green_off, green_on;
if(bh1792_get_green_data(m_bh1792, &green_off, &green_on) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_get_green_data() failed");
if(bh1792_get_green_data(m_bh1792, &green_off, &green_on) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_get_green_data() failed");
std::vector<int> result;
result.reserve(2);
result.push_back(green_off);
result.push_back(green_on);
std::vector<int> result;
result.reserve(2);
result.push_back(green_off);
result.push_back(green_on);
return result;
return result;
}
std::vector<int> BH1792::GetIrData()
{
uint16_t ir_off, ir_on;
uint16_t ir_off, ir_on;
if(bh1792_get_ir_data(m_bh1792, &ir_off, &ir_on) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_get_ir_data() failed");
if(bh1792_get_ir_data(m_bh1792, &ir_off, &ir_on) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_get_ir_data() failed");
std::vector<int> result;
result.reserve(2);
result.push_back(ir_off);
result.push_back(ir_on);
std::vector<int> result;
result.reserve(2);
result.push_back(ir_off);
result.push_back(ir_on);
return result;
return result;
}
void BH1792::EnableSyncMode(uint16_t measFreq, uint16_t green_current)
{
uint8_t status;
uint8_t status;
status = bh1792_enable_sync_mode(m_bh1792, measFreq, green_current);
if(status == UPM_ERROR_INVALID_PARAMETER) {
throw std::invalid_argument(std::string(__FUNCTION__) +
"bh1792_enable_sync_mode() failed, invalid measurement frequncy");
} else if(status != UPM_SUCCESS) {
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_enable_sync_mode() failed");
}
status = bh1792_enable_sync_mode(m_bh1792, measFreq, green_current);
if(status == UPM_ERROR_INVALID_PARAMETER) {
throw std::invalid_argument(std::string(__FUNCTION__) +
"bh1792_enable_sync_mode() failed, invalid measurement frequncy");
} else if(status != UPM_SUCCESS) {
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_enable_sync_mode() failed");
}
}
void BH1792::EnableNonSyncMode(uint16_t ir_current, uint16_t threshold)
{
if(bh1792_enable_non_sync_mode(m_bh1792, ir_current, threshold) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_enable_non_sync_mode() failed");
if(bh1792_enable_non_sync_mode(m_bh1792, ir_current, threshold) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_enable_non_sync_mode() failed");
}
void BH1792::EnableSingleMode(LED_TYPES led_type, uint16_t current)
{
if(bh1792_enable_single_mode(m_bh1792, led_type, current) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_enable_single_mode() failed");
if(bh1792_enable_single_mode(m_bh1792, led_type, current) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_enable_single_mode() failed");
}
void BH1792::InstallISR(mraa_gpio_edge_t edge, int pin, void (*isr)(void *), void *isr_args)
{
if(bh1792_install_isr(m_bh1792, edge, pin, isr, isr_args) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_install_isr() failed");
if(bh1792_install_isr(m_bh1792, edge, pin, isr, isr_args) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_install_isr() failed");
}
void BH1792::InstallISR(int pin, void (*isr)(void *), void *isr_args)
{
if(bh1792_install_isr_falling_edge(m_bh1792, pin, isr, isr_args) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_install_isr_falling_edge() failed");
if(bh1792_install_isr_falling_edge(m_bh1792, pin, isr, isr_args) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_install_isr_falling_edge() failed");
}
void BH1792::RemoveISR()
{
bh1792_remove_isr(m_bh1792);
bh1792_remove_isr(m_bh1792);
}
std::string BH1792::RegistersDump()
{
char dump[255];
std::string dumpStr;
char dump[255];
std::string dumpStr;
if(bh1792_registers_dump(m_bh1792, dump) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_registers_dump() failed");
dumpStr = dump;
return dumpStr;
if(bh1792_registers_dump(m_bh1792, dump) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_registers_dump() failed");
dumpStr = dump;
return dumpStr;
}

View File

@ -37,19 +37,11 @@ extern "C"
#include "bh1792glc_registers.h"
/**
* @brief C API for the bh1792 Heart Rate sensor driver
* @defgroup bh1792 libupm-bh1792
* @ingroup ROHM i2c medical
*/
/**
* @file bh1792.h
* @library bh1792
* @sensor bh1792
* @comname Heart Rate Sensor
* @type medical
* @man ROHM
* @con i2c
* @brief C API for the bh1792 driver
*
* @brief C API for the bh1792 Heart Rate sensor driver
* @include bh1792.c
*/
#define ONE_SEC_IN_MIRCO_SEC 1000000
@ -61,40 +53,40 @@ extern "C"
* and single modes.
*/
typedef enum {
MSR_64Hz = BH1792_MEAS_CONTROL1_MSR_64HZ,
MSR_32Hz = BH1792_MEAS_CONTROL1_MSR_32HZ,
MSR_128Hz = BH1792_MEAS_CONTROL1_MSR_128HZ,
MSR_256Hz = BH1792_MEAS_CONTROL1_MSR_256HZ,
MSR_1024Hz = BH1792_MEAS_CONTROL1_MSR_1024HZ,
MSR_NON_SYNC = BH1792_MEAS_CONTROL1_MSR_NON_SYNCH_MODE,
MSR_SINGLE = BH1792_MEAS_CONTROL1_MSR_SINGLE_MEAS_MODE
MSR_64Hz = BH1792_MEAS_CONTROL1_MSR_64HZ,
MSR_32Hz = BH1792_MEAS_CONTROL1_MSR_32HZ,
MSR_128Hz = BH1792_MEAS_CONTROL1_MSR_128HZ,
MSR_256Hz = BH1792_MEAS_CONTROL1_MSR_256HZ,
MSR_1024Hz = BH1792_MEAS_CONTROL1_MSR_1024HZ,
MSR_NON_SYNC = BH1792_MEAS_CONTROL1_MSR_NON_SYNCH_MODE,
MSR_SINGLE = BH1792_MEAS_CONTROL1_MSR_SINGLE_MEAS_MODE
} MEAS_MODES;
/**
* @brief LED light types
*/
typedef enum {
GREEN,
IR
GREEN,
IR
} LED_TYPES;
/**
* @brief Interrupt modes of the sensor
*/
typedef enum {
WATER_MARK = BH1792_MEAS_CONTROL5_INT_SEL_FIFO_WATERMARK,
IR_THRESHOLD_JUDGE = BH1792_MEAS_CONTROL5_INT_SEL_IR_THRESHOLD,
ON_COMPLETE = BH1792_MEAS_CONTROL5_INT_SEL_ON_COMPLETE
WATER_MARK = BH1792_MEAS_CONTROL5_INT_SEL_FIFO_WATERMARK,
IR_THRESHOLD_JUDGE = BH1792_MEAS_CONTROL5_INT_SEL_IR_THRESHOLD,
ON_COMPLETE = BH1792_MEAS_CONTROL5_INT_SEL_ON_COMPLETE
} INTERRUPT_MODES;
/**
* @brief Operations modes available with the sensor
*/
typedef enum {
SYNCHRONIZED,
NON_SYNCHRONIZED,
SINGLE_GREEN,
SINGLE_IR
SYNCHRONIZED,
NON_SYNCHRONIZED,
SINGLE_GREEN,
SINGLE_IR
} OP_MODES;
/**
@ -102,26 +94,26 @@ typedef enum {
*/
typedef struct _bh1792_context
{
mraa_i2c_context i2c;
mraa_gpio_context interrupt;
bool enabled;
bool isrEnabled;
OP_MODES op_mode;
pthread_t sync_thread;
bool sync_thread_alive;
LED_TYPES led_type;
INTERRUPT_MODES interrupt_mode;
uint16_t meas_freq;
uint8_t green_current;
uint8_t ir_current;
uint16_t threshold;
mraa_i2c_context i2c;
mraa_gpio_context interrupt;
bool enabled;
bool isrEnabled;
OP_MODES op_mode;
pthread_t sync_thread;
bool sync_thread_alive;
LED_TYPES led_type;
INTERRUPT_MODES interrupt_mode;
uint16_t meas_freq;
uint8_t green_current;
uint8_t ir_current;
uint16_t threshold;
} *bh1792_context;
/**
* @brief Init the sensor with specific bus and address. Before starting
* measurement, one of (bh1792_enable_sync_mode, bh1792_enable_non_sync_mode,
* measurement, one of (bh1792_enable_sync_mode, bh1792_enable_non_sync_mode,
* or bh1792_enable_single_mode) have to be called.
*
*
* @param bus I2C bus number
* @param addr I2C sensor address
* @return context of initialized sensor
@ -130,14 +122,14 @@ bh1792_context bh1792_init(int bus, int addr);
/**
* @brief Close and free sensor context
*
*
* @param dev Sensor context
*/
void bh1792_close(bh1792_context dev);
/**
* @brief Check "who am I" register value to identify the sensor
*
*
* @param dev Sensor context
* @return UPM result
*/
@ -145,7 +137,7 @@ upm_result_t bh1792_check_who_am_i(bh1792_context dev);
/**
* @brief Checks if the measuremnt on sensor is enabled
*
*
* @param The sensor context
* @return True if measurement is enabled, or false otherwise
*/
@ -155,7 +147,7 @@ bool bh1792_is_enabled(bh1792_context dev);
* @brief Initiates a software reset to the sensor. All register values will
* be written to their defaults, thus intended operation mode need to be
* enabled.
*
*
* @param dev Sensor context
* @return UPM result
*/
@ -163,7 +155,7 @@ upm_result_t bh1792_soft_reset(bh1792_context dev);
/**
* @brief Gets the value of measurement time is milli-seconds
*
*
* @param dev The sensor context
* @param meas_time_ms Float pointer to store value of measurement time
* @return UPM result
@ -172,7 +164,7 @@ upm_result_t bh1792_get_meas_time_ms(bh1792_context dev, float *meas_time);
/**
* @brief Sets the green LED Current value
*
*
* @param dev The sensor context
* @param current The current value, accepted values are between 0-63
* @return UPM result
@ -181,7 +173,7 @@ upm_result_t bh1792_set_green_leds_current(bh1792_context dev, uint8_t current);
/**
* @brief Gets the green LED current value
*
*
* @param dev The sensor context
* @param current Pointer to store the read current value
* @return UPM result
@ -190,7 +182,7 @@ upm_result_t bh1792_get_green_leds_current(bh1792_context dev, uint8_t *current)
/**
* @brief Sets the IR LED Current value
*
*
* @param dev The sensor context
* @param current The current value, accepted values are between 0-63
* @return UPM result
@ -199,7 +191,7 @@ upm_result_t bh1792_set_ir_led_current(bh1792_context dev, uint8_t current);
/**
* @brief Gets the IR LED current value
*
*
* @param dev The sensor context
* @param current Pointer to store the read current value
* @return UPM result
@ -208,7 +200,7 @@ upm_result_t bh1792_get_ir_led_current(bh1792_context dev, uint8_t *current);
/**
* @brief Sets interrupt ir threshold value for non-synchronized mode
*
*
* @param dev Sensor context
* @param threshold Value to be written, range 0-65536
* @return UPM result
@ -217,7 +209,7 @@ upm_result_t bh1792_set_ir_threshold(bh1792_context dev, uint16_t threshold);
/**
* @brief Gets interrupt ir threshold value
*
*
* @param dev Sensor context
* @param threshold Pointer (uint16_t) to write value
* @return UPM result
@ -226,7 +218,7 @@ upm_result_t bh1792_get_ir_threshold(bh1792_context dev, uint16_t *threshold);
/**
* @brief Gets the current size of built-in FIFO
*
*
* @param dev The sensor context
* @param count The pointer to store the size
* @return UPM result
@ -235,9 +227,9 @@ upm_result_t bh1792_get_fifo_size(bh1792_context dev, uint8_t *count);
/**
* @brief Disables interrupt function. Interrupt is enabled by default on all
* operation modes, so this have to be called after enabling a specific
* operation modes, so this have to be called after enabling a specific
* operation mode
*
*
* @param dev The sensor context
* @return UPM result
*/
@ -245,7 +237,7 @@ upm_result_t bh1792_disable_interrupt(bh1792_context dev);
/**
* @brief Clears the interrupt flag allowing more interrupts to be raised
*
*
* @param dev The sensor context
* @return UPM result
*/
@ -253,7 +245,7 @@ upm_result_t bh1792_clear_interrupt(bh1792_context dev);
/**
* @brief Starts the measuremnt on sensor or enable the sensor
*
*
* @param dev The sensor context
* @return UPM result
*/
@ -263,7 +255,7 @@ upm_result_t bh1792_start_measurement(bh1792_context dev);
* @breif Stops the measurement by setting the software reset bit. This
* function will reset all config registers. To resume from previous
* configuration call bh1792_restart_measurement().
*
*
* @param dev The sensor context
* @return UPM result
*/
@ -273,7 +265,7 @@ upm_result_t bh1792_stop_measurement(bh1792_context dev);
* @brief Restart the measurement, This function stops measurement, then
* re-writes the configuration registers again and start measurement with same
* configuration.
*
*
* @param dev The sensor context
* @return UPM result
*/
@ -282,19 +274,19 @@ upm_result_t bh1792_restart_measurement(bh1792_context dev);
/**
* @brief Gets the fifo data of 32 entries and resets the WATERMARK interrupt
* flag.
*
*
* @param dev The sensor context
* @param fifo_led_off Array/Pointer to store 32 entries of fifo LED_OFF data
* @param fifo_led_on Array/Pointer to store 32 entries of fifo LED_ON data
* @return UPM result
*/
upm_result_t bh1792_get_fifo_data(bh1792_context dev, uint16_t fifo_led_off[],
uint16_t fifo_led_on[]);
uint16_t fifo_led_on[]);
/**
* @brief Reads and discard the 32 FIFO entries to reset the WATERMARK
* interrupt flag.
*
*
* @param dev The sensor context
* @return UPM result
*/
@ -302,34 +294,34 @@ upm_result_t bh1792_discard_fifo_data(bh1792_context dev);
/**
* @brief Gets the values from using green LED light
*
*
* @param dev The sensor context
* @param green_led_off Pointer to store the reading value of LED_OFF
* @param green_led_on Pointer to store the reading value of LED_ON
* @return UPM result
*/
upm_result_t bh1792_get_green_data(bh1792_context dev, uint16_t *green_led_off,
uint16_t *green_led_on);
uint16_t *green_led_on);
/**
* @brief Gets the values from using IR LED light
*
*
* @param dev The sensor context
* @param ir_led_off Pointer to store the reading value of LED_OFF
* @param ir_led_on Pointer to store the reading value of LED_ON
* @return UPM result
*/
upm_result_t bh1792_get_ir_data(bh1792_context dev, uint16_t *ir_led_off,
uint16_t *ir_led_on);
uint16_t *ir_led_on);
/**
* @brief 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.
*
*
* You need to call bh1792_start_measurement() after this.
*
*
* @param dev The sensor context
* @param meas_freq Measurement frequncy mode, valid values 32, 64, 128, 256,
* 1024
@ -337,45 +329,45 @@ upm_result_t bh1792_get_ir_data(bh1792_context dev, uint16_t *ir_led_off,
* @return UPM result
*/
upm_result_t bh1792_enable_sync_mode(bh1792_context dev, uint16_t meas_freq,
uint8_t green_current);
uint8_t green_current);
/**
* @brief 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.
*
*
* You need to call bh1792_start_measurement() after this.
*
*
* @param dev The sensor context
* @param ir_current The IR LED current value
* @param threshold The IR LED interrupt threshold value
* @return UPM result
*/
upm_result_t bh1792_enable_non_sync_mode(bh1792_context dev, uint8_t ir_current,
uint16_t threshold);
uint16_t threshold);
/**
* @brief 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.
*
*
* You need to call bh1792_start_measurement() after this. If you need to get
* continuous values, clear interrupt and bh1792_start_measurement()
* continuously.
*
*
* @param dev The sensor context
* @param led_type LED light type to use, takes GREEN or IR values
* @param current The chosen led_type current value
* @return UPM result
*/
upm_result_t bh1792_enable_single_mode(bh1792_context dev, LED_TYPES led_type,
uint8_t current);
uint8_t current);
/**
* @brief Installs the ISR to a given GPIO pin
*
*
* @param dev Sensor context
* @param edge Edge type to raise ISR with, of type mraa_gpio_edge_t
* @param pin GPIO pin number
@ -384,11 +376,11 @@ upm_result_t bh1792_enable_single_mode(bh1792_context dev, LED_TYPES led_type,
* @return UPM result
*/
upm_result_t bh1792_install_isr(bh1792_context dev, mraa_gpio_edge_t edge,
int pin, void (*isr)(void *), void *isr_args);
int pin, void (*isr)(void *), void *isr_args);
/**
* @brief Installs the ISR to a given GPIO pin
*
*
* @param dev Sensor context
* @param pin GPIO pin number
* @param isr Pointer to ISR function
@ -396,18 +388,18 @@ upm_result_t bh1792_install_isr(bh1792_context dev, mraa_gpio_edge_t edge,
* @return UPM result
*/
upm_result_t bh1792_install_isr_falling_edge(bh1792_context dev, int pin,
void (*isr)(void *), void *isr_args);
void (*isr)(void *), void *isr_args);
/**
* @brief Removes the ISR if it is installed
*
*
* @param dev Sensor context
*/
void bh1792_remove_isr(bh1792_context dev);
void bh1792_remove_isr(bh1792_context dev);
/**
* @brief Gets a dump of configuration registers as a string
*
*
* @param dev Sensor context
* @param dump Pointer of char to save dump string
* @return UPM result

View File

@ -29,294 +29,296 @@
#include "bh1792.h"
/**
* @brief C++ API for the bh1792 Heart Rate sensor driver
* @brief BH1792 Heart Rate Sensor
* @defgroup bh1792 libupm-bh1792
* @ingroup ROHM i2c medical
* @ingroup rohm i2c medical
*/
/**
* @library bh1792
* @sensor bh1792
* @comname Heart Rate Sensor
* @type medical
* @man ROHM
* @man rohm
* @con i2c
*
* @brief C++ API for the bh1792 driver
*
* @snippet bh1792.cxx Interesting
*/
namespace upm {
class BH1792 {
public:
class BH1792 {
public:
/**
* @brief Init the sensor with specific bus and address. Before
* starting measurement, one of (EnableSyncMode, EnableNonSyncMode,
* or EnableSingleMode) has to be called.
*
* @param bus I2C bus number
* @param addr I2C sensor address
* @throws std::runtime_error on initialization failure
*/
BH1792(int bus = 0, int addr = 0x5b);
/**
* @brief Init the sensor with specific bus and address. Before
* starting measurement, one of (EnableSyncMode, EnableNonSyncMode,
* or EnableSingleMode) has to be called.
*
* @param bus I2C bus number
* @param addr I2C sensor address
* @throws std::runtime_error on initialization failure
*/
BH1792(int bus = 0, int addr = 0x5b);
/**
* @brief Close and free sensor
*/
virtual ~BH1792();
/**
* @brief Close and free sensor
*/
virtual ~BH1792();
/**
* @brief Check "who am I" register value to identify the sensor
*
* @throws std::runtime_error if this value is incorrect
*/
void CheckWhoAmI();
/**
* @brief Check "who am I" register value to identify the sensor
*
* @throws std::runtime_error if this value is incorrect
*/
void CheckWhoAmI();
/**
* @brief Checks if the measuremnt on sensor is enabled
*
* @return True if measurement is enabled, or false otherwise
*/
bool IsEnabled();
/**
* @brief Checks if the measuremnt on sensor is enabled
*
* @return True if measurement is enabled, or false otherwise
*/
bool IsEnabled();
/**
* @brief Initiates a software reset to the sensor. All register values
* will be written to their defaults, thus intended operation mode need
* to be enabled.
*
* @throws std::runtime_error if software reset fails
*/
void SoftReset();
/**
* @brief Initiates a software reset to the sensor. All register values
* will be written to their defaults, thus intended operation mode need
* to be enabled.
*
* @throws std::runtime_error if software reset fails
*/
void SoftReset();
/**
* @brief Gets the value of measurement time is milli-seconds
*
* @return measurement time float in milli-seconds
* @throws std::runtime_error if reading measurement time fails
*/
float GetMeasurementTimeMS();
/**
* @brief Gets the value of measurement time is milli-seconds
*
* @return measurement time float in milli-seconds
* @throws std::runtime_error if reading measurement time fails
*/
float GetMeasurementTimeMS();
/**
* @brief Sets the green LED Current value
*
* @param current The current value, accepted values are between 0-63
* @throws std::runtime_error if setting current fails
* @throws std::range_error if current value out of range
*/
void SetGreenLedsCurrent(uint16_t current);
/**
* @brief Sets the green LED Current value
*
* @param current The current value, accepted values are between 0-63
* @throws std::runtime_error if setting current fails
* @throws std::range_error if current value out of range
*/
void SetGreenLedsCurrent(uint16_t current);
/**
* @brief Gets the green LED current value
*
* @return Green LED used current
* @throws std::runtime_error if reading current fails
*/
int GetGreenLedsCurrent();
/**
* @brief Gets the green LED current value
*
* @return Green LED used current
* @throws std::runtime_error if reading current fails
*/
int GetGreenLedsCurrent();
/**
* @brief Sets the IR LED Current value
*
* @param current The current value, accepted values are between 0-63
* @throws std::runtime_error if setting current fails
* @throws std::range_error if current value out of range
*/
void SetIrLedCurrent(uint16_t current);
/**
* @brief Sets the IR LED Current value
*
* @param current The current value, accepted values are between 0-63
* @throws std::runtime_error if setting current fails
* @throws std::range_error if current value out of range
*/
void SetIrLedCurrent(uint16_t current);
/**
* @brief Gets the green LED current value
*
* @return Green LED used current
* @throws std::runtime_error if reading current fails
*/
int GetIrLedCurrent();
/**
* @brief Gets the green LED current value
*
* @return Green LED used current
* @throws std::runtime_error if reading current fails
*/
int GetIrLedCurrent();
/**
* @brief Sets interrupt IR threshold value for non-synchronized mode
*
* @param threshold Value to be written, range 0-65536
* @throws std::runtime_error if setting threshold fails
*/
void SetIrThreshold(uint16_t threshold);
/**
* @brief Sets interrupt IR threshold value for non-synchronized mode
*
* @param threshold Value to be written, range 0-65536
* @throws std::runtime_error if setting threshold fails
*/
void SetIrThreshold(uint16_t threshold);
/**
* @brief Gets interrupt IR threshold value
*
* @return Green LED used current
* @throws std::runtime_error if reading current fails
*/
int GetIrThreshold();
/**
* @brief Gets interrupt IR threshold value
*
* @return Green LED used current
* @throws std::runtime_error if reading current fails
*/
int GetIrThreshold();
/**
* @brief Gets the current size of built-in FIFO
*
* @return Number of entries store in FIFO
* @throws std::runtime_error if reading size fails
*/
int GetFifoSize();
/**
* @brief Gets the current size of built-in FIFO
*
* @return Number of entries store in FIFO
* @throws std::runtime_error if reading size fails
*/
int GetFifoSize();
/**
* @brief Disables interrupt function. Interrupt is enabled by default
* on all operation modes, so this have to be called after enabling a
* specific operation mode
*
* @throws std::runtime_error if setting interrupt disable bits fails
*/
void DisableInterrupt();
/**
* @brief Disables interrupt function. Interrupt is enabled by default
* on all operation modes, so this have to be called after enabling a
* specific operation mode
*
* @throws std::runtime_error if setting interrupt disable bits fails
*/
void DisableInterrupt();
/**
* @brief Clears the interrupt flag allowing more interrupts to be
* raised
*
* @throws std::runtime_error if clearing interrupt fails
*/
void ClearInterrupt();
/**
* @brief Clears the interrupt flag allowing more interrupts to be
* raised
*
* @throws std::runtime_error if clearing interrupt fails
*/
void ClearInterrupt();
/**
* @brief Starts the measuremnt on sensor or enable the sensor
*
* @throws std::runtime_error if starting measurement fails
*/
void StartMeasurement();
/**
* @brief Starts the measuremnt on sensor or enable the sensor
*
* @throws std::runtime_error if starting measurement fails
*/
void StartMeasurement();
/**
* @breif Stops the measurement by setting the software reset bit. This
* function will reset all config registers. To resume from previous
* configuration call RestartMeasurement().
*
* @throws std::runtime_error if disabling measurement fails
*/
void StopMeasurement();
/**
* @breif Stops the measurement by setting the software reset bit. This
* function will reset all config registers. To resume from previous
* configuration call RestartMeasurement().
*
* @throws std::runtime_error if disabling measurement fails
*/
void StopMeasurement();
/**
* @brief Restart the measurement, This function stops measurement,
* then re-writes the configuration registers again and start
* measurement with same configuration.
*
* @throws std::runtime_error if restarting measurement fails
*/
void RestartMeasurement();
/**
* @brief Restart the measurement, This function stops measurement,
* then re-writes the configuration registers again and start
* measurement with same configuration.
*
* @throws std::runtime_error if restarting measurement fails
*/
void RestartMeasurement();
/**
* @brief Gets the fifo data of 32 entries and resets the WATERMARK
* interrupt flag.
*
* @return vector of values of the retrieved FIFO values, which are
* vectors containing 2 values each (led off, led_on)
* @throws std::runtime_error if reading FIFO data fails
*/
std::vector<std::vector<int>> GetFifoData();
/**
* @brief Gets the fifo data of 32 entries and resets the WATERMARK
* interrupt flag.
*
* @return vector of values of the retrieved FIFO values, which are
* vectors containing 2 values each (led off, led_on)
* @throws std::runtime_error if reading FIFO data fails
*/
std::vector<std::vector<int>> GetFifoData();
/**
* @brief Reads and discard the 32 FIFO entries to reset the WATERMARK
* interrupt flag.
*
* @throws std::runtime_error if reading FIFO data fails
*/
void DiscardFifoData();
/**
* @brief Reads and discard the 32 FIFO entries to reset the WATERMARK
* interrupt flag.
*
* @throws std::runtime_error if reading FIFO data fails
*/
void DiscardFifoData();
/**
* @brief Gets the values from using green LED light
*
* @return vector of values (led off, led on) of green led values
* @throws std::runtime_error if reading green data fails
*/
std::vector<int> GetGreenData();
/**
* @brief Gets the values from using green LED light
*
* @return vector of values (led off, led on) of green led values
* @throws std::runtime_error if reading green data fails
*/
std::vector<int> GetGreenData();
/**
* @brief Gets the values from using IR LED light
*
* @return vector of values (led off, led on) of IR led values
* @throws std::runtime_error if reading IR data fails
*/
std::vector<int> GetIrData();
/**
* @brief Gets the values from using IR LED light
*
* @return vector of values (led off, led on) of IR led values
* @throws std::runtime_error if reading IR data fails
*/
std::vector<int> GetIrData();
/**
* @brief 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.
*
* You need to call StartMeasurement() after this.
*
* @param measFreq Measurement frequncy mode, valid values 32, 64, 128,
* 256, 1024
* @param green_current Green LED current value
* @throws std::runtime_error if enabling synchronized mode fails
* @throws std::invalid_argument if measurement frequency is invalid
*/
void EnableSyncMode(uint16_t measFreq, uint16_t green_current);
/**
* @brief 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.
*
* You need to call StartMeasurement() after this.
*
* @param measFreq Measurement frequncy mode, valid values 32, 64, 128,
* 256, 1024
* @param green_current Green LED current value
* @throws std::runtime_error if enabling synchronized mode fails
* @throws std::invalid_argument if measurement frequency is invalid
*/
void EnableSyncMode(uint16_t measFreq, uint16_t green_current);
/**
* @brief 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.
*
* You need to call StartMeasurement() after this.
*
* @param ir_current The IR LED current value
* @param threshold The IR LED interrupt threshold value
*
* @throws std::runtime_error if enabling non-synchronized mode fails
*/
void EnableNonSyncMode(uint16_t ir_current, uint16_t threshold);
/**
* @brief 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.
*
* You need to call StartMeasurement() after this.
*
* @param ir_current The IR LED current value
* @param threshold The IR LED interrupt threshold value
*
* @throws std::runtime_error if enabling non-synchronized mode fails
*/
void EnableNonSyncMode(uint16_t ir_current, uint16_t threshold);
/**
* @brief 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.
*
* You need to call StartMeasurement() after this. If you need to get
* continuous values, clear interrupt and StartMeasurement()
* continuously.
*
* @param led_type LED light type to use, takes GREEN or IR (0 or 1)
* @param current The chosen led_type current value
* @throws std::runtime_error if enabling single mode fails
*/
void EnableSingleMode(LED_TYPES led_type, uint16_t current);
/**
* @brief 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.
*
* You need to call StartMeasurement() after this. If you need to get
* continuous values, clear interrupt and StartMeasurement()
* continuously.
*
* @param led_type LED light type to use, takes GREEN or IR (0 or 1)
* @param current The chosen led_type current value
* @throws std::runtime_error if enabling single mode fails
*/
void EnableSingleMode(LED_TYPES led_type, uint16_t current);
/**
* @brief Installs the ISR to a given GPIO pin
*
* @param edge Edge type to raise ISR with, of type mraa_gpio_edge_t
* @param pin GPIO pin number
* @param isr Pointer to ISR function
* @param isr_args Arguments to pass the ISR function
* @throws std::runtime_error if installing ISR fails
*/
void InstallISR(mraa_gpio_edge_t edge, int pin, void (*isr)(void *),
void *isr_args);
/**
* @brief Installs the ISR to a given GPIO pin
*
* @param edge Edge type to raise ISR with, of type mraa_gpio_edge_t
* @param pin GPIO pin number
* @param isr Pointer to ISR function
* @param isr_args Arguments to pass the ISR function
* @throws std::runtime_error if installing ISR fails
*/
void InstallISR(mraa_gpio_edge_t edge, int pin, void (*isr)(void *),
void *isr_args);
/**
* @brief Installs the ISR to a given GPIO pin
*
* @param pin GPIO pin number
* @param isr Pointer to ISR function
* @param isr_args Arguments to pass the ISR function
* @throws std::runtime_error if installing ISR fails
*/
void InstallISR(int pin, void (*isr)(void *), void *isr_args);
/**
* @brief Removes the ISR if it is installed
*/
void RemoveISR();
/**
* @brief Installs the ISR to a given GPIO pin
*
* @param pin GPIO pin number
* @param isr Pointer to ISR function
* @param isr_args Arguments to pass the ISR function
* @throws std::runtime_error if installing ISR fails
*/
void InstallISR(int pin, void (*isr)(void *), void *isr_args);
/**
* @brief Gets a dump of configuration registers as a string
*
* @return string of dumped registers
* @throws std::runtime_error if reading one of the registers fails
*/
std::string RegistersDump();
/**
* @brief Removes the ISR if it is installed
*/
void RemoveISR();
private:
bh1792_context m_bh1792;
/**
* @brief Gets a dump of configuration registers as a string
*
* @return string of dumped registers
* @throws std::runtime_error if reading one of the registers fails
*/
std::string RegistersDump();
/* Disable implicit copy and assignment operators */
BH1792(const BH1792 &) = delete;
BH1792 &operator=(const BH1792 &) = delete;
};
private:
bh1792_context m_bh1792;
/* Disable implicit copy and assignment operators */
BH1792(const BH1792 &) = delete;
BH1792 &operator=(const BH1792 &) = delete;
};
}

View File

@ -19,30 +19,30 @@
"Specifications": {
"Supply Voltage (VDD)": {
"unit": "V",
"min": 2.5,
"typical": 3.0,
"min": 2.5,
"typical": 3.0,
"max": 3.6
},
"Terminal Input Voltage": {
"unit": "V",
"min": 0.7,
"max": 5.5
},
"Supply Current": {
"Terminal Input Voltage": {
"unit": "V",
"min": 0.7,
"max": 5.5
},
"Supply Current": {
"unit": "uA",
"min": 0.8,
"max": 200
},
"LED Supply Current": {
"unit": "mA",
"typical": 1.4,
"max": 3.0
},
"Standby Mode Current": {
"unit": "uA",
"typical": 0.8,
"max": 1.5
},
},
"LED Supply Current": {
"unit": "mA",
"typical": 1.4,
"max": 3.0
},
"Standby Mode Current": {
"unit": "uA",
"typical": 0.8,
"max": 1.5
},
"Operating Temperature": {
"unit": "°C",
"min": -20,

View File

@ -422,6 +422,10 @@ and is not meant to be installed anywhere.
@ingroup byman
@brief Semtech Corporation
@defgroup rohm ROHM Semiconductor
@ingroup byman
@brief ROHM Semiconductor
### Groups for the various Starter Kits ###