diff --git a/README.md b/README.md index f8d1a63..65ef4d8 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,8 @@ Unexpected Maker W.O.P.R. board. Install using the library manager in the Arduino IDE. +This library is compatible with the ESP32 Arduino core version 2.x and 3.x. + ## Usage The library exposes several classes that you can use to interact with the board. @@ -19,6 +21,31 @@ The library exposes several classes that you can use to interact with the board. - `JBWoprMqttDevice` - This adds MQTT support to the `JBWoprWifiDevice` class. - `JBWoprHomeAssistantDevice` - This adds Home Assistant support to the `JBWoprMqttDevice` class. +## Dependencies + +Depending on the class used the following libraries need to be installed. They can all be installed using the Library Manager. + +### JBWoprDevice + + - [JBLogger](https://github.com/jonnybergdahl/Arduino_JBLogger_Library) + - [Adafruit_GFX>](https://github.com/adafruit/Adafruit-GFX-Library) + - [Adafruit_LEDBackpack](https://github.com/adafruit/Adafruit_LED_Backpack) + - [Adafruit_NeoPixel](https://github.com/adafruit/Adafruit_NeoPixel) + - [OneButton](https://github.com/mathertel/OneButton) + - [ArduinoJson](https://github.com/bblanchon/ArduinoJson) + +### JBWoprWifiDevice + +The above, plus: + + - [WiFiManager](https://github.com/tzapu/WiFiManager) + +### JBWoprMqttDevice + +The above, plus: + + - [WiFiManager](https://github.com/tzapu/WiFiManager) + ### Compiling the examples Due to the size of the library, you may need to change the partition size in the Arduino IDE. @@ -57,20 +84,20 @@ JBWoprDevice wopr; void setup() { // Configure the JBWoprDevice class JBWoprConfiguration* config = wopr.getConfiguration(); - config->timeFormat = "%H %M %s"; + config->timeFormat = "%H %M %s"; config->dateFormat = "%Y-%m-%d"; - config->displayBrightness = 50; - config->defconLedsBrightness = 50; + config->displayBrightness = 50; + config->defconLedsBrightness = 50; - // Initialize the JBWoprDevice class, passing in the board version - // JBWoprBoardVariant::HAXORZ or JBWoprBoardVariant::ORIGINAL - wopr.begin(JBWoprBoardVariant::HAXORZ); + // Initialize the JBWoprDevice class, passing in the board version + // JBWoprBoardVariant::HAXORZ or JBWoprBoardVariant::ORIGINAL + wopr.begin(JBWoprBoardVariant::HAXORZ); } void loop() { - wopr.loop(); + wopr.loop(); - // Add your code here + // Add your code here } ``` @@ -104,11 +131,11 @@ but you can also create your own effects by inheriting from the `JBWoprEffectBas #include #include begin() { - ... - wopr.effectsRegisterEffect(new JBWoprMissileCodeSolveEffect(&wopr, - CodeSolveVariant::MOVIE, - 1000, - "Movie solve")); + ... + wopr.effectsRegisterEffect(new JBWoprMissileCodeSolveEffect(&wopr, + CodeSolveVariant::MOVIE, + 1000, + "Movie solve")); } loop() { diff --git a/library.properties b/library.properties index b39ae3c..3a9bf0d 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=JBWopr -version=1.0.3 +version=1.0.4 author=Jonny Bergdahl maintainer=Jonny Bergdahl sentence=Support library for the Unexpected Maker W.O.P.R. boards diff --git a/src/jbwopr.cpp b/src/jbwopr.cpp index 9c71579..3dc7821 100644 --- a/src/jbwopr.cpp +++ b/src/jbwopr.cpp @@ -66,6 +66,8 @@ bool JBWoprDevice::begin(JBWoprBoardVariant variant, JBWoprBoardPins pins) { _woprVariant = variant; _log->info("JBWoprDevice begin, variant: %i", variant); + _pins = pins; + // Buttons _log->trace("Button pins: %i, %i, %i, %i", pins.buttonFrontLeftPin, pins.buttonFrontRightPin, pins.buttonBackTopPin, pins.buttonBackBottomPin); _buttonFrontLeft = new OneButton(pins.buttonFrontLeftPin, false); @@ -100,12 +102,15 @@ bool JBWoprDevice::begin(JBWoprBoardVariant variant, JBWoprBoardPins pins) { // Audio pinMode(pins.dacPin, OUTPUT); +#if ESP_ARDUINO_VERSION_MAJOR < 3 if (ledcSetup(_audioChannel, _audioFreq, _audioResolution) == 0) { _log->error("Audio setup failed"); return false; }; ledcAttachPin(pins.dacPin, _audioChannel); - +#else + ledcAttachChannel(pins.dacPin, _audioFreq, _audioResolution, _audioChannel); +#endif // Buttons _buttonFrontLeft->attachClick(&JBWoprDevice::_staticButtonFrontLeftClickCallback, this); _buttonFrontLeft->attachDoubleClick(&JBWoprDevice::_staticButtonFrontLeftDoubleClickCallback, this); @@ -498,17 +503,29 @@ void JBWoprDevice::defconLedSetDefconStateColor(JBDefconLevel level, uint32_t co void JBWoprDevice::audioPlayTone(uint16_t freq) { +#if ESP_ARDUINO_VERSION_MAJOR < 3 ledcWriteTone(_audioChannel, freq); +#else + ledcWriteTone(_pins.dacPin, freq); +#endif } void JBWoprDevice::audioPlayNote(note_t note, uint8_t octave) { +#if ESP_ARDUINO_VERSION_MAJOR < 3 ledcWriteNote(_audioChannel, note, octave); +#else + ledcWriteNote(_pins.dacPin, note, octave); +#endif } void JBWoprDevice::audioClear() { +#if ESP_ARDUINO_VERSION_MAJOR < 3 ledcWrite(_audioChannel, 0); +#else + ledcWrite(_pins.dacPin, 0); +#endif } // ------------------------------------------------------------------ diff --git a/src/jbwopr.h b/src/jbwopr.h index d6b91d0..16c4de5 100644 --- a/src/jbwopr.h +++ b/src/jbwopr.h @@ -12,7 +12,7 @@ #include #include #include -#include +//#include #include #include // https://github.com/adafruit/Adafruit-GFX-Library #include // https://github.com/adafruit/Adafruit_LED_Backpack @@ -451,6 +451,7 @@ class JBWoprDevice { // JBWoprBoardVariant _woprVariant; ///< W.O.P.R. board version JBWoprConfiguration _config; ///< JBWoprDevice configuration + JBWoprBoardPins _pins; ///< W.O.P.R. board pin assignements // ==================================================================== // Effects