Skip to content

Commit ddfb51f

Browse files
committed
Quotables examples fixed
1 parent 295e13f commit ddfb51f

File tree

7 files changed

+80
-39
lines changed

7 files changed

+80
-39
lines changed

examples/Inkplate10/Projects/Quotables_Example/Network.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,25 @@ void Network::begin()
4242
WiFi.begin(ssid, pass);
4343

4444
int cnt = 0;
45-
Serial.print(F("Waiting for WiFi to connect..."));
45+
display.print(F("Waiting for WiFi to connect..."));
46+
display.partialUpdate(true);
4647
while ((WiFi.status() != WL_CONNECTED))
4748
{
48-
Serial.print(F("."));
49+
display.print(F("."));
50+
display.partialUpdate(true);
4951
delay(1000);
5052
++cnt;
5153

5254
if (cnt == 20)
5355
{
54-
Serial.println("Can't connect to WIFI, restarting");
56+
display.println("Can't connect to WIFI, restarting");
57+
display.partialUpdate(true);
5558
delay(100);
5659
ESP.restart();
5760
}
5861
}
59-
Serial.println(F(" connected"));
62+
display.println(F(" connected"));
63+
display.partialUpdate(true);
6064

6165
}
6266

@@ -72,7 +76,8 @@ bool Network::getData(char* text, char* auth)
7276
delay(5000);
7377

7478
int cnt = 0;
75-
Serial.println(F("Waiting for WiFi to reconnect..."));
79+
display.println(F("Waiting for WiFi to reconnect..."));
80+
display.partialUpdate(true);
7681
while ((WiFi.status() != WL_CONNECTED))
7782
{
7883
// Prints a dot every second that wifi isn't connected
@@ -162,4 +167,4 @@ bool Network::getData(char* text, char* auth)
162167
WiFi.setSleep(sleep);
163168

164169
return !f;
165-
}
170+
}

examples/Inkplate10/Projects/Quotables_Example/Quotables_Example.ino

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ void setup()
6868
display.begin();
6969
display.setTextWrap(false); // Set text wrapping to true
7070
display.setTextColor(BLACK);
71+
display.setTextSize(3);
72+
73+
display.clearDisplay();
74+
display.display();
7175

7276
// Our begin function
7377
network.begin();
@@ -78,9 +82,8 @@ void setup()
7882
delay(1000);
7983
}
8084

81-
// Our main drawing function
82-
drawAll();
83-
// Full refresh
85+
display.clearDisplay();
86+
drawAll(); //Call funtion to draw screen
8487
display.display();
8588

8689
// Go to sleep before checking again
@@ -106,15 +109,18 @@ void drawAll()
106109
uint16_t cnt = 0;
107110
while (quote[cnt] != '\0')
108111
{
109-
if (display.getCursorX() > display.width() - 80)
112+
if (display.getCursorX() > display.width() - 120 && quote[cnt] == ' ')
110113
{
111114
row++;
112115
display.setCursor(60, display.height() / 2 - 30 * rows + row * 60);
113116
}
114117
display.print(quote[cnt]);
115118
cnt++;
116119
}
117-
display.setCursor(display.width() - 32 * strlen(author), display.height() - 30); // Set cursor to fit author name in lower right corner
120+
uint16_t w, h;
121+
int16_t x, y;
122+
display.getTextBounds(author, 0, 0, &x, &y, &w, &h);
123+
display.setCursor(display.width() - w - 50, display.height() - 30); // Set cursor to fit author name in lower right corner
118124
display.print("-");
119125
display.println(author); // Print author
120126
}

examples/Inkplate6/Projects/Quotables_Example/Network.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,25 @@ void Network::begin()
4242
WiFi.begin(ssid, pass);
4343

4444
int cnt = 0;
45-
Serial.print(F("Waiting for WiFi to connect..."));
45+
display.print(F("Waiting for WiFi to connect..."));
46+
display.partialUpdate(true);
4647
while ((WiFi.status() != WL_CONNECTED))
4748
{
48-
Serial.print(F("."));
49+
display.print(F("."));
50+
display.partialUpdate(true);
4951
delay(1000);
5052
++cnt;
5153

5254
if (cnt == 20)
5355
{
54-
Serial.println("Can't connect to WIFI, restarting");
56+
display.println("Can't connect to WIFI, restarting");
57+
display.partialUpdate(true);
5558
delay(100);
5659
ESP.restart();
5760
}
5861
}
59-
Serial.println(F(" connected"));
62+
display.println(F(" connected"));
63+
display.partialUpdate(true);
6064

