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

#include <date_time.h>

Inheritance diagram for PaperdinkUIDateClass:
PaperdinkUIBaseClass

Public Member Functions

int8_t fetch_data (const char *time_zone, uint8_t week_start_offset=6)
 
void display_day_date_style1_center (GxEPD2_GFX &display, uint16_t x, uint16_t y, uint16_t w)
 
void display_day_date_style2_center (GxEPD2_GFX &display, uint16_t x, uint16_t y, uint16_t w)
 
void display_last_updated_time_style1_center (GxEPD2_GFX &display, uint16_t x, uint16_t y, uint16_t w)
 
void display_calendar (GxEPD2_GFX &display, uint16_t x, uint16_t y)
 

Public Attributes

char wday [4]
 
char month [4]
 
uint8_t month_days
 
uint8_t month_num
 
uint8_t mday
 
uint8_t mil_hour
 
uint8_t hour
 
uint8_t min
 
uint8_t sec
 
uint8_t day_offset
 
int year
 
uint8_t week_start_offset
 
- 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 9 of file date_time.h.

Member Function Documentation

◆ display_calendar()

void PaperdinkUIDateClass::display_calendar ( GxEPD2_GFX & display,
uint16_t x,
uint16_t y )

Definition at line 120 of file date_time.cpp.

121{
122 int16_t xt, yt;
123 uint16_t wt, ht;
124
125 /* Space between text depends on the font
126 * hence font is hardcoded.
127 */
128 display.setFont(&Gobold_Thin9pt7b);
129 display.setTextSize(1);
130 display.setTextColor(primary_color);
131
132#define CAL_STRING "Mon Tue Wed Thu Fri Sat Sun"
133
134 display.setCursor(x, y);
135 display.print(CAL_STRING);
136 display.getTextBounds(CAL_STRING, 0, 0, &xt, &yt, &wt, &ht);
137 uint8_t num_offset, print_valid = 0;
138 uint8_t day = 1;
139
140 for (uint8_t j = 0; j <= 5; j++) {
141 for (uint8_t i = 1; i <= 7 && day <= month_days; i++) {
142 // you can hack around with this value to align your text properly based on what font, font size etc you are using
143 num_offset = 21; // 21 is what works for me for the first 2 columns
144 if (i >= 3 && i <= 7)
145 num_offset = 17; // then I need to reduce to 17
146 if (j == 0 && ((i - 1) == Paperdink_Date.day_offset || Paperdink_Date.day_offset == 0))
147 // start from the offset in the month, ie which day does 1st of the month lie on
148 print_valid = 1;
149 if (print_valid) {
150 display.setCursor(x + (i * (wt / 7)) - num_offset, y + ((j + 1) * ht) + ((j + 1) * 7));
151 if (day == Paperdink_Date.mday) {
152 char str[3];
153 sprintf(str, "%d", day);
154 int16_t x2, y2;
155 uint16_t w2, h2;
156 display.getTextBounds(str, x + (i * (wt / 7)) - num_offset, y + ((j + 1) * ht) + ((j + 1) * 7), &x2, &y2, &w2, &h2);
157 display.fillRect(x2 - 4, y2 - 4, w2 + 8, h2 + 8, primary_color);
158 display.setTextColor(secondary_color);
159 } else {
160 display.setTextColor(primary_color);
161 }
162 // once the offset is reached, start incrementing
163 display.println(day);
164 day += 1;
165 }
166 }
167 }
168}
#define CAL_STRING
PaperdinkUIDateClass Paperdink_Date

◆ display_day_date_style1_center()

void PaperdinkUIDateClass::display_day_date_style1_center ( GxEPD2_GFX & display,
uint16_t x,
uint16_t y,
uint16_t w )

Definition at line 58 of file date_time.cpp.

59{
60 int16_t xt, yt;
61 uint16_t wt, ht, prev_height = 0, prev_width = 0;
62 char date_str[7];
63
64 display.setFont(font);
65 display.setTextColor(primary_color);
66 display.setTextSize(1);
67
68 // Display day
69 display.getTextBounds(wday, 0, 0, &xt, &yt, &wt, &ht);
70 display.setCursor(x + ((w - wt) / 2), y + ht);
71 display.println(wday);
72 prev_height += y + ht;
73
74 // Display date
75 sprintf(date_str, "%d %s", mday, month);
76 display.getTextBounds(date_str, 0, 0, &xt, &yt, &wt, &ht);
77 display.setCursor(x + ((w - wt) / 2), prev_height + ht + 20);
78 display.println(date_str);
79}
const GFXfont * font
Definition ui_base.h:9

◆ display_day_date_style2_center()

void PaperdinkUIDateClass::display_day_date_style2_center ( GxEPD2_GFX & display,
uint16_t x,
uint16_t y,
uint16_t w )

Definition at line 81 of file date_time.cpp.

