Skip to content

Commit b7d72b4

Browse files
committed
Adding PIO support
1 parent 6df497e commit b7d72b4

File tree

5 files changed

+177
-114
lines changed

5 files changed

+177
-114
lines changed

.github/workflows/build-deploy-webflash.yml

Lines changed: 53 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
push:
77
branches: ["main"]
88
paths-ignore:
9-
- '**.md'
9+
- "**.md"
1010

1111
# Allows you to run this workflow manually from the Actions tab
1212
workflow_dispatch:
@@ -28,113 +28,70 @@ jobs:
2828
build:
2929
runs-on: ubuntu-latest
3030
steps:
31-
- name: Checkout
32-
uses: actions/checkout@v3
33-
34-
# Install the Arduino CLI
35-
- name: Install Arduino CLI
36-
uses: arduino/setup-arduino-cli@v1
37-
38-
# Install TFT_eSPI
39-
- name: Install TFT_eSPI library to prepare for modifications
40-
run: |
41-
arduino-cli lib install TFT_eSPI
42-
43-
# Copy binaries to GitHubPages folder for publishing
44-
- name: Copy User_Setup.h for TFT_eSPI
31+
- uses: actions/checkout@v4
32+
- uses: actions/cache@v3
33+
- name: Cache pip
34+
uses: actions/cache@v3
35+
with:
36+
path: ~/.cache/pip
37+
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
38+
restore-keys: |
39+
${{ runner.os }}-pip-
40+
- name: Cache PlatformIO
41+
uses: actions/cache@v3
42+
with:
43+
path: ~/.platformio
44+
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
45+
- name: Set up Python
46+
uses: actions/setup-python@v4
47+
with:
48+
python-version: "3.10"
49+
- name: Install PlatformIO
4550
run: |
46-
\cp -fR DisplayConfig/User_Setup.h ~/Arduino/libraries/TFT_eSPI/
47-
48-
# Build CYD Arduino Code
49-
- uses: arduino/compile-sketches@v1
50-
name: Compile CYD code
51-
with:
52-
fqbn: "esp32:esp32:esp32"
53-
platforms: |
54-
- name: esp32:esp32
55-
source-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
56-
# No need to specify ESP-libraries as these are installed with the platform (on the line above).
57-
# Downloading SpeedyStepper from source to get correct casing on import of Arduino.h (spelled arduino.h in the version from Arduino Library Manager)
58-
libraries: |
59-
- name: SpotifyArduino
60-
source-url: https://github.com/witnessmenow/spotify-api-arduino.git
61-
- name: WiFiManager
62-
- name: ESP_DoubleResetDetector
63-
- name: ArduinoJson
64-
- name: JPEGDEC
65-
- name: Seeed_Arduino_NFC
66-
source-url: https://github.com/witnessmenow/Seeed_Arduino_NFC.git
67-
sketch-paths: |
68-
- SpotifyDiyThing
69-
enable-warnings-report: true
70-
verbose: false
71-
cli-compile-flags: |
72-
- --export-binaries
73-
- --build-property
74-
- compiler.warning_flags=-Wno-error
75-
76-
# Copy binaries to GitHubPages folder for publishing
77-
- name: Copy compiled binaries to CYD
51+
python -m pip install --upgrade pip
52+
pip install --upgrade platformio
53+
54+
#Build CYD
55+
- name: Build CYD
56+
run: platformio run -e cyd
57+
- name: Upload artifact
58+
uses: actions/upload-artifact@v3
59+
with:
60+
name: CYD Firmware
61+
path: .pio/build/cyd/firmware.bin
62+
if-no-files-found: error
63+
- name: Copy compiled binaries for webflash
7864
run: |
79-
# mkdir GitHubPages/ESPWebTools/esp32Firmware
8065
mkdir GitHubPages/ESPWebTools/cyd
8166
8267
# Copy the manifest file for the CYD
8368
cp GitHubPages/ESPWebTools/manifest.json GitHubPages/ESPWebTools/cyd
84-
85-
# Copy compiled binaries that were exported by the `-e` flag in the arduino/compile-sketches task
86-
# Maintain folder structure, for cases where we are compiling for multiple board versions
87-
# If we were sure that we would never need to compile for anything other then esp32:esp32:esp32, we could have used this command instead: cp -r OpenMacroRail_Arduino/build/esp32.esp32.esp32/*.bin GitHubPages/ESPWebTools/esp32Firmware
88-
cd SpotifyDiyThing/build
89-
find . -print | grep -i .bin$ | xargs -i cp --parent {} ../../GitHubPages/ESPWebTools/cyd
90-
cd ../..
91-
92-
# Copy boot_app0.bin to the esp32Firmware folder. This file will be common for all esp32 boards (i think)
93-
# Using a version agnostic search to find the file. grep -m 1 makes sure only one file is copied in case multiple versions are installed.
94-
find /home/runner/.arduino15/packages/esp32/hardware/esp32/ -type f | grep -i -m 1 boot_app0.bin$ | xargs -i cp {} GitHubPages/ESPWebTools/cyd
9569
96-
# Build Matrix Arduino Code
97-
- uses: arduino/compile-sketches@v1
98-
name: Compile Matrix code
99-
with:
100-
fqbn: "esp32:esp32:esp32"
101-
platforms: |
102-
- name: esp32:esp32
103-
source-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
104-
# No need to specify ESP-libraries as these are installed with the platform (on the line above).
105-
# Just need to specify the matrix specific libraries, the others are already installed.
106-
libraries: |
107-
- name: ESP32 HUB75 LED MATRIX PANEL DMA Display
108-
source-url: https://github.com/witnessmenow/ESP32-HUB75-MatrixPanel-I2S-DMA.git
109-
- name: Adafruit GFX Library
110-
sketch-paths: |
111-
- SpotifyDiyThing
112-
enable-warnings-report: true
113-
verbose: false
114-
cli-compile-flags: |
115-
- --build-property
116-
- compiler.cpp.extra_flags=-DMATRIX_DISPLAY
117-
- --build-property
118-
- compiler.warning_flags=-Wno-error
119-
- --export-binaries
120-
121-
# Copy binaries to GitHubPages folder for publishing
122-
- name: Copy compiled binaries to Matrix
70+
cp .pio/build/cyd/bootloader.bin GitHubPages/ESPWebTools/cyd
71+
cp .pio/build/cyd/partitions.bin GitHubPages/ESPWebTools/cyd
72+
cp /home/runner/.platformio/packages/framework-arduinoespressif32/tools/partitions/boot_app0.bin GitHubPages/ESPWebTools/cyd
73+
cp .pio/build/cyd/firmware.bin GitHubPages/ESPWebTools/cyd
74+
75+
#Build Matrix
76+
- name: Build Matrix
77+
run: platformio run -e trinity
78+
- name: Upload artifact
79+
uses: actions/upload-artifact@v3
80+
with:
81+
name: CYD Firmware
82+
path: .pio/build/trinity/firmware.bin
83+
if-no-files-found: error
84+
- name: Copy compiled binaries for webflash
12385
run: |
124-
# Make matrix directory
12586
mkdir GitHubPages/ESPWebTools/matrix
12687
127-
# Copy the manifest file for the matrix
88+
# Copy the manifest file for the CYD
12889
cp GitHubPages/ESPWebTools/manifest.json GitHubPages/ESPWebTools/matrix
129-
130-
cd SpotifyDiyThing/build
131-
find . -print | grep -i .bin$ | xargs -i cp --parent {} ../../GitHubPages/ESPWebTools/matrix
132-
cd ../..
133-
134-
# Copy boot_app0.bin to the esp32Firmware folder. This file will be common for all esp32 boards (i think)
135-
# Using a version agnostic search to find the file. grep -m 1 makes sure only one file is copied in case multiple versions are installed.
136-
find /home/runner/.arduino15/packages/esp32/hardware/esp32/ -type f | grep -i -m 1 boot_app0.bin$ | xargs -i cp {} GitHubPages/ESPWebTools/matrix
13790
91+
cp .pio/build/trinity/bootloader.bin GitHubPages/ESPWebTools/matrix
92+
cp .pio/build/trinity/partitions.bin GitHubPages/ESPWebTools/matrix
93+
cp /home/runner/.platformio/packages/framework-arduinoespressif32/tools/partitions/boot_app0.bin GitHubPages/ESPWebTools/matrix
94+
cp .pio/build/trinity/firmware.bin GitHubPages/ESPWebTools/matrix
13895
13996
# Build GitHub Page
14097
- name: Setup Github Page

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
# Ignore Mac DS_Store files
22
.DS_Store
33
**/.DS_Store
4+
5+
.pio
6+
.vscode

