1919 @brief Ctor for PWMHardware
2020*/
2121/* *************************************************************************/
22- PWMHardware::PWMHardware () {
23- _is_attached = false ;
24- }
22+ PWMHardware::PWMHardware () { _is_attached = false ; }
2523
2624/* *************************************************************************/
2725/* !
@@ -42,21 +40,22 @@ PWMHardware::~PWMHardware() {
4240 @return true if the pin was successfully attached, false otherwise
4341*/
4442/* *************************************************************************/
45- bool PWMHardware::AttachPin (uint8_t pin, uint32_t frequency, uint32_t resolution) {
43+ bool PWMHardware::AttachPin (uint8_t pin, uint32_t frequency,
44+ uint32_t resolution) {
4645#ifdef ARDUINO_ARCH_ESP32
4746 _is_attached = ledcAttach (pin, frequency, resolution);
4847#else
4948 _is_attached = true ;
5049#endif
5150
52- if (_is_attached) {
53- _pin = pin;
54- _frequency = frequency;
55- _resolution = resolution;
56- _duty_cycle = 0 ;
57- }
51+ if (_is_attached) {
52+ _pin = pin;
53+ _frequency = frequency;
54+ _resolution = resolution;
55+ _duty_cycle = 0 ;
56+ }
5857
59- return _is_attached;
58+ return _is_attached;
6059}
6160
6261/* *************************************************************************/
@@ -66,20 +65,20 @@ return _is_attached;
6665*/
6766/* *************************************************************************/
6867bool PWMHardware::DetachPin () {
69- if (! _is_attached) {
70- WS_DEBUG_PRINTLN (" [pwm] Pin not attached!" );
71- return false ;
72- }
73- bool did_detach = false ;
74- #ifdef ARDUINO_ARCH_ESP32
75- did_detach = ledcDetach (_pin);
76- #else
77- digitalWrite (_pin, LOW); // "Disable" the pin's output
78- did_detach = true ;
79- #endif
80-
81- _is_attached = false ; // always mark as false, for tracking
82- return did_detach;
68+ if (!_is_attached) {
69+ WS_DEBUG_PRINTLN (" [pwm] Pin not attached!" );
70+ return false ;
71+ }
72+ bool did_detach = false ;
73+ #ifdef ARDUINO_ARCH_ESP32
74+ did_detach = ledcDetach (_pin);
75+ #else
76+ digitalWrite (_pin, LOW); // "Disable" the pin's output
77+ did_detach = true ;
78+ #endif
79+
80+ _is_attached = false ; // always mark as false, for tracking
81+ return did_detach;
8382}
8483
8584/* *************************************************************************/
@@ -91,18 +90,18 @@ bool PWMHardware::DetachPin() {
9190*/
9291/* *************************************************************************/
9392bool PWMHardware::WriteDutyCycle (uint32_t duty) {
94- if (! _is_attached) {
93+ if (!_is_attached) {
9594 WS_DEBUG_PRINTLN (" [pwm] Pin not attached!" );
9695 return false ;
9796 }
9897 bool did_write = false ;
99- #if defined(ARDUINO_ESP8266_ADAFRUIT_HUZZAH) && defined(STATUS_LED_PIN)
98+ #if defined(ARDUINO_ESP8266_ADAFRUIT_HUZZAH) && defined(STATUS_LED_PIN)
10099 // Adafruit Feather ESP8266's analogWrite() gets inverted since the builtin
101100 // LED is reverse-wired
102101 _duty_cycle = 255 - duty;
103- #else
102+ #else
104103 _duty_cycle = duty;
105- #endif
104+ #endif
106105
107106#ifdef ARDUINO_ARCH_ESP32
108107 did_write = analogWrite (_duty_cycle);
@@ -122,18 +121,18 @@ bool PWMHardware::WriteDutyCycle(uint32_t duty) {
122121*/
123122/* *************************************************************************/
124123uint32_t PWMHardware::WriteTone (uint32_t freq) {
125- if (! _is_attached) {
124+ if (!_is_attached) {
126125 WS_DEBUG_PRINTLN (" [pwm] Pin not attached!" );
127126 return false ;
128127 }
129128
130129 uint32_t rc = 0 ;
131- #ifdef ARDUINO_ARCH_ESP32
130+ #ifdef ARDUINO_ARCH_ESP32
132131 rc = ledcWriteTone (_pin, freq);
133- #else
132+ #else
134133 tone (_pin, freq);
135134 rc = freq;
136- #endif
135+ #endif
137136
138137 return rc;
139138}
@@ -144,9 +143,7 @@ uint32_t PWMHardware::WriteTone(uint32_t freq) {
144143 @return The logical pin number of the PWM pin
145144*/
146145/* *************************************************************************/
147- uint8_t PWMHardware::GetPin () {
148- return _pin;
149- }
146+ uint8_t PWMHardware::GetPin () { return _pin; }
150147
151148// LEDC API Wrappers
152149#ifdef ARDUINO_ARCH_ESP32
0 commit comments