Skip to content

Commit

Permalink
improve bitmaps for next, prev, play, and pause.
Browse files Browse the repository at this point in the history
  • Loading branch information
bmv437 committed Oct 8, 2018
1 parent eb1bafe commit a64a48b
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 58 deletions.
60 changes: 30 additions & 30 deletions examples/spotify/buttons.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,50 @@
#endif
// 'play', 32x32px
const unsigned char play [] PROGMEM = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x0f, 0xff, 0xfe, 0x00, 0x03, 0xff,
0xfc, 0x3f, 0xe1, 0xff, 0xf8, 0xff, 0xf8, 0x7f, 0xf1, 0xff, 0xfc, 0x7f, 0xe3, 0xff, 0xfe, 0x3f,
0xc7, 0xdf, 0xff, 0x1f, 0xcf, 0xc7, 0xff, 0x9f, 0x8f, 0xc1, 0xff, 0x8f, 0x9f, 0xc0, 0xff, 0xcf,
0x1f, 0xc0, 0x3f, 0xc7, 0x3f, 0xc0, 0x0f, 0xe7, 0x3f, 0xc0, 0x03, 0xe7, 0x3f, 0xc0, 0x00, 0xe7,
0x3f, 0xc0, 0x00, 0xe7, 0x3f, 0xc0, 0x03, 0xe7, 0x1f, 0xc0, 0x0f, 0xe7, 0x1f, 0xc0, 0x3f, 0xc7,
0x9f, 0xc0, 0xff, 0xcf, 0x8f, 0xc1, 0xff, 0x8f, 0xcf, 0xc7, 0xff, 0x9f, 0xc7, 0xdf, 0xff, 0x1f,
0xe3, 0xff, 0xfe, 0x3f, 0xf1, 0xff, 0xfc, 0x7f, 0xf8, 0xff, 0xf8, 0xff, 0xfc, 0x3f, 0xe1, 0xff,
0xfe, 0x00, 0x03, 0xff, 0xff, 0x80, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
0xff, 0xf0, 0x0f, 0xff, 0xff, 0x80, 0x01, 0xff, 0xfe, 0x0f, 0xf0, 0x7f, 0xfc, 0x3f, 0xfc, 0x3f,
0xf8, 0xff, 0xff, 0x1f, 0xf1, 0xff, 0xff, 0x8f, 0xe3, 0xff, 0xff, 0xc7, 0xc7, 0x9f, 0xff, 0xe3,
0xcf, 0x87, 0xff, 0xf3, 0x8f, 0x81, 0xff, 0xf1, 0x9f, 0x80, 0x7f, 0xf9, 0x9f, 0x80, 0x1f, 0xf9,
0x3f, 0x80, 0x07, 0xfc, 0x3f, 0x80, 0x01, 0xfc, 0x3f, 0x80, 0x00, 0x7c, 0x3f, 0x80, 0x00, 0x1c,
0x3f, 0x80, 0x00, 0x1c, 0x3f, 0x80, 0x00, 0x7c, 0x3f, 0x80, 0x01, 0xfc, 0x3f, 0x80, 0x07, 0xfc,
0x9f, 0x80, 0x1f, 0xf9, 0x9f, 0x80, 0x7f, 0xf9, 0x8f, 0x81, 0xff, 0xf1, 0xcf, 0x87, 0xff, 0xf3,
0xc7, 0x9f, 0xff, 0xe3, 0xe3, 0xff, 0xff, 0xc7, 0xf1, 0xff, 0xff, 0x8f, 0xf8, 0xff, 0xff, 0x1f,
0xfc, 0x3f, 0xfc, 0x3f, 0xfe, 0x0f, 0xf0, 0x7f, 0xff, 0x80, 0x01, 0xff, 0xff, 0xf0, 0x0f, 0xff
};


// 'pause', 32x32px
const unsigned char pause [] PROGMEM = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x0f, 0xff, 0xfe, 0x00, 0x03, 0xff,
0xfc, 0x3f, 0xe1, 0xff, 0xf8, 0xff, 0xf8, 0xff, 0xf1, 0xff, 0xfc, 0x7f, 0xe3, 0xff, 0xfe, 0x3f,
0xc7, 0xff, 0xff, 0x1f, 0xcf, 0x02, 0x07, 0x9f, 0x8f, 0x02, 0x07, 0x8f, 0x9f, 0x02, 0x07, 0xcf,
0x1f, 0x02, 0x07, 0xc7, 0x1f, 0x02, 0x07, 0xe7, 0x3f, 0x02, 0x07, 0xe7, 0x3f, 0x02, 0x07, 0xe7,
0x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x01, 0xff, 0xff, 0xf0, 0x0f, 0xff
};

