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 a110x-intr.cxx A110X_intr_Example.java a110x-intr.js a110x-intr.py
adc121c021.cxx ADC121C021_Example.java adc121c021.js adc121c021.py adc121c021.cxx ADC121C021_Example.java adc121c021.js adc121c021.py
adxl345.cxx Adxl345_Example.java adxl345.js adxl345.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 biss0001.cxx BISS0001_Example.java biss0001.js biss0001.py
bmpx8x.cxx BMPX8X_Example.java bmpx8x.js bmpx8x.py bmpx8x.cxx BMPX8X_Example.java bmpx8x.js bmpx8x.py
bno055.cxx BNO055_Example.java bno055.js bno055.py bno055.cxx BNO055_Example.java bno055.js bno055.py

View File

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

View File

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

View File

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

View File

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

View File

@ -34,7 +34,7 @@
/** /**
* @brief Reads the value of a register * @brief Reads the value of a register
* *
* @param dev The sensor context * @param dev The sensor context
* @param reg Register address * @param reg Register address
* @param data Pointer of uint8_t to save register value * @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) 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); uint8_t value = mraa_i2c_read_byte_data(dev->i2c, reg);
if(value < 0) { if(value < 0) {
printf("%s: mraa_i2c_read_byte_data() failed\n", __FUNCTION__); printf("%s: mraa_i2c_read_byte_data() failed\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED; return UPM_ERROR_OPERATION_FAILED;
} }
*data = value; *data = value;
return UPM_SUCCESS; return UPM_SUCCESS;
} }
/** /**
* @brief Reads the values of a set of registers * @brief Reads the values of a set of registers
* *
* @param dev The sensor context * @param dev The sensor context
* @param reg Register address * @param reg Register address
* @param data Pointer of uint8_t to save registers values * @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) 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++) { for(int i = 0; i < len; i++) {
if(bh1749_read_register(dev, reg + i, &value) != UPM_SUCCESS) { if(bh1749_read_register(dev, reg + i, &value) != UPM_SUCCESS) {
return UPM_ERROR_OPERATION_FAILED; return UPM_ERROR_OPERATION_FAILED;
} }
*(data + i) = value; *(data + i) = value;
} }
return UPM_SUCCESS; return UPM_SUCCESS;
} }
/** /**
* @brief Writes a value to a register * @brief Writes a value to a register
* *
* @param dev The sensor context * @param dev The sensor context
* @param value Value to write * @param value Value to write
* @param reg Register address * @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) 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) { if (mraa_i2c_write_byte_data(dev->i2c, value, reg) != MRAA_SUCCESS) {
printf("%s: mraa_i2c_write_byte_data() failed\n", __FUNCTION__); printf("%s: mraa_i2c_write_byte_data() failed\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED; return UPM_ERROR_OPERATION_FAILED;
} }
return UPM_SUCCESS; return UPM_SUCCESS;
} }
/** /**
* @brief Sets a bit on in a register with a bit mask * @brief Sets a bit on in a register with a bit mask
* *
* @param dev The sensor context * @param dev The sensor context
* @param reg Register address * @param reg Register address
* @param bit_mask Mask to use * @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) static upm_result_t bh1749_set_bit_on(bh1749_context dev, uint8_t reg, uint8_t bit_mask)
{ {
uint8_t reg_value; uint8_t reg_value;
int status; int status;
status = bh1749_read_register(dev, reg, &reg_value); status = bh1749_read_register(dev, reg, &reg_value);
if(status < 0) { if(status < 0) {
printf("%s: Failed to read register 0x%2X\n", __FUNCTION__, reg); printf("%s: Failed to read register 0x%2X\n", __FUNCTION__, reg);
return UPM_ERROR_OPERATION_FAILED; return UPM_ERROR_OPERATION_FAILED;
} }
reg_value |= bit_mask; reg_value |= bit_mask;
return bh1749_write_register(dev, reg_value, reg); 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 * @brief Sets a bit off in a register with a bit mask
* *
* @param dev The sensor context * @param dev The sensor context
* @param reg Register address * @param reg Register address
* @param bit_mask Mask to use * @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) static upm_result_t bh1749_set_bit_off(bh1749_context dev, uint8_t reg, uint8_t bit_mask)
{ {
uint8_t reg_value; uint8_t reg_value;
int status; int status;
status = bh1749_read_register(dev, reg, &reg_value); status = bh1749_read_register(dev, reg, &reg_value);
if(status < 0) { if(status < 0) {
printf("%s: Failed to read register 0x%2X\n", __FUNCTION__, reg); printf("%s: Failed to read register 0x%2X\n", __FUNCTION__, reg);
return UPM_ERROR_OPERATION_FAILED; return UPM_ERROR_OPERATION_FAILED;
} }
reg_value &= ~bit_mask; reg_value &= ~bit_mask;
return bh1749_write_register(dev, reg_value, reg); 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 * @brief Sets the value of a register as a given pattern with a bit mask
* *
* @param dev The sensor context * @param dev The sensor context
* @param reg Register address * @param reg Register address
* @param value Value to write * @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) 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; uint8_t reg_value;
int status; int status;
status = bh1749_read_register(dev, reg, &reg_value); status = bh1749_read_register(dev, reg, &reg_value);
if(status < 0) { if(status < 0) {
printf("%s: Failed to read register 0x%2X\n", __FUNCTION__, reg); printf("%s: Failed to read register 0x%2X\n", __FUNCTION__, reg);
return UPM_ERROR_OPERATION_FAILED; return UPM_ERROR_OPERATION_FAILED;
} }
reg_value &= ~bit_mask; reg_value &= ~bit_mask;
reg_value |= value; reg_value |= value;
return bh1749_write_register(dev, reg_value, reg); return bh1749_write_register(dev, reg_value, reg);
} }
upm_result_t bh1749_check_who_am_i(bh1749_context dev) upm_result_t bh1749_check_who_am_i(bh1749_context dev)
{ {
uint8_t partId; uint8_t partId;
if(bh1749_read_register(dev, BH1749_SYSTEM_CONTROL, &partId) != UPM_SUCCESS) if(bh1749_read_register(dev, BH1749_SYSTEM_CONTROL, &partId) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED; return UPM_ERROR_OPERATION_FAILED;
partId &= BH1749_SYSTEM_CONTROL_PART_MASK; partId &= BH1749_SYSTEM_CONTROL_PART_MASK;
if(partId != BH1749_SYSTEM_CONTROL_PART_ID) { if(partId != BH1749_SYSTEM_CONTROL_PART_ID) {
printf("%s: wrong manufacturer ID\n", __FUNCTION__); printf("%s: wrong manufacturer ID\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED; return UPM_ERROR_OPERATION_FAILED;
} }
return UPM_SUCCESS; return UPM_SUCCESS;
} }
bh1749_context bh1749_init(int bus, int addr) bh1749_context bh1749_init(int bus, int addr)
{ {
bh1749_context dev = (bh1749_context)malloc(sizeof(struct _bh1749_context)); bh1749_context dev = (bh1749_context)malloc(sizeof(struct _bh1749_context));
if (!dev) if (!dev)
return NULL; return NULL;
dev->i2c = NULL; dev->i2c = NULL;
dev->interrupt = NULL; dev->interrupt = NULL;
if (mraa_init() != MRAA_SUCCESS) { if (mraa_init() != MRAA_SUCCESS) {
printf("%s: mraa_init() failed.\n", __FUNCTION__); printf("%s: mraa_init() failed.\n", __FUNCTION__);
bh1749_close(dev); bh1749_close(dev);
return NULL; return NULL;
@ -206,452 +206,452 @@ bh1749_context bh1749_init(int bus, int addr)
return NULL; return NULL;
} }
if(bh1749_check_who_am_i(dev) != UPM_SUCCESS) if(bh1749_check_who_am_i(dev) != UPM_SUCCESS)
return NULL; return NULL;
dev->enabled = false; dev->enabled = false;
dev->isrEnabled = false; dev->isrEnabled = false;
if(bh1749_sensor_init(dev, DEFAULT_OP_MODE, DEFAULT_MEAS_TIME, if(bh1749_sensor_init(dev, DEFAULT_OP_MODE, DEFAULT_MEAS_TIME,
DEFAULT_RGB_GAIN, DEFAULT_IR_GAIN, DEFAULT_INT_SOURCE) != UPM_SUCCESS) DEFAULT_RGB_GAIN, DEFAULT_IR_GAIN, DEFAULT_INT_SOURCE) != UPM_SUCCESS)
return NULL; return NULL;
bh1749_set_threshold_high(dev, DEFUALT_THRESHOLD_HIGH); bh1749_set_threshold_high(dev, DEFUALT_THRESHOLD_HIGH);
return dev; return dev;
} }
void bh1749_close(bh1749_context dev) void bh1749_close(bh1749_context dev)
{ {
if(dev->isrEnabled) if(dev->isrEnabled)
bh1749_remove_isr(dev); bh1749_remove_isr(dev);
if (dev->i2c) if (dev->i2c)
mraa_i2c_stop(dev->i2c); mraa_i2c_stop(dev->i2c);
free(dev); free(dev);
} }
upm_result_t bh1749_enable(bh1749_context dev) upm_result_t bh1749_enable(bh1749_context dev)
{ {
int status; int status;
status = bh1749_set_bit_on(dev, BH1749_MODE_CONTROL2, status = bh1749_set_bit_on(dev, BH1749_MODE_CONTROL2,
BH1749_MODE_CONTROL2_RGB_MEASUREMENT_MASK); BH1749_MODE_CONTROL2_RGB_MEASUREMENT_MASK);
if(status != UPM_SUCCESS) { if(status != UPM_SUCCESS) {
printf("%s: Failed to bh1749_enable RGB measurement\n", __FUNCTION__); printf("%s: Failed to bh1749_enable RGB measurement\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED; return UPM_ERROR_OPERATION_FAILED;
} }
dev->enabled = true; dev->enabled = true;
return UPM_SUCCESS; return UPM_SUCCESS;
} }
upm_result_t bh1749_disable(bh1749_context dev) upm_result_t bh1749_disable(bh1749_context dev)
{ {
int status; int status;
status = bh1749_set_bit_off(dev, BH1749_MODE_CONTROL2, status = bh1749_set_bit_off(dev, BH1749_MODE_CONTROL2,
BH1749_MODE_CONTROL2_RGB_MEASUREMENT_MASK); BH1749_MODE_CONTROL2_RGB_MEASUREMENT_MASK);
if(status != UPM_SUCCESS) { if(status != UPM_SUCCESS) {
printf("%s: Failed to bh1749_disable RGB measurement\n", __FUNCTION__); printf("%s: Failed to bh1749_disable RGB measurement\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED; return UPM_ERROR_OPERATION_FAILED;
} }
dev->enabled = false; dev->enabled = false;
return UPM_SUCCESS; return UPM_SUCCESS;
} }
upm_result_t bh1749_sensor_init(bh1749_context dev, OPERATING_MODES opMode, upm_result_t bh1749_sensor_init(bh1749_context dev, OPERATING_MODES opMode,
MEAS_TIMES measTime, MEAS_TIMES measTime,
RGB_GAINS rgbGain, RGB_GAINS rgbGain,
IR_GAINS irGain, IR_GAINS irGain,
INT_SOURCES intSource) INT_SOURCES intSource)
{ {
if(bh1749_set_operating_mode(dev, opMode) != UPM_SUCCESS) if(bh1749_set_operating_mode(dev, opMode) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED; return UPM_ERROR_OPERATION_FAILED;
if(bh1749_set_measurement_time(dev, measTime) != UPM_SUCCESS) if(bh1749_set_measurement_time(dev, measTime) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED; return UPM_ERROR_OPERATION_FAILED;
if(bh1749_set_rgb_gain(dev, rgbGain) != UPM_SUCCESS) if(bh1749_set_rgb_gain(dev, rgbGain) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED; return UPM_ERROR_OPERATION_FAILED;
if(bh1749_set_ir_gain(dev, irGain) != UPM_SUCCESS) if(bh1749_set_ir_gain(dev, irGain) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED; return UPM_ERROR_OPERATION_FAILED;
return bh1749_set_int_source(dev, intSource); return bh1749_set_int_source(dev, intSource);
} }
upm_result_t bh1749_set_operating_mode(bh1749_context dev, OPERATING_MODES opMode) upm_result_t bh1749_set_operating_mode(bh1749_context dev, OPERATING_MODES opMode)
{ {
if(bh1749_write_register(dev, opMode, BH1749_PERSISTENCE) != UPM_SUCCESS) { if(bh1749_write_register(dev, opMode, BH1749_PERSISTENCE) != UPM_SUCCESS) {
printf("%s: Setting operating mode failed\n", __FUNCTION__); printf("%s: Setting operating mode failed\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED; return UPM_ERROR_OPERATION_FAILED;
} }
dev->operating_mode = opMode; dev->operating_mode = opMode;
return UPM_SUCCESS; return UPM_SUCCESS;
} }
upm_result_t bh1749_get_operating_mode(bh1749_context dev, uint8_t *opMode) 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) { if(bh1749_read_register(dev, BH1749_PERSISTENCE, &value) != UPM_SUCCESS) {
printf("%s: Failed to read operating mode\n", __FUNCTION__); printf("%s: Failed to read operating mode\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED; return UPM_ERROR_OPERATION_FAILED;
} }
value &= BH1749_PERSISTENCE_MODE_MASK; value &= BH1749_PERSISTENCE_MODE_MASK;
if(value != INT_JUDGE_0 && value != INT_JUDGE_1 && if(value != INT_JUDGE_0 && value != INT_JUDGE_1 &&
value != INT_JUDGE_4 && value != INT_JUDGE_4) { value != INT_JUDGE_4 && value != INT_JUDGE_4) {
printf("%s: Returned invalid mode\n", __FUNCTION__); printf("%s: Returned invalid mode\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED; 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) upm_result_t bh1749_set_measurement_time(bh1749_context dev, MEAS_TIMES measTime)
{ {
if(bh1749_set_bits_with_mask(dev, BH1749_MODE_CONTROL1, measTime, if(bh1749_set_bits_with_mask(dev, BH1749_MODE_CONTROL1, measTime,
BH1749_MODE_CONTROL1_ODR_MASK) != UPM_SUCCESS) { BH1749_MODE_CONTROL1_ODR_MASK) != UPM_SUCCESS) {
printf("%s: Failed setting measurement time\n", __FUNCTION__); printf("%s: Failed setting measurement time\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED; return UPM_ERROR_OPERATION_FAILED;
} }
dev->meas_time = measTime; dev->meas_time = measTime;
return UPM_SUCCESS; return UPM_SUCCESS;
} }
upm_result_t bh1749_get_measurement_time(bh1749_context dev, uint8_t *meas_time) 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) { if(bh1749_read_register(dev, BH1749_MODE_CONTROL1, &time_reg) != UPM_SUCCESS) {
printf("%s: Failed to read measurement time\n", __FUNCTION__); printf("%s: Failed to read measurement time\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED; return UPM_ERROR_OPERATION_FAILED;
} }
time_reg &= BH1749_MODE_CONTROL1_ODR_MASK; time_reg &= BH1749_MODE_CONTROL1_ODR_MASK;
if(time_reg == MEAS_35MS) if(time_reg == MEAS_35MS)
*meas_time = 35; *meas_time = 35;
else if(time_reg == MEAS_120MS) else if(time_reg == MEAS_120MS)
*meas_time = 120; *meas_time = 120;
else if(time_reg == MEAS_240MS) else if(time_reg == MEAS_240MS)
*meas_time = 240; *meas_time = 240;
else { else {
printf("%s: Returned invalid time\n", __FUNCTION__); printf("%s: Returned invalid time\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED; return UPM_ERROR_OPERATION_FAILED;
} }
return UPM_SUCCESS; return UPM_SUCCESS;
} }
upm_result_t bh1749_set_rgb_gain(bh1749_context dev, RGB_GAINS rgbGain) upm_result_t bh1749_set_rgb_gain(bh1749_context dev, RGB_GAINS rgbGain)
{ {
if(bh1749_set_bits_with_mask(dev, BH1749_MODE_CONTROL1, rgbGain, if(bh1749_set_bits_with_mask(dev, BH1749_MODE_CONTROL1, rgbGain,
BH1749_MODE_CONTROL1_RGB_GAIN_MASK) != UPM_SUCCESS) { BH1749_MODE_CONTROL1_RGB_GAIN_MASK) != UPM_SUCCESS) {
printf("%s: Failed setting RGB gain\n", __FUNCTION__); printf("%s: Failed setting RGB gain\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED; return UPM_ERROR_OPERATION_FAILED;
} }
dev->rgb_gain = rgbGain; dev->rgb_gain = rgbGain;
return UPM_SUCCESS; return UPM_SUCCESS;
} }
upm_result_t bh1749_get_rgb_gain(bh1749_context dev, uint8_t *gain) 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) { if(bh1749_read_register(dev, BH1749_MODE_CONTROL1, &rgb_gain) != UPM_SUCCESS) {
printf("%s: Failed to read rgb gain\n", __FUNCTION__); printf("%s: Failed to read rgb gain\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED; return UPM_ERROR_OPERATION_FAILED;
} }
rgb_gain &= BH1749_MODE_CONTROL1_RGB_GAIN_MASK; rgb_gain &= BH1749_MODE_CONTROL1_RGB_GAIN_MASK;
if(rgb_gain == RGB_GAIN_1X) if(rgb_gain == RGB_GAIN_1X)
*gain = 1; *gain = 1;
else if(rgb_gain == RGB_GAIN_32X) else if(rgb_gain == RGB_GAIN_32X)
*gain = 32; *gain = 32;
else { else {
printf("%s: Returned invalid gain\n", __FUNCTION__); printf("%s: Returned invalid gain\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED; return UPM_ERROR_OPERATION_FAILED;
} }
return UPM_SUCCESS; return UPM_SUCCESS;
} }
upm_result_t bh1749_set_ir_gain(bh1749_context dev, IR_GAINS irGain) upm_result_t bh1749_set_ir_gain(bh1749_context dev, IR_GAINS irGain)
{ {
if(bh1749_set_bits_with_mask(dev, BH1749_MODE_CONTROL1, irGain, if(bh1749_set_bits_with_mask(dev, BH1749_MODE_CONTROL1, irGain,
BH1749_MODE_CONTROL1_IR_GAIN_MASK) != UPM_SUCCESS) { BH1749_MODE_CONTROL1_IR_GAIN_MASK) != UPM_SUCCESS) {
printf("%s: Failed setting IR gain\n", __FUNCTION__); printf("%s: Failed setting IR gain\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED; return UPM_ERROR_OPERATION_FAILED;
} }
dev->ir_gain = irGain; dev->ir_gain = irGain;
return UPM_SUCCESS; return UPM_SUCCESS;
} }
upm_result_t bh1749_get_ir_gain(bh1749_context dev, uint8_t *gain) 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) { if(bh1749_read_register(dev, BH1749_MODE_CONTROL1, &ir_gain) != UPM_SUCCESS) {
printf("%s: Failed to read rgb gain\n", __FUNCTION__); printf("%s: Failed to read rgb gain\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED; return UPM_ERROR_OPERATION_FAILED;
} }
ir_gain &= BH1749_MODE_CONTROL1_IR_GAIN_MASK; ir_gain &= BH1749_MODE_CONTROL1_IR_GAIN_MASK;
if(ir_gain == IR_GAIN_1X) if(ir_gain == IR_GAIN_1X)
*gain = 1; *gain = 1;
else if(ir_gain == IR_GAIN_32X) else if(ir_gain == IR_GAIN_32X)
*gain = 32; *gain = 32;
else { else {
printf("%s: Returned invalid gain\n", __FUNCTION__); printf("%s: Returned invalid gain\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED; return UPM_ERROR_OPERATION_FAILED;
} }
return UPM_SUCCESS; return UPM_SUCCESS;
} }
upm_result_t bh1749_set_int_source(bh1749_context dev, INT_SOURCES intSource) upm_result_t bh1749_set_int_source(bh1749_context dev, INT_SOURCES intSource)
{ {
if(bh1749_set_bits_with_mask(dev, BH1749_INTERRUPT, intSource, if(bh1749_set_bits_with_mask(dev, BH1749_INTERRUPT, intSource,
BH1749_INTERRUPT_SOURCE_MASK) != UPM_SUCCESS) { BH1749_INTERRUPT_SOURCE_MASK) != UPM_SUCCESS) {
printf("%s: Failed setting interrupt source gain\n", __FUNCTION__); printf("%s: Failed setting interrupt source gain\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED; return UPM_ERROR_OPERATION_FAILED;
} }
dev->int_src = intSource; dev->int_src = intSource;
return UPM_SUCCESS; return UPM_SUCCESS;
} }
char bh1749_get_interrupt_source_char(bh1749_context dev) char bh1749_get_interrupt_source_char(bh1749_context dev)
{ {
char intSourceChar = ' '; char intSourceChar = ' ';
uint8_t intSource; 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;
}
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) upm_result_t bh1749_enable_interrupt(bh1749_context dev)
{ {
if(bh1749_set_bit_on(dev, BH1749_INTERRUPT, BH1749_INTERRUPT_EN_MASK) != UPM_SUCCESS) if(bh1749_set_bit_on(dev, BH1749_INTERRUPT, BH1749_INTERRUPT_EN_MASK) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED; return UPM_ERROR_OPERATION_FAILED;
return bh1749_reset_interrupt(dev); return bh1749_reset_interrupt(dev);
} }
upm_result_t bh1749_disable_interrupt(bh1749_context 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) 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) bool bh1749_is_interrupted(bh1749_context dev)
{ {
uint8_t intStatus; uint8_t intStatus;
if(bh1749_read_register(dev, BH1749_INTERRUPT, &intStatus) != UPM_SUCCESS) { if(bh1749_read_register(dev, BH1749_INTERRUPT, &intStatus) != UPM_SUCCESS) {
printf("%s: Failed to read interrupt status\n", __FUNCTION__); printf("%s: Failed to read interrupt status\n", __FUNCTION__);
return false; return false;
} }
intStatus &= BH1749_INTERRUPT_STATUS_MASK; intStatus &= BH1749_INTERRUPT_STATUS_MASK;
if(intStatus != BH1749_INTERRUPT_STATUS_ACTIVE) if(intStatus != BH1749_INTERRUPT_STATUS_ACTIVE)
return false; return false;
return true; return true;
} }
bool bh1749_is_interrupt_enabled(bh1749_context dev) bool bh1749_is_interrupt_enabled(bh1749_context dev)
{ {
uint8_t intStatus; uint8_t intStatus;
if(bh1749_read_register(dev, BH1749_INTERRUPT, &intStatus) != UPM_SUCCESS) { if(bh1749_read_register(dev, BH1749_INTERRUPT, &intStatus) != UPM_SUCCESS) {
printf("%s: Failed to read interrupt enabled\n", __FUNCTION__); printf("%s: Failed to read interrupt enabled\n", __FUNCTION__);
return false; return false;
} }
intStatus &= BH1749_INTERRUPT_EN_MASK; intStatus &= BH1749_INTERRUPT_EN_MASK;
if(intStatus != BH1749_INTERRUPT_EN_ENABLE) if(intStatus != BH1749_INTERRUPT_EN_ENABLE)
return false; return false;
return true; return true;
} }
upm_result_t bh1749_soft_reset(bh1749_context dev) 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) upm_result_t bh1749_set_threshold_high(bh1749_context dev, uint16_t threshold)
{ {
if(bh1749_write_register(dev, threshold, BH1749_TH_LSBS) != UPM_SUCCESS || if(bh1749_write_register(dev, threshold, BH1749_TH_LSBS) != UPM_SUCCESS ||
bh1749_write_register(dev, threshold >> 8, BH1749_TH_MSBS) != UPM_SUCCESS) { bh1749_write_register(dev, threshold >> 8, BH1749_TH_MSBS) != UPM_SUCCESS) {
printf("%s: Failed to write high threshold\n", __FUNCTION__); printf("%s: Failed to write high threshold\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED; return UPM_ERROR_OPERATION_FAILED;
} }
dev->int_thh = threshold; dev->int_thh = threshold;
return UPM_SUCCESS; return UPM_SUCCESS;
} }
upm_result_t bh1749_get_threshold_high(bh1749_context dev, uint16_t *threshold) 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]) || if(bh1749_read_register(dev, BH1749_TH_MSBS, &data[0]) ||
bh1749_read_register(dev, BH1749_TH_LSBS, &data[1]) != UPM_SUCCESS) bh1749_read_register(dev, BH1749_TH_LSBS, &data[1]) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED; return UPM_ERROR_OPERATION_FAILED;
*threshold = data[0] << 8 | data[1]; *threshold = data[0] << 8 | data[1];
return UPM_SUCCESS; return UPM_SUCCESS;
} }
upm_result_t bh1749_set_threshold_low(bh1749_context dev, uint16_t threshold) upm_result_t bh1749_set_threshold_low(bh1749_context dev, uint16_t threshold)
{ {
if(bh1749_write_register(dev, threshold, BH1749_TL_LSBS) != UPM_SUCCESS || if(bh1749_write_register(dev, threshold, BH1749_TL_LSBS) != UPM_SUCCESS ||
bh1749_write_register(dev, threshold >> 8, BH1749_TL_MSBS) != UPM_SUCCESS) { bh1749_write_register(dev, threshold >> 8, BH1749_TL_MSBS) != UPM_SUCCESS) {
printf("%s: Failed to write low threshold\n", __FUNCTION__); printf("%s: Failed to write low threshold\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED; return UPM_ERROR_OPERATION_FAILED;
} }
dev->int_thl = threshold; dev->int_thl = threshold;
return UPM_SUCCESS; return UPM_SUCCESS;
} }
upm_result_t bh1749_get_threshold_low(bh1749_context dev, uint16_t *threshold) 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]) || if(bh1749_read_register(dev, BH1749_TL_MSBS, &data[0]) ||
bh1749_read_register(dev, BH1749_TL_LSBS, &data[1]) != UPM_SUCCESS) bh1749_read_register(dev, BH1749_TL_LSBS, &data[1]) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED; return UPM_ERROR_OPERATION_FAILED;
*threshold = data[0] << 8 | data[1]; *threshold = data[0] << 8 | data[1];
return UPM_SUCCESS; return UPM_SUCCESS;
} }
upm_result_t bh1749_get_red(bh1749_context dev, uint16_t *red) 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 || 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) bh1749_read_register(dev, BH1749_RED_DATA_LSBS, &data[1]) != UPM_SUCCESS)
return -UPM_ERROR_OPERATION_FAILED; 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) 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 || 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) bh1749_read_register(dev, BH1749_GREEN_DATA_LSBS, &data[1]) != UPM_SUCCESS)
return -UPM_ERROR_OPERATION_FAILED; 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) 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 || 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) bh1749_read_register(dev, BH1749_BLUE_DATA_LSBS, &data[1]) != UPM_SUCCESS)
return -UPM_ERROR_OPERATION_FAILED; 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) 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 || 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) bh1749_read_register(dev, BH1749_IR_DATA_LSBS, &data[1]) != UPM_SUCCESS)
return -UPM_ERROR_OPERATION_FAILED; 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) 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 || 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) bh1749_read_register(dev, BH1749_GREEN2_DATA_LSBS, &data[1]) != UPM_SUCCESS)
return -UPM_ERROR_OPERATION_FAILED; 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) upm_result_t bh1749_get_measurements(bh1749_context dev, uint16_t *result)
{ {
uint16_t value; uint16_t value;
int step = 0; int step = 0;
if(bh1749_get_red(dev, &value) != UPM_SUCCESS) if(bh1749_get_red(dev, &value) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED; return UPM_ERROR_OPERATION_FAILED;
*(result + step++) = value; *(result + step++) = value;
if(bh1749_get_green(dev, &value) != UPM_SUCCESS) if(bh1749_get_green(dev, &value) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED; return UPM_ERROR_OPERATION_FAILED;
*(result + step++) = value; *(result + step++) = value;
if(bh1749_get_blue(dev, &value) != UPM_SUCCESS) if(bh1749_get_blue(dev, &value) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED; return UPM_ERROR_OPERATION_FAILED;
*(result + step++) = value; *(result + step++) = value;
if(bh1749_get_ir(dev, &value) != UPM_SUCCESS) if(bh1749_get_ir(dev, &value) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED; return UPM_ERROR_OPERATION_FAILED;
*(result + step++) = value; *(result + step++) = value;
if(bh1749_get_green2(dev, &value) != UPM_SUCCESS) if(bh1749_get_green2(dev, &value) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED; return UPM_ERROR_OPERATION_FAILED;
*(result + step++) = value; *(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, 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) if(dev->isrEnabled)
bh1749_remove_isr(dev); 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__); printf("%s: mraa_gpio_init() failed.\n", __FUNCTION__);
return UPM_ERROR_OPERATION_FAILED; 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; return UPM_ERROR_OPERATION_FAILED;
} }
dev->interrupt = isr_gpio; dev->interrupt = isr_gpio;
dev->isrEnabled = true; dev->isrEnabled = true;
return UPM_SUCCESS; return UPM_SUCCESS;
} }
void bh1749_remove_isr(bh1749_context dev) void bh1749_remove_isr(bh1749_context dev)
{ {
mraa_gpio_isr_exit(dev->interrupt); mraa_gpio_isr_exit(dev->interrupt);
mraa_gpio_close(dev->interrupt); mraa_gpio_close(dev->interrupt);
dev->interrupt = NULL; dev->interrupt = NULL;
dev->isrEnabled = false; dev->isrEnabled = false;
} }
upm_result_t bh1749_registers_dump(bh1749_context dev, char *dump) upm_result_t bh1749_registers_dump(bh1749_context dev, char *dump)
{ {
uint8_t reg_values[10]; uint8_t reg_values[10];
int count = 0; int count = 0;
int len = 3; int len = 3;
if(bh1749_read_registers(dev, BH1749_SYSTEM_CONTROL, reg_values, len) != UPM_SUCCESS) if(bh1749_read_registers(dev, BH1749_SYSTEM_CONTROL, reg_values, len) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED; return UPM_ERROR_OPERATION_FAILED;
count += sprintf(dump, "0x40 "); count += sprintf(dump, "0x40 ");
for(int i = 0; i < len; i++) for(int i = 0; i < len; i++)
count += sprintf(dump + count, "%02X ", reg_values[i]); count += sprintf(dump + count, "%02X ", reg_values[i]);
sprintf(dump + count - 1, "\n"); sprintf(dump + count - 1, "\n");
len = 6; len = 6;
if(bh1749_read_registers(dev, BH1749_INTERRUPT, reg_values, len) != UPM_SUCCESS) if(bh1749_read_registers(dev, BH1749_INTERRUPT, reg_values, len) != UPM_SUCCESS)
return UPM_ERROR_OPERATION_FAILED; return UPM_ERROR_OPERATION_FAILED;
count += sprintf(dump + count, "0x60 "); count += sprintf(dump + count, "0x60 ");
for(int i = 0; i < len; i++) for(int i = 0; i < len; i++)
count += sprintf(dump + count, "%02X ", reg_values[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() void BH1749::CheckWhoAmI()
{ {
if(bh1749_check_who_am_i(m_bh1749) != UPM_SUCCESS) if(bh1749_check_who_am_i(m_bh1749) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_check_who_am_i() failed"); "bh1749_check_who_am_i() failed");
} }
BH1749::BH1749(int bus, int addr) : m_bh1749(bh1749_init(bus, addr)) BH1749::BH1749(int bus, int addr) : m_bh1749(bh1749_init(bus, addr))
{ {
if(!m_bh1749) if(!m_bh1749)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_init() failed"); "bh1749_init() failed");
} }
BH1749::~BH1749() BH1749::~BH1749()
{ {
bh1749_close(m_bh1749); bh1749_close(m_bh1749);
} }
void BH1749::Enable() void BH1749::Enable()
{ {
if(bh1749_enable(m_bh1749) != UPM_SUCCESS) if(bh1749_enable(m_bh1749) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_enable() failed"); "bh1749_enable() failed");
} }
void BH1749::Disable() void BH1749::Disable()
{ {
if(bh1749_disable(m_bh1749) != UPM_SUCCESS) if(bh1749_disable(m_bh1749) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_disable() failed"); "bh1749_disable() failed");
} }
void BH1749::SensorInit(OPERATING_MODES opMode, void BH1749::SensorInit(OPERATING_MODES opMode,
MEAS_TIMES measTime, MEAS_TIMES measTime,
RGB_GAINS rgbGain, RGB_GAINS rgbGain,
IR_GAINS irGain, IR_GAINS irGain,
INT_SOURCES intSource) INT_SOURCES intSource)
{ {
if(bh1749_sensor_init(m_bh1749, opMode, measTime, rgbGain, irGain, intSource) != UPM_SUCCESS) if(bh1749_sensor_init(m_bh1749, opMode, measTime, rgbGain, irGain, intSource) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_sensor_init() failed"); "bh1749_sensor_init() failed");
} }
void BH1749::SetOperatingMode(OPERATING_MODES opMode) void BH1749::SetOperatingMode(OPERATING_MODES opMode)
{ {
if(bh1749_set_operating_mode(m_bh1749, opMode) != UPM_SUCCESS) if(bh1749_set_operating_mode(m_bh1749, opMode) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_set_operating_mode() failed"); "bh1749_set_operating_mode() failed");
} }
int BH1749::GetOperatingMode() int BH1749::GetOperatingMode()
{ {
uint8_t opMode; uint8_t opMode;
if(bh1749_get_operating_mode(m_bh1749, &opMode) != UPM_SUCCESS) if(bh1749_get_operating_mode(m_bh1749, &opMode) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_get_operating_mode() failed"); "bh1749_get_operating_mode() failed");
return opMode; return opMode;
} }
void BH1749::SetMeasurementTime(MEAS_TIMES measTime) void BH1749::SetMeasurementTime(MEAS_TIMES measTime)
{ {
if(bh1749_set_measurement_time(m_bh1749, measTime) != UPM_SUCCESS) if(bh1749_set_measurement_time(m_bh1749, measTime) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_set_measurement_time() failed"); "bh1749_set_measurement_time() failed");
} }
int BH1749::GetMeasurementTime() int BH1749::GetMeasurementTime()
{ {
uint8_t measTime; uint8_t measTime;
if(bh1749_get_measurement_time(m_bh1749, &measTime) != UPM_SUCCESS) if(bh1749_get_measurement_time(m_bh1749, &measTime) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_get_measurement_time() failed"); "bh1749_get_measurement_time() failed");
return measTime; return measTime;
} }
void BH1749::SetRgbGain(RGB_GAINS rgbGain) void BH1749::SetRgbGain(RGB_GAINS rgbGain)
{ {
if(bh1749_set_rgb_gain(m_bh1749, rgbGain) != UPM_SUCCESS) if(bh1749_set_rgb_gain(m_bh1749, rgbGain) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_set_rgb_gain() failed"); "bh1749_set_rgb_gain() failed");
} }
int BH1749::GetRgbGain() int BH1749::GetRgbGain()
{ {
uint8_t rgbGain; uint8_t rgbGain;
if(bh1749_get_rgb_gain(m_bh1749, &rgbGain) != UPM_SUCCESS) if(bh1749_get_rgb_gain(m_bh1749, &rgbGain) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_get_rgb_gain() failed"); "bh1749_get_rgb_gain() failed");
return rgbGain; return rgbGain;
} }
void BH1749::SetIrGain(IR_GAINS irGain) void BH1749::SetIrGain(IR_GAINS irGain)
{ {
if(bh1749_set_ir_gain(m_bh1749, irGain) != UPM_SUCCESS) if(bh1749_set_ir_gain(m_bh1749, irGain) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_set_ir_gain() failed"); "bh1749_set_ir_gain() failed");
} }
int BH1749::GetIrGain() int BH1749::GetIrGain()
{ {
uint8_t irGain; uint8_t irGain;
if(bh1749_get_ir_gain(m_bh1749, &irGain) != UPM_SUCCESS) if(bh1749_get_ir_gain(m_bh1749, &irGain) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_get_ir_gain() failed"); "bh1749_get_ir_gain() failed");
return irGain; return irGain;
} }
void BH1749::SetIntSource(INT_SOURCES intSource) void BH1749::SetIntSource(INT_SOURCES intSource)
{ {
if(bh1749_set_int_source(m_bh1749, intSource) != UPM_SUCCESS) if(bh1749_set_int_source(m_bh1749, intSource) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_set_int_source() failed"); "bh1749_set_int_source() failed");
} }
char BH1749::GetInterruptSourceChar() char BH1749::GetInterruptSourceChar()
{ {
char intSource = bh1749_get_interrupt_source_char(m_bh1749); char intSource = bh1749_get_interrupt_source_char(m_bh1749);
if( intSource == ' ') if( intSource == ' ')
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_get_interrupt_source_char() failed"); "bh1749_get_interrupt_source_char() failed");
return intSource; return intSource;
} }
void BH1749::EnableInterrupt() void BH1749::EnableInterrupt()
{ {
if(bh1749_enable_interrupt(m_bh1749) != UPM_SUCCESS) if(bh1749_enable_interrupt(m_bh1749) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_enable_interrupt() failed"); "bh1749_enable_interrupt() failed");
} }
void BH1749::DisableInterrupt() void BH1749::DisableInterrupt()
{ {
if(bh1749_disable_interrupt(m_bh1749) != UPM_SUCCESS) if(bh1749_disable_interrupt(m_bh1749) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_disable_interrupt() failed"); "bh1749_disable_interrupt() failed");
} }
void BH1749::ResetInterrupt() void BH1749::ResetInterrupt()
{ {
if(bh1749_reset_interrupt(m_bh1749) != UPM_SUCCESS) if(bh1749_reset_interrupt(m_bh1749) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_reset_interrupt() failed"); "bh1749_reset_interrupt() failed");
} }
bool BH1749::IsInterrupted() bool BH1749::IsInterrupted()
{ {
return bh1749_is_interrupted(m_bh1749); return bh1749_is_interrupted(m_bh1749);
} }
bool BH1749::IsInterruptEnabled() bool BH1749::IsInterruptEnabled()
{ {
return bh1749_is_interrupt_enabled(m_bh1749); return bh1749_is_interrupt_enabled(m_bh1749);
} }
void BH1749::SoftReset() void BH1749::SoftReset()
{ {
if(bh1749_soft_reset(m_bh1749) != UPM_SUCCESS) if(bh1749_soft_reset(m_bh1749) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_soft_reset() failed"); "bh1749_soft_reset() failed");
} }
void BH1749::SetThresholdHigh(uint16_t threshold) void BH1749::SetThresholdHigh(uint16_t threshold)
{ {
if(bh1749_set_threshold_high(m_bh1749, threshold) != UPM_SUCCESS) if(bh1749_set_threshold_high(m_bh1749, threshold) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_set_threshold_high() failed"); "bh1749_set_threshold_high() failed");
} }
int BH1749::GetThresholdHigh() int BH1749::GetThresholdHigh()
{ {
uint16_t threhold; uint16_t threhold;
if(bh1749_get_threshold_high(m_bh1749, &threhold) != UPM_SUCCESS) if(bh1749_get_threshold_high(m_bh1749, &threhold) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_get_threshold_high() failed"); "bh1749_get_threshold_high() failed");
return threhold; return threhold;
} }
void BH1749::SetThresholdLow(uint16_t threshold) void BH1749::SetThresholdLow(uint16_t threshold)
{ {
if(bh1749_set_threshold_low(m_bh1749, threshold) != UPM_SUCCESS) if(bh1749_set_threshold_low(m_bh1749, threshold) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_set_threshold_low() failed"); "bh1749_set_threshold_low() failed");
} }
int BH1749::GetThresholdLow() int BH1749::GetThresholdLow()
{ {
uint16_t threhold; uint16_t threhold;
if(bh1749_get_threshold_low(m_bh1749, &threhold) != UPM_SUCCESS) if(bh1749_get_threshold_low(m_bh1749, &threhold) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_get_threshold_low() failed"); "bh1749_get_threshold_low() failed");
return threhold; return threhold;
} }
uint16_t BH1749::GetRed() uint16_t BH1749::GetRed()
{ {
uint16_t red; uint16_t red;
if(bh1749_get_red(m_bh1749, &red) != UPM_SUCCESS) if(bh1749_get_red(m_bh1749, &red) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_get_red() failed"); "bh1749_get_red() failed");
return red; return red;
} }
uint16_t BH1749::GetGreen() uint16_t BH1749::GetGreen()
{ {
uint16_t green; uint16_t green;
if(bh1749_get_green(m_bh1749, &green) != UPM_SUCCESS) if(bh1749_get_green(m_bh1749, &green) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_get_green() failed"); "bh1749_get_green() failed");
return green; return green;
} }
uint16_t BH1749::GetBlue() uint16_t BH1749::GetBlue()
{ {
uint16_t blue; uint16_t blue;
if(bh1749_get_blue(m_bh1749, &blue) != UPM_SUCCESS) if(bh1749_get_blue(m_bh1749, &blue) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_get_blue() failed"); "bh1749_get_blue() failed");
return blue; return blue;
} }
uint16_t BH1749::GetIr() uint16_t BH1749::GetIr()
{ {
uint16_t ir; uint16_t ir;
if(bh1749_get_ir(m_bh1749, &ir) != UPM_SUCCESS) if(bh1749_get_ir(m_bh1749, &ir) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_get_ir() failed"); "bh1749_get_ir() failed");
return ir; return ir;
} }
uint16_t BH1749::GetGeen2() uint16_t BH1749::GetGeen2()
{ {
uint16_t green2; uint16_t green2;
if(bh1749_get_green2(m_bh1749, &green2) != UPM_SUCCESS) if(bh1749_get_green2(m_bh1749, &green2) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_get_green2() failed"); "bh1749_get_green2() failed");
return green2; return green2;
} }
std::vector<uint16_t> BH1749::GetMeasurements() std::vector<uint16_t> BH1749::GetMeasurements()
{ {
uint16_t res[5]; uint16_t res[5];
if(bh1749_get_measurements(m_bh1749, res) != UPM_SUCCESS) if(bh1749_get_measurements(m_bh1749, res) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_get_measurements() failed"); "bh1749_get_measurements() failed");
std::vector<uint16_t> result(res, res + sizeof res / sizeof res[0]); std::vector<uint16_t> result(res, res + sizeof res / sizeof res[0]);
return result; return result;
} }
void BH1749::InstallISR(mraa_gpio_edge_t edge, int pin, void (*isr)(void *), void *isr_args) 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) if(bh1749_install_isr(m_bh1749, edge, pin, isr, isr_args) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_install_isr() failed"); "bh1749_install_isr() failed");
} }
void BH1749::RemoveISR() void BH1749::RemoveISR()
{ {
bh1749_remove_isr(m_bh1749); bh1749_remove_isr(m_bh1749);
} }
std::string BH1749::RegistersDump() std::string BH1749::RegistersDump()
{ {
char dump[255]; char dump[255];
std::string dumpStr; std::string dumpStr;
if(bh1749_registers_dump(m_bh1749, dump) != UPM_SUCCESS) if(bh1749_registers_dump(m_bh1749, dump) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1749_registers_dump() failed"); "bh1749_registers_dump() failed");
dumpStr = dump; dumpStr = dump;
return dumpStr; return dumpStr;
} }

View File

@ -36,63 +36,55 @@ extern "C"
#include "bh1749_registers.h" #include "bh1749_registers.h"
/** /**
* @brief C API for the bh1749 color sensor driver * @file bh1749.h
* @defgroup bh1749 libupm-bh1749
* @ingroup ROHM i2c color
*/
/**
* @library bh1749 * @library bh1749
* @sensor bh1749
* @comname ROHM Color Sensor
* @type color
* @man ROHM
* @con i2c
*
* @brief C API for the bh1749 driver * @brief C API for the bh1749 driver
*
* @include bh1749.c
*/ */
/** /**
* @brief Operation modes enum for interrupt modes (persistance) * @brief Operation modes enum for interrupt modes (persistance)
*/ */
typedef enum { typedef enum {
INT_JUDGE_0 = BH1749_PERSISTENCE_MODE_STATUS_ACTIVE_AFTER_MEASUREMENT, INT_JUDGE_0 = BH1749_PERSISTENCE_MODE_STATUS_ACTIVE_AFTER_MEASUREMENT,
INT_JUDGE_1 = BH1749_PERSISTENCE_MODE_STATUS_UPDATE_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_4 = BH1749_PERSISTENCE_MODE_STATUS_UPDATE_AFTER_4_SAME,
INT_JUDGE_8 = BH1749_PERSISTENCE_MODE_STATUS_UPDATE_AFTER_8_SAME, INT_JUDGE_8 = BH1749_PERSISTENCE_MODE_STATUS_UPDATE_AFTER_8_SAME,
} OPERATING_MODES; } OPERATING_MODES;
/** /**
* @brief Measuremnt time choices * @brief Measuremnt time choices
*/ */
typedef enum { typedef enum {
MEAS_35MS = BH1749_MODE_CONTROL1_ODR_28P6, MEAS_35MS = BH1749_MODE_CONTROL1_ODR_28P6,
MEAS_120MS = BH1749_MODE_CONTROL1_ODR_8P333, MEAS_120MS = BH1749_MODE_CONTROL1_ODR_8P333,
MEAS_240MS = BH1749_MODE_CONTROL1_ODR_4P167 MEAS_240MS = BH1749_MODE_CONTROL1_ODR_4P167
} MEAS_TIMES; } MEAS_TIMES;
/** /**
* @brief RGB gain choices * @brief RGB gain choices
*/ */
typedef enum { typedef enum {
RGB_GAIN_1X = BH1749_MODE_CONTROL1_RGB_GAIN_1X, RGB_GAIN_1X = BH1749_MODE_CONTROL1_RGB_GAIN_1X,
RGB_GAIN_32X = BH1749_MODE_CONTROL1_RGB_GAIN_32X RGB_GAIN_32X = BH1749_MODE_CONTROL1_RGB_GAIN_32X
} RGB_GAINS; } RGB_GAINS;
/** /**
* @brief IR gain choices * @brief IR gain choices
*/ */
typedef enum { typedef enum {
IR_GAIN_1X = BH1749_MODE_CONTROL1_IR_GAIN_1X, IR_GAIN_1X = BH1749_MODE_CONTROL1_IR_GAIN_1X,
IR_GAIN_32X = BH1749_MODE_CONTROL1_IR_GAIN_32X IR_GAIN_32X = BH1749_MODE_CONTROL1_IR_GAIN_32X
} IR_GAINS; } IR_GAINS;
/** /**
* @brief Interrupt source choices * @brief Interrupt source choices
*/ */
typedef enum { typedef enum {
RED = BH1749_INTERRUPT_SOURCE_SELECT_RED, RED = BH1749_INTERRUPT_SOURCE_SELECT_RED,
GREEN = BH1749_INTERRUPT_SOURCE_SELECT_GREEN, GREEN = BH1749_INTERRUPT_SOURCE_SELECT_GREEN,
BLUE = BH1749_INTERRUPT_SOURCE_SELECT_BLUE BLUE = BH1749_INTERRUPT_SOURCE_SELECT_BLUE
} INT_SOURCES; } INT_SOURCES;
/** /**
@ -100,32 +92,32 @@ typedef enum {
*/ */
typedef struct _bh1749_context typedef struct _bh1749_context
{ {
mraa_i2c_context i2c; mraa_i2c_context i2c;
mraa_gpio_context interrupt; mraa_gpio_context interrupt;
bool enabled; bool enabled;
bool isrEnabled; bool isrEnabled;
uint16_t int_thh; uint16_t int_thh;
uint16_t int_thl; uint16_t int_thl;
INT_SOURCES int_src; INT_SOURCES int_src;
IR_GAINS ir_gain; IR_GAINS ir_gain;
RGB_GAINS rgb_gain; RGB_GAINS rgb_gain;
MEAS_TIMES meas_time; MEAS_TIMES meas_time;
OPERATING_MODES operating_mode; OPERATING_MODES operating_mode;
} *bh1749_context; } *bh1749_context;
/** /**
* @brief Check "who am I" register value to identify the sensor * @brief Check "who am I" register value to identify the sensor
* *
* @param dev Sensor context * @param dev Sensor context
* @return UPM result * @return UPM result
*/ */
upm_result_t bh1749_check_who_am_i(bh1749_context dev); 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, * the sensor_init() function to set default values for operating mode, gains,
* measurement time, interrupt source and then sets threshold high to 511. * measurement time, interrupt source and then sets threshold high to 511.
* *
* @param bus I2C bus number * @param bus I2C bus number
* @param addr I2C sensor address * @param addr I2C sensor address
* @return context of initialized sensor * @return context of initialized sensor
@ -134,14 +126,14 @@ bh1749_context bh1749_init(int bus, int addr);
/** /**
* @brief Close and free sensor context * @brief Close and free sensor context
* *
* @param dev Sensor context * @param dev Sensor context
*/ */
void bh1749_close(bh1749_context dev); void bh1749_close(bh1749_context dev);
/** /**
* @brief Enables RGB color measurement on the sensor * @brief Enables RGB color measurement on the sensor
* *
* @param dev Sensor context * @param dev Sensor context
* @return UPM result * @return UPM result
*/ */
@ -149,7 +141,7 @@ upm_result_t bh1749_enable(bh1749_context dev);
/** /**
* @brief Disables RGB color measurement on the sensor * @brief Disables RGB color measurement on the sensor
* *
* @param dev Sensor context * @param dev Sensor context
* @return UPM result * @return UPM result
*/ */
@ -157,7 +149,7 @@ upm_result_t bh1749_disable(bh1749_context dev);
/** /**
* @brief Initializes (writes) configuration values to sensor * @brief Initializes (writes) configuration values to sensor
* *
* @param dev Sensor context * @param dev Sensor context
* @param opMode Operating mode choice, a value of OPERATING_MODES enum * @param opMode Operating mode choice, a value of OPERATING_MODES enum
* @param measTime Measurement time choice, a value of MEAS_TIMES 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 * @return UPM result
*/ */
upm_result_t bh1749_sensor_init(bh1749_context dev, OPERATING_MODES opMode, upm_result_t bh1749_sensor_init(bh1749_context dev, OPERATING_MODES opMode,
MEAS_TIMES measTime, MEAS_TIMES measTime,
RGB_GAINS rgbGain, RGB_GAINS rgbGain,
IR_GAINS irGain, IR_GAINS irGain,
INT_SOURCES intSource); INT_SOURCES intSource);
/** /**
* @brief Sets operating mode (interrupt persistance) * @brief Sets operating mode (interrupt persistance)
* *
* @param dev Sensor context * @param dev Sensor context
* @param opMode Operating mode choice, a value of OPERATING_MODES enum * @param opMode Operating mode choice, a value of OPERATING_MODES enum
* @return UPM result * @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 * @brief Gets operating mode (interrupt persistance) value
* *
* @param dev Sensor context * @param dev Sensor context
* @param opMode pointer (uint8_t) to save value * @param opMode pointer (uint8_t) to save value
* @return UPM result * @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) * @brief Sets measurement time (ODR)
* *
* @param dev Sensor context * @param dev Sensor context
* @param measTime measurement time choice, a value of MEAS_TIMES enum * @param measTime measurement time choice, a value of MEAS_TIMES enum
* @return UPM result * @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) * @brief Sets measurement time (ODR)
* *
* @param dev Sensor context * @param dev Sensor context
* @param meas_time pointer (uint8_t) to save value * @param meas_time pointer (uint8_t) to save value
* @return UPM result * @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 * @brief Sets RGB gain values
* *
* @param dev Sensor context * @param dev Sensor context
* @param rgbGain RGB gain choice, a value of RGB_GAINS enum * @param rgbGain RGB gain choice, a value of RGB_GAINS enum
* @return UPM result * @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 * @brief Gets RGB gain value
* *
* @param dev Sensor context * @param dev Sensor context
* @param gain pointer (uint8_t) to save value * @param gain pointer (uint8_t) to save value
* @return UPM result * @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 * @brief Sets IR gain values
* *
* @param dev Sensor context * @param dev Sensor context
* @param irGain IR gain choice, a value of IR_GAINS enum * @param irGain IR gain choice, a value of IR_GAINS enum
* @return UPM result * @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 * @brief Gets IR gain value
* *
* @param dev Sensor context * @param dev Sensor context
* @param gain pointer (uint8_t) to save value * @param gain pointer (uint8_t) to save value
* @return UPM result * @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 * @brief Sets interrupt source value
* *
* @param dev Sensor context * @param dev Sensor context
* @param intSource interrupt source choice, a value of INT_SOURCES enum * @param intSource interrupt source choice, a value of INT_SOURCES enum
* @return UPM result * @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 * @brief Gets interrupt source value
* *
* @param dev Sensor context * @param dev Sensor context
* @return character of interrupt source * @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) * @brief Enables interrupt mode and resets the interrupt status (clear)
* *
* @param dev Sensor context * @param dev Sensor context
* @return UPM result * @return UPM result
*/ */
@ -271,7 +263,7 @@ upm_result_t bh1749_enable_interrupt(bh1749_context dev);
/** /**
* @brief Disables interrupt mode * @brief Disables interrupt mode
* *
* @param dev Sensor context * @param dev Sensor context
* @return UPM result * @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 * @brief Resets interrupt status (clear) to allow new interrupts
* *
* @param dev Sensor context * @param dev Sensor context
* @return UPM result * @return UPM result
*/ */
@ -287,7 +279,7 @@ upm_result_t bh1749_reset_interrupt(bh1749_context dev);
/** /**
* @brief Checks the status of the interrupt * @brief Checks the status of the interrupt
* *
* @param dev Sensor context * @param dev Sensor context
* @return true if there is interrupt, otherwise false * @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 * @brief Checks whether interrupt mode is enabled
* *
* @param dev Sensor context * @param dev Sensor context
* @return true if interrupt is enabled, otherwise false * @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 * @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, * be written to their defaults, thus sensor_init() must be called after this,
* and thresholds also needs to be set. * and thresholds also needs to be set.
* *
* @param dev Sensor context * @param dev Sensor context
* @return UPM result * @return UPM result
*/ */
@ -313,7 +305,7 @@ upm_result_t bh1749_soft_reset(bh1749_context dev);
/** /**
* @brief Sets interrupt threshold high value * @brief Sets interrupt threshold high value
* *
* @param dev Sensor context * @param dev Sensor context
* @param threshold Value to be written, range 0-65536 * @param threshold Value to be written, range 0-65536
* @return UPM result * @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 * @brief Gets interrupt threshold high value
* *
* @param dev Sensor context * @param dev Sensor context
* @param threshold Pointer (uint16_t) to write value * @param threshold Pointer (uint16_t) to write value
* @return UPM result * @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 * @brief Sets interrupt threshold low value
* *
* @param dev Sensor context * @param dev Sensor context
* @param threshold Value to be written, range 0-65536 * @param threshold Value to be written, range 0-65536
* @return UPM result * @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 * @brief Gets interrupt threshold low value
* *
* @param dev Sensor context * @param dev Sensor context
* @param threshold Pointer (uint16_t) to write value * @param threshold Pointer (uint16_t) to write value
* @return UPM result * @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 * @brief Gets value of Red color channel
* *
* @param dev Sensor context * @param dev Sensor context
* @param red Pointer (uint16_t) to write value * @param red Pointer (uint16_t) to write value
* @return UPM result * @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 * @brief Gets value of Green color channel
* *
* @param dev Sensor context * @param dev Sensor context
* @param green Pointer (uint16_t) to write value * @param green Pointer (uint16_t) to write value
* @return UPM result * @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 * @brief Gets value of Blue color channel
* *
* @param dev Sensor context * @param dev Sensor context
* @param blue Pointer (uint16_t) to write value * @param blue Pointer (uint16_t) to write value
* @return UPM result * @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 * @brief Gets value of IR color channel
* *
* @param dev Sensor context * @param dev Sensor context
* @param ir Pointer (uint16_t) to write value * @param ir Pointer (uint16_t) to write value
* @return UPM result * @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 * @brief Gets value of Green2 color channel
* *
* @param dev Sensor context * @param dev Sensor context
* @param green Pointer (uint16_t) to write value * @param green Pointer (uint16_t) to write value
* @return UPM result * @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 * @brief Gets all channels measurements values
* *
* @param dev Sensor context * @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 * Red, Green, Blue, IR, Green2
* *
* @return UPM result * @return UPM result
*/ */
upm_result_t bh1749_get_measurements(bh1749_context dev, uint16_t *result); upm_result_t bh1749_get_measurements(bh1749_context dev, uint16_t *result);
/** /**
* @brief Installs the ISR to a given GPIO pin * @brief Installs the ISR to a given GPIO pin
* *
* @param dev Sensor context * @param dev Sensor context
* @param edge Edge type to raise ISR with, of type mraa_gpio_edge_t * @param edge Edge type to raise ISR with, of type mraa_gpio_edge_t
* @param pin GPIO pin number * @param pin GPIO pin number
@ -414,18 +406,18 @@ upm_result_t bh1749_get_measurements(bh1749_context dev, uint16_t *result);
* @return UPM result * @return UPM result
*/ */
upm_result_t bh1749_install_isr(bh1749_context dev, mraa_gpio_edge_t edge, int pin, 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 * @brief Removes the ISR if it is installed
* *
* @param dev Sensor context * @param dev Sensor context
*/ */
void bh1749_remove_isr(bh1749_context dev); void bh1749_remove_isr(bh1749_context dev);
/** /**
* @brief Gets a dump of configuration registers as a string * @brief Gets a dump of configuration registers as a string
* *
* @param dev Sensor context * @param dev Sensor context
* @param dump Pointer of char to save dump string * @param dump Pointer of char to save dump string
* @return UPM result * @return UPM result

View File

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

View File

@ -32,9 +32,9 @@
"min": -40, "min": -40,
"max": 85 "max": 85
}, "Illumination Detection": { }, "Illumination Detection": {
"unit" : "klx", "unit" : "klx",
"value": 80 "value": 80
} }
}, },
"Urls": { "Urls": {
"Product Pages": [ "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_IR_GAIN_MASK 0x60
#define BH1749_MODE_CONTROL1_RGB_GAIN_MASK 0x18 #define BH1749_MODE_CONTROL1_RGB_GAIN_MASK 0x18
#define BH1749_MODE_CONTROL1_ODR_MASK 0x07 #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, INTERRUPT, T(H/L)_(LSB/MSB) is written or
// MODE_CONTROL2 read. In specification named as VALID. // MODE_CONTROL2 read. In specification named as VALID.
#define BH1749_MODE_CONTROL2_VALID_MASK 0x80 #define BH1749_MODE_CONTROL2_VALID_MASK 0x80

View File

@ -36,7 +36,7 @@ namespace upm {
/** /**
* @brief BH1750 Light Sensor * @brief BH1750 Light Sensor
* @defgroup bh1750 libupm-bh1750 * @defgroup bh1750 libupm-bh1750
* @ingroup dfrobot i2c * @ingroup rohm dfrobot i2c
*/ */
/** /**
@ -44,7 +44,7 @@ namespace upm {
* @sensor bh1750 * @sensor bh1750
* @comname Digital Light Sensor * @comname Digital Light Sensor
* @type light * @type light
* @man dfrobot * @man rohm dfrobot
* @con i2c * @con i2c
* @web http://www.dfrobot.com/index.php?route=product/product&product_id=531 * @web http://www.dfrobot.com/index.php?route=product/product&product_id=531
* *
@ -63,7 +63,7 @@ namespace upm {
/** /**
* BH1750 object constructor (Analog mode) * 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 addr The I2C address of the device
* @param mode The mode to start operation under. One of the * @param mode The mode to start operation under. One of the
* BH1750_OPMODES_T values. The default is the highest precision, * 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)) BH1792::BH1792(int bus, int addr) : m_bh1792(bh1792_init(bus, addr))
{ {
if(!m_bh1792) if(!m_bh1792)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_init() failed"); "bh1792_init() failed");
} }
BH1792::~BH1792() BH1792::~BH1792()
{ {
bh1792_close(m_bh1792); bh1792_close(m_bh1792);
} }
void BH1792::CheckWhoAmI() void BH1792::CheckWhoAmI()
{ {
if(bh1792_check_who_am_i(m_bh1792) != UPM_SUCCESS) if(bh1792_check_who_am_i(m_bh1792) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_check_who_am_i() failed"); "bh1792_check_who_am_i() failed");
} }
bool BH1792::IsEnabled() bool BH1792::IsEnabled()
{ {
return bh1792_is_enabled(m_bh1792); return bh1792_is_enabled(m_bh1792);
} }
void BH1792::SoftReset() void BH1792::SoftReset()
{ {
if(bh1792_soft_reset(m_bh1792) != UPM_SUCCESS) if(bh1792_soft_reset(m_bh1792) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_soft_reset() failed"); "bh1792_soft_reset() failed");
} }
float BH1792::GetMeasurementTimeMS() float BH1792::GetMeasurementTimeMS()
{ {
float meas_time; float meas_time;
if(bh1792_get_meas_time_ms(m_bh1792, &meas_time) != UPM_SUCCESS) if(bh1792_get_meas_time_ms(m_bh1792, &meas_time) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_get_meas_time_ms() failed"); "bh1792_get_meas_time_ms() failed");
return meas_time; return meas_time;
} }
void BH1792::SetGreenLedsCurrent(uint16_t current) void BH1792::SetGreenLedsCurrent(uint16_t current)
{ {
uint8_t status; uint8_t status;
status = bh1792_set_green_leds_current(m_bh1792, current); status = bh1792_set_green_leds_current(m_bh1792, current);
if(status == UPM_ERROR_OUT_OF_RANGE) { if(status == UPM_ERROR_OUT_OF_RANGE) {
throw std::range_error(std::string(__FUNCTION__) + throw std::range_error(std::string(__FUNCTION__) +
"bh1792_set_green_leds_current() failed, current not in range"); "bh1792_set_green_leds_current() failed, current not in range");
} else if(status != UPM_SUCCESS) { } else if(status != UPM_SUCCESS) {
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_set_green_leds_current() failed"); "bh1792_set_green_leds_current() failed");
} }
} }
int BH1792::GetGreenLedsCurrent() int BH1792::GetGreenLedsCurrent()
{ {
uint8_t current; uint8_t current;
if(bh1792_get_green_leds_current(m_bh1792, &current) != UPM_SUCCESS) if(bh1792_get_green_leds_current(m_bh1792, &current) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_get_green_leds_current() failed"); "bh1792_get_green_leds_current() failed");
return (int)current; return (int)current;
} }
void BH1792::SetIrLedCurrent(uint16_t current) void BH1792::SetIrLedCurrent(uint16_t current)
{ {
uint8_t status; uint8_t status;
status = bh1792_set_ir_led_current(m_bh1792, current); status = bh1792_set_ir_led_current(m_bh1792, current);
if(status == UPM_ERROR_OUT_OF_RANGE) { if(status == UPM_ERROR_OUT_OF_RANGE) {
throw std::range_error(std::string(__FUNCTION__) + throw std::range_error(std::string(__FUNCTION__) +
"bh1792_set_ir_led_current() failed, current not in range"); "bh1792_set_ir_led_current() failed, current not in range");
} else if(status != UPM_SUCCESS) { } else if(status != UPM_SUCCESS) {
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_set_ir_led_current() failed"); "bh1792_set_ir_led_current() failed");
} }
} }
int BH1792::GetIrLedCurrent() int BH1792::GetIrLedCurrent()
{ {
uint8_t current; uint8_t current;
if(bh1792_get_ir_led_current(m_bh1792, &current) != UPM_SUCCESS) if(bh1792_get_ir_led_current(m_bh1792, &current) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_get_ir_led_current() failed"); "bh1792_get_ir_led_current() failed");
return (int)current; return (int)current;
} }
void BH1792::SetIrThreshold(uint16_t threshold) void BH1792::SetIrThreshold(uint16_t threshold)
{ {
if(bh1792_set_ir_threshold(m_bh1792, threshold) != UPM_SUCCESS) if(bh1792_set_ir_threshold(m_bh1792, threshold) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_set_ir_threshold() failed"); "bh1792_set_ir_threshold() failed");
} }
int BH1792::GetIrThreshold() int BH1792::GetIrThreshold()
{ {
uint16_t threshold; uint16_t threshold;
if(bh1792_get_ir_threshold(m_bh1792, &threshold) != UPM_SUCCESS) if(bh1792_get_ir_threshold(m_bh1792, &threshold) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_get_ir_threshold() failed"); "bh1792_get_ir_threshold() failed");
return (int)threshold; return (int)threshold;
} }
int BH1792::GetFifoSize() int BH1792::GetFifoSize()
{ {
uint8_t size; uint8_t size;
if(bh1792_get_fifo_size(m_bh1792, &size) != UPM_SUCCESS) if(bh1792_get_fifo_size(m_bh1792, &size) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_get_fifo_size() failed"); "bh1792_get_fifo_size() failed");
return (int)size; return (int)size;
} }
void BH1792::DisableInterrupt() void BH1792::DisableInterrupt()
{ {
if(bh1792_disable_interrupt(m_bh1792) != UPM_SUCCESS) if(bh1792_disable_interrupt(m_bh1792) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_disable_interrupt() failed"); "bh1792_disable_interrupt() failed");
} }
void BH1792::ClearInterrupt() void BH1792::ClearInterrupt()
{ {
if(bh1792_clear_interrupt(m_bh1792) != UPM_SUCCESS) if(bh1792_clear_interrupt(m_bh1792) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_clear_interrupt() failed"); "bh1792_clear_interrupt() failed");
} }
void BH1792::StartMeasurement() void BH1792::StartMeasurement()
{ {
if(bh1792_start_measurement(m_bh1792) != UPM_SUCCESS) if(bh1792_start_measurement(m_bh1792) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_start_measurement() failed"); "bh1792_start_measurement() failed");
} }
void BH1792::StopMeasurement() void BH1792::StopMeasurement()
{ {
if(bh1792_stop_measurement(m_bh1792) != UPM_SUCCESS) if(bh1792_stop_measurement(m_bh1792) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_stop_measurement() failed"); "bh1792_stop_measurement() failed");
} }
void BH1792::RestartMeasurement() void BH1792::RestartMeasurement()
{ {
if(bh1792_restart_measurement(m_bh1792) != UPM_SUCCESS) if(bh1792_restart_measurement(m_bh1792) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_restart_measurement() failed"); "bh1792_restart_measurement() failed");
} }
std::vector<std::vector<int>> BH1792::GetFifoData() 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) if(bh1792_get_fifo_data(m_bh1792, fifo_off, fifo_on) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_get_fifo_data() failed"); "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);
}
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() void BH1792::DiscardFifoData()
{ {
if(bh1792_discard_fifo_data(m_bh1792) != UPM_SUCCESS) if(bh1792_discard_fifo_data(m_bh1792) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_discard_fifo_data() failed"); "bh1792_discard_fifo_data() failed");
} }
std::vector<int> BH1792::GetGreenData() 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) if(bh1792_get_green_data(m_bh1792, &green_off, &green_on) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_get_green_data() failed"); "bh1792_get_green_data() failed");
std::vector<int> result; std::vector<int> result;
result.reserve(2); result.reserve(2);
result.push_back(green_off); result.push_back(green_off);
result.push_back(green_on); result.push_back(green_on);
return result; return result;
} }
std::vector<int> BH1792::GetIrData() 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) if(bh1792_get_ir_data(m_bh1792, &ir_off, &ir_on) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_get_ir_data() failed"); "bh1792_get_ir_data() failed");
std::vector<int> result; std::vector<int> result;
result.reserve(2); result.reserve(2);
result.push_back(ir_off); result.push_back(ir_off);
result.push_back(ir_on); result.push_back(ir_on);
return result; return result;
} }
void BH1792::EnableSyncMode(uint16_t measFreq, uint16_t green_current) 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); status = bh1792_enable_sync_mode(m_bh1792, measFreq, green_current);
if(status == UPM_ERROR_INVALID_PARAMETER) { if(status == UPM_ERROR_INVALID_PARAMETER) {
throw std::invalid_argument(std::string(__FUNCTION__) + throw std::invalid_argument(std::string(__FUNCTION__) +
"bh1792_enable_sync_mode() failed, invalid measurement frequncy"); "bh1792_enable_sync_mode() failed, invalid measurement frequncy");
} else if(status != UPM_SUCCESS) { } else if(status != UPM_SUCCESS) {
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_enable_sync_mode() failed"); "bh1792_enable_sync_mode() failed");
} }
} }
void BH1792::EnableNonSyncMode(uint16_t ir_current, uint16_t threshold) void BH1792::EnableNonSyncMode(uint16_t ir_current, uint16_t threshold)
{ {
if(bh1792_enable_non_sync_mode(m_bh1792, ir_current, threshold) != UPM_SUCCESS) if(bh1792_enable_non_sync_mode(m_bh1792, ir_current, threshold) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_enable_non_sync_mode() failed"); "bh1792_enable_non_sync_mode() failed");
} }
void BH1792::EnableSingleMode(LED_TYPES led_type, uint16_t current) void BH1792::EnableSingleMode(LED_TYPES led_type, uint16_t current)
{ {
if(bh1792_enable_single_mode(m_bh1792, led_type, current) != UPM_SUCCESS) if(bh1792_enable_single_mode(m_bh1792, led_type, current) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_enable_single_mode() failed"); "bh1792_enable_single_mode() failed");
} }
void BH1792::InstallISR(mraa_gpio_edge_t edge, int pin, void (*isr)(void *), void *isr_args) 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) if(bh1792_install_isr(m_bh1792, edge, pin, isr, isr_args) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_install_isr() failed"); "bh1792_install_isr() failed");
} }
void BH1792::InstallISR(int pin, void (*isr)(void *), void *isr_args) 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) if(bh1792_install_isr_falling_edge(m_bh1792, pin, isr, isr_args) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_install_isr_falling_edge() failed"); "bh1792_install_isr_falling_edge() failed");
} }
void BH1792::RemoveISR() void BH1792::RemoveISR()
{ {
bh1792_remove_isr(m_bh1792); bh1792_remove_isr(m_bh1792);
} }
std::string BH1792::RegistersDump() std::string BH1792::RegistersDump()
{ {
char dump[255]; char dump[255];
std::string dumpStr; std::string dumpStr;
if(bh1792_registers_dump(m_bh1792, dump) != UPM_SUCCESS) if(bh1792_registers_dump(m_bh1792, dump) != UPM_SUCCESS)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
"bh1792_registers_dump() failed"); "bh1792_registers_dump() failed");
dumpStr = dump; dumpStr = dump;
return dumpStr; return dumpStr;
} }

View File

@ -37,19 +37,11 @@ extern "C"
#include "bh1792glc_registers.h" #include "bh1792glc_registers.h"
/** /**
* @brief C API for the bh1792 Heart Rate sensor driver * @file bh1792.h
* @defgroup bh1792 libupm-bh1792
* @ingroup ROHM i2c medical
*/
/**
* @library bh1792 * @library bh1792
* @sensor bh1792 * @brief C API for the bh1792 driver
* @comname Heart Rate Sensor
* @type medical
* @man ROHM
* @con i2c
* *
* @brief C API for the bh1792 Heart Rate sensor driver * @include bh1792.c
*/ */
#define ONE_SEC_IN_MIRCO_SEC 1000000 #define ONE_SEC_IN_MIRCO_SEC 1000000
@ -61,40 +53,40 @@ extern "C"
* and single modes. * and single modes.
*/ */
typedef enum { typedef enum {
MSR_64Hz = BH1792_MEAS_CONTROL1_MSR_64HZ, MSR_64Hz = BH1792_MEAS_CONTROL1_MSR_64HZ,
MSR_32Hz = BH1792_MEAS_CONTROL1_MSR_32HZ, MSR_32Hz = BH1792_MEAS_CONTROL1_MSR_32HZ,
MSR_128Hz = BH1792_MEAS_CONTROL1_MSR_128HZ, MSR_128Hz = BH1792_MEAS_CONTROL1_MSR_128HZ,
MSR_256Hz = BH1792_MEAS_CONTROL1_MSR_256HZ, MSR_256Hz = BH1792_MEAS_CONTROL1_MSR_256HZ,
MSR_1024Hz = BH1792_MEAS_CONTROL1_MSR_1024HZ, MSR_1024Hz = BH1792_MEAS_CONTROL1_MSR_1024HZ,
MSR_NON_SYNC = BH1792_MEAS_CONTROL1_MSR_NON_SYNCH_MODE, MSR_NON_SYNC = BH1792_MEAS_CONTROL1_MSR_NON_SYNCH_MODE,
MSR_SINGLE = BH1792_MEAS_CONTROL1_MSR_SINGLE_MEAS_MODE MSR_SINGLE = BH1792_MEAS_CONTROL1_MSR_SINGLE_MEAS_MODE
} MEAS_MODES; } MEAS_MODES;
/** /**
* @brief LED light types * @brief LED light types
*/ */
typedef enum { typedef enum {
GREEN, GREEN,
IR IR
} LED_TYPES; } LED_TYPES;
/** /**
* @brief Interrupt modes of the sensor * @brief Interrupt modes of the sensor
*/ */
typedef enum { typedef enum {
WATER_MARK = BH1792_MEAS_CONTROL5_INT_SEL_FIFO_WATERMARK, WATER_MARK = BH1792_MEAS_CONTROL5_INT_SEL_FIFO_WATERMARK,
IR_THRESHOLD_JUDGE = BH1792_MEAS_CONTROL5_INT_SEL_IR_THRESHOLD, IR_THRESHOLD_JUDGE = BH1792_MEAS_CONTROL5_INT_SEL_IR_THRESHOLD,
ON_COMPLETE = BH1792_MEAS_CONTROL5_INT_SEL_ON_COMPLETE ON_COMPLETE = BH1792_MEAS_CONTROL5_INT_SEL_ON_COMPLETE
} INTERRUPT_MODES; } INTERRUPT_MODES;
/** /**
* @brief Operations modes available with the sensor * @brief Operations modes available with the sensor
*/ */
typedef enum { typedef enum {
SYNCHRONIZED, SYNCHRONIZED,
NON_SYNCHRONIZED, NON_SYNCHRONIZED,
SINGLE_GREEN, SINGLE_GREEN,
SINGLE_IR SINGLE_IR
} OP_MODES; } OP_MODES;
/** /**
@ -102,26 +94,26 @@ typedef enum {
*/ */
typedef struct _bh1792_context typedef struct _bh1792_context
{ {
mraa_i2c_context i2c; mraa_i2c_context i2c;
mraa_gpio_context interrupt; mraa_gpio_context interrupt;
bool enabled; bool enabled;
bool isrEnabled; bool isrEnabled;
OP_MODES op_mode; OP_MODES op_mode;
pthread_t sync_thread; pthread_t sync_thread;
bool sync_thread_alive; bool sync_thread_alive;
LED_TYPES led_type; LED_TYPES led_type;
INTERRUPT_MODES interrupt_mode; INTERRUPT_MODES interrupt_mode;
uint16_t meas_freq; uint16_t meas_freq;
uint8_t green_current; uint8_t green_current;
uint8_t ir_current; uint8_t ir_current;
uint16_t threshold; uint16_t threshold;
} *bh1792_context; } *bh1792_context;
/** /**
* @brief Init the sensor with specific bus and address. Before starting * @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. * or bh1792_enable_single_mode) have to be called.
* *
* @param bus I2C bus number * @param bus I2C bus number
* @param addr I2C sensor address * @param addr I2C sensor address
* @return context of initialized sensor * @return context of initialized sensor
@ -130,14 +122,14 @@ bh1792_context bh1792_init(int bus, int addr);
/** /**
* @brief Close and free sensor context * @brief Close and free sensor context
* *
* @param dev Sensor context * @param dev Sensor context
*/ */
void bh1792_close(bh1792_context dev); void bh1792_close(bh1792_context dev);
/** /**
* @brief Check "who am I" register value to identify the sensor * @brief Check "who am I" register value to identify the sensor
* *
* @param dev Sensor context * @param dev Sensor context
* @return UPM result * @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 * @brief Checks if the measuremnt on sensor is enabled
* *
* @param The sensor context * @param The sensor context
* @return True if measurement is enabled, or false otherwise * @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 * @brief Initiates a software reset to the sensor. All register values will
* be written to their defaults, thus intended operation mode need to be * be written to their defaults, thus intended operation mode need to be
* enabled. * enabled.
* *
* @param dev Sensor context * @param dev Sensor context
* @return UPM result * @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 * @brief Gets the value of measurement time is milli-seconds
* *
* @param dev The sensor context * @param dev The sensor context
* @param meas_time_ms Float pointer to store value of measurement time * @param meas_time_ms Float pointer to store value of measurement time
* @return UPM result * @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 * @brief Sets the green LED Current value
* *
* @param dev The sensor context * @param dev The sensor context
* @param current The current value, accepted values are between 0-63 * @param current The current value, accepted values are between 0-63
* @return UPM result * @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 * @brief Gets the green LED current value
* *
* @param dev The sensor context * @param dev The sensor context
* @param current Pointer to store the read current value * @param current Pointer to store the read current value
* @return UPM result * @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 * @brief Sets the IR LED Current value
* *
* @param dev The sensor context * @param dev The sensor context
* @param current The current value, accepted values are between 0-63 * @param current The current value, accepted values are between 0-63
* @return UPM result * @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 * @brief Gets the IR LED current value
* *
* @param dev The sensor context * @param dev The sensor context
* @param current Pointer to store the read current value * @param current Pointer to store the read current value
* @return UPM result * @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 * @brief Sets interrupt ir threshold value for non-synchronized mode
* *
* @param dev Sensor context * @param dev Sensor context
* @param threshold Value to be written, range 0-65536 * @param threshold Value to be written, range 0-65536
* @return UPM result * @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 * @brief Gets interrupt ir threshold value
* *
* @param dev Sensor context * @param dev Sensor context
* @param threshold Pointer (uint16_t) to write value * @param threshold Pointer (uint16_t) to write value
* @return UPM result * @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 * @brief Gets the current size of built-in FIFO
* *
* @param dev The sensor context * @param dev The sensor context
* @param count The pointer to store the size * @param count The pointer to store the size
* @return UPM result * @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 * @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 * operation mode
* *
* @param dev The sensor context * @param dev The sensor context
* @return UPM result * @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 * @brief Clears the interrupt flag allowing more interrupts to be raised
* *
* @param dev The sensor context * @param dev The sensor context
* @return UPM result * @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 * @brief Starts the measuremnt on sensor or enable the sensor
* *
* @param dev The sensor context * @param dev The sensor context
* @return UPM result * @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 * @breif Stops the measurement by setting the software reset bit. This
* function will reset all config registers. To resume from previous * function will reset all config registers. To resume from previous
* configuration call bh1792_restart_measurement(). * configuration call bh1792_restart_measurement().
* *
* @param dev The sensor context * @param dev The sensor context
* @return UPM result * @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 * @brief Restart the measurement, This function stops measurement, then
* re-writes the configuration registers again and start measurement with same * re-writes the configuration registers again and start measurement with same
* configuration. * configuration.
* *
* @param dev The sensor context * @param dev The sensor context
* @return UPM result * @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 * @brief Gets the fifo data of 32 entries and resets the WATERMARK interrupt
* flag. * flag.
* *
* @param dev The sensor context * @param dev The sensor context
* @param fifo_led_off Array/Pointer to store 32 entries of fifo LED_OFF data * @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 * @param fifo_led_on Array/Pointer to store 32 entries of fifo LED_ON data
* @return UPM result * @return UPM result
*/ */
upm_result_t bh1792_get_fifo_data(bh1792_context dev, uint16_t fifo_led_off[], 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 * @brief Reads and discard the 32 FIFO entries to reset the WATERMARK
* interrupt flag. * interrupt flag.
* *
* @param dev The sensor context * @param dev The sensor context
* @return UPM result * @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 * @brief Gets the values from using green LED light
* *
* @param dev The sensor context * @param dev The sensor context
* @param green_led_off Pointer to store the reading value of LED_OFF * @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 * @param green_led_on Pointer to store the reading value of LED_ON
* @return UPM result * @return UPM result
*/ */
upm_result_t bh1792_get_green_data(bh1792_context dev, uint16_t *green_led_off, 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 * @brief Gets the values from using IR LED light
* *
* @param dev The sensor context * @param dev The sensor context
* @param ir_led_off Pointer to store the reading value of LED_OFF * @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 * @param ir_led_on Pointer to store the reading value of LED_ON
* @return UPM result * @return UPM result
*/ */
upm_result_t bh1792_get_ir_data(bh1792_context dev, uint16_t *ir_led_off, 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 * @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 * 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 * reaches 32 entries. To clear that interrupt flag FIFO must be read or
* discarded. This mode uses only green LED. * discarded. This mode uses only green LED.
* *
* You need to call bh1792_start_measurement() after this. * You need to call bh1792_start_measurement() after this.
* *
* @param dev The sensor context * @param dev The sensor context
* @param meas_freq Measurement frequncy mode, valid values 32, 64, 128, 256, * @param meas_freq Measurement frequncy mode, valid values 32, 64, 128, 256,
* 1024 * 1024
@ -337,45 +329,45 @@ upm_result_t bh1792_get_ir_data(bh1792_context dev, uint16_t *ir_led_off,
* @return UPM result * @return UPM result
*/ */
upm_result_t bh1792_enable_sync_mode(bh1792_context dev, uint16_t meas_freq, 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 * @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 * 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 * value is equal or greater than the threshold value. Interrupt must be
* cleared before receiving new interrupts. This mode uses only IR LED. * cleared before receiving new interrupts. This mode uses only IR LED.
* *
* You need to call bh1792_start_measurement() after this. * You need to call bh1792_start_measurement() after this.
* *
* @param dev The sensor context * @param dev The sensor context
* @param ir_current The IR LED current value * @param ir_current The IR LED current value
* @param threshold The IR LED interrupt threshold value * @param threshold The IR LED interrupt threshold value
* @return UPM result * @return UPM result
*/ */
upm_result_t bh1792_enable_non_sync_mode(bh1792_context dev, uint8_t ir_current, 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 * @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 * sensor to take only one measurement and raise an interrupt after measurement
* is finished. Interrupt flags has to be cleared to recieved new interrupts. * is finished. Interrupt flags has to be cleared to recieved new interrupts.
* This mode uses both green and IR LEDs. * This mode uses both green and IR LEDs.
* *
* You need to call bh1792_start_measurement() after this. If you need to get * You need to call bh1792_start_measurement() after this. If you need to get
* continuous values, clear interrupt and bh1792_start_measurement() * continuous values, clear interrupt and bh1792_start_measurement()
* continuously. * continuously.
* *
* @param dev The sensor context * @param dev The sensor context
* @param led_type LED light type to use, takes GREEN or IR values * @param led_type LED light type to use, takes GREEN or IR values
* @param current The chosen led_type current value * @param current The chosen led_type current value
* @return UPM result * @return UPM result
*/ */
upm_result_t bh1792_enable_single_mode(bh1792_context dev, LED_TYPES led_type, 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 * @brief Installs the ISR to a given GPIO pin
* *
* @param dev Sensor context * @param dev Sensor context
* @param edge Edge type to raise ISR with, of type mraa_gpio_edge_t * @param edge Edge type to raise ISR with, of type mraa_gpio_edge_t
* @param pin GPIO pin number * @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 * @return UPM result
*/ */
upm_result_t bh1792_install_isr(bh1792_context dev, mraa_gpio_edge_t edge, 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 * @brief Installs the ISR to a given GPIO pin
* *
* @param dev Sensor context * @param dev Sensor context
* @param pin GPIO pin number * @param pin GPIO pin number
* @param isr Pointer to ISR function * @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 * @return UPM result
*/ */
upm_result_t bh1792_install_isr_falling_edge(bh1792_context dev, int pin, 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 * @brief Removes the ISR if it is installed
* *
* @param dev Sensor context * @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 * @brief Gets a dump of configuration registers as a string
* *
* @param dev Sensor context * @param dev Sensor context
* @param dump Pointer of char to save dump string * @param dump Pointer of char to save dump string
* @return UPM result * @return UPM result

View File

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

View File

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

View File

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