changed NaN to 0's, added value check and set fd = -1 if not present

pull/26/head
alanbjohnston 6 years ago committed by GitHub
parent c3d58f88db
commit 0f7af2be1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -80,9 +80,9 @@ struct SensorData {
*/
struct SensorData read_sensor_data(struct SensorConfig sensor) {
struct SensorData data = {
.current = NAN,
.voltage = NAN,
.power = NAN };
.current = 0,
.voltage = 0,
.power = 0 };
if (sensor.fd < 0) {
return data;
@ -92,6 +92,11 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) {
wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CONFIG, sensor.config);
wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue);
int value = wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT);
if (value == -1)
{
sensor.fd = -1;
return data;
}
data.current = (float) twosToInt(value, 16) / (float) sensor.currentDivider;
wiringPiI2CWrite(sensor.fd, INA219_REG_BUSVOLTAGE);

Loading…
Cancel
Save

Powered by TurnKey Linux.