diff --git a/Adafruit_INA219.cpp b/Adafruit_INA219.cpp index aa0e64d..d354ca7 100644 --- a/Adafruit_INA219.cpp +++ b/Adafruit_INA219.cpp @@ -151,6 +151,24 @@ void Adafruit_INA219::setCalibration_32V_2A() { wireWriteRegister(INA219_REG_CONFIG, config); } +/*! + * @brief Set power save mode according to parameters + * @param on + * boolean value + */ +void Adafruit_INA219::powerSave(bool on) { + uint16_t current; + wireReadRegister(INA219_REG_CONFIG, ¤t); + uint8_t next; + if (on) { + next = current | INA219_CONFIG_MODE_POWERDOWN; + } else { + next = current & ~INA219_CONFIG_MODE_POWERDOWN; + } + wireWriteRegister(INA219_REG_CONFIG, next); +} + + /*! * @brief Configures to INA219 to be able to measure up to 32V and 1A * of current. Each unit of current corresponds to 40uA, and each diff --git a/Adafruit_INA219.h b/Adafruit_INA219.h index 491f7a0..1f76531 100644 --- a/Adafruit_INA219.h +++ b/Adafruit_INA219.h @@ -131,13 +131,14 @@ class Adafruit_INA219 { public: Adafruit_INA219(uint8_t addr = INA219_ADDRESS); void begin(TwoWire *theWire = &Wire); - void setCalibration_32V_2A(void); - void setCalibration_32V_1A(void); - void setCalibration_16V_400mA(void); - float getBusVoltage_V(void); - float getShuntVoltage_mV(void); - float getCurrent_mA(void); - float getPower_mW(void); + void setCalibration_32V_2A(); + void setCalibration_32V_1A(); + void setCalibration_16V_400mA(); + float getBusVoltage_V(); + float getShuntVoltage_mV(); + float getCurrent_mA(); + float getPower_mW(); + void powerSave(bool on); private: TwoWire *_i2c; @@ -152,10 +153,10 @@ class Adafruit_INA219 { void init(); void wireWriteRegister(uint8_t reg, uint16_t value); void wireReadRegister(uint8_t reg, uint16_t *value); - int16_t getBusVoltage_raw(void); - int16_t getShuntVoltage_raw(void); - int16_t getCurrent_raw(void); - int16_t getPower_raw(void); + int16_t getBusVoltage_raw(); + int16_t getShuntVoltage_raw(); + int16_t getCurrent_raw(); + int16_t getPower_raw(); }; #endif