// 'next', 32x32px
const unsigned char next [] PROGMEM = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x7f, 0xff, 0xff, 0xf0, 0x7f, 0xfd, 0xff, 0xf0, 0x1f, 0xfc, 0x7f, 0xf0, 0x1f, 0xfc, 0x7f, 0xf0,
0x0f, 0xfc, 0x1f, 0xf0, 0x07, 0xfc, 0x1f, 0xf0, 0x03, 0xfc, 0x0f, 0xf0, 0x01, 0xfc, 0x07, 0xf0,
0x00, 0xfc, 0x03, 0xf0, 0x00, 0x3c, 0x00, 0xf0, 0x00, 0x3c, 0x00, 0xf0, 0x00, 0x0c, 0x00, 0x30,
0x00, 0x0c, 0x00, 0x30, 0x00, 0x3c, 0x00, 0xf0, 0x00, 0x3c, 0x00, 0xf0, 0x00, 0xfc, 0x03, 0xf0,
0x00, 0xfc, 0x07, 0xf0, 0x03, 0xfc, 0x0f, 0xf0, 0x07, 0xfc, 0x1f, 0xf0, 0x07, 0xfc, 0x1f, 0xf0,
0x1f, 0xfc, 0x7f, 0xf0, 0x1f, 0xfc, 0x7f, 0xf0, 0x7f, 0xfd, 0xff, 0xf0, 0x7f, 0xfd, 0xff, 0xf0,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x7f, 0xfd, 0xff, 0xf0, 0x3f, 0xfc, 0xff, 0xf0, 0x1f, 0xfc, 0x7f, 0xf0, 0x0f, 0xfc, 0x3f, 0xf0,
0x07, 0xfc, 0x1f, 0xf0, 0x03, 0xfc, 0x0f, 0xf0, 0x01, 0xfc, 0x07, 0xf0, 0x00, 0xfc, 0x03, 0xf0,
0x00, 0x7c, 0x01, 0xf0, 0x00, 0x3c, 0x00, 0xf0, 0x00, 0x1c, 0x00, 0x70, 0x00, 0x0c, 0x00, 0x30,
0x00, 0x0c, 0x00, 0x30, 0x00, 0x1c, 0x00, 0x70, 0x00, 0x3c, 0x00, 0xf0, 0x00, 0x7c, 0x01, 0xf0,
0x00, 0xfc, 0x03, 0xf0, 0x01, 0xfc, 0x07, 0xf0, 0x03, 0xfc, 0x0f, 0xf0, 0x07, 0xfc, 0x1f, 0xf0,
0x0f, 0xfc, 0x3f, 0xf0, 0x1f, 0xfc, 0x7f, 0xf0, 0x3f, 0xfc, 0xff, 0xf0, 0x7f, 0xfd, 0xff, 0xf0,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
};


