-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAlbumArtDisplay.ino
252 lines (221 loc) · 6.55 KB
/
AlbumArtDisplay.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
/*!
\file
\brief flipflip's Album Art Display: documentation (see \ref mainpage)
- Copyright (c) 2020 Philippe Kehl (flipflip at oinkzwurgl dot org),
https://oinkzwurgl.org/projaeggd/album-art-display
*/
#define DO_TESTS 0
/* ********************************************************************************************** */
#include <Arduino.h>
#if !defined(ESP32)
# error Unsupported target!
#endif
#include <core_version.h>
#include "src/stuff.h"
#include "src/config.h"
#include "src/debug.h"
#include "src/status.h"
#include "src/display.h"
#include "src/wifi.h"
#include "src/gifs.h"
#include "src/lms.h"
/* ********************************************************************************************** */
void setup()
{
// Initialise stuff
debugInit();
statusInit();
displayInit();
randomSeed(ESP.getCycleCount());
// Say hello
NOTICE("--------------------------------------------------------------------------------------------");
NOTICE("Album Art Display " CONFIG_SOFTWARE_VERSION
" (" CONFIG_VERSION_GIT_HASH ", " CONFIG_PLATFORM_NAME ", " CONFIG_VERSION_YYYYMMDD " " CONFIG_VERSION_HHMMSS ")");
NOTICE("Copyright (c) 2020 Philippe Kehl & flipflip industries <flipflip at oinkzwurgl dot org>");
NOTICE("Parts copyright by others. See source code.");
NOTICE("https://oinkzwurgl.org/projaeggd/album-art-display");
NOTICE("--------------------------------------------------------------------------------------------");
#if defined(ESP32)
DEBUG("ESP32: rev=0x%02x, cpu=%uMHz", ESP.getChipRevision(), ESP.getCpuFreqMHz());
DEBUG("ESP32: %s, Arduino %s", ESP.getSdkVersion(), ARDUINO_ESP32_RELEASE);
DEBUG("ESP32: flash: size=%u (%uKiB)", ESP.getFlashChipSize(), ESP.getFlashChipSize() >> 10);
DEBUG("ESP32: heap: minFree=%u (%u), maxBlock=%u (%u), free=%u (%u)",
heap_caps_get_minimum_free_size(MALLOC_CAP_DEFAULT), ESP.getMinFreeHeap(),
heap_caps_get_largest_free_block(MALLOC_CAP_DEFAULT), ESP.getMaxAllocHeap(),
heap_caps_get_free_size(MALLOC_CAP_DEFAULT), ESP.getFreeHeap());
#endif
DEBUG("GCC: " __VERSION__); // /*", FreeRTOS " tskKERNEL_VERSION_NUMBER */
//DEBUG("Arduino: sketch=%u (%uKiB), free=%u (%uKiB)",
// ESP.getSketchSize(), ESP.getSketchSize() >> 10,
// ESP.getFreeSketchSpace(), ESP.getFreeSketchSpace() >> 10);
// Initialise more things
wifiInit();
lmsInit();
#if DO_TESTS == 0
displayNoise(true);
#endif
gifsInit();
#if 0
while (true)
{
const uint32_t t0 = millis();
const char *gif = gifsGetNext();
DEBUG("next is: %s", gif);
displayGif(gif);
while ((millis() - t0) < 5000)
{
DEBUG("playing...");
delay(1000);
}
}
#endif
NOTICE("Here we go...");
statusLed(STATUS_LED_OFFLINE);
statusNoise(STATUS_NOISE_FFI);
delay(1000);
pinMode(CONFIG_BUTTON_PIN, INPUT_PULLUP);
}
typedef enum LOOP_e
{
LOOP_NOISE, LOOP_GIF, LOOP_COVER
} LOOP_t;
void loop()
{
#if DO_TESTS == 0
static int numFail;
displayNoise(true);
LOOP_t loopMode = LOOP_NOISE;
// Wait for WiFi connection, play noise until online
if (!wifiIsConnected())
{
PRINT("Waiting for wifi...");
while (!wifiWaitForConnect())
{
delay(100);
}
return;
}
statusLed(STATUS_LED_UPDATE);
if (!lmsConnect())
{
delay(1000);
return;
}
static String coverArtPlayerId;
LMS_STATE_t state = LMS_STATE_STOPPED;
uint32_t lastGifChange;
bool doGetCoverArt = false;
bool doChangeGif = false;
while (state != LMS_STATE_FAIL)
{
// Changes in LMS state can change the display
const LMS_STATE_t newState = lmsLoop(coverArtPlayerId);
if (state != newState)
{
DEBUG("State change: %d -> %d", state, newState);
}
switch (newState)
{
case LMS_STATE_FAIL:
break;
case LMS_STATE_STOPPED:
if (state != LMS_STATE_STOPPED)
{
PRINT("Now stopped");
doChangeGif = true;
}
break;
case LMS_STATE_PLAYING:
if (state != LMS_STATE_PLAYING)
{
PRINT("Now playing");
}
if (coverArtPlayerId.length() > 0)
{
doGetCoverArt = true;
}
break;
}
state = newState;
// Button press can change the display
static uint32_t buttonDown;
if (digitalRead(CONFIG_BUTTON_PIN) == 0)
{
if (buttonDown == 0)
{
buttonDown = millis();
}
}
else
{
if ( (buttonDown != 0) && ((millis() - buttonDown) > 100) )
{
buttonDown = 0;
statusNoise(STATUS_NOISE_TICK);
doChangeGif = true;
}
}
// Time can change the display
switch (loopMode)
{
case LOOP_GIF:
if ( (millis() - lastGifChange) > 60000 )
{
doChangeGif = true;
}
break;
case LOOP_COVER:
break;
case LOOP_NOISE:
break;
}
// Change display
if (doChangeGif)
{
const int r = random(10);
PRINT("New gif (%d)", r);
if (r < 1)
{
displayRGBerset(true);
}
else if (r < 2)
{
displayNyan(true);
}
else
{
displayGif(gifsGetRandom());
}
doChangeGif = false;
lastGifChange = millis();
loopMode = LOOP_GIF;
}
if (doGetCoverArt)
{
PRINT("new coverart");
if (!displayCoverArt(coverArtPlayerId.c_str()))
{
statusNoise(STATUS_NOISE_FAIL);
}
doGetCoverArt = false;
loopMode = LOOP_COVER;
}
// Wait a bit...
delay(99);
} // while connected to LMS CLI...
ERROR("No longer connected...");
displayNoise(true);
statusLed(STATUS_LED_FAIL);
statusNoise(STATUS_NOISE_ERROR);
delay(5000);
numFail++;
if (numFail >= 5)
{
statusNoise(STATUS_NOISE_BOMB);
delay(1000);
ESP.restart();
}
#else
displayTest();
#endif
}