diff --git a/src/INA226_asukiaaa.cpp b/src/INA226_asukiaaa.cpp index 1656164..9db682b 100644 --- a/src/INA226_asukiaaa.cpp +++ b/src/INA226_asukiaaa.cpp @@ -51,10 +51,26 @@ int INA226_asukiaaa::readMV(int16_t* volt) { return 0; } +int INA226_asukiaaa::readV(float* volt) { + uint16_t mv; + int result = readMV(&mv); + if (result != 0) return result; + *volt = (float) mv / 1000; + return 0; +} + int INA226_asukiaaa::readMA(int16_t* current) { return read(INA226_ASUKIAAA_REGISTER_CURRENT, (uint16_t*) current); } +int INA226_asukiaaa::readA(float* current) { + uint16_t ma; + int result = readMA(&ma); + if (result != 0) return result; + *current = (float) ma / 1000; + return 0; +} + int INA226_asukiaaa::readMW(int16_t* watt) { uint16_t powerVoltage; int result = read(INA226_ASUKIAAA_REGISTER_POWER, (uint16_t*) &powerVoltage); @@ -63,6 +79,14 @@ int INA226_asukiaaa::readMW(int16_t* watt) { return 0; } +int INA226_asukiaaa::readW(float* watt) { + uint16_t mw; + int result = readMW(&mw); + if (result != 0) return result; + *watt = (float) mw / 1000; + return 0; +} + int INA226_asukiaaa::write(uint8_t reg, uint16_t val) { wire->beginTransmission(address); wire->write(reg); diff --git a/src/INA226_asukiaaa.h b/src/INA226_asukiaaa.h index 84a6c44..3b7490b 100644 --- a/src/INA226_asukiaaa.h +++ b/src/INA226_asukiaaa.h @@ -32,8 +32,11 @@ class INA226_asukiaaa { int begin(); int readMV(int16_t* volt); + int readV(float* volt); int readMA(int16_t* current); + int readA(float* current); int readMW(int16_t* watt); + int readW(float* watt); private: int address;