|
|
|
@ -110,7 +110,8 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) {
|
|
|
|
wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue);
|
|
|
|
wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue);
|
|
|
|
wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CONFIG, sensor.config);
|
|
|
|
wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CONFIG, sensor.config);
|
|
|
|
wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue);
|
|
|
|
wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue);
|
|
|
|
// data.current = (float)((int16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT)) / (float)sensor.currentDivider;
|
|
|
|
data.current = (float)((int16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT)) / (float)sensor.currentDivider;
|
|
|
|
|
|
|
|
/*
|
|
|
|
int16_t value0 = 1; // (int16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT);
|
|
|
|
int16_t value0 = 1; // (int16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT);
|
|
|
|
wiringPiI2CWrite(sensor.fd, INA219_REG_CURRENT);
|
|
|
|
wiringPiI2CWrite(sensor.fd, INA219_REG_CURRENT);
|
|
|
|
delay(1); // Max 12-bit conversion time is 586us per sample
|
|
|
|
delay(1); // Max 12-bit conversion time is 586us per sample
|
|
|
|
@ -119,9 +120,10 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) {
|
|
|
|
//int16_t value = (int16_t)((wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd));
|
|
|
|
//int16_t value = (int16_t)((wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd));
|
|
|
|
//int16_t value = (( ((int16_t)byte) << 8 ) | (int16_t)wiringPiI2CRead (sensor.fd));
|
|
|
|
//int16_t value = (( ((int16_t)byte) << 8 ) | (int16_t)wiringPiI2CRead (sensor.fd));
|
|
|
|
int16_t value = (int16_t)(( ((uint8_t)byte) << 8 ) | (uint8_t)wiringPiI2CRead (sensor.fd));
|
|
|
|
int16_t value = (int16_t)(( ((uint8_t)byte) << 8 ) | (uint8_t)wiringPiI2CRead (sensor.fd));
|
|
|
|
float value1 = (float) value;
|
|
|
|
float value1 = (float) value;
|
|
|
|
data.current = value1 / (float)sensor.currentDivider;
|
|
|
|
data.current = value1 / (float)sensor.currentDivider;
|
|
|
|
printf("********* value0 %d value1 %f value %d data.current %f \n", value0, value1, value, data.current);
|
|
|
|
printf("********* value0 %d value1 %f value %d data.current %f \n", value0, value1, value, data.current);
|
|
|
|
|
|
|
|
*/
|
|
|
|
uint16_t value2 = (uint16_t)wireReadRegister(sensor.fd, INA219_REG_BUSVOLTAGE);
|
|
|
|
uint16_t value2 = (uint16_t)wireReadRegister(sensor.fd, INA219_REG_BUSVOLTAGE);
|
|
|
|
data.voltage = ((double)(value2 >> 3) * 4) / 1000;
|
|
|
|
data.voltage = ((double)(value2 >> 3) * 4) / 1000;
|
|
|
|
data.power = (float)((uint16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_POWER)) * (float)sensor.powerMultiplier;
|
|
|
|
data.power = (float)((uint16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_POWER)) * (float)sensor.powerMultiplier;
|
|
|
|
|