diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4df8ce8..ad5f070 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -29,10 +29,10 @@ Please ensure to specify the following: Arduino IDE version: 1.8.19 ESP8266 Core Version v3.0.2 OS: Ubuntu 20.04 LTS -Linux xy-Inspiron-3593 5.4.0-100-generic #113-Ubuntu SMP Thu Feb 3 18:43:29 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux +Linux xy-Inspiron-3593 5.15.0-53-generic #59~20.04.1-Ubuntu SMP Thu Oct 20 15:10:22 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux Context: -I encountered a crash while trying to use the Timer Interrupt. +I encountered a crash while using this library Steps to reproduce: 1. ... @@ -40,13 +40,34 @@ Steps to reproduce: 3. ... 4. ... ``` + +--- + ### Sending Feature Requests Feel free to post feature requests. It's helpful if you can explain exactly why the feature would be useful. There are usually some outstanding feature requests in the [existing issues list](https://github.com/khoih-prog/ESP8266_ISR_Servo/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement), feel free to add comments to them. +--- + ### Sending Pull Requests Pull Requests with changes and fixes are also welcome! +Please use the `astyle` to reformat the updated library code as follows (demo for Ubuntu Linux) + +1. Change directory to the library GitHub + +``` +xy@xy-Inspiron-3593:~$ cd Arduino/xy/ESP8266_ISR_Servo_GitHub/ +xy@xy-Inspiron-3593:~/Arduino/xy/ESP8266_ISR_Servo_GitHub$ +``` + +2. Issue astyle command + +``` +xy@xy-Inspiron-3593:~/Arduino/xy/ESP8266_ISR_Servo_GitHub$ bash utils/restyle.sh +``` + + diff --git a/README.md b/README.md index 0ff6817..2530954 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,12 @@ [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](#Contributing) [![GitHub issues](https://img.shields.io/github/issues/khoih-prog/ESP8266_ISR_Servo.svg)](http://github.com/khoih-prog/ESP8266_ISR_Servo/issues) + Donate to my libraries using BuyMeACoffee + + + --- --- @@ -60,8 +64,6 @@ Please have a look at [HOWTO Fix `Multiple Definitions` Linker Error](#howto-fix-multiple-definitions-linker-error) - - --- --- @@ -147,14 +149,14 @@ The current library implementation, using `xyz-Impl.h` instead of standard `xyz. You can include this `.hpp` file -``` +```cpp // Can be included as many times as necessary, without `Multiple Definitions` Linker Error #include "ESP8266_ISR_Servo.hpp" //https://github.com/khoih-prog/ESP8266_ISR_Servo ``` in many files. But be sure to use the following `.h` file **in just 1 `.h`, `.cpp` or `.ino` file**, which must **not be included in any other file**, to avoid `Multiple Definitions` Linker Error -``` +```cpp // To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error #include "ESP8266_ISR_Servo.h" //https://github.com/khoih-prog/ESP8266_ISR_Servo ``` @@ -186,7 +188,7 @@ The timer1 counters can be configured to support automatic reload. ### New functions -``` +```cpp // returns last position in degrees if success, or -1 on wrong servoIndex int getPosition(unsigned servoIndex); @@ -249,7 +251,7 @@ https://github.com/khoih-prog/ESP8266_ISR_Servo/blob/9a8757117d2c901bed222990f11 ### 1. ESP8266_MultipleRandomServos on ESP8266_NODEMCU_ESP12E -``` +```cpp Starting ESP8266_MultipleRandomServos on ESP8266_NODEMCU_ESP12E ESP8266_ISR_Servo v1.3.0 [ISR_SERVO] ESP8266FastTimerInterrupt: _fre = 5000000.00 , _count = 50 @@ -353,7 +355,7 @@ Servos idx = 5, act. pos. (deg) = [ISR_SERVO] Idx = 5 ### 2. ESP8266_ISR_MultiServos on ESP8266_NODEMCU_ESP12E -``` +```cpp Starting ESP8266_ISR_MultiServos on ESP8266_NODEMCU_ESP12E ESP8266_ISR_Servo v1.3.0 [ISR_SERVO] ESP8266FastTimerInterrupt: _fre = 5000000.00 , _count = 50 @@ -480,4 +482,4 @@ If you want to contribute to this project: ## Copyright -Copyright 2019- Khoi Hoang +Copyright (c) 2019- Khoi Hoang diff --git a/changelog.md b/changelog.md index 60cb898..e596701 100644 --- a/changelog.md +++ b/changelog.md @@ -6,6 +6,12 @@ [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](#Contributing) [![GitHub issues](https://img.shields.io/github/issues/khoih-prog/ESP8266_ISR_Servo.svg)](http://github.com/khoih-prog/ESP8266_ISR_Servo/issues) + +Donate to my libraries using BuyMeACoffee + + + + --- --- @@ -31,7 +37,7 @@ ### Releases v1.2.0 -1. Update to match new ESP8266 core v3.0.0 +1. Update to match new ESP8266 core `v3.0.0` ### Releases v1.1.0 diff --git a/examples/ESP8266_ISR_MultiServos/ESP8266_ISR_MultiServos.ino b/examples/ESP8266_ISR_MultiServos/ESP8266_ISR_MultiServos.ino index 20a4b56..312891e 100644 --- a/examples/ESP8266_ISR_MultiServos/ESP8266_ISR_MultiServos.ino +++ b/examples/ESP8266_ISR_MultiServos/ESP8266_ISR_MultiServos.ino @@ -2,10 +2,10 @@ ESP8266_ISR_MultiServos.ino For ESP8266 boards Written by Khoi Hoang - + Built by Khoi Hoang https://github.com/khoih-prog/ESP8266_ISR_Servo Licensed under MIT license - + The ESP8266 timers are badly designed, using only 23-bit counter along with maximum 256 prescaler. They're only better than UNO / Mega. The ESP8266 has two hardware timers, but timer0 has been used for WiFi and it's not advisable to use. Only timer1 is available. The timer1's 23-bit counter terribly can count only up to 8,388,607. So the timer1 maximum interval is very short. @@ -19,7 +19,7 @@ Loosely based on SimpleTimer - A timer library for Arduino. Author: mromani@ottotecnica.com Copyright (c) 2010 OTTOTECNICA Italy - + The ESP8266 timers are badly designed, using only 23-bit counter along with maximum 256 prescaler. They're only better than UNO / Mega. The ESP8266 has two hardware timers, but timer0 has been used for WiFi and it's not advisable to use. Only timer1 is available. The timer1's 23-bit counter terribly can count only up to 8,388,607. So the timer1 maximum interval is very short. @@ -87,13 +87,15 @@ int servoIndex2 = -1; void setup() { Serial.begin(115200); + while (!Serial); delay(200); - Serial.print(F("\nStarting ESP8266_ISR_MultiServos on ")); Serial.println(ARDUINO_BOARD); + Serial.print(F("\nStarting ESP8266_ISR_MultiServos on ")); + Serial.println(ARDUINO_BOARD); Serial.println(ESP8266_ISR_SERVO_VERSION); - + servoIndex1 = ISR_Servo.setupServo(D8, MIN_MICROS, MAX_MICROS); servoIndex2 = ISR_Servo.setupServo(D7, MIN_MICROS, MAX_MICROS); @@ -121,10 +123,12 @@ void loop() if (position % 30 == 0) { - Serial.print(F("Servo1 pos = ")); Serial.print(position); - Serial.print(F(", Servo2 pos = ")); Serial.println(180 - position); + Serial.print(F("Servo1 pos = ")); + Serial.print(position); + Serial.print(F(", Servo2 pos = ")); + Serial.println(180 - position); } - + ISR_Servo.setPosition(servoIndex1, position); ISR_Servo.setPosition(servoIndex2, 180 - position); // waits 15ms for the servo to reach the position diff --git a/examples/ESP8266_MultipleRandomServos/ESP8266_MultipleRandomServos.ino b/examples/ESP8266_MultipleRandomServos/ESP8266_MultipleRandomServos.ino index 780a5f0..96a2b79 100644 --- a/examples/ESP8266_MultipleRandomServos/ESP8266_MultipleRandomServos.ino +++ b/examples/ESP8266_MultipleRandomServos/ESP8266_MultipleRandomServos.ino @@ -2,10 +2,10 @@ ESP8266_MultipleRandomServos.ino For ESP8266 boards Written by Khoi Hoang - + Built by Khoi Hoang https://github.com/khoih-prog/ESP8266_ISR_Servo Licensed under MIT license - + The ESP8266 timers are badly designed, using only 23-bit counter along with maximum 256 prescaler. They're only better than UNO / Mega. The ESP8266 has two hardware timers, but timer0 has been used for WiFi and it's not advisable to use. Only timer1 is available. The timer1's 23-bit counter terribly can count only up to 8,388,607. So the timer1 maximum interval is very short. @@ -88,11 +88,13 @@ ISR_servo_t ISR_servo[NUM_SERVOS] = void setup() { Serial.begin(115200); + while (!Serial); delay(200); - Serial.print(F("\nStarting ESP8266_MultipleRandomServos on ")); Serial.println(ARDUINO_BOARD); + Serial.print(F("\nStarting ESP8266_MultipleRandomServos on ")); + Serial.println(ARDUINO_BOARD); Serial.println(ESP8266_ISR_SERVO_VERSION); for (int index = 0; index < NUM_SERVOS; index++) @@ -101,11 +103,13 @@ void setup() if (ISR_servo[index].servoIndex != -1) { - Serial.print(F("Setup OK Servo index = ")); Serial.println(ISR_servo[index].servoIndex); + Serial.print(F("Setup OK Servo index = ")); + Serial.println(ISR_servo[index].servoIndex); } else { - Serial.print(F("Setup Failed Servo index = ")); Serial.println(ISR_servo[index].servoIndex); + Serial.print(F("Setup Failed Servo index = ")); + Serial.println(ISR_servo[index].servoIndex); } } } @@ -126,42 +130,42 @@ void loop() position = 0; Serial.println(F("Servos @ 0 degree")); - + for (int index = 0; index < NUM_SERVOS; index++) { ISR_Servo.setPosition(ISR_servo[index].servoIndex, position ); printServoInfo(index); } - + // waits 5s between test delay(5000); position = 90; Serial.println(F("Servos @ 90 degree")); - + for (int index = 0; index < NUM_SERVOS; index++) { ISR_Servo.setPosition(ISR_servo[index].servoIndex, position ); printServoInfo(index); } - + // waits 5s between test delay(5000); position = 180; Serial.println(F("Servos @ 180 degree")); - + for (int index = 0; index < NUM_SERVOS; index++) { ISR_Servo.setPosition(ISR_servo[index].servoIndex, position ); printServoInfo(index); } - + // waits 5s between test delay(5000); Serial.println(F("Servos sweeps from 0-180 degress")); - + for (position = 0; position <= 180; position += 1) { // goes from 0 degrees to 180 degrees @@ -170,16 +174,16 @@ void loop() { ISR_Servo.setPosition(ISR_servo[index].servoIndex, position ); } - + // waits 50ms for the servo to reach the position delay(50); } - + // waits 5s between test delay(5000); Serial.println(F("Servos sweeps from 180-0 degress")); - + for (position = 180; position >= 0; position -= 1) { // goes from 0 degrees to 180 degrees @@ -188,16 +192,16 @@ void loop() { ISR_Servo.setPosition(ISR_servo[index].servoIndex, position ); } - + // waits 50ms for the servo to reach the position delay(50); } - + // waits 5s between test delay(5000); Serial.println(F("Servos, index depending, be somewhere from 0-180 degress")); - + for (position = 0; position <= 180; position += 1) { // goes from 0 degrees to 180 degrees @@ -206,15 +210,15 @@ void loop() { ISR_Servo.setPosition(ISR_servo[index].servoIndex, (position + index * (180 / NUM_SERVOS)) % 180 ); } - + // waits 50ms for the servo to reach the position delay(50); } - + delay(5000); Serial.println(F("Servos, index depending, be somewhere from 180-0 degress")); - + for (position = 180; position >= 0; position -= 1) { // goes from 0 degrees to 180 degrees @@ -223,11 +227,11 @@ void loop() { ISR_Servo.setPosition(ISR_servo[index].servoIndex, (position + index * (180 / NUM_SERVOS)) % 180 ); } - + // waits 50ms for the servo to reach the position delay(50); } - + // waits 5s between test delay(5000); } diff --git a/examples/ESP8266_MultipleServos/ESP8266_MultipleServos.ino b/examples/ESP8266_MultipleServos/ESP8266_MultipleServos.ino index fefc7fe..e75a22f 100644 --- a/examples/ESP8266_MultipleServos/ESP8266_MultipleServos.ino +++ b/examples/ESP8266_MultipleServos/ESP8266_MultipleServos.ino @@ -2,10 +2,10 @@ ESP8266_MultipleServos.ino For ESP8266 boards Written by Khoi Hoang - + Built by Khoi Hoang https://github.com/khoih-prog/ESP8266_ISR_Servo Licensed under MIT license - + The ESP8266 timers are badly designed, using only 23-bit counter along with maximum 256 prescaler. They're only better than UNO / Mega. The ESP8266 has two hardware timers, but timer0 has been used for WiFi and it's not advisable to use. Only timer1 is available. The timer1's 23-bit counter terribly can count only up to 8,388,607. So the timer1 maximum interval is very short. @@ -88,24 +88,28 @@ ISR_servo_t ISR_servo[NUM_SERVOS] = void setup() { Serial.begin(115200); + while (!Serial); delay(200); - Serial.print(F("\nStarting ESP8266_MultipleServos on ")); Serial.println(ARDUINO_BOARD); + Serial.print(F("\nStarting ESP8266_MultipleServos on ")); + Serial.println(ARDUINO_BOARD); Serial.println(ESP8266_ISR_SERVO_VERSION); - + for (int index = 0; index < NUM_SERVOS; index++) { ISR_servo[index].servoIndex = ISR_Servo.setupServo(ISR_servo[index].servoPin, MIN_MICROS, MAX_MICROS); if (ISR_servo[index].servoIndex != -1) { - Serial.print(F("Setup OK Servo index = ")); Serial.println(ISR_servo[index].servoIndex); + Serial.print(F("Setup OK Servo index = ")); + Serial.println(ISR_servo[index].servoIndex); } else { - Serial.print(F("Setup Failed Servo index = ")); Serial.println(ISR_servo[index].servoIndex); + Serial.print(F("Setup Failed Servo index = ")); + Serial.println(ISR_servo[index].servoIndex); } } } @@ -122,7 +126,7 @@ void loop() { ISR_Servo.setPosition(ISR_servo[index].servoIndex, (position + index * (180 / NUM_SERVOS)) % 180 ); } - + // waits 1s for the servo to reach the position delay(1000); } @@ -135,7 +139,7 @@ void loop() { ISR_Servo.setPosition(ISR_servo[index].servoIndex, (position + index * (180 / NUM_SERVOS)) % 180); } - + // waits 1s for the servo to reach the position delay(1000); } diff --git a/examples/ISR_MultiServos/ISR_MultiServos.ino b/examples/ISR_MultiServos/ISR_MultiServos.ino index b7e4e71..4b54545 100644 --- a/examples/ISR_MultiServos/ISR_MultiServos.ino +++ b/examples/ISR_MultiServos/ISR_MultiServos.ino @@ -2,7 +2,7 @@ ISR_MultiServos.ino For ESP8266 boards Written by Khoi Hoang - + Built by Khoi Hoang https://github.com/khoih-prog/ESP8266_ISR_Servo Licensed under MIT license The ESP8266 timers are badly designed, using only 23-bit counter along with maximum 256 prescaler. They're only better than UNO / Mega. @@ -77,13 +77,15 @@ int servoIndex2 = -1; void setup() { Serial.begin(115200); + while (!Serial); delay(200); - Serial.print(F("\nStarting ISR_MultiServos on ")); Serial.println(ARDUINO_BOARD); + Serial.print(F("\nStarting ISR_MultiServos on ")); + Serial.println(ARDUINO_BOARD); Serial.println(ESP8266_ISR_SERVO_VERSION); - + servoIndex1 = ISR_Servo.setupServo(D8, MIN_MICROS, MAX_MICROS); servoIndex2 = ISR_Servo.setupServo(D7, MIN_MICROS, MAX_MICROS); @@ -111,10 +113,12 @@ void loop() if (position % 30 == 0) { - Serial.print(F("Servo1 pos = ")); Serial.print(position); - Serial.print(F(", Servo2 pos = ")); Serial.println(180 - position); + Serial.print(F("Servo1 pos = ")); + Serial.print(position); + Serial.print(F(", Servo2 pos = ")); + Serial.println(180 - position); } - + ISR_Servo.setPosition(servoIndex1, position); ISR_Servo.setPosition(servoIndex2, 180 - position); // waits 15ms for the servo to reach the position @@ -128,10 +132,12 @@ void loop() // goes from 180 degrees to 0 degrees if (position % 30 == 0) { - Serial.print(F("Servo1 pos = ")); Serial.print(position); - Serial.print(F(", Servo2 pos = ")); Serial.println(180 - position); + Serial.print(F("Servo1 pos = ")); + Serial.print(position); + Serial.print(F(", Servo2 pos = ")); + Serial.println(180 - position); } - + ISR_Servo.setPosition(servoIndex1, position); ISR_Servo.setPosition(servoIndex2, 180 - position); // waits 15ms for the servo to reach the position diff --git a/examples/MultipleRandomServos/MultipleRandomServos.ino b/examples/MultipleRandomServos/MultipleRandomServos.ino index 2ea1549..6ee750a 100644 --- a/examples/MultipleRandomServos/MultipleRandomServos.ino +++ b/examples/MultipleRandomServos/MultipleRandomServos.ino @@ -2,10 +2,10 @@ MultipleRandomServos.ino For ESP8266 boards Written by Khoi Hoang - + Built by Khoi Hoang https://github.com/khoih-prog/ESP8266_ISR_Servo Licensed under MIT license - + The ESP8266 timers are badly designed, using only 23-bit counter along with maximum 256 prescaler. They're only better than UNO / Mega. The ESP8266 has two hardware timers, but timer0 has been used for WiFi and it's not advisable to use. Only timer1 is available. The timer1's 23-bit counter terribly can count only up to 8,388,607. So the timer1 maximum interval is very short. @@ -88,11 +88,13 @@ ISR_servo_t ISR_servo[NUM_SERVOS] = void setup() { Serial.begin(115200); + while (!Serial); delay(200); - Serial.print(F("\nStarting MultipleRandomServos on ")); Serial.println(ARDUINO_BOARD); + Serial.print(F("\nStarting MultipleRandomServos on ")); + Serial.println(ARDUINO_BOARD); Serial.println(ESP8266_ISR_SERVO_VERSION); for (int index = 0; index < NUM_SERVOS; index++) @@ -101,11 +103,13 @@ void setup() if (ISR_servo[index].servoIndex != -1) { - Serial.print(F("Setup OK Servo index = ")); Serial.println(ISR_servo[index].servoIndex); + Serial.print(F("Setup OK Servo index = ")); + Serial.println(ISR_servo[index].servoIndex); } else { - Serial.print(F("Setup Failed Servo index = ")); Serial.println(ISR_servo[index].servoIndex); + Serial.print(F("Setup Failed Servo index = ")); + Serial.println(ISR_servo[index].servoIndex); } } } @@ -126,42 +130,42 @@ void loop() position = 0; Serial.println(F("Servos @ 0 degree")); - + for (int index = 0; index < NUM_SERVOS; index++) { ISR_Servo.setPosition(ISR_servo[index].servoIndex, position ); printServoInfo(index); } - + // waits 5s between test delay(5000); position = 90; Serial.println(F("Servos @ 90 degree")); - + for (int index = 0; index < NUM_SERVOS; index++) { ISR_Servo.setPosition(ISR_servo[index].servoIndex, position ); printServoInfo(index); } - + // waits 5s between test delay(5000); position = 180; Serial.println(F("Servos @ 180 degree")); - + for (int index = 0; index < NUM_SERVOS; index++) { ISR_Servo.setPosition(ISR_servo[index].servoIndex, position ); printServoInfo(index); } - + // waits 5s between test delay(5000); Serial.println(F("Servos sweeps from 0-180 degress")); - + for (position = 0; position <= 180; position += 1) { // goes from 0 degrees to 180 degrees @@ -170,16 +174,16 @@ void loop() { ISR_Servo.setPosition(ISR_servo[index].servoIndex, position ); } - + // waits 50ms for the servo to reach the position delay(50); } - + // waits 5s between test delay(5000); Serial.println(F("Servos sweeps from 180-0 degress")); - + for (position = 180; position >= 0; position -= 1) { // goes from 0 degrees to 180 degrees @@ -188,16 +192,16 @@ void loop() { ISR_Servo.setPosition(ISR_servo[index].servoIndex, position ); } - + // waits 50ms for the servo to reach the position delay(50); } - + // waits 5s between test delay(5000); Serial.println(F("Servos, index depending, be somewhere from 0-180 degress")); - + for (position = 0; position <= 180; position += 1) { // goes from 0 degrees to 180 degrees @@ -206,15 +210,15 @@ void loop() { ISR_Servo.setPosition(ISR_servo[index].servoIndex, (position + index * (180 / NUM_SERVOS)) % 180 ); } - + // waits 50ms for the servo to reach the position delay(50); } - + delay(5000); Serial.println(F("Servos, index depending, be somewhere from 180-0 degress")); - + for (position = 180; position >= 0; position -= 1) { // goes from 0 degrees to 180 degrees @@ -223,11 +227,11 @@ void loop() { ISR_Servo.setPosition(ISR_servo[index].servoIndex, (position + index * (180 / NUM_SERVOS)) % 180 ); } - + // waits 50ms for the servo to reach the position delay(50); } - + // waits 5s between test delay(5000); } diff --git a/examples/MultipleServos/MultipleServos.ino b/examples/MultipleServos/MultipleServos.ino index 35a844d..850c07c 100644 --- a/examples/MultipleServos/MultipleServos.ino +++ b/examples/MultipleServos/MultipleServos.ino @@ -2,10 +2,10 @@ MultipleServos.ino For ESP8266 boards Written by Khoi Hoang - + Built by Khoi Hoang https://github.com/khoih-prog/ESP8266_ISR_Servo Licensed under MIT license - + The ESP8266 timers are badly designed, using only 23-bit counter along with maximum 256 prescaler. They're only better than UNO / Mega. The ESP8266 has two hardware timers, but timer0 has been used for WiFi and it's not advisable to use. Only timer1 is available. The timer1's 23-bit counter terribly can count only up to 8,388,607. So the timer1 maximum interval is very short. @@ -113,6 +113,7 @@ void loop() { ISR_Servo.setPosition(ISR_servo[index].servoIndex, (position + index * (180 / NUM_SERVOS)) % 180 ); } + // waits 1s for the servo to reach the position delay(1000); } @@ -125,6 +126,7 @@ void loop() { ISR_Servo.setPosition(ISR_servo[index].servoIndex, (position + index * (180 / NUM_SERVOS)) % 180); } + // waits 1s for the servo to reach the position delay(1000); } diff --git a/examples/multiFileProject/multiFileProject.cpp b/examples/multiFileProject/multiFileProject.cpp index 3b2ed98..9e15ef8 100644 --- a/examples/multiFileProject/multiFileProject.cpp +++ b/examples/multiFileProject/multiFileProject.cpp @@ -2,7 +2,7 @@ multiFileProject.cpp For ESP8266 boards Written by Khoi Hoang - + Built by Khoi Hoang https://github.com/khoih-prog/ESP8266_ISR_Servo Licensed under MIT license *****************************************************************************************************************************/ diff --git a/examples/multiFileProject/multiFileProject.h b/examples/multiFileProject/multiFileProject.h index 95803ff..c4da6b2 100644 --- a/examples/multiFileProject/multiFileProject.h +++ b/examples/multiFileProject/multiFileProject.h @@ -2,7 +2,7 @@ multiFileProject.h For ESP8266 boards Written by Khoi Hoang - + Built by Khoi Hoang https://github.com/khoih-prog/ESP8266_ISR_Servo Licensed under MIT license *****************************************************************************************************************************/ diff --git a/examples/multiFileProject/multiFileProject.ino b/examples/multiFileProject/multiFileProject.ino index 0f8a9d7..3e4e677 100644 --- a/examples/multiFileProject/multiFileProject.ino +++ b/examples/multiFileProject/multiFileProject.ino @@ -2,7 +2,7 @@ multiFileProject.ino For ESP8266 boards Written by Khoi Hoang - + Built by Khoi Hoang https://github.com/khoih-prog/ESP8266_ISR_Servo Licensed under MIT license *****************************************************************************************************************************/ @@ -21,24 +21,27 @@ // To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error #include "ESP8266_ISR_Servo.h" -void setup() +void setup() { Serial.begin(115200); + while (!Serial); - + Serial.println("\nStart multiFileProject"); Serial.println(ESP8266_ISR_SERVO_VERSION); #if defined(ESP8266_ISR_SERVO_VERSION_MIN) + if (ESP8266_ISR_SERVO_VERSION_INT < ESP8266_ISR_SERVO_VERSION_MIN) { Serial.print("Warning. Must use this example on Version equal or later than : "); Serial.println(ESP8266_ISR_SERVO_VERSION_MIN_TARGET); } + #endif } -void loop() +void loop() { // put your main code here, to run repeatedly: } diff --git a/platformio/platformio.ini b/platformio/platformio.ini index 40e8b11..d455075 100644 --- a/platformio/platformio.ini +++ b/platformio/platformio.ini @@ -27,6 +27,8 @@ upload_speed = 921600 ; Checks for the compatibility with frameworks and dev/platforms lib_compat_mode = strict +lib_ldf_mode = chain+ +;lib_ldf_mode = deep+ lib_deps = diff --git a/src/ESP8266FastTimerInterrupt.h b/src/ESP8266FastTimerInterrupt.h index daa85a3..a900c30 100644 --- a/src/ESP8266FastTimerInterrupt.h +++ b/src/ESP8266FastTimerInterrupt.h @@ -22,7 +22,7 @@ Based on BlynkTimer.h Author: Volodymyr Shymanskyy - + The ESP8266 timers are badly designed, using only 23-bit counter along with maximum 256 prescaler. They're only better than UNO / Mega. The ESP8266 has two hardware timers, but timer0 has been used for WiFi and it's not advisable to use. Only timer1 is available. The timer1's 23-bit counter terribly can count only up to 8,388,607. So the timer1 maximum interval is very short. @@ -51,13 +51,13 @@ #if !defined(ESP8266_ISR_SERVO_VERSION) #define ESP8266_ISR_SERVO_VERSION "ESP8266_ISR_Servo v1.3.0" - + #define ESP8266_ISR_SERVO_VERSION_MAJOR 1 #define ESP8266_ISR_SERVO_VERSION_MINOR 3 #define ESP8266_ISR_SERVO_VERSION_PATCH 0 #define ESP8266_ISR_SERVO_VERSION_INT 1003000 - + #endif @@ -81,11 +81,11 @@ }; //timer int_types - #define TIM_EDGE 0 - #define TIM_LEVEL 1 + #define TIM_EDGE 0 + #define TIM_LEVEL 1 //timer reload values - #define TIM_SINGLE 0 //on interrupt routine you need to write a new value to start the timer again - #define TIM_LOOP 1 //on interrupt the counter will start with the same value again + #define TIM_SINGLE 0 //on interrupt routine you need to write a new value to start the timer again + #define TIM_LOOP 1 //on interrupt the counter will start with the same value again */ diff --git a/src/ESP8266_ISR_Servo.h b/src/ESP8266_ISR_Servo.h index da7704d..d0c705a 100644 --- a/src/ESP8266_ISR_Servo.h +++ b/src/ESP8266_ISR_Servo.h @@ -22,7 +22,7 @@ Based on BlynkTimer.h Author: Volodymyr Shymanskyy - + The ESP8266 timers are badly designed, using only 23-bit counter along with maximum 256 prescaler. They're only better than UNO / Mega. The ESP8266 has two hardware timers, but timer0 has been used for WiFi and it's not advisable to use. Only timer1 is available. The timer1's 23-bit counter terribly can count only up to 8,388,607. So the timer1 maximum interval is very short. diff --git a/src/ESP8266_ISR_Servo_Debug.h b/src/ESP8266_ISR_Servo_Debug.h index c9d663f..d63fe9b 100644 --- a/src/ESP8266_ISR_Servo_Debug.h +++ b/src/ESP8266_ISR_Servo_Debug.h @@ -22,7 +22,7 @@ Based on BlynkTimer.h Author: Volodymyr Shymanskyy - + The ESP8266 timers are badly designed, using only 23-bit counter along with maximum 256 prescaler. They're only better than UNO / Mega. The ESP8266 has two hardware timers, but timer0 has been used for WiFi and it's not advisable to use. Only timer1 is available. The timer1's 23-bit counter terribly can count only up to 8,388,607. So the timer1 maximum interval is very short. diff --git a/src/ESP8266_ISR_Servo_Impl.h b/src/ESP8266_ISR_Servo_Impl.h index 3894bf4..44f19a4 100644 --- a/src/ESP8266_ISR_Servo_Impl.h +++ b/src/ESP8266_ISR_Servo_Impl.h @@ -22,7 +22,7 @@ Based on BlynkTimer.h Author: Volodymyr Shymanskyy - + The ESP8266 timers are badly designed, using only 23-bit counter along with maximum 256 prescaler. They're only better than UNO / Mega. The ESP8266 has two hardware timers, but timer0 has been used for WiFi and it's not advisable to use. Only timer1 is available. The timer1's 23-bit counter terribly can count only up to 8,388,607. So the timer1 maximum interval is very short. @@ -73,7 +73,7 @@ void ESP8266_ISR_Servo::init() else { // Can't set ITimer correctly. Select another freq. or interval - ISR_SERVO_LOGERROR("Fail setup ESP8266_ITimer"); + ISR_SERVO_LOGERROR("Fail setup ESP8266_ITimer"); } for (int8_t servoIndex = 0; servoIndex < MAX_SERVOS; servoIndex++) @@ -172,7 +172,7 @@ int8_t ESP8266_ISR_Servo::setupServo(const uint8_t& pin, const uint16_t& min, co pinMode(pin, OUTPUT); numServos++; - + ISR_SERVO_LOGDEBUG3("Index =", servoIndex, ", count =", servo[servoIndex].count); ISR_SERVO_LOGDEBUG3("min =", servo[servoIndex].min, ", max =", servo[servoIndex].max); @@ -188,11 +188,12 @@ bool ESP8266_ISR_Servo::setPosition(const uint8_t& servoIndex, const uint16_t& p if ( servo[servoIndex].enabled && (servo[servoIndex].pin <= ESP8266_MAX_PIN) ) { servo[servoIndex].position = position; - servo[servoIndex].count = map(position, 0, 180, servo[servoIndex].min, servo[servoIndex].max) / TIMER_INTERVAL_MICRO; + servo[servoIndex].count = map(position, 0, 180, servo[servoIndex].min, + servo[servoIndex].max) / TIMER_INTERVAL_MICRO; ISR_SERVO_LOGERROR1("Idx =", servoIndex); - ISR_SERVO_LOGERROR3("cnt =", servo[servoIndex].count, ", pos =",servo[servoIndex].position); - + ISR_SERVO_LOGERROR3("cnt =", servo[servoIndex].count, ", pos =", servo[servoIndex].position); + return true; } @@ -210,7 +211,7 @@ int ESP8266_ISR_Servo::getPosition(const uint8_t& servoIndex) if ( servo[servoIndex].enabled && (servo[servoIndex].pin <= ESP8266_MAX_PIN) ) { ISR_SERVO_LOGERROR1("Idx =", servoIndex); - ISR_SERVO_LOGERROR3("cnt =", servo[servoIndex].count, ", pos =",servo[servoIndex].position); + ISR_SERVO_LOGERROR3("cnt =", servo[servoIndex].count, ", pos =", servo[servoIndex].position); return (servo[servoIndex].position); } @@ -241,7 +242,7 @@ bool ESP8266_ISR_Servo::setPulseWidth(const uint8_t& servoIndex, uint16_t& pulse servo[servoIndex].position = map(pulseWidth, servo[servoIndex].min, servo[servoIndex].max, 0, 180); ISR_SERVO_LOGERROR1("Idx =", servoIndex); - ISR_SERVO_LOGERROR3("cnt =", servo[servoIndex].count, ", pos =",servo[servoIndex].position); + ISR_SERVO_LOGERROR3("cnt =", servo[servoIndex].count, ", pos =", servo[servoIndex].position); return true; } @@ -260,7 +261,7 @@ unsigned int ESP8266_ISR_Servo::getPulseWidth(const uint8_t& servoIndex) if ( servo[servoIndex].enabled && (servo[servoIndex].pin <= ESP8266_MAX_PIN) ) { ISR_SERVO_LOGERROR1("Idx =", servoIndex); - ISR_SERVO_LOGERROR3("cnt =", servo[servoIndex].count, ", pos =",servo[servoIndex].position); + ISR_SERVO_LOGERROR3("cnt =", servo[servoIndex].count, ", pos =", servo[servoIndex].position); return (servo[servoIndex].count * TIMER_INTERVAL_MICRO ); } @@ -352,8 +353,8 @@ void ESP8266_ISR_Servo::enableAll() { // Bug fix. See "Fixed count >= min comparison for servo enable." // (https://github.com/khoih-prog/ESP32_ISR_Servo/pull/1) - if ( (servo[servoIndex].count >= servo[servoIndex].min / TIMER_INTERVAL_MICRO ) && !servo[servoIndex].enabled - && (servo[servoIndex].pin <= ESP8266_MAX_PIN) ) + if ( (servo[servoIndex].count >= servo[servoIndex].min / TIMER_INTERVAL_MICRO ) && !servo[servoIndex].enabled + && (servo[servoIndex].pin <= ESP8266_MAX_PIN) ) { servo[servoIndex].enabled = true; } diff --git a/utils/astyle_library.conf b/utils/astyle_library.conf new file mode 100644 index 0000000..8a73bc2 --- /dev/null +++ b/utils/astyle_library.conf @@ -0,0 +1,70 @@ +# Code formatting rules for Arduino libraries, modified from for KH libraries: +# +# https://github.com/arduino/Arduino/blob/master/build/shared/examples_formatter.conf +# + +# astyle --style=allman -s2 -t2 -C -S -xW -Y -M120 -f -p -xg -H -xb -c --xC120 -xL *.h *.cpp *.ino + +--mode=c +--lineend=linux +--style=allman + +# -r or -R +#--recursive + +# -c => Converts tabs into spaces +convert-tabs + +# -s2 => 2 spaces indentation +--indent=spaces=2 + +# -t2 => tab =2 spaces +#--indent=tab=2 + +# -C +--indent-classes + +# -S +--indent-switches + +# -xW +--indent-preproc-block + +# -Y => indent classes, switches (and cases), comments starting at column 1 +--indent-col1-comments + +# -M120 => maximum of 120 spaces to indent a continuation line +--max-continuation-indent=120 + +# -xC120 => max‑code‑length will break a line if the code exceeds # characters +--max-code-length=120 + +# -f => +--break-blocks + +# -p => put a space around operators +--pad-oper + +# -xg => Insert space padding after commas +--pad-comma + +# -H => put a space after if/for/while +pad-header + +# -xb => Break one line headers (e.g. if/for/while) +--break-one-line-headers + +# -c => Converts tabs into spaces +#--convert-tabs + +# if you like one-liners, keep them +#keep-one-line-statements + +# -xV +--attach-closing-while + +#unpad-paren + +# -xp +remove-comment-prefix + diff --git a/utils/restyle.sh b/utils/restyle.sh new file mode 100644 index 0000000..bcd846f --- /dev/null +++ b/utils/restyle.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +for dir in . ; do + find $dir -type f \( -name "*.c" -o -name "*.h" -o -name "*.cpp" -o -name "*.ino" \) -exec astyle --suffix=none --options=./utils/astyle_library.conf \{\} \; +done +