Bug fixes in example projects.
This commit is contained in:
parent
5bc7b9d96e
commit
6fa2de7ed9
|
@ -0,0 +1,9 @@
|
||||||
|
#include "Inkplate.h"
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
|
||||||
|
}
|
|
@ -57,6 +57,13 @@ Network network;
|
||||||
// Contants used for drawing icons
|
// Contants used for drawing icons
|
||||||
char abbrs[32][16] ={ "sn", "sl", "h", "t", "hr", "lr", "s", "hc", "lc", "c" };
|
char abbrs[32][16] ={ "sn", "sl", "h", "t", "hr", "lr", "s", "hc", "lc", "c" };
|
||||||
const uint8_t *logos[16] ={ icon_sn, icon_sl, icon_h, icon_t, icon_hr, icon_lr, icon_s, icon_hc, icon_lc, icon_c };
|
const uint8_t *logos[16] ={ icon_sn, icon_sl, icon_h, icon_t, icon_hr, icon_lr, icon_s, icon_hc, icon_lc, icon_c };
|
||||||
|
const uint8_t *s_logos[16] ={ icon_s_sn, icon_s_sl, icon_s_h, icon_s_t, icon_s_hr, icon_s_lr, icon_s_s, icon_s_hc, icon_s_lc, icon_s_c };
|
||||||
|
|
||||||
|
|
||||||
|
char abbr1[16];
|
||||||
|
char abbr2[16];
|
||||||
|
char abbr3[16];
|
||||||
|
char abbr4[16];
|
||||||
|
|
||||||
// Variables for storing temperature
|
// Variables for storing temperature
|
||||||
char temps[8][4] ={
|
char temps[8][4] ={
|
||||||
|
@ -138,7 +145,7 @@ void loop()
|
||||||
// Get all relevant data, see Network.cpp for info
|
// Get all relevant data, see Network.cpp for info
|
||||||
network.getTime(currentTime);
|
network.getTime(currentTime);
|
||||||
network.getDays(days[0], days[1], days[2], days[3]);
|
network.getDays(days[0], days[1], days[2], days[3]);
|
||||||
network.getData(city, temps[0], temps[1], temps[2], temps[3], currentTemp, currentWind, currentTime, currentWeather, currentWeatherAbbr);
|
network.getData(city, temps[0], temps[1], temps[2], temps[3], currentTemp, currentWind, currentTime, currentWeather, currentWeatherAbbr, abbr1, abbr2, abbr3, abbr4);
|
||||||
|
|
||||||
// Draw data, see functions below for info
|
// Draw data, see functions below for info
|
||||||
drawWeather();
|
drawWeather();
|
||||||
|
@ -222,16 +229,16 @@ void drawTemps()
|
||||||
display.setTextSize(1);
|
display.setTextSize(1);
|
||||||
display.setTextColor(WHITE, BLACK);
|
display.setTextColor(WHITE, BLACK);
|
||||||
|
|
||||||
display.setCursor(1 * rectSpacing + 0 * rectWidth + textMargin, 300 + textMargin + 70);
|
display.setCursor(1 * rectSpacing + 0 * rectWidth + textMargin, 300 + textMargin + 40);
|
||||||
display.println(days[0]);
|
display.println(days[0]);
|
||||||
|
|
||||||
display.setCursor(2 * rectSpacing + 1 * rectWidth + textMargin, 300 + textMargin + 70);
|
display.setCursor(2 * rectSpacing + 1 * rectWidth + textMargin, 300 + textMargin + 40);
|
||||||
display.println(days[1]);
|
display.println(days[1]);
|
||||||
|
|
||||||
display.setCursor(3 * rectSpacing + 2 * rectWidth + textMargin, 300 + textMargin + 70);
|
display.setCursor(3 * rectSpacing + 2 * rectWidth + textMargin, 300 + textMargin + 40);
|
||||||
display.println(days[2]);
|
display.println(days[2]);
|
||||||
|
|
||||||
display.setCursor(4 * rectSpacing + 3 * rectWidth + textMargin, 300 + textMargin + 70);
|
display.setCursor(4 * rectSpacing + 3 * rectWidth + textMargin, 300 + textMargin + 40);
|
||||||
display.println(days[3]);
|
display.println(days[3]);
|
||||||
|
|
||||||
//Drawing temperature values into black rectangles
|
//Drawing temperature values into black rectangles
|
||||||
|
@ -239,21 +246,49 @@ void drawTemps()
|
||||||
display.setTextSize(1);
|
display.setTextSize(1);
|
||||||
display.setTextColor(WHITE, BLACK);
|
display.setTextColor(WHITE, BLACK);
|
||||||
|
|
||||||
display.setCursor(1 * rectSpacing + 0 * rectWidth + textMargin, 300 + textMargin + 160);
|
display.setCursor(1 * rectSpacing + 0 * rectWidth + textMargin, 300 + textMargin + 120);
|
||||||
display.print(temps[0]);
|
display.print(temps[0]);
|
||||||
display.println(F("C"));
|
display.println(F("C"));
|
||||||
|
|
||||||
display.setCursor(2 * rectSpacing + 1 * rectWidth + textMargin, 300 + textMargin + 160);
|
display.setCursor(2 * rectSpacing + 1 * rectWidth + textMargin, 300 + textMargin + 120);
|
||||||
display.print(temps[1]);
|
display.print(temps[1]);
|
||||||
display.println(F("C"));
|
display.println(F("C"));
|
||||||
|
|
||||||
display.setCursor(3 * rectSpacing + 2 * rectWidth + textMargin, 300 + textMargin + 160);
|
display.setCursor(3 * rectSpacing + 2 * rectWidth + textMargin, 300 + textMargin + 120);
|
||||||
display.print(temps[2]);
|
display.print(temps[2]);
|
||||||
display.println(F("C"));
|
display.println(F("C"));
|
||||||
|
|
||||||
display.setCursor(4 * rectSpacing + 3 * rectWidth + textMargin, 300 + textMargin + 160);
|
display.setCursor(4 * rectSpacing + 3 * rectWidth + textMargin, 300 + textMargin + 120);
|
||||||
display.print(temps[3]);
|
display.print(temps[3]);
|
||||||
display.println(F("C"));
|
display.println(F("C"));
|
||||||
|
|
||||||
|
for (int i = 0; i < 18; ++i)
|
||||||
|
{
|
||||||
|
//If found draw specified icon
|
||||||
|
if (strcmp(abbr1, abbrs[i]) == 0)
|
||||||
|
display.drawBitmap(1 * rectSpacing + 0 * rectWidth + textMargin, 300 + textMargin + 150, s_logos[i], 48, 48, WHITE, BLACK);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 18; ++i)
|
||||||
|
{
|
||||||
|
//If found draw specified icon
|
||||||
|
if (strcmp(abbr2, abbrs[i]) == 0)
|
||||||
|
display.drawBitmap(2 * rectSpacing + 1 * rectWidth + textMargin, 300 + textMargin + 150, s_logos[i], 48, 48, WHITE, BLACK);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 18; ++i)
|
||||||
|
{
|
||||||
|
//If found draw specified icon
|
||||||
|
if (strcmp(abbr3, abbrs[i]) == 0)
|
||||||
|
display.drawBitmap(3 * rectSpacing + 2 * rectWidth + textMargin, 300 + textMargin + 150, s_logos[i], 48, 48, WHITE, BLACK);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 18; ++i)
|
||||||
|
{
|
||||||
|
//If found draw specified icon
|
||||||
|
if (strcmp(abbr4, abbrs[i]) == 0)
|
||||||
|
display.drawBitmap(4 * rectSpacing + 3 * rectWidth + textMargin, 300 + textMargin + 150, s_logos[i], 48, 48, WHITE, BLACK);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Current weather drawing function
|
// Current weather drawing function
|
||||||
|
|
|
@ -84,7 +84,7 @@ void formatWind(char *str, float wind)
|
||||||
dtostrf(wind, 2, 0, str);
|
dtostrf(wind, 2, 0, str);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Network::getData(char *city, char *temp1, char *temp2, char *temp3, char *temp4, char *currentTemp, char *currentWind, char *currentTime, char *currentWeather, char *currentWeatherAbbr)
|
void Network::getData(char *city, char *temp1, char *temp2, char *temp3, char *temp4, char *currentTemp, char *currentWind, char *currentTime, char *currentWeather, char *currentWeatherAbbr, char* abbr1, char* abbr2, char* abbr3, char* abbr4)
|
||||||
{
|
{
|
||||||
// Reconnect if wifi isn't connected
|
// Reconnect if wifi isn't connected
|
||||||
if (WiFi.status() != WL_CONNECTED) {
|
if (WiFi.status() != WL_CONNECTED) {
|
||||||
|
@ -146,6 +146,11 @@ void Network::getData(char *city, char *temp1, char *temp2, char *temp3, char *t
|
||||||
strcpy(currentWeather, doc["consolidated_weather"][0]["weather_state_name"].as<char *>());
|
strcpy(currentWeather, doc["consolidated_weather"][0]["weather_state_name"].as<char *>());
|
||||||
strcpy(currentWeatherAbbr, doc["consolidated_weather"][0]["weather_state_abbr"].as<char *>());
|
strcpy(currentWeatherAbbr, doc["consolidated_weather"][0]["weather_state_abbr"].as<char *>());
|
||||||
|
|
||||||
|
strcpy(abbr1, doc["consolidated_weather"][0]["weather_state_abbr"].as<char *>());
|
||||||
|
strcpy(abbr2, doc["consolidated_weather"][1]["weather_state_abbr"].as<char *>());
|
||||||
|
strcpy(abbr3, doc["consolidated_weather"][2]["weather_state_abbr"].as<char *>());
|
||||||
|
strcpy(abbr4, doc["consolidated_weather"][3]["weather_state_abbr"].as<char *>());
|
||||||
|
|
||||||
formatTemp(temp1, doc["consolidated_weather"][0][F("the_temp")].as<float>());
|
formatTemp(temp1, doc["consolidated_weather"][0][F("the_temp")].as<float>());
|
||||||
formatTemp(temp2, doc["consolidated_weather"][1][F("the_temp")].as<float>());
|
formatTemp(temp2, doc["consolidated_weather"][1][F("the_temp")].as<float>());
|
||||||
formatTemp(temp3, doc["consolidated_weather"][2][F("the_temp")].as<float>());
|
formatTemp(temp3, doc["consolidated_weather"][2][F("the_temp")].as<float>());
|
||||||
|
|
|
@ -24,7 +24,7 @@ public:
|
||||||
// Functions we can access in main file
|
// Functions we can access in main file
|
||||||
void begin(char *city);
|
void begin(char *city);
|
||||||
void getTime(char *timeStr);
|
void getTime(char *timeStr);
|
||||||
void getData(char *city, char *temp1, char *temp2, char *temp3, char *temp4, char *currentTemp, char *currentWind, char *currentTime, char *currentWeather, char *currentWeatherAbbr);
|
void getData(char *city, char *temp1, char *temp2, char *temp3, char *temp4, char *currentTemp, char *currentWind, char *currentTime, char *currentWeather, char *currentWeatherAbbr, char* abbr1, char* abbr2, char* abbr3, char* abbr4);
|
||||||
void getDays(char *day, char *day1, char *day2, char *day3);
|
void getDays(char *day, char *day1, char *day2, char *day3);
|
||||||
|
|
||||||
// Used to store loaction woeid (world id), set in findCity()
|
// Used to store loaction woeid (world id), set in findCity()
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -15,16 +15,16 @@ if not os.path.isdir("./binary_icons"):
|
||||||
|
|
||||||
for file in os.listdir("./icons"):
|
for file in os.listdir("./icons"):
|
||||||
im = Image.open("./icons/" + file)
|
im = Image.open("./icons/" + file)
|
||||||
im = im.resize((152, 152))
|
im = im.resize((48, 48))
|
||||||
alp = im.split()[-1]
|
alp = im.split()[-1]
|
||||||
s = [0 for x in range(152 * 152)]
|
s = [0 for x in range(48 * 48)]
|
||||||
for y in range(152):
|
for y in range(48):
|
||||||
for x in range(152):
|
for x in range(48):
|
||||||
# print(im.getpixel((x, y)))
|
# print(im.getpixel((x, y)))
|
||||||
if alp.getpixel((x, y)) > 128:
|
if alp.getpixel((x, y)) > 128:
|
||||||
s[(x + 152 * y) // 8] |= 1 << (7 - (x + 152 * y) % 8)
|
s[(x + 48 * y) // 8] |= 1 << (7 - (x + 48 * y) % 8)
|
||||||
|
|
||||||
with open("./binary_icons/icon_" + file[:-4] + ".h", "w") as f:
|
with open("./binary_icons/icon_s_" + file[:-4] + ".h", "w") as f:
|
||||||
print("const uint8_t icon_" + file[:-4] + "[] PROGMEM = {", file=f)
|
print("const uint8_t icon_s_" + file[:-4] + "[] PROGMEM = {", file=f)
|
||||||
print(",".join(list(map(hex, s))), file=f)
|
print(",".join(list(map(hex, s))), file=f)
|
||||||
print("};", file=f)
|
print("};", file=f)
|
||||||
|
|
|
@ -12,4 +12,15 @@
|
||||||
#include "binary_icons/icon_sn.h"
|
#include "binary_icons/icon_sn.h"
|
||||||
#include "binary_icons/icon_t.h"
|
#include "binary_icons/icon_t.h"
|
||||||
|
|
||||||
|
#include "binary_icons/icon_s_c.h"
|
||||||
|
#include "binary_icons/icon_s_h.h"
|
||||||
|
#include "binary_icons/icon_s_hc.h"
|
||||||
|
#include "binary_icons/icon_s_hr.h"
|
||||||
|
#include "binary_icons/icon_s_lc.h"
|
||||||
|
#include "binary_icons/icon_s_lr.h"
|
||||||
|
#include "binary_icons/icon_s_s.h"
|
||||||
|
#include "binary_icons/icon_s_sl.h"
|
||||||
|
#include "binary_icons/icon_s_sn.h"
|
||||||
|
#include "binary_icons/icon_s_t.h"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -152,6 +152,14 @@ bool Network::getData(char *city, char *temp1, char *temp2, char *temp3, char *t
|
||||||
f = 0;
|
f = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (httpCode == 401) {
|
||||||
|
display.setCursor(50, 290);
|
||||||
|
display.setTextSize(3);
|
||||||
|
display.print(F("Network error, probably wrong api key"));
|
||||||
|
display.display();
|
||||||
|
while (1)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
//Stop http and clear document
|
//Stop http and clear document
|
||||||
doc.clear();
|
doc.clear();
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
|
|
||||||
|
#include "Inkplate.h"
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
|
|
||||||
#include <HTTPClient.h>
|
#include <HTTPClient.h>
|
||||||
|
@ -18,6 +19,8 @@ extern char *lat;
|
||||||
|
|
||||||
extern char *apiKey;
|
extern char *apiKey;
|
||||||
|
|
||||||
|
extern Inkplate display;
|
||||||
|
|
||||||
#ifndef NETWORK_H
|
#ifndef NETWORK_H
|
||||||
#define NETWORK_H
|
#define NETWORK_H
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,7 @@ Network network;
|
||||||
|
|
||||||
//Variables for time and raw event info
|
//Variables for time and raw event info
|
||||||
char date[64];
|
char date[64];
|
||||||
char data[32000];
|
char* data;
|
||||||
|
|
||||||
//Struct for storing calender event info
|
//Struct for storing calender event info
|
||||||
struct entry
|
struct entry
|
||||||
|
@ -92,6 +92,8 @@ void setup()
|
||||||
{
|
{
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
|
||||||
|
data = (char*)ps_malloc(100000);
|
||||||
|
|
||||||
//Initial display settings
|
//Initial display settings
|
||||||
display.begin();
|
display.begin();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue