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

#include <youtube.h>

Inheritance diagram for PaperdinkUIYoutubeClass:
PaperdinkUIBaseClass

Public Member Functions

int8_t fetch_data (const char *channel_id, const char *api_id)
 
void display_subscribers_med (GxEPD2_GFX &display, int16_t x, int16_t y, int16_t w=0, int16_t h=0)
 
void display_views_med (GxEPD2_GFX &display, int16_t x, int16_t y, int16_t w=0, int16_t h=0)
 

Public Attributes

uint64_t subscribers = 0
 
uint64_t views = 0
 
- 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 11 of file youtube.h.

Member Function Documentation

◆ display_subscribers_med()

void PaperdinkUIYoutubeClass::display_subscribers_med ( GxEPD2_GFX & display,
int16_t x,
int16_t y,
int16_t w = 0,
int16_t h = 0 )

Definition at line 81 of file youtube.cpp.

82{
83 int16_t xt, yt;
84 uint16_t wt, ht, prev_height = y, prev_width = x;
85 char subscribers_str[MAX_YOUTUBE_SUBSCRIBER_COUNT];
86
87 display.setFont(font);
88 display.setTextColor(primary_color);
89 display.setTextSize(1);
90
91 // Display subscribers count
92 snprintf(subscribers_str, MAX_YOUTUBE_SUBSCRIBER_COUNT, "%lld", subscribers);
93 display.getTextBounds(subscribers_str, 0, 0, &xt, &yt, &wt, &ht);
94 if (w == 0 || h == 0) {
95 /* No centering */
96 // 5px and 4px margin
97 display.setCursor(prev_width + 5, prev_height + ht + 4);
98 } else {
99 display.setCursor(prev_width + 5 + ((w - wt) / 2) + (user_med_width / 2), prev_height + 4 + ((h - ht) / 2));
100 prev_width += 5 + ((w + wt) / 2) + (user_med_width / 2);
101 prev_height += 4 + (ht);
102 }
103 display.print(subscribers_str);
104
105 // 3 px margin
106 display.drawBitmap(prev_width - wt - user_med_width - 5, prev_height - user_med_height + 3, user_med, user_med_width, user_med_height, primary_color);
107}
const GFXfont * font
Definition ui_base.h:9
#define user_med_height
Definition user_med.h:2
const unsigned char user_med[128]
Definition user_med.h:4
#define user_med_width
Definition user_med.h:1
#define MAX_YOUTUBE_SUBSCRIBER_COUNT
Definition youtube.h:8

◆ display_views_med()

void PaperdinkUIYoutubeClass::display_views_med ( GxEPD2_GFX & display,
int16_t x,
int16_t y,
int16_t w = 0,
int16_t h = 0 )

Definition at line 109 of file youtube.cpp.

110{
111 int16_t xt, yt;
112 uint16_t wt, ht, prev_height = y, prev_width = x;
113 const int16_t block_width = 100;
114 char views_str[MAX_YOUTUBE_VIEWS_COUNT];
115
116 display.setFont(font);
117 display.setTextColor(primary_color);
118 display.setTextSize(1);
119
120 // Display ticker
121 snprintf(views_str, MAX_YOUTUBE_VIEWS_COUNT, "%lld", views);
122 display.getTextBounds(views_str, 0, 0, &xt, &yt, &wt, &ht);
123 if (w == 0 || h == 0) {
124 /* No centering */
125 // 5px and 4px margin
126 display.setCursor(prev_width + 5, prev_height + ht + 4);
127 } else {
128 display.setCursor(prev_width + 5 + ((w - wt) / 2) + (eye_med_width / 2), prev_height + 4 + ((h - ht) / 2));
129 prev_width += 5 + ((w + wt) / 2) + (eye_med_width / 2);
130 prev_height += 4 + (ht);
131 }
132 display.print(views_str);
133
134 // 3 px margin
135 display.drawBitmap(prev_width - wt - eye_med_width - 5, prev_height - eye_med_height + 3, eye_med, eye_med_width, eye_med_height, primary_color);
136}
#define eye_med_height
Definition eye_med.h:2
#define eye_med_width
Definition eye_med.h:1
const unsigned char eye_med[128]
Definition eye_med.h:4
#define MAX_YOUTUBE_VIEWS_COUNT
Definition youtube.h:9

◆ fetch_data()

int8_t PaperdinkUIYoutubeClass::fetch_data ( const char * channel_id,
const char * api_id )

Definition at line 42 of file youtube.cpp.

43{
44 int httpCode, ret = 0;
45 String payload;
46 WiFiClientSecure *client = new WiFiClientSecure;
47 client->setCACert(cert);
48
49 String get_url = url;
50 get_url.replace("{0}", channel_id);
51 get_url.replace("{1}", api_id);
52
53 {
54 HTTPClient https;
55 https.begin(*client, get_url.c_str());
56 https.addHeader("Content-Type", "application/json", 0, 0);
57
58 httpCode = https.GET();
59
60 if (httpCode == HTTP_CODE_OK) {
61 // HTTP header has been send and Server response header has been handled
62 DEBUG.printf("[HTTP] GET SUCCESS\r\n");
63 //String payload = https.getString();
64 //Serial.println(payload);
66 parser.setListener(&youtube_listener);
67 https.writeToStream(&parser);
68 } else {
69 DEBUG.printf("[HTTP] Failed, error: %s\r\n", https.errorToString(httpCode).c_str());
70 ret = -1;
71 }
72
73 https.end();
74 }
75
76 delete client;
77 DEBUG.printf("[HTTP] COMPLETED \r\n");
78 return ret;
79}
YoutubeJsonListener youtube_listener
Definition youtube.cpp:8
#define DEBUG
Definition youtube.h:6

Member Data Documentation

◆ subscribers

uint64_t PaperdinkUIYoutubeClass::subscribers = 0

Definition at line 14 of file youtube.h.

◆ views

uint64_t PaperdinkUIYoutubeClass::views = 0

Definition at line 15 of file youtube.h.


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