From 6d26de2eff6f13830a56bf3c950f00529b67ecc7 Mon Sep 17 00:00:00 2001 From: Jan Hoffmann Date: Thu, 6 Jun 2019 18:32:13 +0200 Subject: [PATCH] requested change --- Adafruit_INA219.cpp | 23 ++++++++++------------- Adafruit_INA219.h | 3 +-- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/Adafruit_INA219.cpp b/Adafruit_INA219.cpp index aedaacd..d354ca7 100644 --- a/Adafruit_INA219.cpp +++ b/Adafruit_INA219.cpp @@ -152,22 +152,19 @@ void Adafruit_INA219::setCalibration_32V_2A() { } /*! - * @brief Enable power save mode + * @brief Set power save mode according to parameters + * @param on + * boolean value */ -void Adafruit_INA219::powerSaveModeOn() { +void Adafruit_INA219::powerSave(bool on) { uint16_t current; wireReadRegister(INA219_REG_CONFIG, ¤t); - uint16_t next = current | INA219_CONFIG_MODE_POWERDOWN; - wireWriteRegister(INA219_REG_CONFIG, next); -} - -/*! - * @brief Disable power save mode - */ -void Adafruit_INA219::powerSaveModeOff() { - uint16_t current; - wireReadRegister(INA219_REG_CONFIG, ¤t); - uint8_t next = current & ~INA219_CONFIG_MODE_POWERDOWN; + uint8_t next; + if (on) { + next = current | INA219_CONFIG_MODE_POWERDOWN; + } else { + next = current & ~INA219_CONFIG_MODE_POWERDOWN; + } wireWriteRegister(INA219_REG_CONFIG, next); } diff --git a/Adafruit_INA219.h b/Adafruit_INA219.h index 09e1dd0..1f76531 100644 --- a/Adafruit_INA219.h +++ b/Adafruit_INA219.h @@ -138,8 +138,7 @@ class Adafruit_INA219 { float getShuntVoltage_mV(); float getCurrent_mA(); float getPower_mW(); - void powerSaveModeOn(); - void powerSaveModeOff(); + void powerSave(bool on); private: TwoWire *_i2c;