Example fix.

This commit is contained in:
nitko12 2020-09-11 12:28:42 +02:00
parent 35a4ea4ef0
commit 8c4303180b
7 changed files with 123 additions and 147 deletions

View File

@ -46,9 +46,9 @@ char *apiKey = "";
#include "Network.h" #include "Network.h"
// Including fonts used // Including fonts used
#include "Fonts/Roboto_Light_48.h"
#include "Fonts/Roboto_Light_36.h"
#include "Fonts/Roboto_Light_120.h" #include "Fonts/Roboto_Light_120.h"
#include "Fonts/Roboto_Light_36.h"
#include "Fonts/Roboto_Light_48.h"
// Including icons generated by the py file // Including icons generated by the py file
#include "icons.h" #include "icons.h"
@ -63,51 +63,20 @@ Inkplate display(INKPLATE_1BIT);
Network network; Network network;
// Contants used for drawing icons // Contants used for drawing icons
char abbrs[32][32] ={ "01d", "02d", "03d", "04d", "09d", "10d", "11d", "13d", "50d", "01n", "02n", "03n", "04n", "09n", "10n", "11n", "13n", "50n" }; char abbrs[32][32] = {"01d", "02d", "03d", "04d", "09d", "10d", "11d", "13d", "50d",
"01n", "02n", "03n", "04n", "09n", "10n", "11n", "13n", "50n"};
const uint8_t *logos[18] = { const uint8_t *logos[18] = {
icon_01d, icon_01d, icon_02d, icon_03d, icon_04d, icon_09d, icon_10d, icon_11d, icon_13d, icon_50d,
icon_02d, icon_01n, icon_02n, icon_03n, icon_04n, icon_09n, icon_10n, icon_11n, icon_13n, icon_50n,
icon_03d,
icon_04d,
icon_09d,
icon_10d,
icon_11d,
icon_13d,
icon_50d,
icon_01n,
icon_02n,
icon_03n,
icon_04n,
icon_09n,
icon_10n,
icon_11n,
icon_13n,
icon_50n,
}; };
const uint8_t *s_logos[18] = { const uint8_t *s_logos[18] = {
icon_s_01d, icon_s_01d, icon_s_02d, icon_s_03d, icon_s_04d, icon_s_09d, icon_s_10d, icon_s_11d, icon_s_13d, icon_s_50d,
icon_s_02d, icon_s_01n, icon_s_02n, icon_s_03n, icon_s_04n, icon_s_09n, icon_s_10n, icon_s_11n, icon_s_13n, icon_s_50n,
icon_s_03d,
icon_s_04d,
icon_s_09d,
icon_s_10d,
icon_s_11d,
icon_s_13d,
icon_s_50d,
icon_s_01n,
icon_s_02n,
icon_s_03n,
icon_s_04n,
icon_s_09n,
icon_s_10n,
icon_s_11n,
icon_s_13n,
icon_s_50n,
}; };
// Variables for storing temperature // Variables for storing temperature
char temps[8][4] ={ char temps[4][8] = {
"0F", "0F",
"0F", "0F",
"0F", "0F",
@ -115,7 +84,7 @@ char temps[8][4] ={
}; };
// Variables for storing hour strings // Variables for storing hour strings
char hours[8][4] ={ char hours[4][8] = {
"", "",
"", "",
"", "",
@ -181,7 +150,8 @@ void loop()
network.getTime(currentTime); network.getTime(currentTime);
if (refreshes % fullRefresh == 0) if (refreshes % fullRefresh == 0)
{ {
while (!network.getData(city, temps[0], temps[1], temps[2], temps[3], currentTemp, currentWind, currentTime, currentWeather, currentWeatherAbbr, abbr1, abbr2, abbr3, abbr4)) while (!network.getData(city, temps[0], temps[1], temps[2], temps[3], currentTemp, currentWind, currentTime,
currentWeather, currentWeatherAbbr, abbr1, abbr2, abbr3, abbr4))
{ {
Serial.println("Retrying fetching data!"); Serial.println("Retrying fetching data!");
delay(5000); delay(5000);
@ -306,28 +276,32 @@ void drawTemps()
{ {
// If found draw specified icon // If found draw specified icon
if (strcmp(abbr1, abbrs[i]) == 0) if (strcmp(abbr1, abbrs[i]) == 0)
display.drawBitmap(1 * rectSpacing + 0 * rectWidth + textMargin, 300 + textMargin + 150, s_logos[i], 48, 48, WHITE, BLACK); display.drawBitmap(1 * rectSpacing + 0 * rectWidth + textMargin, 300 + textMargin + 150, s_logos[i], 48, 48,
WHITE, BLACK);
} }
for (int i = 0; i < 18; ++i) for (int i = 0; i < 18; ++i)
{ {
// If found draw specified icon // If found draw specified icon
if (strcmp(abbr2, abbrs[i]) == 0) if (strcmp(abbr2, abbrs[i]) == 0)
display.drawBitmap(2 * rectSpacing + 1 * rectWidth + textMargin, 300 + textMargin + 150, s_logos[i], 48, 48, WHITE, BLACK); display.drawBitmap(2 * rectSpacing + 1 * rectWidth + textMargin, 300 + textMargin + 150, s_logos[i], 48, 48,
WHITE, BLACK);
} }
for (int i = 0; i < 18; ++i) for (int i = 0; i < 18; ++i)
{ {
// If found draw specified icon // If found draw specified icon
if (strcmp(abbr3, abbrs[i]) == 0) if (strcmp(abbr3, abbrs[i]) == 0)
display.drawBitmap(3 * rectSpacing + 2 * rectWidth + textMargin, 300 + textMargin + 150, s_logos[i], 48, 48, WHITE, BLACK); display.drawBitmap(3 * rectSpacing + 2 * rectWidth + textMargin, 300 + textMargin + 150, s_logos[i], 48, 48,
WHITE, BLACK);
} }
for (int i = 0; i < 18; ++i) for (int i = 0; i < 18; ++i)
{ {
// If found draw specified icon // If found draw specified icon
if (strcmp(abbr4, abbrs[i]) == 0) if (strcmp(abbr4, abbrs[i]) == 0)
display.drawBitmap(4 * rectSpacing + 3 * rectWidth + textMargin, 300 + textMargin + 150, s_logos[i], 48, 48, WHITE, BLACK); display.drawBitmap(4 * rectSpacing + 3 * rectWidth + textMargin, 300 + textMargin + 150, s_logos[i], 48, 48,
WHITE, BLACK);
} }
} }

View File

@ -2,8 +2,8 @@
// They have been declared in seperate file to increase readability // They have been declared in seperate file to increase readability
#include "Network.h" #include "Network.h"
#include <WiFi.h>
#include <HTTPClient.h> #include <HTTPClient.h>
#include <WiFi.h>
#include <WiFiClientSecure.h> #include <WiFiClientSecure.h>
#include <ArduinoJson.h> #include <ArduinoJson.h>
@ -55,7 +55,7 @@ void Network::getTime(char *timeStr)
strncpy(timeStr, asctime(&timeinfo) + 11, 5); strncpy(timeStr, asctime(&timeinfo) + 11, 5);
// Setting time string timezone // Setting time string timezone
int hr = 10 * timeStr[0] + timeStr[1] + timeZone; int hr = 10 * (timeStr[0] - '0') + (timeStr[1] - '0') + timeZone;
// Better defined modulo, in case timezone makes hours to go below 0 // Better defined modulo, in case timezone makes hours to go below 0
hr = (hr % 24 + 24) % 24; hr = (hr % 24 + 24) % 24;
@ -77,7 +77,9 @@ void formatWind(char *str, float wind)
dtostrf(wind, 2, 0, str); dtostrf(wind, 2, 0, str);
} }
bool 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) bool 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)
{ {
bool f = 0; bool f = 0;
// If not connected to wifi reconnect wifi // If not connected to wifi reconnect wifi

View File

@ -28,15 +28,15 @@ class Inkplate : public System, public Graphics
bool joinAP(const char *ssid, const char *pass) bool joinAP(const char *ssid, const char *pass)
{ {
return Network::joinAP(ssid, pass); return NetworkClient::joinAP(ssid, pass);
} }
void disconnect() void disconnect()
{ {
Network::disconnect(); NetworkClient::disconnect();
}; };
bool isConnected() bool isConnected()
{ {
return Network::isConnected(); return NetworkClient::isConnected();
}; };
private: private:

View File

@ -4,11 +4,11 @@
#include "../libs/Adafruit-GFX-Library/Adafruit_GFX.h" #include "../libs/Adafruit-GFX-Library/Adafruit_GFX.h"
#include "../libs/SdFat/SdFat.h" #include "../libs/SdFat/SdFat.h"
#include "Arduino.h" #include "Arduino.h"
#include "Network.h" #include "NetworkClient.h"
#include "WiFiClient.h" #include "WiFiClient.h"
#include "defines.h" #include "defines.h"
class Image : virtual public Network, virtual public Adafruit_GFX class Image : virtual public NetworkClient, virtual public Adafruit_GFX
{ {
public: public:
Image(int16_t w, int16_t h); Image(int16_t w, int16_t h);

View File

@ -1,6 +1,6 @@
#include "Network.h" #include "NetworkClient.h"
bool Network::joinAP(const char *ssid, const char *pass) bool NetworkClient::joinAP(const char *ssid, const char *pass)
{ {
WiFi.mode(WIFI_MODE_STA); WiFi.mode(WIFI_MODE_STA);
WiFi.begin(ssid, pass); WiFi.begin(ssid, pass);
@ -17,18 +17,18 @@ bool Network::joinAP(const char *ssid, const char *pass)
return 1; return 1;
} }
void Network::disconnect() void NetworkClient::disconnect()
{ {
WiFi.mode(WIFI_OFF); WiFi.mode(WIFI_OFF);
} }
bool Network::isConnected() bool NetworkClient::isConnected()
{ {
return WiFi.status() == WL_CONNECTED; return WiFi.status() == WL_CONNECTED;
} }
uint8_t *Network::downloadFile(const char *url, int32_t *defaultLen) uint8_t *NetworkClient::downloadFile(const char *url, int32_t *defaultLen)
{ {
if (!isConnected()) if (!isConnected())
return NULL; return NULL;
@ -82,7 +82,7 @@ uint8_t *Network::downloadFile(const char *url, int32_t *defaultLen)
return buffer; return buffer;
} }
uint8_t *Network::downloadFile(WiFiClient *s, int32_t len) uint8_t *NetworkClient::downloadFile(WiFiClient *s, int32_t len)
{ {
if (!isConnected()) if (!isConnected())
return NULL; return NULL;

View File

@ -1,5 +1,5 @@
#ifndef __NETWORK_H__ #ifndef __NETWORKCLIENT_H__
#define __NETWORK_H__ #define __NETWORKCLIENT_H__
#include "Arduino.h" #include "Arduino.h"
#include "HTTPClient.h" #include "HTTPClient.h"
@ -18,7 +18,7 @@ struct bitmapHeader
uint32_t compression; uint32_t compression;
}; };
class Network class NetworkClient
{ {
public: public:
bool joinAP(const char *ssid, const char *pass); bool joinAP(const char *ssid, const char *pass);

View File

@ -7,9 +7,9 @@
#include "Esp.h" #include "Esp.h"
#include "Mcp.h" #include "Mcp.h"
#include "Network.h" #include "NetworkClient.h"
class System : public Esp, public Mcp, virtual public Network class System : public Esp, public Mcp, virtual public NetworkClient
{ {
public: public:
void setPanelState(uint8_t s); void setPanelState(uint8_t s);