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 CL 0x01 //GPIO0
#define CL_SET {GPIO.out_w1ts = CL;}
#define CL_CLEAR {GPIO.out_w1tc = CL;}
#define CL_SET \
{ \
GPIO.out_w1ts = CL; \
}
#define CL_CLEAR \
{ \
GPIO.out_w1tc = CL; \
}
#define LE 0x04 //GPIO2
#define LE_SET {GPIO.out_w1ts = LE;}
#define LE_CLEAR {GPIO.out_w1tc = LE;}
#define LE_SET \
{ \
GPIO.out_w1ts = LE; \
}
#define LE_CLEAR \
{ \
GPIO.out_w1tc = LE; \
}
#define CKV 0x01 //GPIO32
#define CKV_SET {GPIO.out1_w1ts.val = CKV;}
#define CKV_CLEAR {GPIO.out1_w1tc.val = CKV;}
#define CKV_SET \
{ \
GPIO.out1_w1ts.val = CKV; \
}
#define CKV_CLEAR \
{ \
GPIO.out1_w1tc.val = CKV; \
}
#define SPH 0x02 //GPIO33
#define SPH_SET {GPIO.out1_w1ts.val = SPH;}
#define SPH_CLEAR {GPIO.out1_w1tc.val = SPH;}
#define SPH_SET \
{ \
GPIO.out1_w1ts.val = SPH; \
}
#define SPH_CLEAR \
{ \
GPIO.out1_w1tc.val = SPH; \
}
//#define SPV 15 //GPIO15
//#define SPV_SET {digitalWrite(SPV, HIGH);}
@ -53,33 +77,74 @@
//I/O Expander - A Channel
#define GMOD 1 //GPIOA1
#define GMOD_SET {mcp.digitalWrite(GMOD, HIGH);}
#define GMOD_CLEAR {mcp.digitalWrite(GMOD, LOW);}
#define GMOD_SET \
{ \
mcp.digitalWrite(GMOD, HIGH); \
}
#define GMOD_CLEAR \
{ \
mcp.digitalWrite(GMOD, LOW); \
}
#define OE 0 //GPIOA0
#define OE_SET {mcp.digitalWrite(OE, HIGH);}
#define OE_CLEAR {mcp.digitalWrite(OE, LOW);}
#define OE_SET \
{ \
mcp.digitalWrite(OE, HIGH); \
}
#define OE_CLEAR \
{ \
mcp.digitalWrite(OE, LOW); \
}
#define SPV 2 //GPIOA5
#define SPV_SET {mcp.digitalWrite(SPV, HIGH);}
#define SPV_CLEAR {mcp.digitalWrite(SPV, LOW);}
#define SPV_SET \
{ \
mcp.digitalWrite(SPV, HIGH); \
}
#define SPV_CLEAR \
{ \
mcp.digitalWrite(SPV, LOW); \
}
#define WAKEUP 3 //GPIOA3
#define WAKEUP_SET {mcp.digitalWrite(WAKEUP, HIGH);}
#define WAKEUP_CLEAR {mcp.digitalWrite(WAKEUP, LOW);}
#define WAKEUP_SET \
{ \
mcp.digitalWrite(WAKEUP, HIGH); \
}
#define WAKEUP_CLEAR \
{ \
mcp.digitalWrite(WAKEUP, LOW); \
}
#define PWRUP 4 //GPIOA4
#define PWRUP_SET {mcp.digitalWrite(PWRUP, HIGH);}
#define PWRUP_CLEAR {mcp.digitalWrite(PWRUP, LOW);}
#define PWRUP_SET \
{ \
mcp.digitalWrite(PWRUP, HIGH); \
}
#define PWRUP_CLEAR \
{ \
mcp.digitalWrite(PWRUP, LOW); \
}
#define VCOM 5 //GPIOA6
#define VCOM_SET {mcp.digitalWrite(VCOM, HIGH);}
#define VCOM_CLEAR {mcp.digitalWrite(VCOM, LOW);}
#define VCOM_SET \
{ \
mcp.digitalWrite(VCOM, HIGH); \
}
#define VCOM_CLEAR \
{ \
mcp.digitalWrite(VCOM, LOW); \
}
#define CKV_CLOCK ckvClock();
#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
extern Adafruit_MCP23017 mcp;
@ -88,7 +153,8 @@ extern SdFat sd;
static void ckvClock();
static void usleep1();
class Inkplate : public Adafruit_GFX {
class Inkplate : public Adafruit_GFX
{
public:
uint8_t *D_memory_new;
uint8_t *_partial;
@ -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.
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;
uint32_t fileSize;
uint32_t startRAW;
@ -135,6 +202,8 @@ class Inkplate : public Adafruit_GFX {
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(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();
SdFat getSdFat();
SPIClass getSPI();

View File

@ -6,47 +6,55 @@
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,
in this example Metaweather public weather API which provide weather info.
As a result, you get a functional weather station which shows today's
forecast and 3 days forecast on your Inkplate display.
e.g. Metaweather public weather API
IMPORTANT:
Make sure you have changed your desired city, timezone and WiFi credentials below.
You will also need to install ArduinoJSON library.
Download from here: https://github.com/bblanchon/ArduinoJson
Make sure to change your desired city, timezone and wifi credentials below
Also have ArduinoJSON installed in your Arduino libraries
Want to learn more about Inkplate? Visit www.inkplate.io
Looking to get support? Write on our forums: http://forum.e-radionica.com/en/
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
char *ssid = "";
char *pass = "";
// Change to your wifi ssid and password
char *ssid = "e-radionica.com";
char *pass = "croduino";
#define DELAY_MS 15000 //Delay between screen refreshes goes here
// ----------------------------------------------
// ----------------------------------
// Include Inkplate library to the sketch
#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_36.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"};
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};
@ -66,13 +74,18 @@ char days[8][4] = {
"",
};
long refreshes = 0; //Variable for counting partial refreshes
const int fullRefresh = 10; //Constant to determine when to full update
// Variable for counting partial refreshes
long refreshes = 0;
// Constant to determine when to full update
const int fullRefresh = 10;
// Variables for storing current time and weather info
char currentTemp[16] = "0F";
char currentWind[16] = "0m/s";
char currentTime[16] = "9:41";
char currentWeather[32] = "-";
char currentWeatherAbbr[8] = "th";
@ -85,9 +98,9 @@ void drawTime();
void setup()
{
//Begin serial and and begin display
// Begin serial and display
Serial.begin(115200);
display.begin(); //Call this function only once!
display.begin();
// Initial cleaning of buffer and physical screen
display.clearDisplay();
@ -96,7 +109,7 @@ void setup()
// Calling our begin from network.h file
network.begin(city);
//If city not found, write error message and stop
// If city not found, do nothing
if (network.location == -1)
{
display.setCursor(50, 290);
@ -114,7 +127,7 @@ void setup()
display.display();
// Wait a bit before proceeding
delay(3000);
delay(5000);
}
void loop()
@ -127,14 +140,14 @@ void loop()
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);
//Draw data, see functions below in Network.cpp for info
// Draw data, see functions below for info
drawWeather();
drawCurrent();
drawTemps();
drawCity();
drawTime();
//Refresh full screen every fullRefresh times
// Refresh full screen every fullRefresh times, defined above
if (refreshes % fullRefresh == 0)
display.display();
else
@ -152,12 +165,12 @@ void drawWeather()
// Searching for weather state abbreviation
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)
display.drawBitmap(50, 50, logos[i], 152, 152, BLACK);
}
//Draw current weather state
// Draw weather state
display.setTextColor(BLACK, WHITE);
display.setFont(&Roboto_Light_36);
display.setTextSize(1);
@ -168,7 +181,7 @@ void drawWeather()
// Function for drawing current time
void drawTime()
{
//Drawing current time stored in currentTime variable
// Drawing current time
display.setTextColor(BLACK, WHITE);
display.setFont(&Roboto_Light_36);
display.setTextSize(1);
@ -192,7 +205,7 @@ void drawCity()
// Function for drawing temperatures
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 rectSpacing = (800 - rectWidth * 4) / 5;
@ -203,7 +216,6 @@ void drawTemps()
int textMargin = 6;
//Setting font specifics, writing the actual weather info
display.setFont(&Roboto_Light_48);
display.setTextSize(1);
display.setTextColor(WHITE, BLACK);

View File

@ -57,7 +57,7 @@ void Network::getTime(char *timeStr)
// Get seconds since 1.1.1970.
time_t nowSecs = time(nullptr);
//Struct used to store time
// Used to store time
struct tm timeinfo;
gmtime_r(&nowSecs, &timeinfo);
@ -75,45 +75,42 @@ void Network::getTime(char *timeStr)
timeStr[1] = hr % 10 + '0';
}
//Helper function to convert float to char*
void formatTemp(char *str, float temp)
{
// Built in function for float to char* conversion
dtostrf(temp, 2, 0, str);
}
//Helper function to convert float to char*
void formatWind(char *str, float wind)
{
// Built in function for float to char* conversion
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)
{
// Return if wifi isn't connected
if (WiFi.status() != WL_CONNECTED)
return;
//Wake up WiFi if sleeping and save inital state
// Wake up if sleeping and save inital state
bool sleep = WiFi.getSleep();
WiFi.setSleep(false);
//HTTP object used to make get request
// Http object used to make get request
HTTPClient http;
http.getStream().setNoDelay(true);
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];
sprintf(url, "https://www.metaweather.com/api/location/%d/", location);
// Initiate http
http.begin(url);
//Actually make HTTPS GET request
// Actually do request
int httpCode = http.GET();
if (httpCode == 200)
{
@ -157,7 +154,6 @@ void Network::getData(char *city, char *temp1, char *temp2, char *temp3, char *t
WiFi.setSleep(sleep);
}
//Used to set correct time received from NTP server
void Network::setTime()
{
// Used for setting correct time
@ -184,7 +180,6 @@ void Network::setTime()
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)
{
// Seconds since 1.1.1970.
@ -204,32 +199,31 @@ void Network::getDays(char *day, char *day1, char *day2, char *day3)
strncpy(day3, weekDays[(dayWeek + 3) % 7], 3);
}
//Make API query to receive city woeid - city identification specific to API
void Network::findCity(char *city)
{
//If not connected to WiFi, return
// If not connected to wifi, return
if (WiFi.status() != WL_CONNECTED)
return;
//Wake WiFi module and save initial state
// Wake wifi module and save initial state
bool sleep = WiFi.getSleep();
WiFi.setSleep(false);
//HTTP object
// Http object
HTTPClient http;
http.getStream().setNoDelay(true);
http.getStream().setTimeout(1);
//Add query parameter to URL
// Add query param to url
char url[256];
strcpy(url, "https://www.metaweather.com/api/location/search/?query=");
strcat(url, city);
//Initiate HTTP
// Initiate http
http.begin(url);
//Make GET HTTP request
// Do get request
int httpCode = http.GET();
if (httpCode == 200) // 200: http success
{
@ -240,7 +234,7 @@ void Network::findCity(char *city)
// Try to parse JSON object
DeserializationError error = deserializeJson(doc, http.getStream());
//Print error to Serial monitor if one exists
// Print error to Serial monitor if one exsists
if (error)
{
Serial.print(F("deserializeJson() failed: "));
@ -248,14 +242,14 @@ void Network::findCity(char *city)
}
else
{
//Empty list means no matches for the city
// Empty list means no matches
if (doc.size() == 0)
{
Serial.println(F("City not found"));
}
else
{
//woeid id used for fetching data later on
// Woeid id used for fetching data later on
location = doc[0]["woeid"].as<int>();
Serial.println(F("Found city, woied:"));

View File

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