diff --git a/Makefile b/Makefile index 8d4e701..decdc33 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ CC = g++ ifdef RPI CFLAGS = -Wall -pthread WPIFLAG = -DWPI -LDFLAGS = +LDFLAGS = -lwiringPi else CFLAGS = -Wall -pthread -g WPIFLAG = @@ -19,10 +19,10 @@ smartdisplay.o: smartdisplay.cpp $(CC) $(CFLAGS) -c smartdisplay.cpp displays.o: displays.cpp displays.hpp - $(CC) $(CFLAGS) -c displays.cpp $(WPIFLAG) $(LDFLAGS) + $(CC) $(CFLAGS) -c displays.cpp $(WPIFLAG) providers.o: providers.cpp providers.hpp - $(CC) $(CFLAGS) -c providers.cpp + $(CC) $(CFLAGS) -c providers.cpp -ljsoncpp -lcurl clean: $(RM) smartdisplay *.o *~ *.h*.gch diff --git a/README.md b/README.md index abd8aa2..4e2b16c 100644 --- a/README.md +++ b/README.md @@ -24,26 +24,48 @@ These define the interface and implementation related to the providers of the da ### smartdisplay.cpp Main application combining the previous functionality. ## Build & Run +### Prerequisites +- WiringPi (only in your Raspberry Pi) +``` +sudo apt-get install wiringpi +``` +- ncurses +``` +sudo apt-get install libncurses5-dev +``` +- jsoncpp +``` +sudo apt-get install libjsoncpp-dev +``` +- curl +``` +sudo apt-get install libcurl4-openssl-dev +``` +### Commands +#### From your dev environment Build the project (no WiringPi library needed) ``` +$ make clean $ make ``` +Run the project +``` +$ ./smartdisplay +``` Push the sources to your Raspberry Pi (to `/root/smartdisplay/`) ``` $ make push RPI_IP=172.16.0.1 ``` -Build the project from your Raspberry Pi (WiringPi library needs to be installed) +#### From your Raspberry Pi +Build the project (WiringPi library needed!) ``` +$ make clean $ make RPI=true ``` Run the project ``` $ ./smartdisplay ``` -Clean the project -``` -$ make clean -``` ## Result *Coming soon!* # Related work diff --git a/providers.cpp b/providers.cpp index 90019b0..e60df9e 100644 --- a/providers.cpp +++ b/providers.cpp @@ -2,6 +2,8 @@ #include #include #include +#include +#include #include "providers.hpp" Provider::Provider() @@ -17,39 +19,36 @@ string Provider::getIp() return "172.16.0.1"; } -struct tm *getLocaltime() +string Provider::getTimeInfo(string format) { time_t rawtime; time(&rawtime); - return localtime(&rawtime); -} -string Provider::getTime() -{ tm *timeinfo; - timeinfo = getLocaltime(); - char buffer[32]; - strftime(buffer, sizeof(buffer), "%T", timeinfo); + timeinfo = localtime(&rawtime); + + char buffer[16]; + strftime(buffer, sizeof(buffer), format.c_str(), timeinfo); string s(buffer); return s; } -string Provider::getDate() +string Provider::getBtcExchangeRate(string currency) { - tm *timeinfo; - timeinfo = getLocaltime(); - char buffer[32]; - strftime(buffer, sizeof(buffer), "%F", timeinfo); - string s(buffer); - return s; + return "404"; } -string Provider::getDateTime() +string Provider::getTemperature(string city) { - tm *timeinfo; - timeinfo = getLocaltime(); - char buffer[32]; - strftime(buffer, sizeof(buffer), "%a %b %e %R", timeinfo); - string s(buffer); - return s; + return "404"; +} + +string Provider::getQuoteOfTheDay() +{ + return "404"; +} + +string Provider::getStocks() +{ + return "404"; } \ No newline at end of file diff --git a/providers.hpp b/providers.hpp index 876e03f..a262a10 100644 --- a/providers.hpp +++ b/providers.hpp @@ -2,6 +2,20 @@ using namespace std; +// CONSTANTS + +// From https://www.cplusplus.com/reference/ctime/strftime/ +const string TIME1 = "%T"; // "12:34:56" +const string TIME2 = "%R"; // "12:34" +const string DATE1 = "%a %d %b %Y"; // "Fri 25 Dec 2020" +const string DATE2 = "%d/%m/%Y"; // "25/12/2020" +const string TIMEDATE1 = "%a %d %b %R"; // "Thu 24 Jun 17:30" +const string TIMEDATE2 = TIME2 + " " + DATE2; // "17:30 24/06/2021" + +const string EXCHANGE_URL = "https://api.cryptonator.com/api/ticker/"; +const string USD = "btc-usd"; +const string EUR = "btc-eur"; + class Provider { public: @@ -9,7 +23,9 @@ class Provider ~Provider(); static string getIp(); - static string getTime(); - static string getDate(); - static string getDateTime(); + static string getTimeInfo(string format); + static string getBtcExchangeRate(string currency); + static string getTemperature(string city); + static string getQuoteOfTheDay(); + static string getStocks(); }; diff --git a/smartdisplay.cpp b/smartdisplay.cpp index b38e6dd..af459d3 100644 --- a/smartdisplay.cpp +++ b/smartdisplay.cpp @@ -4,9 +4,12 @@ void topThread(Display d) { + string ip; + ip = Display::alignCenter(Provider::getIp()); for (;;) { - d.demo(); + d.fadeBlink(ip); + // d.demo(); // d.fadeBlink(Display::alignCenter(Provider::getTime())); } }