SpotifyDiyThing/SpotifyDiyThing.ino

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,23 @@
1515
// (Uncomment the required #define)
1616

1717
// 1. Cheap yellow display (Using TFT-eSPI library)
18-
//#define YELLOW_DISPLAY
18+
// #define YELLOW_DISPLAY
1919

2020
// 2. Matrix Displays (Like the ESP32 Trinity)
21-
//#define MATRIX_DISPLAY
21+
// #define MATRIX_DISPLAY
2222

2323
// If no defines are set, it will default to CYD
2424
#if !defined(YELLOW_DISPLAY) && !defined(MATRIX_DISPLAY)
2525
#define YELLOW_DISPLAY // Default to Yellow Display for display type
2626
#endif
2727

28-
2928
#define NFC_ENABLED 1
3029

3130
// ----------------------------
3231
// Library Defines - Need to be defined before library import
3332
// ----------------------------
3433

35-
#define ESP_DRD_USE_SPIFFS true
34+
#define ESP_DRD_USE_SPIFFS true
3635

3736
// ----------------------------
3837
// Standard Libraries
@@ -57,7 +56,7 @@
5756
// A library for checking if the reset button has been pressed twice
5857
// Can be used to enable config mode
5958
// Can be installed from the library manager (Search for "ESP_DoubleResetDetector")
60-
//https://github.com/khoih-prog/ESP_DoubleResetDetector
59+
// https://github.com/khoih-prog/ESP_DoubleResetDetector
6160

