Skip to content

Commit

Permalink
Added new methods to the provider
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiosagu committed Jun 5, 2021
1 parent ce43acc commit bae7e66
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 34 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ CC = g++
ifdef RPI
CFLAGS = -Wall -pthread
WPIFLAG = -DWPI
LDFLAGS =
LDFLAGS = -lwiringPi
else
CFLAGS = -Wall -pthread -g
WPIFLAG =
Expand All @@ -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
Expand Down
32 changes: 27 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 21 additions & 22 deletions providers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include <string>
#include <cstdlib>
#include <ctime>
#include <curl/curl.h>
#include <jsoncpp/json/json.h>
#include "providers.hpp"

Provider::Provider()
Expand All @@ -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";
}
22 changes: 19 additions & 3 deletions providers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,30 @@

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:
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();
};
5 changes: 4 additions & 1 deletion smartdisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
}
Expand Down

0 comments on commit bae7e66

Please sign in to comment.