From 15f7f913db7610a6c1f8c49261f47cc877d6e763 Mon Sep 17 00:00:00 2001 From: Wayne Piekarski Date: Wed, 22 Jun 2022 09:46:56 -0700 Subject: [PATCH] Add ability to detect I2C errors within setPWM() while compatible with existing code --- Adafruit_PWMServoDriver.cpp | 6 ++++-- Adafruit_PWMServoDriver.h | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Adafruit_PWMServoDriver.cpp b/Adafruit_PWMServoDriver.cpp index 23b7365..56099c2 100755 --- a/Adafruit_PWMServoDriver.cpp +++ b/Adafruit_PWMServoDriver.cpp @@ -218,8 +218,10 @@ uint8_t Adafruit_PWMServoDriver::getPWM(uint8_t num) { * @param num One of the PWM output pins, from 0 to 15 * @param on At what point in the 4096-part cycle to turn the PWM output ON * @param off At what point in the 4096-part cycle to turn the PWM output OFF + * @return result from endTransmission */ -void Adafruit_PWMServoDriver::setPWM(uint8_t num, uint16_t on, uint16_t off) { +uint8_t Adafruit_PWMServoDriver::setPWM(uint8_t num, uint16_t on, + uint16_t off) { #ifdef ENABLE_DEBUG_OUTPUT Serial.print("Setting PWM "); Serial.print(num); @@ -235,7 +237,7 @@ void Adafruit_PWMServoDriver::setPWM(uint8_t num, uint16_t on, uint16_t off) { _i2c->write(on >> 8); _i2c->write(off); _i2c->write(off >> 8); - _i2c->endTransmission(); + return _i2c->endTransmission(); } /*! diff --git a/Adafruit_PWMServoDriver.h b/Adafruit_PWMServoDriver.h index e0857d8..742002e 100644 --- a/Adafruit_PWMServoDriver.h +++ b/Adafruit_PWMServoDriver.h @@ -85,7 +85,7 @@ class Adafruit_PWMServoDriver { void setPWMFreq(float freq); void setOutputMode(bool totempole); uint8_t getPWM(uint8_t num); - void setPWM(uint8_t num, uint16_t on, uint16_t off); + uint8_t setPWM(uint8_t num, uint16_t on, uint16_t off); void setPin(uint8_t num, uint16_t val, bool invert = false); uint8_t readPrescale(void); void writeMicroseconds(uint8_t num, uint16_t Microseconds);