6261
#include <SpotifyArduino.h>
6362

@@ -88,7 +87,7 @@ WiFiClientSecure client;
8887

8988
#include "serialPrint.h"
9089

91-
#include "WifiManager.h"
90+
#include "WifiManagerHandler.h"
9291

9392
// ----------------------------
9493
// Display Handling Code
@@ -98,12 +97,12 @@ WiFiClientSecure client;
9897

9998
#include "cheapYellowLCD.h"
10099
CheapYellowDisplay cyd;
101-
SpotifyDisplay* spotifyDisplay = &cyd;
100+
SpotifyDisplay *spotifyDisplay = &cyd;
102101

103102
#elif defined MATRIX_DISPLAY
104103
#include "matrixDisplay.h"
105104
MatrixDisplay matrixDisplay;
106-
SpotifyDisplay* spotifyDisplay = &matrixDisplay;
105+
SpotifyDisplay *spotifyDisplay = &matrixDisplay;
107106

108107
#endif
109108
// ----------------------------
@@ -112,7 +111,8 @@ SpotifyDisplay* spotifyDisplay = &matrixDisplay;
112111
#include "nfc.h"
113112
#endif
114113

115-
void drawWifiManagerMessage(WiFiManager *myWiFiManager){
114+
void drawWifiManagerMessage(WiFiManager *myWiFiManager)
115+
{
116116
spotifyDisplay->drawWifiManagerMessage(myWiFiManager);
117117
}
118118

@@ -123,17 +123,21 @@ void setup()
123123
bool forceConfig = false;
124124

125125
drd = new DoubleResetDetector(DRD_TIMEOUT, DRD_ADDRESS);
126-
if (drd->detectDoubleReset()) {
126+
if (drd->detectDoubleReset())
127+
{
127128
Serial.println(F("Forcing config mode as there was a Double reset detected"));
128129
forceConfig = true;
129130
}
130131

131132
spotifyDisplay->displaySetup(&spotify);
132133

133134
#ifdef NFC_ENABLED
134-
if (nfcSetup(&spotify)) {
135+
if (nfcSetup(&spotify))
136+
{
135137
Serial.println("NFC Good");
136-
} else {
138+
}
139+
else
140+
{
137141
Serial.println("NFC Bad");
138142
}
139143
#endif
@@ -152,9 +156,9 @@ void setup()
152156
}
153157
Serial.println("\r\nInitialisation done.");
154158

155-
pinMode(0, INPUT); //has an internal pullup
156159
refreshToken[0] = '\0';
157-
if (!fetchConfigFile(refreshToken, clientId, clientSecret)) {
160+
if (!fetchConfigFile(refreshToken, clientId, clientSecret))
161+
{
158162
// Failed to fetch config file, need to launch Wifi Manager
159163
forceConfig = true;
160164
}
@@ -167,11 +171,28 @@ void setup()
167171

168172
spotifySetup(spotifyDisplay, clientId, clientSecret);
169173

174+
#if defined YELLOW_DISPLAY
175+
176+
pinMode(0, INPUT); // has an internal pullup
177+
bool forceRefreshToken = digitalRead(0) == LOW;
178+
if (forceRefreshToken)
179+
{
180+
Serial.println("GPIO 0 is low, forcing refreshToken");
181+
}
182+
183+
#else
184+
bool forceRefreshToken = false;
185+
186+
#endif
187+
170188
// Check if we have a refresh Token
171-
if (digitalRead(0) == LOW || refreshToken[0] == '\0') {
189+
if (forceRefreshToken || refreshToken[0] == '\0')
190+
{
191+
172192
spotifyDisplay->drawRefreshTokenMessage();
173193
Serial.println("Launching refresh token flow");
174-
if (launchRefreshTokenFlow(&spotify, clientId)) {
194+
if (launchRefreshTokenFlow(&spotify, clientId))
195+
{
175196
Serial.print("Refresh Token: ");
176197
Serial.println(refreshToken);
177198
saveConfigFile(refreshToken, clientId, clientSecret);
@@ -194,9 +215,8 @@ void loop()
194215
#else
195216
bool forceUpdate = false;
196217
#endif
197-
218+
198219
updateCurrentlyPlaying(forceUpdate);
199220

200221
updateProgressBar();
201-
202222
}

SpotifyDiyThing/WifiManager.h renamed to SpotifyDiyThing/WifiManagerHandler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
// Number of seconds after reset during which a
23
// subseqent reset will be considered a double reset.
34
#define DRD_TIMEOUT 10

0 commit comments

Comments
 (0)