diff --git a/afsk/main.c b/afsk/main.c index a1b93c92..e6019861 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -120,9 +120,9 @@ 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 valueC = (int16_t)((wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd)); - - float valuec3 = (float)(valueC); + int valueC = ((wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd)); + int twos = twosToInt(valueC, 16); + float valuec3 = (float)(twos); data.current = valuec3 / (float)sensor.currentDivider; // uint16_t value3 = (uint16_t)wireReadRegister(sensor.fd, INA219_REG_BUSVOLTAGE);