Merge pull request #6141 from haukepetersen/opt_bh1750fvi_namedreturnvalues
drivers/bh1750fvi: added names to return values
This commit is contained in:
commit
9c7d9eb06f
@ -25,6 +25,9 @@
|
|||||||
#include "bh1750fvi.h"
|
#include "bh1750fvi.h"
|
||||||
#include "bh1750fvi_internal.h"
|
#include "bh1750fvi_internal.h"
|
||||||
|
|
||||||
|
#define ENABLE_DEBUG (0)
|
||||||
|
#include "debug.h"
|
||||||
|
|
||||||
int bh1750fvi_init(bh1750fvi_t *dev, bh1750fvi_params_t *params)
|
int bh1750fvi_init(bh1750fvi_t *dev, bh1750fvi_params_t *params)
|
||||||
{
|
{
|
||||||
int res;
|
int res;
|
||||||
@ -41,9 +44,9 @@ int bh1750fvi_init(bh1750fvi_t *dev, bh1750fvi_params_t *params)
|
|||||||
res = i2c_write_byte(dev->i2c, dev->addr, OP_POWER_DOWN);
|
res = i2c_write_byte(dev->i2c, dev->addr, OP_POWER_DOWN);
|
||||||
i2c_release(dev->i2c);
|
i2c_release(dev->i2c);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
return -1;
|
return BH1750FVI_ERR_I2C;
|
||||||
}
|
}
|
||||||
return 0;
|
return BH1750FVI_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t bh1750fvi_sample(bh1750fvi_t *dev)
|
uint16_t bh1750fvi_sample(bh1750fvi_t *dev)
|
||||||
@ -52,6 +55,7 @@ uint16_t bh1750fvi_sample(bh1750fvi_t *dev)
|
|||||||
uint8_t raw[2];
|
uint8_t raw[2];
|
||||||
|
|
||||||
/* power on the device and send single H-mode measurement command */
|
/* power on the device and send single H-mode measurement command */
|
||||||
|
DEBUG("[bh1750fvi] sample: triggering a conversion\n");
|
||||||
i2c_acquire(dev->i2c);
|
i2c_acquire(dev->i2c);
|
||||||
i2c_write_byte(dev->i2c, dev->addr, OP_POWER_ON);
|
i2c_write_byte(dev->i2c, dev->addr, OP_POWER_ON);
|
||||||
i2c_write_byte(dev->i2c, dev->addr, OP_SINGLE_HRES1);
|
i2c_write_byte(dev->i2c, dev->addr, OP_SINGLE_HRES1);
|
||||||
@ -61,6 +65,7 @@ uint16_t bh1750fvi_sample(bh1750fvi_t *dev)
|
|||||||
xtimer_usleep(DELAY_HMODE);
|
xtimer_usleep(DELAY_HMODE);
|
||||||
|
|
||||||
/* read the results */
|
/* read the results */
|
||||||
|
DEBUG("[bh1750fvi] sample: reading the results\n");
|
||||||
i2c_acquire(dev->i2c);
|
i2c_acquire(dev->i2c);
|
||||||
i2c_read_bytes(dev->i2c, dev->addr, raw, 2);
|
i2c_read_bytes(dev->i2c, dev->addr, raw, 2);
|
||||||
i2c_release(dev->i2c);
|
i2c_release(dev->i2c);
|
||||||
|
|||||||
@ -48,6 +48,14 @@ extern "C" {
|
|||||||
*/
|
*/
|
||||||
#define BH1750FVI_I2C_MAX_CLK I2C_SPEED_FAST
|
#define BH1750FVI_I2C_MAX_CLK I2C_SPEED_FAST
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Status and error return codes
|
||||||
|
*/
|
||||||
|
enum {
|
||||||
|
BH1750FVI_OK = 0, /**< everything was fine */
|
||||||
|
BH1750FVI_ERR_I2C = -1 /**< error initializing the I2C bus */
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Device descriptor for BH1570FVI devices
|
* @brief Device descriptor for BH1570FVI devices
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -28,13 +28,18 @@
|
|||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
int res;
|
||||||
bh1750fvi_t dev;
|
bh1750fvi_t dev;
|
||||||
uint32_t last = xtimer_now();
|
uint32_t last = xtimer_now();
|
||||||
|
|
||||||
puts("BH1750FVI ambient light sensor test\n");
|
puts("BH1750FVI ambient light sensor test\n");
|
||||||
|
|
||||||
/* initialize the device */
|
/* initialize the device */
|
||||||
bh1750fvi_init(&dev, (bh1750fvi_params_t *)(&bh1750fvi_params));
|
res = bh1750fvi_init(&dev, (bh1750fvi_params_t *)(&bh1750fvi_params));
|
||||||
|
if (res != BH1750FVI_OK) {
|
||||||
|
puts("error: unable to initialize sensor [I2C initialization error]");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/* periodically sample the sensor */
|
/* periodically sample the sensor */
|
||||||
while(1) {
|
while(1) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user