arduino-mpduino/layout.ino

74 lines
1.8 KiB
C++

/*
Define one function to control all of the layout.
It works per line with only one variable (tick).
This one gives a way of scrolling through text.
*/
void layout(unsigned int tick) {
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setTextWrap(false);
if ( playing || tick % 3 ) {
display.setCursor(0, 0);
// First line (20)
if (volume < 100 ) display.print(' ');
display.print(volume);
display.print(F("% || "));
if (repeat_bool) display.print('r');
else display.print(' ');
if (random_bool) display.print('x');
else display.print(' ');
if (single_bool) display.print('s');
else display.print(' ');
if (consume_bool) display.print('c');
else display.print(' ');
if (shuffle_bool) display.print('z');
else display.print(' ');
if (updating_bool) display.print('u');
else display.print(' ');
display.print(" || ");
display.print(progress);
display.print("% ");
}
//line 2
display.setCursor(0, 8);
display.print(textscroll(title,tick));
display.startscrollleft(0x06, 0x0F);
//line 3
display.setCursor(0, 16);
display.print(textscroll(artist, tick));
//line 4
display.setCursor(0, 24);
display.print(textscroll(album, tick));
display.display();
}
String textscroll(String text, unsigned int tick) {
int chars = 21;
int len = text.length();
String newstring = "";
if ( len < chars) return text;
text = text + " - ";
for ( int i = 0; i < chars; i++ )
newstring += text.charAt((tick + i) % (len+3));
return newstring;
}
int calcMaxTicks() {
maxticks = title.length() * artist.length() * album.length();
Serial.print("MT:");
Serial.println(maxticks);
return maxticks;
}