6165
}
6266

@@ -72,7 +76,8 @@ bool Network::getData(char* text, char* auth)
7276
delay(5000);
7377

7478
int cnt = 0;
75-
Serial.println(F("Waiting for WiFi to reconnect..."));
79+
display.println(F("Waiting for WiFi to reconnect..."));
80+
display.partialUpdate(true);
7681
while ((WiFi.status() != WL_CONNECTED))
7782
{
7883
// Prints a dot every second that wifi isn't connected
@@ -162,4 +167,4 @@ bool Network::getData(char* text, char* auth)
162167
WiFi.setSleep(sleep);
163168

164169
return !f;
165-
}
170+
}

examples/Inkplate6/Projects/Quotables_Example/Quotables_Example.ino

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ char pass[] = "";
4343

4444
// Our networking functions, declared in Network.cpp
4545
#include "Network.h"
46+
#include "driver/rtc_io.h" // Include ESP32 library for RTC pin I/O (needed for rtc_gpio_isolate() function)
47+
#include <rom/rtc.h> // Include ESP32 library for RTC (needed for rtc_get_reset_reason() function)
4648

4749
// create object with all networking functions
4850
Network network;
@@ -68,6 +70,10 @@ void setup()
6870
display.begin();
6971
display.setTextWrap(false); // Set text wrapping to true
7072
display.setTextColor(BLACK);
73+
display.setTextSize(3);
74+
75+
display.clearDisplay();
76+
display.display();
7177

7278
// Our begin function
7379
network.begin();
@@ -78,9 +84,8 @@ void setup()
7884
delay(1000);
7985
}
8086

81-
// Our main drawing function
82-
drawAll();
83-
// Full refresh
87+
display.clearDisplay();
88+
drawAll(); //Call funtion to draw screen
8489
display.display();
8590

8691
// Go to sleep before checking again
@@ -106,15 +111,18 @@ void drawAll()
106111
uint16_t cnt = 0;
107112
while (quote[cnt] != '\0')
108113
{
109-
if (display.getCursorX() > display.width() - 75)
114+
if (display.getCursorX() > display.width() - 100 && quote[cnt] == ' ')
110115
{
111116
row++;
112117
display.setCursor(48, display.height() / 2 - 24 * rows + row * 48);
113118
}
114119
display.print(quote[cnt]);
115120
cnt++;
116121
}
117-
display.setCursor(display.width() - 32 * strlen(author), display.height() - 30); // Set cursor to fit author name in lower right corner
122+
uint16_t w, h;
123+
int16_t x, y;
124+
display.getTextBounds(author, 0, 0, &x, &y, &w, &h);
125+
display.setCursor(display.width() - w - 50, display.height() - 30); // Set cursor to fit author name in lower right corner
118126
display.print("-");
119127
display.println(author); // Print author
120128
}

examples/Inkplate6COLOR/Projects/Quotables_Example/Quotables_Example.ino

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,18 @@ void drawAll()
109109
uint16_t cnt = 0;
110110
while (quote[cnt] != '\0')
111111
{
112-
if (display.getCursorX() > display.width() - 75)
112+
if (display.getCursorX() > display.width() - 90 && quote[cnt] == ' ')
113113
{
114114
row++;
115115
display.setCursor(48, display.height() / 2 - 24 * rows + row * 48);
116116
}
117117
display.print(quote[cnt]);
118118
cnt++;
119119
}
120-
display.setCursor(display.width() - 32 * strlen(author), display.height() - 30); // Set cursor to fit author name in lower right corner
120+
uint16_t w,h;
121+
int16_t x,y;
122+
display.getTextBounds(author, 0, 0, &x, &y, &w, &h);
123+
display.setCursor(display.width() - w - 50, display.height() - 30); // Set cursor to fit author name in lower right corner
121124
display.print("-");
122125
display.println(author); // Print author
123126
}

examples/Inkplate6PLUS/Projects/Quotables_Example/Network.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,25 @@ void Network::begin()
4242
WiFi.begin(ssid, pass);
4343