82{
83 int16_t xt, yt;
84 uint16_t wt, ht, prev_height = 0, prev_width = 0;
85 char mday_str[3];
86
87 display.setFont(font);
88 display.setTextColor(secondary_color);
89 display.setTextSize(1);
90
91 // Display day
92 sprintf(mday_str, "%02d", Paperdink_Date.mday);
93 display.getTextBounds(mday_str, 0, 0, &xt, &yt, &wt, &ht);
94 display.setCursor(x + ((w - wt) / 2), y + ht);
95 display.println(mday_str);
96 prev_height += y + ht;
97
98 // Display month
99 display.getTextBounds(Paperdink_Date.month, 0, 0, &xt, &yt, &wt, &ht);
100 display.setCursor(x + ((w - wt) / 2), prev_height + ht + 5);
101 display.println(Paperdink_Date.month);
102}

◆ display_last_updated_time_style1_center()

void PaperdinkUIDateClass::display_last_updated_time_style1_center ( GxEPD2_GFX & display,
uint16_t x,
uint16_t y,
uint16_t w )

Definition at line 104 of file date_time.cpp.

105{
106 int16_t xt, yt;
107 uint16_t wt, ht, prev_height = 0, prev_width = 0;
108 char time_str[] = "Updated at: XX:XX";
109
110 display.setFont(font);
111 display.setTextColor(primary_color);
112 display.setTextSize(1);
113
114 sprintf(&time_str[12], "%02d:%02d", mil_hour, min);
115 display.getTextBounds(time_str, 0, 0, &xt, &yt, &wt, &ht);
116 display.setCursor(x + ((w - wt) / 2), y + ht);
117 display.print(time_str);
118}

◆ fetch_data()

int8_t PaperdinkUIDateClass::fetch_data ( const char * time_zone,
uint8_t week_start_offset = 6 )

Definition at line 4 of file date_time.cpp.

5{
6 struct tm timeinfo;
7 time_t epoch;
8 const int MONTHS[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
9
10 for (uint8_t i = 0; i < CONFIG_TIME_RETRY_COUNT; i++) {
11 configTime(0, 0, NTP_SERVER);
12
13 Serial.printf("TZ: %s\r\n", time_zone);
14 setenv("TZ", time_zone, 1);
15
16 if (!getLocalTime(&timeinfo)) {
17 Serial.println("Failed to obtain time. Retrying...");
18 delay(1000);
20 return -1;
21 } else {
22 break;
23 }
24 }
25
26 epoch = mktime(&timeinfo);
27
28 sscanf(ctime(&epoch), "%s %s %hhd %hhd:%hhd:%hhd %d", wday, month, &mday, &mil_hour, &min, &sec, &year);
29
30 month_num = timeinfo.tm_mon + 1;
31 // Gives offset of first day of the month with respect to Monday
32 // https://www.tondering.dk/claus/cal/chrweek.php#calcdow
33 // 0=Sunday, 1=Monday ... 6=Saturday
34 uint16_t a = (14 - month_num) / 12;
35 uint16_t y = year - a;
36 uint16_t m = month_num + (12 * a) - 2;
37
38 day_offset = (1 + y + (y / 4) - (y / 100) + (y / 400) + ((31 * m) / 12)) % 7;
39 // Change the offset based on user preference
41
42 // Convert to 12 hour
43 if (mil_hour > 12)
44 hour = mil_hour - 12;
45 else
46 hour = mil_hour;
47
48 // Get number of days in a month
49 month_days = MONTHS[month_num];
50 // Handle leap years
51 if (month_num == 1 && (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)))
52 month_days = 29;
53
54 Serial.printf("Time is %d %d:%d:%d on %s on the %d/%d/%d . It is the month of %s. day_offset: %d\r\n", mil_hour, hour, min, sec, wday, mday, month_num, year, month, day_offset);
55 return 0;
56}
uint8_t week_start_offset
Definition date_time.h:24
#define CONFIG_TIME_RETRY_COUNT
Definition date_time.h:7
#define NTP_SERVER
Definition date_time.h:6

Member Data Documentation

◆ day_offset

uint8_t PaperdinkUIDateClass::day_offset

Definition at line 21 of file date_time.h.

◆ hour

uint8_t PaperdinkUIDateClass::hour

Definition at line 18 of file date_time.h.

◆ mday

uint8_t PaperdinkUIDateClass::mday

Definition at line 16 of file date_time.h.

◆ mil_hour

uint8_t PaperdinkUIDateClass::mil_hour

Definition at line 17 of file date_time.h.

◆ min

uint8_t PaperdinkUIDateClass::min

Definition at line 19 of file date_time.h.

◆ month

char PaperdinkUIDateClass::month[4]

Definition at line 13 of file date_time.h.

◆ month_days

uint8_t PaperdinkUIDateClass::month_days

Definition at line 14 of file date_time.h.

◆ month_num

uint8_t PaperdinkUIDateClass::month_num

Definition at line 15 of file date_time.h.

◆ sec

uint8_t PaperdinkUIDateClass::sec

Definition at line 20 of file date_time.h.

◆ wday

char PaperdinkUIDateClass::wday[4]

Definition at line 12 of file date_time.h.

◆ week_start_offset

uint8_t PaperdinkUIDateClass::week_start_offset

Definition at line 24 of file date_time.h.

◆ year

int PaperdinkUIDateClass::year

Definition at line 22 of file date_time.h.


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