Paperd.Ink Library 0.0.5
Library for interacting with Paperd.Ink devices.
Loading...
Searching...
No Matches
PaperdinkUICryptoClass Class Reference

#include <crypto.h>

Inheritance diagram for PaperdinkUICryptoClass:
PaperdinkUIBaseClass

Public Member Functions

int8_t fetch_data (const char *ticker)
 
void display_med_box (GxEPD2_GFX &display, int16_t x, int16_t y, const char *ticker)
 

Public Attributes

char price [CRYPTO_MAX_PRICE_LENGTH_STR] = "USD XXX"
 
char change [CRYPTO_MAX_CHANGE_LENGTH_STR] = "XXXX%"
 
- Public Attributes inherited from PaperdinkUIBaseClass
const GFXfont * font = &PAPERDINK_FONT_SML
 
const GFXfont * font_bold = &PAPERDINK_FONT_SML_BOLD
 
int primary_color = GxEPD_BLACK
 
int secondary_color = GxEPD_WHITE
 
int tertiary_color = GxEPD_BLACK
 

Detailed Description

Definition at line 19 of file crypto.h.

Member Function Documentation

◆ display_med_box()

void PaperdinkUICryptoClass::display_med_box ( GxEPD2_GFX & display,
int16_t x,
int16_t y,
const char * ticker )

Definition at line 71 of file crypto.cpp.

72{
73 int16_t xt, yt;
74 uint16_t wt, ht, prev_height = 0, prev_width = 0;
75 const int16_t block_width = 100;
76 const int16_t block_height = 50;
77
78 //const char ticker[] = "Bitcoin";
79 const char dummy_price[] = "USD 7.77777777"; // decides width of the box
80 //const char change[] = "1.32%";
81
82 display.setFont(font_bold);
83 display.setTextColor(primary_color);
84 display.setTextSize(1);
85
86 /* Display ticker string */
87 display.getTextBounds(F("Bitcoin"), 0, 0, &xt, &yt, &wt, &ht);
88 display.setCursor(x + 14, y + ht + 3);
89 display.print(ticker);
90
91 display.setFont(font);
92 /* Display background */
93 display.getTextBounds(dummy_price, 0, 0, &xt, &yt, &wt, &ht);
94 display.fillRoundRect(x + 5, y + 30, wt + 20, ht + 10, ht + 10, secondary_color);
95 prev_width += x + 5 + wt + 20;
96 prev_height += y + 30;
97
98 /* Display current price */
99 display.setTextColor(tertiary_color);
100 display.getTextBounds(price, 0, 0, &xt, &yt, &wt, &ht);
101 display.setCursor(5 + ((x + prev_width - wt) / 2), prev_height + ht + 4);
102 display.print(price);
103 prev_width += 4;
104 prev_height += -2;
105
106 /* Display arrow */
107 const uint8_t *arrow = up_arrow_sml;
108 uint16_t color = primary_color;
109 if (change[0] == '-') {
110 arrow = down_arrow_sml;
111 if (display.epd2.hasColor)
112 color = secondary_color;
113 }
114 display.drawBitmap(prev_width, prev_height, arrow, 24, 24, color);
115 prev_width += 24; // Size of bitmap
116
117 // Display percentage change
118 display.setTextColor(primary_color);
119 display.getTextBounds(change, 0, 0, &xt, &yt, &wt, &ht);
120 display.setCursor(prev_width - wt, y + ht + 3);
121 display.print(change);
122}
const bool hasColor
Definition GxEPD2_EPD.h:30
GxEPD2_EPD & epd2
Definition GxEPD2_GFX.h:94
const GFXfont * font
Definition ui_base.h:9
const GFXfont * font_bold
Definition ui_base.h:10
char change[CRYPTO_MAX_CHANGE_LENGTH_STR]
Definition crypto.h:23
char price[CRYPTO_MAX_PRICE_LENGTH_STR]
Definition crypto.h:22
const unsigned char down_arrow_sml[72]
const unsigned char up_arrow_sml[72]
Definition up_arrow_sml.h:1

◆ fetch_data()

int8_t PaperdinkUICryptoClass::fetch_data ( const char * ticker)

Definition at line 33 of file crypto.cpp.

34{
35 int httpCode, ret = 0;
36 String payload;
37 WiFiClientSecure *client = new WiFiClientSecure;
38 client->setCACert(cert);
39
40 {
41 HTTPClient https;
42
43 String get_url = url + ticker;
44
45 https.begin(*client, get_url.c_str());
46 https.addHeader("Content-Type", "application/json", 0, 0);
47
48 httpCode = https.GET();
49
50 if (httpCode == HTTP_CODE_OK) {
51 // HTTP header has been send and Server response header has been handled
52 DEBUG.printf("[HTTP] GET SUCCESS\r\n");
53 //String payload = https.getString();
54 //Serial.println(payload);
56 parser.setListener(&crypto_listener);
57 https.writeToStream(&parser);
58 } else {
59 DEBUG.printf("[HTTP] Failed, error: %s\r\n", https.errorToString(httpCode).c_str());
60 ret = -1;
61 }
62
63 https.end();
64 }
65
66 delete client;
67 DEBUG.printf("[HTTP] COMPLETED \r\n");
68 return ret;
69}
CryptoJsonListener crypto_listener
Definition crypto.cpp:8
#define DEBUG
Definition crypto.h:6

Member Data Documentation

◆ change

char PaperdinkUICryptoClass::change[CRYPTO_MAX_CHANGE_LENGTH_STR] = "XXXX%"

Definition at line 23 of file crypto.h.

◆ price

char PaperdinkUICryptoClass::price[CRYPTO_MAX_PRICE_LENGTH_STR] = "USD XXX"

Definition at line 22 of file crypto.h.


The documentation for this class was generated from the following files: