@@ -63,13 +63,13 @@ Network network;
63
63
// create display object
64
64
Inkplate display (INKPLATE_3BIT);
65
65
66
- // Delay between API calls in miliseconds
67
- #define DELAY_MS 5000
66
+ // Delay between refreshed calls in miliseconds
67
+ #define DELAY_MS 3 * 60 * 1000
68
68
69
69
// Variable for counting partial refreshes
70
- long refreshes = 0 ;
70
+ RTC_DATA_ATTR unsigned refreshes = 0 ;
71
71
72
- // Constant to determine when to full update
72
+ // Constant to determine when to full update and fetch
73
73
const int fullRefresh = 20 ;
74
74
75
75
// Used for storing raw price values
@@ -98,18 +98,7 @@ char maximum[16];
98
98
99
99
// All months in a year, for finding current date
100
100
char *months[] = {
101
- " Jan"
102
- " Feb" ,
103
- " Mar" ,
104
- " Apr" ,
105
- " May" ,
106
- " Jun" ,
107
- " Jul" ,
108
- " Aug" ,
109
- " Sep" ,
110
- " Oct" ,
111
- " Nov" ,
112
- " Dec" ,
101
+ " Jan" , " Feb" , " Mar" , " Apr" , " May" , " Jun" , " Jul" , " Aug" , " Sep" , " Oct" , " Nov" , " Dec" ,
113
102
};
114
103
115
104
// Out UI elements data
@@ -139,44 +128,76 @@ void setup()
139
128
140
129
// Initial display settings
141
130
display.begin ();
142
- display.clearDisplay ();
143
- display.display ();
144
131
display.setTextWrap (false );
145
132
display.setTextColor (0 , 7 );
146
133
147
- // Welcome screen
148
- display.setCursor (70 , 230 );
149
- display.setTextSize (2 );
150
- display.println (F (" Welcome to Inkplate 10 cryptocurrency tracker example!" ));
151
- display.setCursor (70 , 250 );
152
- display.println (F (" Connecting to WiFi..." ));
153
- display.display ();
154
-
155
- delay (5000 );
156
-
157
- // Our begin function
158
- network.begin ();
159
- }
134
+ if (refreshes == 0 )
135
+ {
136
+ // Welcome screen
137
+ display.setCursor (70 , 230 );
138
+ display.setTextSize (2 );
139
+ display.println (F (" Welcome to Inkplate 10 cryptocurrency tracker example!" ));
140
+ display.setCursor (70 , 250 );
141
+ display.println (F (" Connecting to WiFi..." ));
142
+ display.display ();
143
+ display.clearDisplay ();
144
+ delay (1000 );
145
+ }
160
146
161
- void loop ()
162
- {
163
- // Do a new network request every fullRefresh times, defined above
164
147
if (refreshes % fullRefresh == 0 )
148
+ {
149
+ // Our begin function
150
+ network.begin ();
151
+
165
152
while (!network.getData (data))
166
153
{
167
154
Serial.println (" Retrying retriving data!" );
168
155
delay (1000 );
169
156
}
170
157
171
- // Our main drawing function
172
- drawAll ();
158
+ // Our main drawing function
159
+ drawAll ();
160
+ // Time drawing function
161
+ drawTime ();
162
+ // Full refresh
163
+ display.display ();
164
+ }
165
+ else
166
+ {
167
+ display.setDisplayMode (INKPLATE_1BIT);
168
+ Serial.println (" heree" );
169
+ // Reset screen where date is drawn
170
+ int16_t x1, y1;
171
+ uint16_t w1, h1;
172
+ display.setFont (elements[1 ].font );
173
+ display.setTextSize (1 );
174
+ network.getTime (date);
175
+ display.getTextBounds (date, (int )(elements[1 ].x * 0.96 ), (int )(elements[1 ].y ), &x1, &y1, &w1, &h1);
176
+
177
+ Serial.printf (" %d %d %d %d\n " , x1, y1, w1, h1);
178
+ display.fillRect (x1, y1, w1, h1, BLACK);
179
+ display.partialUpdate ();
180
+ display.fillRect (x1, y1, w1, h1, WHITE);
181
+ display.partialUpdate ();
173
182
174
- // Go to sleep before checking again
175
- esp_sleep_enable_timer_wakeup (1000L * DELAY_MS);
176
- (void )esp_light_sleep_start ();
183
+ // Time drawing function
184
+ drawTime ();
185
+
186
+ // Just update time
187
+ display.partialUpdate ();
188
+ }
177
189
178
190
// Increment refresh count
179
191
++refreshes;
192
+
193
+ // Go to sleep before checking again
194
+ esp_sleep_enable_timer_wakeup (1000ll * DELAY_MS);
195
+ (void )esp_deep_sleep_start ();
196
+ }
197
+
198
+ void loop ()
199
+ {
200
+ // Never here
180
201
}
181
202
182
203
// Function to draw our graph
@@ -230,7 +251,7 @@ void drawGraph()
230
251
for (int i = 0 ; i < 12 ; ++i)
231
252
{
232
253
if (strncmp (months[i], date, 3 ) == 0 )
233
- month = (( i + 2 ) % 12 ? i + 2 : 12 ) ;
254
+ month = i + 1 ;
234
255
}
235
256
236
257
// Find days to display underneath the graph
@@ -304,72 +325,54 @@ void drawGraph()
304
325
display.drawThickLine (x1, y1, x2, y1, 0 , 3 );
305
326
}
306
327
307
- // Our main drawing function
308
- void drawAll ()
309
- { // Do a full refresh every fullRefresh times, defined above
310
- if (refreshes % fullRefresh == 0 )
311
- {
312
- // Initial screen clear
313
- display.clearDisplay ();
328
+ // Function to draw time
329
+ void drawTime ()
330
+ {
331
+ // Just draw time
332
+ int i = 1 ;
314
333
315
- // Save current date string, more about it in Network.cpp
316
- network.getTime (date);
334
+ // Save current date string, more about it in Network.cpp
335
+ network.getTime (date);
317
336
318
- // Find current day from string
319
- int day;
320
- sscanf (date + 3 , " %d" , &day);
337
+ // Text settings
338
+ if (display.getDisplayMode () == INKPLATE_3BIT)
339
+ display.setTextColor (0 , 7 );
340
+ else
341
+ display.setTextColor (BLACK, WHITE);
342
+ display.setFont (elements[i].font );
343
+ display.setTextSize (1 );
321
344
322
- // Find what month is it numericly and display it
323
- for (int i = 0 ; i < 12 ; ++i)
324
- {
325
- if (strncmp (months[i], date, 3 ) == 0 )
326
- sprintf (fromToDate, " %d.%d. to %d.%d." , day, ((i + 1 ) % 12 ? i + 1 : 12 ), day,
327
- ((i + 2 ) % 12 ? i + 2 : 12 ));
328
- }
345
+ // 0 is aligned by left bottom corner, 1 by right
346
+ if (elements[i].align == 0 )
347
+ display.setCursor ((int )(elements[i].x * 0.96 ), (int )(elements[i].y ));
329
348
330
- // Draw graph
331
- drawGraph ();
349
+ // Print out text to above set cursor location
350
+ display.print (date);
351
+ }
332
352
333
- // Draw our UI elements
334
- for (int i = 0 ; i < sizeof (elements) / sizeof (elements[0 ]); ++i)
335
- {
336
- // Text settings
337
- display.setTextColor (0 , 7 );
338
- display.setFont (elements[i].font );
339
- display.setTextSize (1 );
340
-
341
- // 0 is aligned by left bottom corner, 1 by right
342
- if (elements[i].align == 0 )
343
- display.setCursor ((int )(elements[i].x * 0.96 ), (int )(elements[i].y ));
344
- else if (elements[i].align == 1 )
345
- {
346
- int16_t x, y;
347
- uint16_t w, h;
348
-
349
- // Get hot much the textx offsets pointer and draw it that much more left
350
- display.getTextBounds (elements[i].text , 0 , 0 , &x, &y, &w, &h);
351
-
352
- display.setCursor ((int )(elements[i].x * 0.96 ) - w, (int )(elements[i].y ));
353
- }
354
-
355
- // Print out text to above set cursor location
356
- display.print (elements[i].text );
357
- }
353
+ // Our main drawing function
354
+ void drawAll ()
355
+ {
356
+ // Save current date string, more about it in Network.cpp
357
+ network.getTime (date);
358
358
359
- // Display all
360
- display.display ();
361
- }
362
- else
363
- {
364
- // Just draw time
365
- int i = 1 ;
359
+ // Find current day from string
360
+ int day;
361
+ sscanf (date + 3 , " %d" , &day);
366
362
367
- // Initial screen clear
368
- display.clearDisplay ();
363
+ // Find what month is it numericly and display it
364
+ for (int i = 0 ; i < 12 ; ++i)
365
+ {
366
+ if (strncmp (months[i], date, 3 ) == 0 )
367
+ sprintf (fromToDate, " %d.%d. to %d.%d." , day, ((i + 1 ) % 12 ? i + 1 : 12 ), day, ((i + 2 ) % 12 ? i + 2 : 12 ));
368
+ }
369
369
370
- // Save current date string, more about it in Network.cpp
371
- network. getTime (date );
370
+ // Draw graph
371
+ drawGraph ( );
372
372
373
+ // Draw our UI elements
374
+ for (int i = 0 ; i < sizeof (elements) / sizeof (elements[0 ]); ++i)
375
+ {
373
376
// Text settings
374
377
display.setTextColor (0 , 7 );
375
378
display.setFont (elements[i].font );
@@ -378,11 +381,18 @@ void drawAll()
378
381
// 0 is aligned by left bottom corner, 1 by right
379
382
if (elements[i].align == 0 )
380
383
display.setCursor ((int )(elements[i].x * 0.96 ), (int )(elements[i].y ));
384
+ else if (elements[i].align == 1 )
385
+ {
386
+ int16_t x, y;
387
+ uint16_t w, h;
381
388
382
- // Print out text to above set cursor location
383
- display.print (date );
389
+ // Get how much the textx offsets pointer and draw it that much more left
390
+ display.getTextBounds (elements[i]. text , 0 , 0 , &x, &y, &w, &h );
384
391
385
- // Just update time
386
- display.partialUpdate ();
392
+ display.setCursor ((int )(elements[i].x * 0.96 ) - w, (int )(elements[i].y ));
393
+ }
394
+
395
+ // Print out text to above set cursor location
396
+ display.print (elements[i].text );
387
397
}
388
398
}
0 commit comments