4444
int cnt = 0;
45-
Serial.print(F("Waiting for WiFi to connect..."));
45+
display.print(F("Waiting for WiFi to connect..."));
46+
display.partialUpdate(true);
4647
while ((WiFi.status() != WL_CONNECTED))
4748
{
48-
Serial.print(F("."));
49+
display.print(F("."));
50+
display.partialUpdate(true);
4951
delay(1000);
5052
++cnt;
5153

5254
if (cnt == 20)
5355
{
54-
Serial.println("Can't connect to WIFI, restarting");
56+
display.println("Can't connect to WIFI, restarting");
57+
display.partialUpdate(true);
5558
delay(100);
5659
ESP.restart();
5760
}
5861
}
59-
Serial.println(F(" connected"));
62+
display.println(F(" connected"));
63+
display.partialUpdate(true);
6064

6165
}
6266

@@ -72,7 +76,8 @@ bool Network::getData(char* text, char* auth)
7276
delay(5000);
7377

7478
int cnt = 0;
75-
Serial.println(F("Waiting for WiFi to reconnect..."));
79+
display.println(F("Waiting for WiFi to reconnect..."));
80+
display.partialUpdate(true);
7681
while ((WiFi.status() != WL_CONNECTED))
7782
{
7883
// Prints a dot every second that wifi isn't connected
@@ -162,4 +167,4 @@ bool Network::getData(char* text, char* auth)
162167
WiFi.setSleep(sleep);
163168

164169
return !f;
165-
}
170+
}

examples/Inkplate6PLUS/Projects/Quotables_Example/Quotables_Example.ino

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
//---------- CHANGE HERE -------------:
3131

3232
// Put in your ssid and password
33-
char ssid[] = "";
34-
char pass[] = "";
33+
char ssid[] = "Soldered";
34+
char pass[] = "dasduino";
3535

3636
//----------------------------------
3737

@@ -43,6 +43,8 @@ char pass[] = "";
4343

4444
// Our networking functions, declared in Network.cpp
4545
#include "Network.h"
46+
#include "driver/rtc_io.h" // Include ESP32 library for RTC pin I/O (needed for rtc_gpio_isolate() function)
47+
#include <rom/rtc.h> // Include ESP32 library for RTC (needed for rtc_get_reset_reason() function)
4648

4749
// create object with all networking functions
4850
Network network;
@@ -51,7 +53,7 @@ Network network;
5153
Inkplate display(INKPLATE_1BIT);
5254

5355
// Delay between API calls in seconds, 300 seconds is 5 minutes
54-
#define DELAY_S 300
56+
#define DELAY_S 10
5557

5658
// Our functions declared below setup and loop
5759
void drawAll();
@@ -68,19 +70,23 @@ void setup()
6870
display.begin();
6971
display.setTextWrap(false); // Set text wrapping to true
7072
display.setTextColor(BLACK);
73+
display.setTextSize(3);
74+
75+
display.clearDisplay();
76+
display.display();
7177

7278
// Our begin function
7379
network.begin();
7480

7581
while (!network.getData(quote, author))
7682
{
77-
Serial.println("Retrying retriving data!");
83+
//display.println("Retrying retriving data!");
84+
//display.partialUpdate(true);
7885
delay(1000);
7986
}
8087

81-
// Our main drawing function
82-
drawAll();
83-
// Full refresh
88+
display.clearDisplay();
89+
drawAll(); //Call funtion to draw screen
8490
display.display();
8591

8692
// Go to sleep before checking again
@@ -106,15 +112,18 @@ void drawAll()
106112
uint16_t cnt = 0;
107113
while (quote[cnt] != '\0')
108114
{
109-
if (display.getCursorX() > display.width() - 80)
115+
if (display.getCursorX() > display.width() - 120 && quote[cnt] == ' ')
110116
{
111117
row++;
112118
display.setCursor(60, display.height() / 2 - 30 * rows + row * 60);
113119
}
114120
display.print(quote[cnt]);
115121
cnt++;
116122
}
117-
display.setCursor(display.width() - 32 * strlen(author), display.height() - 30); // Set cursor to fit author name in lower right corner
123+
uint16_t w, h;
124+
int16_t x, y;
125+
display.getTextBounds(author, 0, 0, &x, &y, &w, &h);
126+
display.setCursor(display.width() - w - 50, display.height() - 30); // Set cursor to fit author name in lower right corner
118127
display.print("-");
119128
display.println(author); // Print author
120129
}

0 commit comments

Comments
 (0)