Skip to content

Commit

Permalink
Add support for Arduino ESP32 core version 3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
bergdahl committed Jun 7, 2024
1 parent 073f8c8 commit 368a954
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 16 deletions.
53 changes: 40 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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
}
```

Expand Down Expand Up @@ -104,11 +131,11 @@ but you can also create your own effects by inheriting from the `JBWoprEffectBas
#include <jbwopr.h>
#include <effects/jbwopreffets.h>
begin() {
...
wopr.effectsRegisterEffect(new JBWoprMissileCodeSolveEffect(&wopr,
CodeSolveVariant::MOVIE,
1000,
"Movie solve"));
...
wopr.effectsRegisterEffect(new JBWoprMissileCodeSolveEffect(&wopr,
CodeSolveVariant::MOVIE,
1000,
"Movie solve"));
}

loop() {
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=JBWopr
version=1.0.3
version=1.0.4
author=Jonny Bergdahl
maintainer=Jonny Bergdahl <[email protected]>
sentence=Support library for the Unexpected Maker W.O.P.R. boards
Expand Down
19 changes: 18 additions & 1 deletion src/jbwopr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
}

// ------------------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion src/jbwopr.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <Arduino.h>
#include <map>
#include <list>
#include <driver/i2s.h>
//#include <driver/i2s.h>
#include <jblogger.h>
#include <Adafruit_GFX.h> // https://github.com/adafruit/Adafruit-GFX-Library
#include <Adafruit_LEDBackpack.h> // https://github.com/adafruit/Adafruit_LED_Backpack
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 368a954

Please sign in to comment.