// 'prev', 32x32px
const unsigned char prev [] PROGMEM = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x0f, 0xff, 0xff, 0xff, 0x0f, 0xff, 0xbf, 0xfe, 0x0f, 0xff, 0x3f, 0xf8, 0x0f, 0xfe, 0x3f, 0xf8,
0x0f, 0xfc, 0x3f, 0xf0, 0x0f, 0xf8, 0x3f, 0xe0, 0x0f, 0xf0, 0x3f, 0xc0, 0x0f, 0xe0, 0x3f, 0x80,
0x0f, 0xc0, 0x3f, 0x00, 0x0f, 0x80, 0x3e, 0x00, 0x0f, 0x00, 0x3c, 0x00, 0x0e, 0x00, 0x38, 0x00,
0x0c, 0x00, 0x30, 0x00, 0x0f, 0x00, 0x3c, 0x00, 0x0f, 0x00, 0x3c, 0x00, 0x0f, 0xc0, 0x3f, 0x00,
0x0f, 0xe0, 0x3f, 0x80, 0x0f, 0xf0, 0x3f, 0xc0, 0x0f, 0xf8, 0x3f, 0xe0, 0x0f, 0xfc, 0x3f, 0xf0,
0x0f, 0xfe, 0x3f, 0xf8, 0x0f, 0xfe, 0x3f, 0xf8, 0x0f, 0xff, 0xbf, 0xfe, 0x0f, 0xff, 0xbf, 0xfe,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x0f, 0xff, 0xbf, 0xfe, 0x0f, 0xff, 0x3f, 0xfc, 0x0f, 0xfe, 0x3f, 0xf8, 0x0f, 0xfc, 0x3f, 0xf0,
0x0f, 0xf8, 0x3f, 0xe0, 0x0f, 0xf0, 0x3f, 0xc0, 0x0f, 0xe0, 0x3f, 0x80, 0x0f, 0xc0, 0x3f, 0x00,
0x0f, 0x80, 0x3e, 0x00, 0x0f, 0x00, 0x3c, 0x00, 0x0e, 0x00, 0x38, 0x00, 0x0c, 0x00, 0x30, 0x00,
0x0c, 0x00, 0x30, 0x00, 0x0e, 0x00, 0x38, 0x00, 0x0f, 0x00, 0x3c, 0x00, 0x0f, 0x80, 0x3e, 0x00,
0x0f, 0xc0, 0x3f, 0x00, 0x0f, 0xe0, 0x3f, 0x80, 0x0f, 0xf0, 0x3f, 0xc0, 0x0f, 0xf8, 0x3f, 0xe0,
0x0f, 0xfc, 0x3f, 0xf0, 0x0f, 0xfe, 0x3f, 0xf8, 0x0f, 0xff, 0x3f, 0xfc, 0x0f, 0xff, 0xbf, 0xfe,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
};
56 changes: 28 additions & 28 deletions examples/spotify/spotify.ino
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void setup(){
}

display.init();

pinMode(1,INPUT_PULLUP); //down
pinMode(3,INPUT_PULLUP); //left
pinMode(5,INPUT_PULLUP); //center
Expand Down Expand Up @@ -93,7 +93,7 @@ void loop(){
(digitalRead(5) == 0 ? 0 : (1<<2)) | //center
(digitalRead(12) == 0 ? 0 : (1<<3)) | //right
(digitalRead(10) == 0 ? 0 : (1<<4)); //up

if(reading != lastButtonState){
lastDebounceTime = millis();
}
Expand Down Expand Up @@ -127,7 +127,7 @@ void loop(){
case 4:
//do something when the user presses up
showText("You pressed the up button!");
break;
break;
default:
break;
}
Expand All @@ -141,7 +141,7 @@ void loop(){
getPlayback();
lastUpdate = millis();
}

}

