@@ -64,10 +64,10 @@ Network network;
6464Inkplate display (INKPLATE_3BIT);
6565
6666// Delay between API calls in miliseconds
67- #define DELAY_MS 5000
67+ #define DELAY_MS 3 * 60 * 1000
6868
6969// Variable for counting partial refreshes
70- long refreshes = 0 ;
70+ RTC_DATA_ATTR unsigned refreshes = 0 ;
7171
7272// Constant to determine when to full update
7373const int fullRefresh = 20 ;
@@ -98,18 +98,7 @@ char maximum[16];
9898
9999// All months in a year, for finding current date
100100char *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" ,
113102};
114103
115104// Out UI elements data
@@ -139,44 +128,75 @@ void setup()
139128
140129 // Initial display settings
141130 display.begin ();
142- display.clearDisplay ();
143- display.display ();
144131 display.setTextWrap (false );
145132 display.setTextColor (0 , 7 );
146133
147- // Welcome screen
148- display.setCursor (70 , 230 );
149- display.setTextSize (2 );
150- display.println (F (" Welcome to Inkplate 6 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 6 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+ }
160146
161- void loop ()
162- {
163- // Do a new network request every fullRefresh times, defined above
164147 if (refreshes % fullRefresh == 0 )
148+ {
149+ // Our begin function
150+ network.begin ();
151+
165152 while (!network.getData (data))
166153 {
167154 Serial.println (" Retrying retriving data!" );
168155 delay (1000 );
169156 }
170157
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 ();
173182
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+ }
177189
178- // Increment refresh count
179190 ++refreshes;
191+
192+ // Go to sleep before checking again
193+ esp_sleep_enable_timer_wakeup (1000ll * DELAY_MS);
194+ (void )esp_deep_sleep_start ();
195+ }
196+
197+ void loop ()
198+ {
199+ // Never here
180200}
181201
182202// Function to draw our graph
@@ -230,7 +250,7 @@ void drawGraph()
230250 for (int i = 0 ; i < 12 ; ++i)
231251 {
232252 if (strncmp (months[i], date, 3 ) == 0 )
233- month = (( i + 2 ) % 12 ? i + 2 : 12 ) ;
253+ month = i + 1 ;
234254 }
235255
236256 // Find days to display underneath the graph
@@ -304,72 +324,54 @@ void drawGraph()
304324 display.drawThickLine (x1, y1, x2, y1, 0 , 3 );
305325}
306326
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 ();
327+ // Function to draw time
328+ void drawTime ()
329+ {
330+ // Just draw time
331+ int i = 1 ;
314332
315- // Save current date string, more about it in Network.cpp
316- network.getTime (date);
333+ // Save current date string, more about it in Network.cpp
334+ network.getTime (date);
317335
318- // Find current day from string
319- int day;
320- sscanf (date + 3 , " %d" , &day);
336+ // Text settings
337+ if (display.getDisplayMode () == INKPLATE_3BIT)
338+ display.setTextColor (0 , 7 );
339+ else
340+ display.setTextColor (BLACK, WHITE);
341+ display.setFont (elements[i].font );
342+ display.setTextSize (1 );
321343
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- }
344+ // 0 is aligned by left bottom corner, 1 by right
345+ if (elements[i].align == 0 )
346+ display.setCursor ((int )(elements[i].x * 0.96 ), (int )(elements[i].y ));
329347
330- // Draw graph
331- drawGraph ();
348+ // Print out text to above set cursor location
349+ display.print (date);
350+ }
332351
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- }
352+ // Our main drawing function
353+ void drawAll ()
354+ {
355+ // Save current date string, more about it in Network.cpp
356+ network.getTime (date);
358357
359- // Display all
360- display.display ();
361- }
362- else
363- {
364- // Just draw time
365- int i = 1 ;
358+ // Find current day from string
359+ int day;
360+ sscanf (date + 3 , " %d" , &day);
366361
367- // Initial screen clear
368- display.clearDisplay ();
362+ // Find what month is it numericly and display it
363+ for (int i = 0 ; i < 12 ; ++i)
364+ {
365+ if (strncmp (months[i], date, 3 ) == 0 )
366+ sprintf (fromToDate, " %d.%d. to %d.%d." , day, ((i + 1 ) % 12 ? i + 1 : 12 ), day, ((i + 2 ) % 12 ? i + 2 : 12 ));
367+ }
369368
370- // Save current date string, more about it in Network.cpp
371- network. getTime (date );
369+ // Draw graph
370+ drawGraph ( );
372371
372+ // Draw our UI elements
373+ for (int i = 0 ; i < sizeof (elements) / sizeof (elements[0 ]); ++i)
374+ {
373375 // Text settings
374376 display.setTextColor (0 , 7 );
375377 display.setFont (elements[i].font );
@@ -378,11 +380,18 @@ void drawAll()
378380 // 0 is aligned by left bottom corner, 1 by right
379381 if (elements[i].align == 0 )
380382 display.setCursor ((int )(elements[i].x * 0.96 ), (int )(elements[i].y ));
383+ else if (elements[i].align == 1 )
384+ {
385+ int16_t x, y;
386+ uint16_t w, h;
381387
382- // Print out text to above set cursor location
383- display.print (date );
388+ // Get how much the textx offsets pointer and draw it that much more left
389+ display.getTextBounds (elements[i]. text , 0 , 0 , &x, &y, &w, &h );
384390
385- // Just update time
386- display.partialUpdate ();
391+ display.setCursor ((int )(elements[i].x * 0.96 ) - w, (int )(elements[i].y ));
392+ }
393+
394+ // Print out text to above set cursor location
395+ display.print (elements[i].text );
387396 }
388397}
0 commit comments