Skip to content

Commit

Permalink
Merge pull request #32 from hoffmannjan/master
Browse files Browse the repository at this point in the history
power save mode support added
  • Loading branch information
ladyada authored Jun 6, 2019
2 parents 283245c + 6d26de2 commit 41e7f60
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
18 changes: 18 additions & 0 deletions Adafruit_INA219.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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, &current);
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
Expand Down
23 changes: 12 additions & 11 deletions Adafruit_INA219.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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

0 comments on commit 41e7f60

Please sign in to comment.