separate value1 and value2 byte reads

pull/18/head
alanbjohnston 7 years ago committed by GitHub
parent 7d79af0af9
commit 751da0655e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -120,11 +120,13 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) {
wiringPiI2CWrite(sensor.fd, INA219_REG_CURRENT);
delay(1); // Max 12-bit conversion time is 586us per sample
int16_t valuex = (int16_t)((wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd));
int value1 = wiringPiI2CRead(sensor.fd);
int value2 = wiringPiI2CRead(sensor.fd);
int16_t valuex = (int16_t)(value1 << 8 ) | value2);
// uint16_t valuex = (uint16_t)wireReadRegister(sensor.fd, INA219_REG_CURRENT);
data.current = (double)valuex / (double)sensor.currentDivider;
printf("&&&&&&&& valuex %d current %f \n", valuex, data.current);
printf("&&&&&&&& value1 %d value2 %d valuex %d current %f \n", value1, value2, valuex, data.current);
uint16_t value2 = (uint16_t)wireReadRegister(sensor.fd, INA219_REG_BUSVOLTAGE);
data.voltage = ((double)(value2 >> 3) * 4) / 1000;

Loading…
Cancel
Save

Powered by TurnKey Linux.