arduino-mpduino/mpduino/layout.ino

96 lines
2.3 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.
*/
#define FLASH_LINE_TICKS 3
void initial_layout() {
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0, 8);
display.println("Waiting..");
display.display();
}
void layout( unsigned int tick ) {
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setTextWrap(false);
if ( playing || tick % FLASH_LINE_TICKS ) {
display.setCursor(0, 0);
// First line (20)
if (volume == 100 || volume == 0){
if (volume == 100) display.print('00');
else display.print('--');
}
else display.print(volume);
display.print(F("% "));
display.print(round(temperature));
display.print(F("C "));
display.print(round(humidity));
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(' ');
}
//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) {
for ( int i = len; i < chars -1; i+=2){
text = " "+text+" ";
}
if ( text.length() == chars - 1) text = text+" ";
return text;
}
text = text + " - ";
for ( int i = 0; i < chars; i++ )
newstring += text.charAt((2*tick + i) % (len+3));
return newstring;
}
int calcMaxTicks() {
maxticks = title.length() * artist.length() * album.length();
Serial.print("MT:");
Serial.println(maxticks);
return maxticks;
}