void configModeCallback (WiFiManager *myWiFiManager){
Expand All @@ -153,7 +153,7 @@ void configModeCallback (WiFiManager *myWiFiManager){
display.setCursor(0,50);
display.println("Connect to Badgy AP");
display.println("to setup your WiFi!");
display.update();
display.update();
}

void showIP(){
Expand All @@ -170,11 +170,11 @@ void showIP(){
url.toCharArray(urlCharArray, charArraySize);

display.println("You are now connected!");
display.println("");
display.println("");
display.println("Go to:");
display.println(urlCharArray);
display.println("to upload a new sketch.");
display.update();
display.update();
}

void showText(char *text)
Expand All @@ -190,7 +190,7 @@ void showText(char *text)
}

String getToken(){

/* Check if refresh token exists*/
String refreshToken = "";
showText("Loading config");
Expand All @@ -213,7 +213,7 @@ String getToken(){
/********************************************************************************/
if(!MDNS.begin(MDNSName.c_str())){
//Serial.println("Error setting up MDNS responder!");
while(1){
while(1){
delay(1000);
}
}
Expand All @@ -225,9 +225,9 @@ String getToken(){

/* Server route handlers */
server.on("/", [&server](){
server.sendHeader("Location", String("https://accounts.spotify.com/authorize/?client_id="
server.sendHeader("Location", String("https://accounts.spotify.com/authorize/?client_id="
+ clientId
+ "&response_type=code&redirect_uri="
+ "&response_type=code&redirect_uri="
+ "http://" + MDNSName + ".local/callback/"
+ "&scope=user-read-playback-state%20user-modify-playback-state"), true);
server.send(302, "text/plain", "");
Expand All @@ -254,14 +254,14 @@ String getToken(){
}//refreshToken == ""
/**************************************************************************************************************/
/* 3. Use authorization code from previous step to obtain an API token */
/**************************************************************************************************************/
/**************************************************************************************************************/

/* Initiate HTTPS connection to Spotify's authentication endpoint */
WiFiClientSecure client;
if(!client.connect(authHost.c_str(), httpsPort)){
showText("Connection Failed!");
}

/* There are 2 grant types, authorization_code for a new token, and refresh_token if you're refreshing */
String grantType = (refreshToken == "") ? "authorization_code" : "refresh_token";
String codeType = (refreshToken == "") ? "code" : "refresh_token";
Expand All @@ -272,11 +272,11 @@ String getToken(){
"&client_id=" + clientId +
"&client_secret=" + clientSecret +
"&redirect_uri=" + "http%3A%2F%2F" + MDNSName + ".local%2Fcallback%2F";
/* HTTPS request string */
/* HTTPS request string */
String httpsString = "POST " + tokenAPI + " "
"HTTP/1.1\r\n" + "Host: " + authHost.c_str() + "\r\n" +
"Content-Length: " + String(requestBody.length()) + "\r\n" +
"Content-Type: application/x-www-form-urlencoded\r\n" +
"Content-Length: " + String(requestBody.length()) + "\r\n" +
"Content-Type: application/x-www-form-urlencoded\r\n" +
"Connection: close\r\n\r\n" + requestBody;
/* Send request */
//Serial.println(httpsString);
Expand Down Expand Up @@ -339,7 +339,7 @@ void controlPlayer(int control){
}else{
return;
}

if(token == ""){
token = getToken();
}
Expand All @@ -348,11 +348,11 @@ void controlPlayer(int control){
if(!client.connect(apiHost.c_str(), httpsPort)){
showText("Connection Failed!");
}

String request = "" + method + currentPlayerAPI + command + " HTTP/1.1\r\n" +
"Host: " + apiHost + "\r\n" +
"Authorization: Bearer " + token + "\r\n" +
"Content-Length: 0\r\n" +
"Content-Length: 0\r\n" +
"Connection: close\r\n\r\n";
client.print(request);

Expand All @@ -369,7 +369,7 @@ void controlPlayer(int control){
showText(status);
return;
}

char endOfHeaders[] = "\r\n\r\n";
if (!client.find(endOfHeaders)) {
showText("Invalid Response...");
Expand All @@ -390,13 +390,13 @@ void getPlayback(){
if(token == ""){
token = getToken();
}

/* Construct request string and send */
WiFiClientSecure client;
if(!client.connect(apiHost.c_str(), httpsPort)){
showText("Connection Failed!");
}

String request = "GET " + currentPlayerAPI + " HTTP/1.1\r\n" +
"Host: " + apiHost + "\r\n" +
"Authorization: Bearer " + token + "\r\n" +
Expand All @@ -416,7 +416,7 @@ void getPlayback(){
showText("Unexpected Response...");
return;
}

char endOfHeaders[] = "\r\n\r\n";
if (!client.find(endOfHeaders)) {
showText("Invalid Response...");
Expand All @@ -436,15 +436,15 @@ void getPlayback(){
String currentAlbum = root["item"]["album"]["name"];
String currentArtist = root["item"]["artists"][0]["name"];
isPlaying = root["is_playing"] == "true";


/* Print current track details on display */
long currentProgress = root["progress_ms"];
long currentDuration = root["item"]["duration_ms"];
int minutes = (currentProgress/1000) / 60;
int seconds = (currentProgress/1000) % 60;
int location = ((currentProgress * (296 - 20)) / currentDuration) + 10;

// Serial.println(currentTrack);
// Serial.println(currentAlbum);
// Serial.println(currentArtist);
Expand All @@ -471,9 +471,9 @@ void getPlayback(){
display.fillCircle(location, 72, 5, GxEPD_BLACK);
//display.update();
if(isPlaying){
display.drawBitmap(play, 133, 84, 30, 30, GxEPD_WHITE);
display.drawBitmap(play, 133, 84, 32, 32, GxEPD_WHITE);
}else{
display.drawBitmap(pause, 133, 84, 30, 30, GxEPD_WHITE);
display.drawBitmap(pause, 133, 84, 32, 32, GxEPD_WHITE);
}
display.drawBitmap(prev, 73, 84, 32, 32, GxEPD_WHITE);
display.drawBitmap(next, 193, 84, 32, 32, GxEPD_WHITE);
Expand Down

0 comments on commit a64a48b

Please sign in to comment.