arduino-mpduino/mpduino/layout.ino

96 lines
2.3 KiB
Arduino
Raw Normal View History

2017-01-29 22:23:58 +01:00
/*
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.
*/
2017-02-26 04:13:16 +01:00
#define FLASH_LINE_TICKS 3
2017-01-29 22:23:58 +01:00
2017-02-26 04:13:16 +01:00
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 ) {
2017-01-29 22:23:58 +01:00
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setTextWrap(false);
2017-02-26 04:13:16 +01:00
if ( playing || tick % FLASH_LINE_TICKS ) {
2017-02-04 23:35:03 +01:00
display.setCursor(0, 0);
// First line (20)
2017-02-26 04:13:16 +01:00
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("% |"));
2017-02-04 23:35:03 +01:00
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(' ');
}
2017-01-29 22:23:58 +01:00
2017-02-04 23:35:03 +01:00
//line 2
2017-01-29 22:23:58 +01:00
display.setCursor(0, 8);
display.print(textscroll(title,tick));
display.startscrollleft(0x06, 0x0F);
2017-02-04 23:35:03 +01:00
//line 3
2017-01-29 22:23:58 +01:00
display.setCursor(0, 16);
display.print(textscroll(artist, tick));
2017-02-04 23:35:03 +01:00
//line 4
2017-01-29 22:23:58 +01:00
display.setCursor(0, 24);
display.print(textscroll(album, tick));
2017-02-04 23:35:03 +01:00
display.display();
2017-01-29 22:23:58 +01:00
}
2017-02-04 23:35:03 +01:00
2017-01-29 22:23:58 +01:00
String textscroll(String text, unsigned int tick) {
int chars = 21;
int len = text.length();
String newstring = "";
2017-02-26 04:13:16 +01:00
if ( len < chars) {
for ( int i = len; i < chars -1; i+=2){
text = " "+text+" ";
}
if ( text.length() == chars - 1) text = text+" ";
return text;
}
2017-01-29 22:23:58 +01:00
text = text + " - ";
for ( int i = 0; i < chars; i++ )
newstring += text.charAt((2*tick + i) % (len+3));
2017-01-29 22:23:58 +01:00
return newstring;
}
int calcMaxTicks() {
maxticks = title.length() * artist.length() * album.length();
2017-02-04 23:35:03 +01:00
Serial.print("MT:");
Serial.println(maxticks);
2017-01-29 22:23:58 +01:00
return maxticks;
}