-
Notifications
You must be signed in to change notification settings - Fork 2
/
Liquid-dap-duino.ino
345 lines (284 loc) · 7.83 KB
/
Liquid-dap-duino.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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
#include <LiquidCrystal4.h>
//#include <SoftwareSerial.h>
//SoftwareSerial Serial1(3, 2);
LiquidCrystal lcd(11, 10, 9, 12, 8, 7, 6, 5);
// rs, rw, en1, en2, d0, d1, d2, d3
//fix these if using different LCD
byte maxCols = 40;
byte maxRows = 4;
int posStart, posEnd, posNext, pos;
char playerId[18], title[40], artist[40], album[40], type[5];
float samplerate, samplesize;
byte volume, repeat, mode;
char inChar;
boolean changedValue;
String buff;
String centered(String text)
{
text.trim();
int len = text.length();
if (len > maxCols)
{
return text.substring(0, maxCols - 4) + "...";
}
len = (maxCols - len) / 2;
text.reserve(maxCols);
for (int i = 0; i < len; i++)
{
text = " " + text + " ";
}
if (len % 2)
{
text = text + " ";
}
return text;
}
void printLines(String *lines, byte size, bool cls)
{
if(cls)
{
lcd.clear();
}
for (int i = 0; i < size; i++)
{
lcd.setCursor(0, i);
lcd.print(centered(lines[i]));
}
}
void setup()
{
delay(1000);
lcd.begin(maxCols, maxRows);
Serial.begin(9600);
String initLines[] = { "Liquid-dap-duino", "DAPHILE 2 DDDAC1794S", "", "waiting for player..." };
printLines(initLines,4,true);
delay(1000);
findPlayerId();
while (String(playerId).indexOf(":") < 0)
{
delay(5000);
findPlayerId();
}
lcd.setCursor(0, 2);
lcd.print(playerId);
Serial.println(String(playerId) + " status - 1 tags:oTIalG subscribe:5");
//5a:bd:60:86:ed:fb status - 1 tags:oTIalG subscribe:0
/*
5a:bd:60:86:ed:fb status - 1 tags:oTIalG subscribe:0
player_name:WaveIO USB Audio 2.0
player_connected:1
player_ip:127.0.0.1:53222
power:1
signalstrength:0
mode:play
time:337.414047037125
rate:1
duration:347.4
can_seek:1
mixer volume:100
playlist repeat:2
playlist shuffle:0
playlist mode:off
seq_no:0
playlist_cur_index:1
playlist_timestamp:1480528920.84089
playlist_tracks:10
digital_volume_control:0
playlist index:1
id:12685
title:Ne si go prodavaj Koljo...
type:flc
samplerate:44100
samplesize:16
artist:Vlatko Stefanovski %26 Miroslav Tadic
album:Treta Majka
genres:Instrumental
*/
}
void findPlayerId()
{
//empty buffer...
String strPlayerId;
Serial.readString();
Serial.println("player id 0 ?");
while (Serial.available() < 39)
{
delay(5);
}
delay(5);
Serial.readString();
// found some jibberish stuff in first response... dump it...
Serial.println("player id 0 ?");
while (Serial.available() < 39)
{
delay(5);
}
strPlayerId = Serial.readString();
strPlayerId.replace("%3A", ":");
strPlayerId.replace("player id 0 ", "");
strPlayerId.replace("\r", "");
strPlayerId.replace("\n", "");
strPlayerId.trim();
strPlayerId.toCharArray(playerId, 18);
}
String secondsToHMS(const uint32_t seconds)
{
uint32_t s, m, h;
uint32_t t = seconds;
s = t % 60;
t = (t - s) / 60;
m = t % 60;
t = (t - m) / 60;
h = t;
return String(String(h) + ":" + String(m) + ":" + String(s));
}
void loop()
//After creating a setup() function, which initializes and sets the initial values, the loop() function does precisely what its name suggests, and loops consecutively, allowing your program to change and respond. Use it to actively control the Arduino board.
{
volume = getValue("mixer volume", volume);
getValue("title", 40, title);
getValue("type", 5, type);
samplerate = getValue("samplerate", samplerate);
samplesize = getValue("samplesize", samplesize);
getValue("artist", 40, artist);
getValue("album", 40, album);
if (String("flc") == String(type))
{
String("FLAC").toCharArray(type, 5);
}
else if (String("ape") == String(type))
{
String("APE").toCharArray(type, 5);
}
else if (String("mp3") == String(type))
{
String("MP3").toCharArray(type, 5);
}
else if (String("alc") == String(type))
{
String("ALAC").toCharArray(type, 5);
}
//displayInfo[3] = type + " " + samplerate + "bits " + samplesize + "Hz";
if (changedValue)
{
char sRate[9], sSize[9];
dtostrf(samplerate / 1000, 1, 1, sRate);
dtostrf(samplesize, 1, 0, sSize);
String initLines[] = { artist, album, title, String(type) + " " + String(sRate) + "kHz " + String(sSize) + "bit"};
printLines(initLines,4,false);
changedValue = false;
}
}
void getValue(String sFind, int len, char tmpArr[])
{
posStart = buff.indexOf(sFind);
posNext = buff.indexOf(" ", posStart);
posEnd = buff.indexOf("\n", posStart);
if (posStart > -1 && (posNext > posStart || posEnd > posStart))
{
if (posNext > posStart)
pos = posNext;
else
pos = posEnd;
String X = buff.substring(posStart + sFind.length() + 3, pos);
X.replace("%3A", ":");
X.replace("%20", " ");
X.replace("%26", "&");
X.replace("%22", """");
X.replace("%2C", ",");
X.toCharArray(tmpArr, len);
buff = buff.substring(pos);
changedValue = true;
}
}
float getValue(String sFind, float val)
{
posStart = buff.indexOf(sFind);
posNext = buff.indexOf(" ", posStart);
posEnd = buff.indexOf("\n", posStart);
if (posStart > -1 && (posNext > posStart || posEnd > posStart))
{
if (posNext > posStart)
pos = posNext;
else
pos = posEnd;
String X = buff.substring(posStart + sFind.length() + 3, pos);
X.trim();
val = X.toFloat();
buff = buff.substring(pos);
changedValue = true;
}
return val;
}
byte getValue(String sFind, byte val)
{
posStart = buff.indexOf(sFind);
posNext = buff.indexOf(" ", posStart);
posEnd = buff.indexOf("\n", posStart);
if (posStart > -1 && (posNext > posStart || posEnd > posStart))
{
if (posNext > posStart)
pos = posNext;
else
pos = posEnd;
String X = buff.substring(posStart + sFind.length() + 3, pos);
X.trim();
val = X.toInt();
buff = buff.substring(pos);
changedValue = true;
}
return val;
}
/*
SerialEvent occurs whenever a new data comes in the
hardware serial RX. This routine is run between each
time loop() runs, so using delay inside loop can delay
response. Multiple bytes of data may be available.
*/
void serialEvent()
{
pullSerial();
if (false)
{
lcd.clear();
lcd.home();
/* lcd.print(
"len:" + String(lmsStatus.length())
+ " title:" + String(lmsStatus.indexOf("title"))
+ " n end:" + String(lmsStatus.indexOf("\n"))
+ " r end:" + String(lmsStatus.indexOf("\r")));*/
}
}
void pullSerial()
{
pinMode(13, OUTPUT);
while (Serial.available() > 0)
{
digitalWrite(13, HIGH);
inChar = (char)Serial.read();
buff += inChar;
}
digitalWrite(13, LOW);
}
/*
9600
-parenb cs8 NO generate parity bit in output and expect parity bit in input
-cstopb use two stop bits per character (one with '-')
-crtscts NO enable RTS/CTS handshaking
-ixon NO enable XON/XOFF flow control
-ixoff NO enable sending of start/stop characters
ignbrk YES ignore break characters
-brkint NO breaks cause an interrupt signal
-imaxbel NO beep and do not flush a full input buffer on a character
-opost NO postprocess output
-onlcr NO translate newline to carriage return-newline
-isig NO enable interrupt, quit, and suspend special characters
-icanon NO enable erase, kill, werase, and rprnt special characters
-iexten NO enable non-POSIX special characters
-echo NO echo input characters
-echoe NO echo erase characters as backspace-space-backspace
-echok NO echo a newline after a kill character
-echoctl NO echo control characters in hat notation ('^c')
-echoke NO kill all line by obeying the echoctl and echok settings
noflsh YES disable flushing after interrupt and quit special characters
*/