fixed merging problem

This commit is contained in:
nitko12 2020-07-31 12:09:01 +02:00
parent 42b5494400
commit 0c5d9f8cce
5 changed files with 848 additions and 568 deletions

File diff suppressed because it is too large Load Diff

View File

@ -32,20 +32,44 @@
#define DATA 0x0E8C0030 //D0-D7 = GPIO4 GPIO5 GPIO18 GPIO19 GPIO23 GPIO25 GPIO26 GPIO27 #define DATA 0x0E8C0030 //D0-D7 = GPIO4 GPIO5 GPIO18 GPIO19 GPIO23 GPIO25 GPIO26 GPIO27
#define CL 0x01 //GPIO0 #define CL 0x01 //GPIO0
#define CL_SET {GPIO.out_w1ts = CL;} #define CL_SET \
#define CL_CLEAR {GPIO.out_w1tc = CL;} { \
GPIO.out_w1ts = CL; \
}
#define CL_CLEAR \
{ \
GPIO.out_w1tc = CL; \
}
#define LE 0x04 //GPIO2 #define LE 0x04 //GPIO2
#define LE_SET {GPIO.out_w1ts = LE;} #define LE_SET \
#define LE_CLEAR {GPIO.out_w1tc = LE;} { \
GPIO.out_w1ts = LE; \
}
#define LE_CLEAR \
{ \
GPIO.out_w1tc = LE; \
}
#define CKV 0x01 //GPIO32 #define CKV 0x01 //GPIO32
#define CKV_SET {GPIO.out1_w1ts.val = CKV;} #define CKV_SET \
#define CKV_CLEAR {GPIO.out1_w1tc.val = CKV;} { \
GPIO.out1_w1ts.val = CKV; \
}
#define CKV_CLEAR \
{ \
GPIO.out1_w1tc.val = CKV; \
}
#define SPH 0x02 //GPIO33 #define SPH 0x02 //GPIO33
#define SPH_SET {GPIO.out1_w1ts.val = SPH;} #define SPH_SET \
#define SPH_CLEAR {GPIO.out1_w1tc.val = SPH;} { \
GPIO.out1_w1ts.val = SPH; \
}
#define SPH_CLEAR \
{ \
GPIO.out1_w1tc.val = SPH; \
}
//#define SPV 15 //GPIO15 //#define SPV 15 //GPIO15
//#define SPV_SET {digitalWrite(SPV, HIGH);} //#define SPV_SET {digitalWrite(SPV, HIGH);}
@ -53,33 +77,74 @@
//I/O Expander - A Channel //I/O Expander - A Channel
#define GMOD 1 //GPIOA1 #define GMOD 1 //GPIOA1
#define GMOD_SET {mcp.digitalWrite(GMOD, HIGH);} #define GMOD_SET \
#define GMOD_CLEAR {mcp.digitalWrite(GMOD, LOW);} { \
mcp.digitalWrite(GMOD, HIGH); \
}
#define GMOD_CLEAR \
{ \
mcp.digitalWrite(GMOD, LOW); \
}
#define OE 0 //GPIOA0 #define OE 0 //GPIOA0
#define OE_SET {mcp.digitalWrite(OE, HIGH);} #define OE_SET \
#define OE_CLEAR {mcp.digitalWrite(OE, LOW);} { \
mcp.digitalWrite(OE, HIGH); \
}
#define OE_CLEAR \
{ \
mcp.digitalWrite(OE, LOW); \
}
#define SPV 2 //GPIOA5 #define SPV 2 //GPIOA5
#define SPV_SET {mcp.digitalWrite(SPV, HIGH);} #define SPV_SET \
#define SPV_CLEAR {mcp.digitalWrite(SPV, LOW);} { \
mcp.digitalWrite(SPV, HIGH); \
}
#define SPV_CLEAR \
{ \
mcp.digitalWrite(SPV, LOW); \
}
#define WAKEUP 3 //GPIOA3 #define WAKEUP 3 //GPIOA3
#define WAKEUP_SET {mcp.digitalWrite(WAKEUP, HIGH);} #define WAKEUP_SET \
#define WAKEUP_CLEAR {mcp.digitalWrite(WAKEUP, LOW);} { \
mcp.digitalWrite(WAKEUP, HIGH); \
}
#define WAKEUP_CLEAR \
{ \
mcp.digitalWrite(WAKEUP, LOW); \
}
#define PWRUP 4 //GPIOA4 #define PWRUP 4 //GPIOA4
#define PWRUP_SET {mcp.digitalWrite(PWRUP, HIGH);} #define PWRUP_SET \
#define PWRUP_CLEAR {mcp.digitalWrite(PWRUP, LOW);} { \
mcp.digitalWrite(PWRUP, HIGH); \
}
#define PWRUP_CLEAR \
{ \
mcp.digitalWrite(PWRUP, LOW); \
}
#define VCOM 5 //GPIOA6 #define VCOM 5 //GPIOA6
#define VCOM_SET {mcp.digitalWrite(VCOM, HIGH);} #define VCOM_SET \
#define VCOM_CLEAR {mcp.digitalWrite(VCOM, LOW);} { \
mcp.digitalWrite(VCOM, HIGH); \
}
#define VCOM_CLEAR \
{ \
mcp.digitalWrite(VCOM, LOW); \
}
#define CKV_CLOCK ckvClock(); #define CKV_CLOCK ckvClock();
#ifndef _swap_int16_t #ifndef _swap_int16_t
#define _swap_int16_t(a, b) { int16_t t = a; a = b; b = t; } #define _swap_int16_t(a, b) \
{ \
int16_t t = a; \
a = b; \
b = t; \
}
#endif #endif
extern Adafruit_MCP23017 mcp; extern Adafruit_MCP23017 mcp;
@ -88,12 +153,13 @@ extern SdFat sd;
static void ckvClock(); static void ckvClock();
static void usleep1(); static void usleep1();
class Inkplate : public Adafruit_GFX { class Inkplate : public Adafruit_GFX
public: {
uint8_t* D_memory_new; public:
uint8_t* _partial; uint8_t *D_memory_new;
uint8_t* D_memory4Bit; uint8_t *_partial;
uint8_t * _pBuffer; uint8_t *D_memory4Bit;
uint8_t *_pBuffer;
const uint8_t LUT2[16] = {B10101010, B10101001, B10100110, B10100101, B10011010, B10011001, B10010110, B10010101, B01101010, B01101001, B01100110, B01100101, B01011010, B01011001, B01010110, B01010101}; const uint8_t LUT2[16] = {B10101010, B10101001, B10100110, B10100101, B10011010, B10011001, B10010110, B10010101, B01101010, B01101001, B01100110, B01100101, B01011010, B01011001, B01010110, B01010101};
const uint8_t LUTW[16] = {B11111111, B11111110, B11111011, B11111010, B11101111, B11101110, B11101011, B11101010, B10111111, B10111110, B10111011, B10111010, B10101111, B10101110, B10101011, B10101010}; const uint8_t LUTW[16] = {B11111111, B11111110, B11111011, B11111010, B11101111, B11101110, B11101011, B11101010, B10111111, B10111110, B10111011, B10111010, B10101111, B10101110, B10101011, B10101010};
const uint8_t LUTB[16] = {B11111111, B11111101, B11110111, B11110101, B11011111, B11011101, B11010111, B11010101, B01111111, B01111101, B01110111, B01110101, B01011111, B01011101, B01010111, B01010101}; const uint8_t LUTB[16] = {B11111111, B11111101, B11110111, B11110101, B11011111, B11011101, B11010111, B11010101, B01111111, B01111101, B01110111, B01110101, B01011111, B01011101, B01010111, B01010101};
@ -108,7 +174,8 @@ class Inkplate : public Adafruit_GFX {
//PVI waveform for cleaning screen, not sure if it is correct, but it cleans screen properly. //PVI waveform for cleaning screen, not sure if it is correct, but it cleans screen properly.
const uint32_t waveform[50] = {0x00000008, 0x00000008, 0x00200408, 0x80281888, 0x60a81898, 0x60a8a8a8, 0x60a8a8a8, 0x6068a868, 0x6868a868, 0x6868a868, 0x68686868, 0x6a686868, 0x5a686868, 0x5a686868, 0x5a586a68, 0x5a5a6a68, 0x5a5a6a68, 0x55566a68, 0x55565a64, 0x55555654, 0x55555556, 0x55555556, 0x55555556, 0x55555516, 0x55555596, 0x15555595, 0x95955595, 0x95959595, 0x95949495, 0x94949495, 0x94949495, 0xa4949494, 0x9494a4a4, 0x84a49494, 0x84948484, 0x84848484, 0x84848484, 0x84848484, 0xa5a48484, 0xa9a4a4a8, 0xa9a8a8a8, 0xa5a9a9a4, 0xa5a5a5a4, 0xa1a5a5a1, 0xa9a9a9a9, 0xa9a9a9a9, 0xa9a9a9a9, 0xa9a9a9a9, 0x15151515, 0x11111111}; const uint32_t waveform[50] = {0x00000008, 0x00000008, 0x00200408, 0x80281888, 0x60a81898, 0x60a8a8a8, 0x60a8a8a8, 0x6068a868, 0x6868a868, 0x6868a868, 0x68686868, 0x6a686868, 0x5a686868, 0x5a686868, 0x5a586a68, 0x5a5a6a68, 0x5a5a6a68, 0x55566a68, 0x55565a64, 0x55555654, 0x55555556, 0x55555556, 0x55555556, 0x55555516, 0x55555596, 0x15555595, 0x95955595, 0x95959595, 0x95949495, 0x94949495, 0x94949495, 0xa4949494, 0x9494a4a4, 0x84a49494, 0x84948484, 0x84848484, 0x84848484, 0x84848484, 0xa5a48484, 0xa9a4a4a8, 0xa9a8a8a8, 0xa5a9a9a4, 0xa5a5a5a4, 0xa1a5a5a1, 0xa9a9a9a9, 0xa9a9a9a9, 0xa9a9a9a9, 0xa9a9a9a9, 0x15151515, 0x11111111};
struct bitmapHeader { struct bitmapHeader
{
uint16_t signature; uint16_t signature;
uint32_t fileSize; uint32_t fileSize;
uint32_t startRAW; uint32_t startRAW;
@ -125,16 +192,18 @@ class Inkplate : public Adafruit_GFX {
void clearDisplay(); void clearDisplay();
void display(); void display();
void partialUpdate(); void partialUpdate();
void drawBitmap3Bit(int16_t _x, int16_t _y, const unsigned char* _p, int16_t _w, int16_t _h); void drawBitmap3Bit(int16_t _x, int16_t _y, const unsigned char *_p, int16_t _w, int16_t _h);
void setRotation(uint8_t); void setRotation(uint8_t);
void einkOff(void); void einkOff(void);
void einkOn(void); void einkOn(void);
void selectDisplayMode(uint8_t _mode); void selectDisplayMode(uint8_t _mode);
uint8_t getDisplayMode(); uint8_t getDisplayMode();
int drawBitmapFromSD(SdFile* p, int x, int y, bool invert = false); int drawBitmapFromSD(SdFile *p, int x, int y, bool invert = false);
int drawBitmapFromSD(char* fileName, int x, int y, bool invert = false); int drawBitmapFromSD(char *fileName, int x, int y, bool invert = false);
int drawBitmapFromWeb(WiFiClient* s, int x, int y, int len, bool invert = false); int drawBitmapFromWeb(WiFiClient *s, int x, int y, int len, bool invert = false);
int drawBitmapFromWeb(char* url, int x, int y, bool invert = false); int drawBitmapFromWeb(char *url, int x, int y, bool invert = false);
void drawThickLine(int x1, int y1, int x2, int y2, int color, float thickness);
void drawGradientLine(int x1, int y1, int x2, int y2, int color1, int color2, float thickness = -1);
int sdCardInit(); int sdCardInit();
SdFat getSdFat(); SdFat getSdFat();
SPIClass getSPI(); SPIClass getSPI();
@ -152,7 +221,7 @@ class Inkplate : public Adafruit_GFX {
void pinsZstate(); void pinsZstate();
void pinsAsOutputs(); void pinsAsOutputs();
private: private:
uint8_t gammaLUT[256]; uint8_t gammaLUT[256];
int8_t _temperature; int8_t _temperature;
uint8_t _panelOn = 0; uint8_t _panelOn = 0;
@ -164,8 +233,8 @@ class Inkplate : public Adafruit_GFX {
void display1b(); void display1b();
void display3b(); void display3b();
uint32_t read32(uint8_t* c); uint32_t read32(uint8_t *c);
uint16_t read16(uint8_t* c); uint16_t read16(uint8_t *c);
void readBmpHeaderSd(SdFile *_f, struct bitmapHeader *_h); void readBmpHeaderSd(SdFile *_f, struct bitmapHeader *_h);
void readBmpHeaderWeb(WiFiClient *_s, struct bitmapHeader *_h); void readBmpHeaderWeb(WiFiClient *_s, struct bitmapHeader *_h);
int drawMonochromeBitmapSd(SdFile *f, struct bitmapHeader bmpHeader, int x, int y, bool invert); int drawMonochromeBitmapSd(SdFile *f, struct bitmapHeader bmpHeader, int x, int y, bool invert);
@ -176,7 +245,7 @@ class Inkplate : public Adafruit_GFX {
int drawGrayscaleBitmap4Web(WiFiClient *s, struct bitmapHeader bmpHeader, int x, int y, int len, bool invert); int drawGrayscaleBitmap4Web(WiFiClient *s, struct bitmapHeader bmpHeader, int x, int y, int len, bool invert);
int drawGrayscaleBitmap8Web(WiFiClient *s, struct bitmapHeader bmpHeader, int x, int y, int len, bool invert); int drawGrayscaleBitmap8Web(WiFiClient *s, struct bitmapHeader bmpHeader, int x, int y, int len, bool invert);
int drawGrayscaleBitmap24Web(WiFiClient *s, struct bitmapHeader bmpHeader, int x, int y, int len, bool invert); int drawGrayscaleBitmap24Web(WiFiClient *s, struct bitmapHeader bmpHeader, int x, int y, int len, bool invert);
void precalculateGamma(uint8_t* c, float gamma); void precalculateGamma(uint8_t *c, float gamma);
}; };
#endif #endif

View File

@ -6,51 +6,59 @@
https://e-radionica.com/en/blog/add-inkplate-6-to-arduino-ide/ https://e-radionica.com/en/blog/add-inkplate-6-to-arduino-ide/
This example will show you how you can use Inkplate 6 to display API data, This example will show you how you can use Inkplate 6 to display API data,
in this example Metaweather public weather API which provide weather info. e.g. Metaweather public weather API
As a result, you get a functional weather station which shows today's
forecast and 3 days forecast on your Inkplate display.
IMPORTANT: IMPORTANT:
Make sure you have changed your desired city, timezone and WiFi credentials below. Make sure to change your desired city, timezone and wifi credentials below
You will also need to install ArduinoJSON library. Also have ArduinoJSON installed in your Arduino libraries
Download from here: https://github.com/bblanchon/ArduinoJson
Want to learn more about Inkplate? Visit www.inkplate.io Want to learn more about Inkplate? Visit www.inkplate.io
Looking to get support? Write on our forums: http://forum.e-radionica.com/en/ Looking to get support? Write on our forums: http://forum.e-radionica.com/en/
28 July 2020 by e-radionica.com 28 July 2020 by e-radionica.com
*/ */
// ---------------- CHANGE HERE ---------------: // ---------- CHANGE HERE -------------:
int timeZone = 2; //Update your timezone here. 2 means UTC+2 // Time zone for adding hours
int timeZone = 2;
char city[128] = "ZAGREB"; //Enter city name you wish to get forecast for // City search query
char city[128] = "ZAGREB";
// Change to your WiFi SSID and password // Change to your wifi ssid and password
char *ssid = ""; char *ssid = "e-radionica.com";
char *pass = ""; char *pass = "croduino";
#define DELAY_MS 15000 //Delay between screen refreshes goes here // ----------------------------------
// ----------------------------------------------
// Include Inkplate library to the sketch
#include "Inkplate.h" #include "Inkplate.h"
#include "Network.h" //Header file for easier code readability
//Include custom fonts & icons used // Header file for easier code readability
#include "Network.h"
// Including fonts used
#include "Fonts/Roboto_Light_48.h" #include "Fonts/Roboto_Light_48.h"
#include "Fonts/Roboto_Light_36.h" #include "Fonts/Roboto_Light_36.h"
#include "Fonts/Roboto_Light_120.h" #include "Fonts/Roboto_Light_120.h"
#include "icons.h" //Generated using embedded iconConvert.py script
Inkplate display(INKPLATE_1BIT); //Inkplate object // Including icons generated by the py file
#include "icons.h"
Network network; // All our network functions are in this object, see Network.h // Delay between API calls
#define DELAY_MS 15000
//Constants used for drawing icons // Inkplate object
Inkplate display(INKPLATE_1BIT);
// All our network functions are in this object, see Network.h
Network network;
// 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};
//Variables for storing temperature // Variables for storing temperature
char temps[8][4] = { char temps[8][4] = {
"0F", "0F",
"0F", "0F",
@ -58,7 +66,7 @@ char temps[8][4] = {
"0F", "0F",
}; };
//Variables for storing days of the week // Variables for storing days of the week
char days[8][4] = { char days[8][4] = {
"", "",
"", "",
@ -66,13 +74,18 @@ char days[8][4] = {
"", "",
}; };
long refreshes = 0; //Variable for counting partial refreshes // Variable for counting partial refreshes
const int fullRefresh = 10; //Constant to determine when to full update long refreshes = 0;
//Variables for storing current time and weather info // Constant to determine when to full update
const int fullRefresh = 10;
// Variables for storing current time and weather info
char currentTemp[16] = "0F"; char currentTemp[16] = "0F";
char currentWind[16] = "0m/s"; char currentWind[16] = "0m/s";
char currentTime[16] = "9:41"; char currentTime[16] = "9:41";
char currentWeather[32] = "-"; char currentWeather[32] = "-";
char currentWeatherAbbr[8] = "th"; char currentWeatherAbbr[8] = "th";
@ -85,18 +98,18 @@ void drawTime();
void setup() void setup()
{ {
//Begin serial and and begin display // Begin serial and display
Serial.begin(115200); Serial.begin(115200);
display.begin(); //Call this function only once! display.begin();
//Initial cleaning of buffer and physical screen // Initial cleaning of buffer and physical screen
display.clearDisplay(); display.clearDisplay();
display.clean(); display.clean();
//Calling our begin from network.h file // Calling our begin from network.h file
network.begin(city); network.begin(city);
//If city not found, write error message and stop // If city not found, do nothing
if (network.location == -1) if (network.location == -1)
{ {
display.setCursor(50, 290); display.setCursor(50, 290);
@ -107,57 +120,57 @@ void setup()
; ;
} }
//Welcome screen // Welcome screen
display.setCursor(50, 290); display.setCursor(50, 290);
display.setTextSize(3); display.setTextSize(3);
display.print(F("Welcome to Inkplate 6 weather example!")); display.print(F("Welcome to Inkplate 6 weather example!"));
display.display(); display.display();
//Wait a bit before proceeding // Wait a bit before proceeding
delay(3000); delay(5000);
} }
void loop() void loop()
{ {
//Clear display // Clear display
display.clearDisplay(); display.clearDisplay();
//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);
//Draw data, see functions below in Network.cpp for info // Draw data, see functions below for info
drawWeather(); drawWeather();
drawCurrent(); drawCurrent();
drawTemps(); drawTemps();
drawCity(); drawCity();
drawTime(); drawTime();
//Refresh full screen every fullRefresh times // Refresh full screen every fullRefresh times, defined above
if (refreshes % fullRefresh == 0) if (refreshes % fullRefresh == 0)
display.display(); display.display();
else else
display.partialUpdate(); display.partialUpdate();
//Go to sleep before checking again // Go to sleep before checking again
esp_sleep_enable_timer_wakeup(1000L * DELAY_MS); esp_sleep_enable_timer_wakeup(1000L * DELAY_MS);
(void)esp_light_sleep_start(); (void)esp_light_sleep_start();
++refreshes; ++refreshes;
} }
//Function for drawing weather info // Function for drawing weather info
void drawWeather() void drawWeather()
{ {
// Searching for weather state abbreviation // Searching for weather state abbreviation
for (int i = 0; i < 10; ++i) for (int i = 0; i < 10; ++i)
{ {
//If found draw specified icon, draw it // If found draw specified icon
if (strcmp(abbrs[i], currentWeatherAbbr) == 0) if (strcmp(abbrs[i], currentWeatherAbbr) == 0)
display.drawBitmap(50, 50, logos[i], 152, 152, BLACK); display.drawBitmap(50, 50, logos[i], 152, 152, BLACK);
} }
//Draw current weather state // Draw weather state
display.setTextColor(BLACK, WHITE); display.setTextColor(BLACK, WHITE);
display.setFont(&Roboto_Light_36); display.setFont(&Roboto_Light_36);
display.setTextSize(1); display.setTextSize(1);
@ -165,10 +178,10 @@ void drawWeather()
display.println(currentWeather); display.println(currentWeather);
} }
//Function for drawing current time // Function for drawing current time
void drawTime() void drawTime()
{ {
//Drawing current time stored in currentTime variable // Drawing current time
display.setTextColor(BLACK, WHITE); display.setTextColor(BLACK, WHITE);
display.setFont(&Roboto_Light_36); display.setFont(&Roboto_Light_36);
display.setTextSize(1); display.setTextSize(1);
@ -177,10 +190,10 @@ void drawTime()
display.println(currentTime); display.println(currentTime);
} }
//Function for drawing city name // Function for drawing city name
void drawCity() void drawCity()
{ {
//Drawing city name // Drawing city name
display.setTextColor(BLACK, WHITE); display.setTextColor(BLACK, WHITE);
display.setFont(&Roboto_Light_36); display.setFont(&Roboto_Light_36);
display.setTextSize(1); display.setTextSize(1);
@ -189,10 +202,10 @@ void drawCity()
display.println(city); display.println(city);
} }
//Function for drawing temperatures // Function for drawing temperatures
void drawTemps() void drawTemps()
{ {
//Drawing 4 black rectangles into which temperatures will be written // Drawing 4 black rectangles in which temperatures will be written
int rectWidth = 150; int rectWidth = 150;
int rectSpacing = (800 - rectWidth * 4) / 5; int rectSpacing = (800 - rectWidth * 4) / 5;
@ -203,7 +216,6 @@ void drawTemps()
int textMargin = 6; int textMargin = 6;
//Setting font specifics, writing the actual weather info
display.setFont(&Roboto_Light_48); display.setFont(&Roboto_Light_48);
display.setTextSize(1); display.setTextSize(1);
display.setTextColor(WHITE, BLACK); display.setTextColor(WHITE, BLACK);
@ -220,7 +232,7 @@ void drawTemps()
display.setCursor(4 * rectSpacing + 3 * rectWidth + textMargin, 300 + textMargin + 70); display.setCursor(4 * rectSpacing + 3 * rectWidth + textMargin, 300 + textMargin + 70);
display.println(days[3]); display.println(days[3]);
//Drawing temperature values into black rectangles // Drawing temperature values into black rectangles
display.setFont(&Roboto_Light_48); display.setFont(&Roboto_Light_48);
display.setTextSize(1); display.setTextSize(1);
display.setTextColor(WHITE, BLACK); display.setTextColor(WHITE, BLACK);
@ -242,10 +254,10 @@ void drawTemps()
display.println(F("C")); display.println(F("C"));
} }
//Current weather drawing function // Current weather drawing function
void drawCurrent() void drawCurrent()
{ {
//Drawing current information // Drawing current information
// Temperature: // Temperature:
display.setFont(&Roboto_Light_120); display.setFont(&Roboto_Light_120);
@ -264,7 +276,7 @@ void drawCurrent()
display.setCursor(x, y); display.setCursor(x, y);
display.println(F("C")); display.println(F("C"));
//Wind: // Wind:
display.setFont(&Roboto_Light_120); display.setFont(&Roboto_Light_120);
display.setTextSize(1); display.setTextSize(1);
display.setTextColor(BLACK, WHITE); display.setTextColor(BLACK, WHITE);
@ -281,7 +293,7 @@ void drawCurrent()
display.setCursor(x, y); display.setCursor(x, y);
display.println(F("m/s")); display.println(F("m/s"));
//Labels underneath // Labels underneath
display.setFont(&Roboto_Light_36); display.setFont(&Roboto_Light_36);
display.setTextSize(1); display.setTextSize(1);

View File

@ -1,5 +1,5 @@
//Network.cpp contains various functions and classes that enable Weather station // Network.cpp contains various functions and classes that enable Weather station
//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 <WiFi.h>
@ -9,13 +9,13 @@
#include <ArduinoJson.h> #include <ArduinoJson.h>
//WiFiMulti object declaration // WiFiMulti object declaration
WiFiMulti WiFiMulti; WiFiMulti WiFiMulti;
//Static Json from ArduinoJson library // Static Json from ArduinoJson library
StaticJsonDocument<6000> doc; StaticJsonDocument<6000> doc;
//Declared week days // Declared week days
char weekDays[8][8] = { char weekDays[8][8] = {
"Mon", "Mon",
"Tue", "Tue",
@ -28,92 +28,89 @@ char weekDays[8][8] = {
void Network::begin(char *city) void Network::begin(char *city)
{ {
//Initiating wifi, like in BasicHttpClient example // Initiating wifi, like in BasicHttpClient example
WiFi.mode(WIFI_STA); WiFi.mode(WIFI_STA);
WiFiMulti.addAP(ssid, pass); WiFiMulti.addAP(ssid, pass);
Serial.print(F("Waiting for WiFi to connect...")); Serial.print(F("Waiting for WiFi to connect..."));
while ((WiFiMulti.run() != WL_CONNECTED)) while ((WiFiMulti.run() != WL_CONNECTED))
{ {
//Printing a dot to Serial monitor every second while waiting to connect // Printing a dot to Serial monitor every second while waiting to connect
Serial.print(F(".")); Serial.print(F("."));
delay(1000); delay(1000);
} }
Serial.println(F(" connected")); Serial.println(F(" connected"));
//Find internet time // Find internet time
setTime(); setTime();
//Search for given cities woeid // Search for given cities woeid
findCity(city); findCity(city);
//reduce power by making WiFi module sleep // reduce power by making WiFi module sleep
WiFi.setSleep(1); WiFi.setSleep(1);
} }
//Gets time from ntp server // Gets time from ntp server
void Network::getTime(char *timeStr) void Network::getTime(char *timeStr)
{ {
//Get seconds since 1.1.1970. // Get seconds since 1.1.1970.
time_t nowSecs = time(nullptr); time_t nowSecs = time(nullptr);
//Struct used to store time // Used to store time
struct tm timeinfo; struct tm timeinfo;
gmtime_r(&nowSecs, &timeinfo); gmtime_r(&nowSecs, &timeinfo);
//Copies time string into timeStr //Copies time string into 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] + timeStr[1] + 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;
//Adding time to '0' char makes it into whatever time char, for both digits // Adding time to '0' char makes it into whatever time char, for both digits
timeStr[0] = hr / 10 + '0'; timeStr[0] = hr / 10 + '0';
timeStr[1] = hr % 10 + '0'; timeStr[1] = hr % 10 + '0';
} }
//Helper function to convert float to char*
void formatTemp(char *str, float temp) void formatTemp(char *str, float temp)
{ {
//Built in function for float to char* conversion // Built in function for float to char* conversion
dtostrf(temp, 2, 0, str); dtostrf(temp, 2, 0, str);
} }
//Helper function to convert float to char*
void formatWind(char *str, float wind) void formatWind(char *str, float wind)
{ {
//Built in function for float to char* conversion // Built in function for float to char* conversion
dtostrf(wind, 2, 0, str); dtostrf(wind, 2, 0, str);
} }
//Function that connects to API and gets the weather data
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)
{ {
//Return if wifi isn't connected // Return if wifi isn't connected
if (WiFi.status() != WL_CONNECTED) if (WiFi.status() != WL_CONNECTED)
return; return;
//Wake up WiFi if sleeping and save inital state // Wake up if sleeping and save inital state
bool sleep = WiFi.getSleep(); bool sleep = WiFi.getSleep();
WiFi.setSleep(false); WiFi.setSleep(false);
//HTTP object used to make get request // Http object used to make get request
HTTPClient http; HTTPClient http;
http.getStream().setNoDelay(true); http.getStream().setNoDelay(true);
http.getStream().setTimeout(1); http.getStream().setTimeout(1);
//Add woeid to api call. woeid is API specific variable name used to set location // Add woeid to api call
char url[256]; char url[256];
sprintf(url, "https://www.metaweather.com/api/location/%d/", location); sprintf(url, "https://www.metaweather.com/api/location/%d/", location);
//Initiate http // Initiate http
http.begin(url); http.begin(url);
//Actually make HTTPS GET request // Actually do request
int httpCode = http.GET(); int httpCode = http.GET();
if (httpCode == 200) if (httpCode == 200)
{ {
@ -121,10 +118,10 @@ void Network::getData(char *city, char *temp1, char *temp2, char *temp3, char *t
if (len > 0) if (len > 0)
{ {
//Try parsing JSON object // Try parsing JSON object
DeserializationError error = deserializeJson(doc, http.getStream()); DeserializationError error = deserializeJson(doc, http.getStream());
//If an error happens print it to Serial monitor // If an error happens print it to Serial monitor
if (error) if (error)
{ {
Serial.print(F("deserializeJson() failed: ")); Serial.print(F("deserializeJson() failed: "));
@ -132,8 +129,8 @@ void Network::getData(char *city, char *temp1, char *temp2, char *temp3, char *t
} }
else else
{ {
//Set all data got from internet using formatTemp and formatWind defined above // Set all data got from internet using formatTemp and formatWind defined above
//This part relies heavily on ArduinoJson library // This part relies heavily on ArduinoJson library
formatTemp(currentTemp, doc["consolidated_weather"][0][F("the_temp")].as<float>()); formatTemp(currentTemp, doc["consolidated_weather"][0][F("the_temp")].as<float>());
formatWind(currentWind, doc["consolidated_weather"][0][F("wind_speed")].as<float>()); formatWind(currentWind, doc["consolidated_weather"][0][F("wind_speed")].as<float>());
@ -149,18 +146,17 @@ void Network::getData(char *city, char *temp1, char *temp2, char *temp3, char *t
} }
} }
//Clear document and end http // Clear document and end http
doc.clear(); doc.clear();
http.end(); http.end();
//Return to initial state // Return to initial state
WiFi.setSleep(sleep); WiFi.setSleep(sleep);
} }
//Used to set correct time received from NTP server
void Network::setTime() void Network::setTime()
{ {
//Used for setting correct time // Used for setting correct time
configTime(0, 0, "pool.ntp.org", "time.nist.gov"); configTime(0, 0, "pool.ntp.org", "time.nist.gov");
Serial.print(F("Waiting for NTP time sync: ")); Serial.print(F("Waiting for NTP time sync: "));
@ -176,7 +172,7 @@ void Network::setTime()
Serial.println(); Serial.println();
//Used to store time info // Used to store time info
struct tm timeinfo; struct tm timeinfo;
gmtime_r(&nowSecs, &timeinfo); gmtime_r(&nowSecs, &timeinfo);
@ -184,17 +180,16 @@ void Network::setTime()
Serial.print(asctime(&timeinfo)); Serial.print(asctime(&timeinfo));
} }
//From epoch received from NTP server, get day of the week
void Network::getDays(char *day, char *day1, char *day2, char *day3) void Network::getDays(char *day, char *day1, char *day2, char *day3)
{ {
// Seconds since 1.1.1970. // Seconds since 1.1.1970.
time_t nowSecs = time(nullptr); time_t nowSecs = time(nullptr);
//Find weekday // Find weekday
//We get seconds since 1970, add 3600 (1 hour) times the time zone and add 3 to // We get seconds since 1970, add 3600 (1 hour) times the time zone and add 3 to
//make monday the first day of the week, as 1.1.1970. was a thursday // make monday the first day of the week, as 1.1.1970. was a thursday
//finally do mod 7 to insure our day is within [0, 6] // finally do mod 7 to insure our day is within [0, 6]
int dayWeek = ((long)((nowSecs + 3600L * timeZone) / 86400L) + 3) % 7; int dayWeek = ((long)((nowSecs + 3600L * timeZone) / 86400L) + 3) % 7;
// Copy day data to globals in main file // Copy day data to globals in main file
@ -204,32 +199,31 @@ void Network::getDays(char *day, char *day1, char *day2, char *day3)
strncpy(day3, weekDays[(dayWeek + 3) % 7], 3); strncpy(day3, weekDays[(dayWeek + 3) % 7], 3);
} }
//Make API query to receive city woeid - city identification specific to API
void Network::findCity(char *city) void Network::findCity(char *city)
{ {
//If not connected to WiFi, return // If not connected to wifi, return
if (WiFi.status() != WL_CONNECTED) if (WiFi.status() != WL_CONNECTED)
return; return;
//Wake WiFi module and save initial state // Wake wifi module and save initial state
bool sleep = WiFi.getSleep(); bool sleep = WiFi.getSleep();
WiFi.setSleep(false); WiFi.setSleep(false);
//HTTP object // Http object
HTTPClient http; HTTPClient http;
http.getStream().setNoDelay(true); http.getStream().setNoDelay(true);
http.getStream().setTimeout(1); http.getStream().setTimeout(1);
//Add query parameter to URL // Add query param to url
char url[256]; char url[256];
strcpy(url, "https://www.metaweather.com/api/location/search/?query="); strcpy(url, "https://www.metaweather.com/api/location/search/?query=");
strcat(url, city); strcat(url, city);
//Initiate HTTP // Initiate http
http.begin(url); http.begin(url);
//Make GET HTTP request // Do get request
int httpCode = http.GET(); int httpCode = http.GET();
if (httpCode == 200) // 200: http success if (httpCode == 200) // 200: http success
{ {
@ -237,10 +231,10 @@ void Network::findCity(char *city)
if (len > 0) if (len > 0)
{ {
//Try to parse JSON object // Try to parse JSON object
DeserializationError error = deserializeJson(doc, http.getStream()); DeserializationError error = deserializeJson(doc, http.getStream());
//Print error to Serial monitor if one exists // Print error to Serial monitor if one exsists
if (error) if (error)
{ {
Serial.print(F("deserializeJson() failed: ")); Serial.print(F("deserializeJson() failed: "));
@ -248,14 +242,14 @@ void Network::findCity(char *city)
} }
else else
{ {
//Empty list means no matches for the city // Empty list means no matches
if (doc.size() == 0) if (doc.size() == 0)
{ {
Serial.println(F("City not found")); Serial.println(F("City not found"));
} }
else else
{ {
//woeid id used for fetching data later on // Woeid id used for fetching data later on
location = doc[0]["woeid"].as<int>(); location = doc[0]["woeid"].as<int>();
Serial.println(F("Found city, woied:")); Serial.println(F("Found city, woied:"));
@ -265,10 +259,10 @@ void Network::findCity(char *city)
} }
} }
//Clear document and end http // Clear document and end http
doc.clear(); doc.clear();
http.end(); http.end();
//Return module to initial state // Return module to initial state
WiFi.setSleep(sleep); WiFi.setSleep(sleep);
}; };

View File

@ -5,8 +5,6 @@
# #
# Takes all files from /icons and saves them to /binary_icons # Takes all files from /icons and saves them to /binary_icons
# #
#July 2020 by e-radionica.com
#
# ----------- # -----------
from PIL import Image from PIL import Image