diff --git a/laboite.ino b/laboite.ino index 2ee7d23..5ba8ced 100644 --- a/laboite.ino +++ b/laboite.ino @@ -1,6 +1,6 @@ /* - laboite v3.4 + laboite v3.5 This Arduino firmware is part of laboite project https://laboite.cc/help It is a connected device displaying a lot of information (A LOT !) coming from an Internet server with a laboite web app deployed (e.g. https://laboite.cc/ ). @@ -24,6 +24,8 @@ * Emails * RATP * Agenda + * Parking + * Metro Circuit: * Ethernet shield attached to pins 10, 11, 12, 13 (Arduino Yún support from v3.4) @@ -32,7 +34,7 @@ created 15 Dec 2011 by Baptiste Gaultier and Tanguy Ropitault - modified 31 Mar 2015 + modified 23 Jul 2015 by Baptiste Gaultier This code is in the public domain. @@ -78,10 +80,12 @@ String currentLine = ""; // string to hold the text from server // Modular Apps code // (uncomment only the apps you need, otherwise the sketch will be too big) -#define ENERGY +//#define ENERGY #define MESSAGES -#define COFFEES +//#define COFFEES #define AGENDA +//#define PARKING +//#define METRO // Variables used to display infos @@ -121,8 +125,19 @@ char message[140]; char coffees[3]; #endif +#ifdef AGENDA char eventStart[5]; char eventSummary[64]; +#endif + +#ifdef PARKING +char parkingOpen[2]; +char parkingSpaces[4]; +#endif + +#ifdef METRO +char metroFailure[2]; +#endif // Parser variables boolean readingTime = false; @@ -146,6 +161,15 @@ boolean readingDay5 = false; boolean readingDay6 = false; #endif +#ifdef PARKING +boolean readingParkingOpen = false; +boolean readingParkingSpaces = false; +#endif + +#ifdef METRO +boolean readingMetroFailure = false; +#endif + boolean readingMessage = false; #ifdef COFFEES @@ -154,9 +178,10 @@ boolean readingCoffees = false; boolean readingEmails = false; +#ifdef AGENDA boolean readingEventStart = false; boolean readingEventSummary = false; - +#endif // Apps variables @@ -175,6 +200,12 @@ boolean coffeesEnabled = false; #ifdef AGENDA boolean agendaEnabled = false; #endif +#ifdef PARKING +boolean parkingEnabled = false; +#endif +#ifdef METRO +boolean metroEnabled = false; +#endif #ifdef SENSORS // Sensors constants won't change. They're used here to @@ -217,6 +248,14 @@ uint16_t coffeeSprite[8] = {0x4800, 0x2400, 0x4800, 0xff00, 0x8500, 0x8600, 0x84 // agenda app sprite uint16_t calendarSprite[8] = { 0b01111111, 0b01111111, 0b01000001, 0b01001001, 0b01001001, 0b01001001, 0b01000001, 0b01111111 }; #endif +#ifdef PARKING +// parking app sprite +uint16_t parkingSprite[8] = { 0x01fc, 0x0106, 0x0132, 0x0132, 0x0106, 0x013c, 0x0120, 0x01e0 }; +#endif +#ifdef METRO +// metro app sprite +uint16_t metroSprite[8] = { 0x039c, 0x07fe, 0x0666, 0x0666, 0x0666, 0x0666, 0x0666, 0x0666 }; +#endif boolean scrolling = true; // value modified when button is pressed @@ -234,7 +273,7 @@ void setup() { // display a welcome message: #ifdef DEBUG - Serial.println("laboite v3.4 starting..."); + Serial.println("laboite v3.5 starting..."); #endif // attempt a DHCP connection: diff --git a/laboiteLib.ino b/laboiteLib.ino index afe3481..83fbfb8 100644 --- a/laboiteLib.ino +++ b/laboiteLib.ino @@ -19,7 +19,7 @@ void connectToServer() { client.println("Connection: close"); client.println(); } -} +} boolean parseJSON() { // make sure all apps are not enabled @@ -315,7 +315,7 @@ boolean parseJSON() { } #endif - #ifdef AGENDA. + #ifdef AGENDA // fetch Agenda app data if (currentLine.endsWith("\"dtstart\":")) { readingEventStart = true; @@ -397,6 +397,77 @@ boolean parseJSON() { } #endif + #ifdef PARKING + // fetch Parking app data + if (currentLine.endsWith("\"spaces\":")) { + readingParkingSpaces = true; + content = ""; + } + + if (readingParkingSpaces) { + if (inChar != ',' && inChar != '}') { + if (inChar != '"' && inChar != ':') + content += inChar; + } + else { + readingParkingSpaces = false; + parkingSpaces[0] = content.charAt(0); + parkingSpaces[1] = content.charAt(1); + parkingSpaces[2] = content.charAt(2); + parkingSpaces[3] = '\0'; + } + } + + if (currentLine.endsWith("\"open\":")) { + readingParkingOpen = true; + content = ""; + } + + if (readingParkingOpen) { + if (inChar != ',' && inChar != '}') { + if (inChar != '"' && inChar != ':') + content += inChar; + } + else { + readingParkingOpen = false; + parkingOpen[0] = content.charAt(0); + parkingOpen[1] = '\0'; + parkingEnabled = true; + #ifdef DEBUG + Serial.print("Parking: "); + Serial.print(parkingOpen[0] == 't'); + Serial.print(", "); + Serial.println(parkingSpaces); + #endif + } + } + #endif + + #ifdef METRO + // fetch Metro app data + if (currentLine.endsWith("\"failure\":")) { + readingMetroFailure = true; + content = ""; + } + + if (readingMetroFailure) { + if (inChar != ',' && inChar != '}') { + if (inChar != '"' && inChar != ':') + content += inChar; + } + else { + readingMetroFailure = false; + metroFailure[0] = content.charAt(0); + metroFailure[1] = '\0'; + metroEnabled = true; + #ifdef DEBUG + Serial.print("Metro failure: "); + Serial.print(metroFailure[0] == 't'); + #endif + } + } + #endif + // fetch Weather app data if (currentLine.endsWith("y\":{\"icon\":")) { readingTodayIcon = true; @@ -519,6 +590,12 @@ void resetApps() { #ifdef AGENDA agendaEnabled = false; #endif + #ifdef PARKING + parkingEnabled = false; + #endif + #ifdef METRO + metroEnabled = false; + #endif } int stringToInt(String string) { @@ -640,41 +717,7 @@ void scrollThirdPanel(int x) { void scrollFourthPanel(int x) { - //fourth panel : coffees and energy -64→-96 - if(x <= -33) { - // bus app - if(busEnabled) { - if(bus[0] == '-') - bus[0] = '<'; - if(bus[1] == '\0') { - dotmatrix.putchar(x+68, 10, bus[0], GREEN); - dotmatrix.putchar(x+73, 10, '\'', GREEN); - } - else { - dotmatrix.putchar(x+66, 10, bus[0], GREEN); - dotmatrix.putchar(x+71, 10, bus[1], GREEN); - dotmatrix.putchar(x+76, 10, '\'', GREEN); - } - - dotmatrix.putbitmap(x+67, 0, busSprite, 9, 9, ORANGE); - } - - // bikes app - if(bikesEnabled) { - dotmatrix.putchar(x+92, 0, ' ', ORANGE); - dotmatrix.putchar(x+92, 3, ' ', ORANGE); - dotmatrix.putbitmap(x+77, 0, bikeSprite, 16, 9, ORANGE); - - if(bikes[1] != '\0') { - dotmatrix.putchar(x+82, 10, bikes[0], GREEN); - dotmatrix.putchar(x+87, 10, bikes[1], GREEN); - } - else - dotmatrix.putchar(x+85, 10, bikes[0], GREEN); - } - } - - if(x <= -63) { + if(x <= -65) { #ifdef EMAILS // emails app if(emailsEnabled) { @@ -697,11 +740,60 @@ void scrollFourthPanel(int x) { } #endif + // parking app + #ifdef PARKING + if(parkingEnabled) { + byte marginLeft = 0; + // if we have two digits + if(parkingSpaces[2] == '\0') + marginLeft = 2; + else + marginLeft = 0; + + if(!marginLeft) { + color = GREEN; + dotmatrix.putchar(x+105+marginLeft, 10, parkingSpaces[2], color); + } + else { + color = ORANGE; + if(parkingSpaces[1] == '\0') + color = RED; + } + + dotmatrix.putchar(x+95+marginLeft, 10, parkingSpaces[0], color); + if(parkingSpaces[1] == '\0') + parkingSpaces[1] = '!'; + else + dotmatrix.putchar(x+100+marginLeft, 10, parkingSpaces[1], color); + + dotmatrix.putbitmap(x+97, 0, parkingSprite, 10, 8, color); + } + #endif + + // parking app + #ifdef METRO + if(metroEnabled) { + if(metroFailure[0] == 't') { + color = RED; + dotmatrix.putchar(x+113, 10, '1', color); + dotmatrix.putchar(x+118, 10, '1', color); + dotmatrix.putchar(x+123, 10, '\'', color); + } + else { + color = GREEN; + dotmatrix.putchar(x+113, 10, 'O', color); + dotmatrix.putchar(x+118, 10, 'K', color); + } + + dotmatrix.putbitmap(x+113, 0, metroSprite, 11, 8, color); + } + #endif + // energy app #ifdef ENERGY if(energyEnabled) { for(int i = 0; i < 7; i++) { - drawChart(x + 97 + (i*4), energy[i]); + drawChart(x + 96 + (i*4), energy[i]); } } #endif @@ -714,8 +806,42 @@ void scrollFourthPanel(int x) { if(timeEnabled) printTime(x+129); } + + if(x <= -33) { + // bus app + if(busEnabled) { + if(bus[0] == '-') + bus[0] = '<'; + if(bus[1] == '\0') { + dotmatrix.putchar(x+68, 10, bus[0], GREEN); + dotmatrix.putchar(x+73, 10, '\'', GREEN); + } + else { + dotmatrix.putchar(x+66, 10, bus[0], GREEN); + dotmatrix.putchar(x+71, 10, bus[1], GREEN); + dotmatrix.putchar(x+76, 10, '\'', GREEN); + } + + dotmatrix.putbitmap(x+67, 0, busSprite, 9, 9, ORANGE); + } + + // bikes app + if(bikesEnabled) { + dotmatrix.putchar(x+92, 0, ' ', ORANGE); + dotmatrix.putchar(x+92, 3, ' ', ORANGE); + dotmatrix.putbitmap(x+77, 0, bikeSprite, 16, 9, ORANGE); + + if(bikes[1] != '\0') { + dotmatrix.putchar(x+82, 10, bikes[0], GREEN); + dotmatrix.putchar(x+87, 10, bikes[1], GREEN); + } + else + dotmatrix.putchar(x+85, 10, bikes[0], GREEN); + } + } } +#ifdef AGENDA void scrollFifthPanel(int x) { //fourth panel : coffees and energy -64→-96 if(x <= -63) { @@ -742,6 +868,7 @@ void scrollFifthPanel(int x) { } } } +#endif #ifdef MESSAGES void scrollSixthPanel() {