Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers/bh1750fvi: added names to return values #6141

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions drivers/bh1750fvi/bh1750fvi.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
#include "bh1750fvi.h"
#include "bh1750fvi_internal.h"

#define ENABLE_DEBUG (0)
#include "debug.h"

int bh1750fvi_init(bh1750fvi_t *dev, bh1750fvi_params_t *params)
{
int res;
Expand All @@ -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);
i2c_release(dev->i2c);
if (res < 0) {
return -1;
return BH1750FVI_ERR_I2C;
}
return 0;
return BH1750FVI_OK;
}

uint16_t bh1750fvi_sample(bh1750fvi_t *dev)
Expand All @@ -52,6 +55,7 @@ uint16_t bh1750fvi_sample(bh1750fvi_t *dev)
uint8_t raw[2];

/* power on the device and send single H-mode measurement command */
DEBUG("[bh1750fvi] sample: triggering a conversion\n");
i2c_acquire(dev->i2c);
i2c_write_byte(dev->i2c, dev->addr, OP_POWER_ON);
i2c_write_byte(dev->i2c, dev->addr, OP_SINGLE_HRES1);
Expand All @@ -61,6 +65,7 @@ uint16_t bh1750fvi_sample(bh1750fvi_t *dev)
xtimer_usleep(DELAY_HMODE);

/* read the results */
DEBUG("[bh1750fvi] sample: reading the results\n");
i2c_acquire(dev->i2c);
i2c_read_bytes(dev->i2c, dev->addr, raw, 2);
i2c_release(dev->i2c);
Expand Down
8 changes: 8 additions & 0 deletions drivers/include/bh1750fvi.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ extern "C" {
*/
#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
*/
Expand Down
7 changes: 6 additions & 1 deletion tests/driver_bh1750/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,18 @@

int main(void)
{
int res;
bh1750fvi_t dev;
uint32_t last = xtimer_now();

puts("BH1750FVI ambient light sensor test\n");

/* 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 */
while(1) {
Expand Down