fixed indentation

This commit is contained in:
byteneumann 2019-07-31 09:48:00 +00:00
parent 4c9406ecfd
commit 64356f5f7e

View File

@ -18,14 +18,14 @@ int fd;
int8_t user_i2c_read(uint8_t id, uint8_t reg_addr, uint8_t *data, uint16_t len)
{
write(fd, &reg_addr,1);
write(fd, &reg_addr, 1);
read(fd, data, len);
return 0;
}
void user_delay_ms(uint32_t period)
{
usleep(period*1000);
usleep(period * 1000);
}
int8_t user_i2c_write(uint8_t id, uint8_t reg_addr, uint8_t *data, uint16_t len)
@ -33,8 +33,8 @@ int8_t user_i2c_write(uint8_t id, uint8_t reg_addr, uint8_t *data, uint16_t len)
int8_t *buf;
buf = malloc(len +1);
buf[0] = reg_addr;
memcpy(buf +1, data, len);
write(fd, buf, len +1);
memcpy(buf + 1, data, len);
write(fd, buf, len + 1);
free(buf);
return 0;
}
@ -42,9 +42,9 @@ int8_t user_i2c_write(uint8_t id, uint8_t reg_addr, uint8_t *data, uint16_t len)
void print_sensor_data(struct bme280_data *comp_data)
{
#ifdef BME280_FLOAT_ENABLE
printf("temp %0.2f, p %0.2f, hum %0.2f\r\n",comp_data->temperature, comp_data->pressure, comp_data->humidity);
printf("temp %0.2f, p %0.2f, hum %0.2f\n", comp_data->temperature, comp_data->pressure, comp_data->humidity);
#else
printf("temp %ld, p %ld, hum %ld\r\n",comp_data->temperature, comp_data->pressure, comp_data->humidity);
printf("temp %d, p %d, hum %d\n", comp_data->temperature, comp_data->pressure, comp_data->humidity);
#endif
}
@ -63,8 +63,13 @@ int8_t stream_sensor_data_forced_mode(struct bme280_dev *dev)
settings_sel = BME280_OSR_PRESS_SEL | BME280_OSR_TEMP_SEL | BME280_OSR_HUM_SEL | BME280_FILTER_SEL;
rslt = bme280_set_sensor_settings(settings_sel, dev);
if (rslt != BME280_OK)
{
fprintf(stderr, "Failed to set sensor settings.");
return rslt;
}
printf("Temperature, Pressure, Humidity\r\n");
printf("Temperature, Pressure, Humidity\n");
/* Continuously stream sensor data */
while (1)
{
@ -88,7 +93,7 @@ int main(int argc, char* argv[])
if (argc < 2)
{
printf("Missing argument for I2C device.\n");
fprintf(stderr, "Missing argument for i2c bus.\n");
exit(1);
}
@ -107,25 +112,27 @@ int main(int argc, char* argv[])
dev.write = user_i2c_write;
dev.delay_ms = user_delay_ms;
if ((fd = open(argv[1], O_RDWR)) < 0) {
printf("Failed to open the i2c bus %s\n", argv[1]);
if ((fd = open(argv[1], O_RDWR)) < 0)
{
fprintf(stderr, "Failed to open the i2c bus %s\n", argv[1]);
exit(1);
}
if (ioctl(fd, I2C_SLAVE, dev.dev_id) < 0) {
printf("Failed to acquire bus access and/or talk to slave.\n");
if (ioctl(fd, I2C_SLAVE, dev.dev_id) < 0)
{
fprintf(stderr, "Failed to acquire bus access and/or talk to slave.\n");
exit(1);
}
rslt = bme280_init(&dev);
if (rslt != BME280_OK)
{
printf("Failed to initialize the device.\n");
fprintf(stderr, "Failed to initialize the device.\n");
exit(1);
}
rslt = stream_sensor_data_forced_mode(&dev);
if (rslt != BME280_OK)
{
printf("Failed to stream sensor data.\n");
fprintf(stderr, "Failed to stream sensor data.\n");
exit(1);
}
return 0;