Compare commits

...

21 Commits

Author SHA1 Message Date
SQFMI 2cdfeaa0d1
Merge pull request #199 from sqfmi/dev
Dev
2022-12-26 12:53:02 -05:00
SQFMI 7333873f08
Merge pull request #193 from Alex-K37/ambig_overload
fixed compilation error: ambiguous overload for 'operator='
2022-12-26 12:51:10 -05:00
SQFMI 9a64af8b3d
Merge pull request #178 from DarkZeros/OptimizeDisplay
Optimise GxEPD2 Display
2022-12-26 12:21:00 -05:00
SQFMI 5921655691
Merge pull request #188 from shtrom/fix/gmtOffset_from_weather
Set GMT offset from weatherdata. Will override GMT offset in settings after API call.
2022-12-26 12:16:40 -05:00
SQFMI 472eee733d
Merge branch 'master' into fix/gmtOffset_from_weather 2022-12-26 12:15:56 -05:00
SQFMI 6e41b9c982
Merge pull request #190 from shtrom/feature/exit-inactive-menu
Exit menu after some inactive time
2022-12-26 12:07:11 -05:00
Olivier Mehani dd3797f2d5
Exit menu after some inactive time
Signed-off-by: Olivier Mehani <shtrom@ssji.net>
2022-12-07 22:27:34 +11:00
Alex-K37 5e451fbf04 fixed compilation error: ambiguous overload for 'operator='
.pio/libdeps/watchy/Watchy/src/Watchy.cpp: In member function 'weatherData Watchy::getWeatherData(String, String, String, String, String, uint8_t)':
.pio/libdeps/watchy/Watchy/src/Watchy.cpp:620:48: error: ambiguous overload for 'operator=' (operand types are 'String' and 'JSONVar')
             responseObject["weather"][0]["main"];
                                                ^
In file included from /home/krupp/.platformio/packages/framework-arduinoespressif32/cores/esp32/Arduino.h:166,
                 from .pio/libdeps/watchy/Watchy/src/Watchy.h:4,
                 from .pio/libdeps/watchy/Watchy/src/Watchy.cpp:1:
/home/build/.platformio/packages/framework-arduinoespressif32/cores/esp32/WString.h:102:18: note: candidate: 'String& String::operator=(const String&)'
         String & operator =(const String &rhs);
                  ^~~~~~~~
/home/build/.platformio/packages/framework-arduinoespressif32/cores/esp32/WString.h:103:18: note: candidate: 'String& String::operator=(const char*)'
         String & operator =(const char *cstr);
                  ^~~~~~~~
2022-11-26 22:07:29 +01:00
Olivier Mehani c750754e8a
fixup! Get gmtOffset from weather data, for use in all NTP requests 2022-10-24 22:20:12 +11:00
Olivier Mehani 2bd89ef250
Get gmtOffset from weather data, for use in all NTP requests
Signed-off-by: Olivier Mehani <shtrom@ssji.net>
2022-10-16 22:29:21 +11:00
sqfmi 9e5d7ad19c Merge branch 'master' into dev 2022-10-14 22:23:24 -04:00
sqfmi a24b1d0945 Merge branch 'master' into dev 2022-10-08 16:23:36 -04:00
SQFMI 4c56a38f34
Merge pull request #181 from ITCactus/fix-version-about-screen
fix "LibVer" info on "About Watchy" screen
2022-10-08 02:55:25 -04:00
sqfmi c5ceab1a49 Merge branch 'pr/178' into dev 2022-08-27 16:09:25 -04:00
sqfmi 5e0834f309 Merge branch 'master' into dev 2022-08-27 16:06:03 -04:00
ITCactus 819606e892 fix "LibVer" info on "About Watchy" screen 2022-08-05 15:07:56 +02:00
Daniel Ansorregui 5c27f4721f Optimise GxEPD2 Display
* This change implements certain
  speed improvements on top of
  upstream GxEPD2 that are not fully
  accepted by the upstream maintainer.
* The change Adds a new WatchyDisplay class
  and implements the mods in there.

* Using transactions for SPI communication
* Remove extra delays for yield()
* Remove 10ms active waits in resets

* This reduces (874ms -> 657ms) the display
  update. Making it more responsive and
  Saving 21mJ/update or 2.6mAh/day
2022-08-03 17:08:12 +01:00
sqfmi 2e957fb80b Merge branch 'master' into dev 2022-07-10 12:10:28 -04:00
sqfmi 44c51fce90 Merge branch 'master' into dev 2022-07-10 12:09:04 -04:00
SQFMI c5ddfb4e7b
Update library.json 2022-05-06 22:29:08 -04:00
SQFMI 8440fc7960
Update library.properties 2022-05-06 22:28:55 -04:00
11 changed files with 543 additions and 22 deletions

View File

@ -10,7 +10,7 @@
#define WEATHER_UPDATE_INTERVAL 30 //must be greater than 5, measured in minutes
//NTP Settings
#define NTP_SERVER "pool.ntp.org"
#define GMT_OFFSET_SEC 3600 * -5 //New York is UTC -5 EST, -4 EDT
#define GMT_OFFSET_SEC 3600 * -5 //New York is UTC -5 EST, -4 EDT, will be overwritten by weather data
watchySettings settings{
.cityID = CITY_ID,
@ -24,4 +24,4 @@ watchySettings settings{
.vibrateOClock = true,
};
#endif
#endif

View File

@ -10,7 +10,7 @@
#define WEATHER_UPDATE_INTERVAL 30 //must be greater than 5, measured in minutes
//NTP Settings
#define NTP_SERVER "pool.ntp.org"
#define GMT_OFFSET_SEC 3600 * -5 //New York is UTC -5 EST, -4 EDT
#define GMT_OFFSET_SEC 3600 * -5 //New York is UTC -5 EST, -4 EDT, will be overwritten by weather data
watchySettings settings{
.cityID = CITY_ID,
@ -23,4 +23,4 @@ watchySettings settings{
.gmtOffset = GMT_OFFSET_SEC,
};
#endif
#endif

View File

@ -10,7 +10,7 @@
#define WEATHER_UPDATE_INTERVAL 30 //must be greater than 5, measured in minutes
//NTP Settings
#define NTP_SERVER "pool.ntp.org"
#define GMT_OFFSET_SEC 3600 * -5 //New York is UTC -5 EST, -4 EDT
#define GMT_OFFSET_SEC 3600 * -5 //New York is UTC -5 EST, -4 EDT, will be overwritten by weather data
watchySettings settings{
.cityID = CITY_ID,
@ -23,4 +23,4 @@ watchySettings settings{
.gmtOffset = GMT_OFFSET_SEC,
};
#endif
#endif

View File

@ -10,7 +10,7 @@
#define WEATHER_UPDATE_INTERVAL 30 //must be greater than 5, measured in minutes
//NTP Settings
#define NTP_SERVER "pool.ntp.org"
#define GMT_OFFSET_SEC 3600 * -5 //New York is UTC -5 EST, -4 EDT
#define GMT_OFFSET_SEC 3600 * -5 //New York is UTC -5 EST, -4 EDT, will be overwritten by weather data
watchySettings settings{
.cityID = CITY_ID,
@ -23,4 +23,4 @@ watchySettings settings{
.gmtOffset = GMT_OFFSET_SEC,
};
#endif
#endif

View File

@ -10,7 +10,7 @@
#define WEATHER_UPDATE_INTERVAL 30 //must be greater than 5, measured in minutes
//NTP Settings
#define NTP_SERVER "pool.ntp.org"
#define GMT_OFFSET_SEC 3600 * -5 //New York is UTC -5 EST, -4 EDT
#define GMT_OFFSET_SEC 3600 * -5 //New York is UTC -5 EST, -4 EDT, will be overwritten by weather data
watchySettings settings{
.cityID = CITY_ID,
@ -23,4 +23,4 @@ watchySettings settings{
.gmtOffset = GMT_OFFSET_SEC,
};
#endif
#endif

View File

@ -10,7 +10,7 @@
#define WEATHER_UPDATE_INTERVAL 30 //must be greater than 5, measured in minutes
//NTP Settings
#define NTP_SERVER "pool.ntp.org"
#define GMT_OFFSET_SEC 3600 * -5 //New York is UTC -5 EST, -4 EDT
#define GMT_OFFSET_SEC 3600 * -5 //New York is UTC -5 EST, -4 EDT, will be overwritten by weather data
watchySettings settings{
.cityID = CITY_ID,
@ -23,4 +23,4 @@ watchySettings settings{
.gmtOffset = GMT_OFFSET_SEC,
};
#endif
#endif

View File

@ -10,7 +10,7 @@
#define WEATHER_UPDATE_INTERVAL 30 //must be greater than 5, measured in minutes
//NTP Settings
#define NTP_SERVER "pool.ntp.org"
#define GMT_OFFSET_SEC 3600 * -5 //New York is UTC -5 EST, -4 EDT
#define GMT_OFFSET_SEC 3600 * -5 //New York is UTC -5 EST, -4 EDT, will be overwritten by weather data
watchySettings settings{
.cityID = CITY_ID,
@ -23,4 +23,4 @@ watchySettings settings{
.gmtOffset = GMT_OFFSET_SEC,
};
#endif
#endif

416
src/Display.cpp Normal file
View File

@ -0,0 +1,416 @@
// Display Library for SPI e-paper panels from Dalian Good Display and boards from Waveshare.
// Requires HW SPI and Adafruit_GFX. Caution: the e-paper panels require 3.3V supply AND data lines!
//
// based on Demo Example from Good Display, available here: http://www.e-paper-display.com/download_detail/downloadsId=806.html
// Panel: GDEH0154D67 : http://www.e-paper-display.com/products_detail/productId=455.html
// Controller : SSD1681 : http://www.e-paper-display.com/download_detail/downloadsId=825.html
//
// Author: Jean-Marc Zingg
//
// Version: see library.properties
//
// Library: https://github.com/ZinggJM/GxEPD2
//
// The original code from the author has been slightly modified to improve the performance for Watchy Project:
// Link: https://github.com/sqfmi/Watchy
#include "Display.h"
WatchyDisplay::WatchyDisplay(int16_t cs, int16_t dc, int16_t rst, int16_t busy) :
GxEPD2_EPD(cs, dc, rst, busy, HIGH, 10000000, WIDTH, HEIGHT, panel, hasColor, hasPartialUpdate, hasFastPartialUpdate)
{
selectSPI(SPI, SPISettings(20000000, MSBFIRST, SPI_MODE0)); // Set SPI to 20Mhz (default is 4Mhz)
}
void WatchyDisplay::clearScreen(uint8_t value)
{
writeScreenBuffer(value);
refresh(true);
writeScreenBufferAgain(value);
}
void WatchyDisplay::writeScreenBuffer(uint8_t value)
{
if (!_using_partial_mode) _Init_Part();
if (_initial_write) _writeScreenBuffer(0x26, value); // set previous
_writeScreenBuffer(0x24, value); // set current
_initial_write = false; // initial full screen buffer clean done
}
void WatchyDisplay::writeScreenBufferAgain(uint8_t value)
{
if (!_using_partial_mode) _Init_Part();
_writeScreenBuffer(0x24, value); // set current
}
void WatchyDisplay::_writeScreenBuffer(uint8_t command, uint8_t value)
{
_startTransfer();
_transferCommand(command);
for (uint32_t i = 0; i < uint32_t(WIDTH) * uint32_t(HEIGHT) / 8; i++)
{
_transfer(value);
}
_endTransfer();
}
void WatchyDisplay::writeImage(const uint8_t bitmap[], int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
{
_writeImage(0x24, bitmap, x, y, w, h, invert, mirror_y, pgm);
}
void WatchyDisplay::writeImageForFullRefresh(const uint8_t bitmap[], int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
{
_writeImage(0x26, bitmap, x, y, w, h, invert, mirror_y, pgm);
_writeImage(0x24, bitmap, x, y, w, h, invert, mirror_y, pgm);
}
void WatchyDisplay::writeImageAgain(const uint8_t bitmap[], int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
{
_writeImage(0x24, bitmap, x, y, w, h, invert, mirror_y, pgm);
}
void WatchyDisplay::_writeImage(uint8_t command, const uint8_t bitmap[], int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
{
if (_initial_write) writeScreenBuffer(); // initial full screen buffer clean
#if defined(ESP8266) || defined(ESP32)
yield(); // avoid wdt
#endif
int16_t wb = (w + 7) / 8; // width bytes, bitmaps are padded
x -= x % 8; // byte boundary
w = wb * 8; // byte boundary
int16_t x1 = x < 0 ? 0 : x; // limit
int16_t y1 = y < 0 ? 0 : y; // limit
int16_t w1 = x + w < int16_t(WIDTH) ? w : int16_t(WIDTH) - x; // limit
int16_t h1 = y + h < int16_t(HEIGHT) ? h : int16_t(HEIGHT) - y; // limit
int16_t dx = x1 - x;
int16_t dy = y1 - y;
w1 -= dx;
h1 -= dy;
if ((w1 <= 0) || (h1 <= 0)) return;
if (!_using_partial_mode) _Init_Part();
_setPartialRamArea(x1, y1, w1, h1);
_startTransfer();
_transferCommand(command);
for (int16_t i = 0; i < h1; i++)
{
for (int16_t j = 0; j < w1 / 8; j++)
{
uint8_t data;
// use wb, h of bitmap for index!
int16_t idx = mirror_y ? j + dx / 8 + ((h - 1 - (i + dy))) * wb : j + dx / 8 + (i + dy) * wb;
if (pgm)
{
#if defined(__AVR) || defined(ESP8266) || defined(ESP32)
data = pgm_read_byte(&bitmap[idx]);
#else
data = bitmap[idx];
#endif
}
else
{
data = bitmap[idx];
}
if (invert) data = ~data;
_transfer(data);
}
}
_endTransfer();
#if defined(ESP8266) || defined(ESP32)
yield(); // avoid wdt
#endif
}
void WatchyDisplay::writeImagePart(const uint8_t bitmap[], int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap,
int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
{
_writeImagePart(0x24, bitmap, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, invert, mirror_y, pgm);
}
void WatchyDisplay::writeImagePartAgain(const uint8_t bitmap[], int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap,
int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
{
_writeImagePart(0x24, bitmap, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, invert, mirror_y, pgm);
}
void WatchyDisplay::_writeImagePart(uint8_t command, const uint8_t bitmap[], int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap,
int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
{
if (_initial_write) writeScreenBuffer(); // initial full screen buffer clean
#if defined(ESP8266) || defined(ESP32)
yield(); // avoid wdt
#endif
if ((w_bitmap < 0) || (h_bitmap < 0) || (w < 0) || (h < 0)) return;
if ((x_part < 0) || (x_part >= w_bitmap)) return;
if ((y_part < 0) || (y_part >= h_bitmap)) return;
int16_t wb_bitmap = (w_bitmap + 7) / 8; // width bytes, bitmaps are padded
x_part -= x_part % 8; // byte boundary
w = w_bitmap - x_part < w ? w_bitmap - x_part : w; // limit
h = h_bitmap - y_part < h ? h_bitmap - y_part : h; // limit
x -= x % 8; // byte boundary
w = 8 * ((w + 7) / 8); // byte boundary, bitmaps are padded
int16_t x1 = x < 0 ? 0 : x; // limit
int16_t y1 = y < 0 ? 0 : y; // limit
int16_t w1 = x + w < int16_t(WIDTH) ? w : int16_t(WIDTH) - x; // limit
int16_t h1 = y + h < int16_t(HEIGHT) ? h : int16_t(HEIGHT) - y; // limit
int16_t dx = x1 - x;
int16_t dy = y1 - y;
w1 -= dx;
h1 -= dy;
if ((w1 <= 0) || (h1 <= 0)) return;
if (!_using_partial_mode) _Init_Part();
_setPartialRamArea(x1, y1, w1, h1);
_startTransfer();
_transferCommand(command);
for (int16_t i = 0; i < h1; i++)
{
for (int16_t j = 0; j < w1 / 8; j++)
{
uint8_t data;
// use wb_bitmap, h_bitmap of bitmap for index!
int16_t idx = mirror_y ? x_part / 8 + j + dx / 8 + ((h_bitmap - 1 - (y_part + i + dy))) * wb_bitmap : x_part / 8 + j + dx / 8 + (y_part + i + dy) * wb_bitmap;
if (pgm)
{
#if defined(__AVR) || defined(ESP8266) || defined(ESP32)
data = pgm_read_byte(&bitmap[idx]);
#else
data = bitmap[idx];
#endif
}
else
{
data = bitmap[idx];
}
if (invert) data = ~data;
_transfer(data);
}
}
_endTransfer();
#if defined(ESP8266) || defined(ESP32)
yield(); // avoid wdt
#endif
}
void WatchyDisplay::writeImage(const uint8_t* black, const uint8_t* color, int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
{
if (black)
{
writeImage(black, x, y, w, h, invert, mirror_y, pgm);
}
}
void WatchyDisplay::writeImagePart(const uint8_t* black, const uint8_t* color, int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap,
int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
{
if (black)
{
writeImagePart(black, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, invert, mirror_y, pgm);
}
}
void WatchyDisplay::writeNative(const uint8_t* data1, const uint8_t* data2, int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
{
if (data1)
{
writeImage(data1, x, y, w, h, invert, mirror_y, pgm);
}
}
void WatchyDisplay::drawImage(const uint8_t bitmap[], int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
{
writeImage(bitmap, x, y, w, h, invert, mirror_y, pgm);
refresh(x, y, w, h);
writeImageAgain(bitmap, x, y, w, h, invert, mirror_y, pgm);
}
void WatchyDisplay::drawImagePart(const uint8_t bitmap[], int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap,
int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
{
writeImagePart(bitmap, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, invert, mirror_y, pgm);
refresh(x, y, w, h);
writeImagePartAgain(bitmap, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, invert, mirror_y, pgm);
}
void WatchyDisplay::drawImage(const uint8_t* black, const uint8_t* color, int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
{
if (black)
{
drawImage(black, x, y, w, h, invert, mirror_y, pgm);
}
}
void WatchyDisplay::drawImagePart(const uint8_t* black, const uint8_t* color, int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap,
int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
{
if (black)
{
drawImagePart(black, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, invert, mirror_y, pgm);
}
}
void WatchyDisplay::drawNative(const uint8_t* data1, const uint8_t* data2, int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
{
if (data1)
{
drawImage(data1, x, y, w, h, invert, mirror_y, pgm);
}
}
void WatchyDisplay::refresh(bool partial_update_mode)
{
if (partial_update_mode) refresh(0, 0, WIDTH, HEIGHT);
else
{
if (_using_partial_mode) _Init_Full();
_Update_Full();
_initial_refresh = false; // initial full update done
}
}
void WatchyDisplay::refresh(int16_t x, int16_t y, int16_t w, int16_t h)
{
if (_initial_refresh) return refresh(false); // initial update needs be full update
// intersection with screen
int16_t w1 = x < 0 ? w + x : w; // reduce
int16_t h1 = y < 0 ? h + y : h; // reduce
int16_t x1 = x < 0 ? 0 : x; // limit
int16_t y1 = y < 0 ? 0 : y; // limit
w1 = x1 + w1 < int16_t(WIDTH) ? w1 : int16_t(WIDTH) - x1; // limit
h1 = y1 + h1 < int16_t(HEIGHT) ? h1 : int16_t(HEIGHT) - y1; // limit
if ((w1 <= 0) || (h1 <= 0)) return;
// make x1, w1 multiple of 8
w1 += x1 % 8;
if (w1 % 8 > 0) w1 += 8 - w1 % 8;
x1 -= x1 % 8;
if (!_using_partial_mode) _Init_Part();
_setPartialRamArea(x1, y1, w1, h1);
_Update_Part();
}
void WatchyDisplay::powerOff()
{
_PowerOff();
}
void WatchyDisplay::hibernate()
{
//_PowerOff(); // Not needed before entering deep sleep
if (_rst >= 0)
{
_writeCommand(0x10); // deep sleep mode
_writeData(0x1); // enter deep sleep
_hibernating = true;
}
}
void WatchyDisplay::_setPartialRamArea(uint16_t x, uint16_t y, uint16_t w, uint16_t h)
{
_startTransfer();
_transferCommand(0x11); // set ram entry mode
_transfer(0x03); // x increase, y increase : normal mode
_transferCommand(0x44);
_transfer(x / 8);
_transfer((x + w - 1) / 8);
_transferCommand(0x45);
_transfer(y % 256);
_transfer(y / 256);
_transfer((y + h - 1) % 256);
_transfer((y + h - 1) / 256);
_transferCommand(0x4e);
_transfer(x / 8);
_transferCommand(0x4f);
_transfer(y % 256);
_transfer(y / 256);
_endTransfer();
}
void WatchyDisplay::_PowerOn()
{
if (!_power_is_on)
{
_startTransfer();
_transferCommand(0x22);
_transfer(0xf8);
_transferCommand(0x20);
_endTransfer();
_waitWhileBusy("_PowerOn", power_on_time);
}
_power_is_on = true;
}
void WatchyDisplay::_PowerOff()
{
if (_power_is_on)
{
_startTransfer();
_transferCommand(0x22);
_transfer(0x83);
_transferCommand(0x20);
_endTransfer();
_waitWhileBusy("_PowerOff", power_off_time);
}
_power_is_on = false;
_using_partial_mode = false;
}
void WatchyDisplay::_InitDisplay()
{
if (_hibernating) _reset();
_writeCommand(0x12); // soft reset
_waitWhileBusy("_SoftReset", 10); // 10ms max according to specs
_startTransfer();
_transferCommand(0x01); // Driver output control
_transfer(0xC7);
_transfer(0x00);
_transfer(0x00);
_transferCommand(0x3C); // BorderWavefrom
_transfer(darkBorder ? 0x02 : 0x05);
_transferCommand(0x18); // Read built-in temperature sensor
_transfer(0x80);
_endTransfer();
_setPartialRamArea(0, 0, WIDTH, HEIGHT);
}
void WatchyDisplay::_Init_Full()
{
_InitDisplay();
_PowerOn();
_using_partial_mode = false;
}
void WatchyDisplay::_Init_Part()
{
_InitDisplay();
_PowerOn();
_using_partial_mode = true;
}
void WatchyDisplay::_Update_Full()
{
_startTransfer();
_transferCommand(0x22);
_transfer(0xf4);
_transferCommand(0x20);
_endTransfer();
_waitWhileBusy("_Update_Full", full_refresh_time);
}
void WatchyDisplay::_Update_Part()
{
_startTransfer();
_transferCommand(0x22);
//_transfer(0xcc); // skip temperature load (-5ms)
_transfer(0xfc);
_transferCommand(0x20);
_endTransfer();
_waitWhileBusy("_Update_Part", partial_refresh_time);
}
void WatchyDisplay::_transferCommand(uint8_t value)
{
if (_dc >= 0) digitalWrite(_dc, LOW);
SPI.transfer(value);
if (_dc >= 0) digitalWrite(_dc, HIGH);
}

86
src/Display.h Normal file
View File

@ -0,0 +1,86 @@
// Display Library for SPI e-paper panels from Dalian Good Display and boards from Waveshare.
// Requires HW SPI and Adafruit_GFX. Caution: the e-paper panels require 3.3V supply AND data lines!
//
// based on Demo Example from Good Display, available here: http://www.e-paper-display.com/download_detail/downloadsId=806.html
// Panel: GDEH0154D67 : http://www.e-paper-display.com/products_detail/productId=455.html
// Controller : SSD1681 : http://www.e-paper-display.com/download_detail/downloadsId=825.html
//
// Author: Jean-Marc Zingg
//
// Version: see library.properties
//
// Library: https://github.com/ZinggJM/GxEPD2
//
// The original code from the author has been slightly modified to improve the performance for Watchy Project:
// Link: https://github.com/sqfmi/Watchy
#pragma once
#include <GxEPD2_EPD.h>
class WatchyDisplay : public GxEPD2_EPD
{
public:
// attributes
static const uint16_t WIDTH = 200;
static const uint16_t HEIGHT = 200;
static const GxEPD2::Panel panel = GxEPD2::GDEH0154D67;
static const bool hasColor = false;
static const bool hasPartialUpdate = true;
static const bool hasFastPartialUpdate = true;
static const uint16_t power_on_time = 100; // ms, e.g. 95583us
static const uint16_t power_off_time = 150; // ms, e.g. 140621us
static const uint16_t full_refresh_time = 2600; // ms, e.g. 2509602us
static const uint16_t partial_refresh_time = 500; // ms, e.g. 457282us
// constructor
WatchyDisplay(int16_t cs, int16_t dc, int16_t rst, int16_t busy);
// methods (virtual)
// Support for Bitmaps (Sprites) to Controller Buffer and to Screen
void clearScreen(uint8_t value = 0xFF); // init controller memory and screen (default white)
void writeScreenBuffer(uint8_t value = 0xFF); // init controller memory (default white)
void writeScreenBufferAgain(uint8_t value = 0xFF); // init previous buffer controller memory (default white)
// write to controller memory, without screen refresh; x and w should be multiple of 8
void writeImage(const uint8_t bitmap[], int16_t x, int16_t y, int16_t w, int16_t h, bool invert = false, bool mirror_y = false, bool pgm = false);
void writeImageForFullRefresh(const uint8_t bitmap[], int16_t x, int16_t y, int16_t w, int16_t h, bool invert = false, bool mirror_y = false, bool pgm = false);
void writeImagePart(const uint8_t bitmap[], int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap,
int16_t x, int16_t y, int16_t w, int16_t h, bool invert = false, bool mirror_y = false, bool pgm = false);
void writeImage(const uint8_t* black, const uint8_t* color, int16_t x, int16_t y, int16_t w, int16_t h, bool invert = false, bool mirror_y = false, bool pgm = false);
void writeImagePart(const uint8_t* black, const uint8_t* color, int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap,
int16_t x, int16_t y, int16_t w, int16_t h, bool invert = false, bool mirror_y = false, bool pgm = false);
// for differential update: set current and previous buffers equal (for fast partial update to work correctly)
void writeImageAgain(const uint8_t bitmap[], int16_t x, int16_t y, int16_t w, int16_t h, bool invert = false, bool mirror_y = false, bool pgm = false);
void writeImagePartAgain(const uint8_t bitmap[], int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap,
int16_t x, int16_t y, int16_t w, int16_t h, bool invert = false, bool mirror_y = false, bool pgm = false);
// write sprite of native data to controller memory, without screen refresh; x and w should be multiple of 8
void writeNative(const uint8_t* data1, const uint8_t* data2, int16_t x, int16_t y, int16_t w, int16_t h, bool invert = false, bool mirror_y = false, bool pgm = false);
// write to controller memory, with screen refresh; x and w should be multiple of 8
void drawImage(const uint8_t bitmap[], int16_t x, int16_t y, int16_t w, int16_t h, bool invert = false, bool mirror_y = false, bool pgm = false);
void drawImagePart(const uint8_t bitmap[], int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap,
int16_t x, int16_t y, int16_t w, int16_t h, bool invert = false, bool mirror_y = false, bool pgm = false);
void drawImage(const uint8_t* black, const uint8_t* color, int16_t x, int16_t y, int16_t w, int16_t h, bool invert = false, bool mirror_y = false, bool pgm = false);
void drawImagePart(const uint8_t* black, const uint8_t* color, int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap,
int16_t x, int16_t y, int16_t w, int16_t h, bool invert = false, bool mirror_y = false, bool pgm = false);
// write sprite of native data to controller memory, with screen refresh; x and w should be multiple of 8
void drawNative(const uint8_t* data1, const uint8_t* data2, int16_t x, int16_t y, int16_t w, int16_t h, bool invert = false, bool mirror_y = false, bool pgm = false);
void refresh(bool partial_update_mode = false); // screen refresh from controller memory to full screen
void refresh(int16_t x, int16_t y, int16_t w, int16_t h); // screen refresh from controller memory, partial screen
void powerOff(); // turns off generation of panel driving voltages, avoids screen fading over time
void hibernate(); // turns powerOff() and sets controller to deep sleep for minimum power use, ONLY if wakeable by RST (rst >= 0)
bool darkBorder = false; // adds a dark border outside the normal screen area
private:
void _writeScreenBuffer(uint8_t command, uint8_t value);
void _writeImage(uint8_t command, const uint8_t bitmap[], int16_t x, int16_t y, int16_t w, int16_t h, bool invert = false, bool mirror_y = false, bool pgm = false);
void _writeImagePart(uint8_t command, const uint8_t bitmap[], int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap,
int16_t x, int16_t y, int16_t w, int16_t h, bool invert = false, bool mirror_y = false, bool pgm = false);
void _setPartialRamArea(uint16_t x, uint16_t y, uint16_t w, uint16_t h);
void _PowerOn();
void _PowerOff();
void _InitDisplay();
void _Init_Full();
void _Init_Part();
void _Update_Full();
void _Update_Part();
void _transferCommand(uint8_t command);
};

View File

@ -1,8 +1,8 @@
#include "Watchy.h"
WatchyRTC Watchy::RTC;
GxEPD2_BW<GxEPD2_154_D67, GxEPD2_154_D67::HEIGHT> Watchy::display(
GxEPD2_154_D67(DISPLAY_CS, DISPLAY_DC, DISPLAY_RES, DISPLAY_BUSY));
GxEPD2_BW<WatchyDisplay, WatchyDisplay::HEIGHT> Watchy::display(
WatchyDisplay(DISPLAY_CS, DISPLAY_DC, DISPLAY_RES, DISPLAY_BUSY));
RTC_DATA_ATTR int guiState;
RTC_DATA_ATTR int menuIndex;
@ -12,6 +12,8 @@ RTC_DATA_ATTR bool BLE_CONFIGURED;
RTC_DATA_ATTR weatherData currentWeather;
RTC_DATA_ATTR int weatherIntervalCounter = -1;
RTC_DATA_ATTR bool displayFullInit = true;
RTC_DATA_ATTR long gmtOffset = 0;
RTC_DATA_ATTR bool alreadyInMenu = true;
void Watchy::init(String datetime) {
esp_sleep_wakeup_cause_t wakeup_reason;
@ -27,8 +29,9 @@ void Watchy::init(String datetime) {
switch (wakeup_reason) {
case ESP_SLEEP_WAKEUP_EXT0: // RTC Alarm
if (guiState == WATCHFACE_STATE) {
RTC.read(currentTime);
RTC.read(currentTime);
switch (guiState) {
case WATCHFACE_STATE:
showWatchFace(true); // partial updates on tick
if (settings.vibrateOClock) {
if (currentTime.Minute == 0) {
@ -36,6 +39,16 @@ void Watchy::init(String datetime) {
vibMotor(75, 4);
}
}
break;
case MAIN_MENU_STATE:
// Return to watchface if in menu for more than one tick
if (alreadyInMenu) {
guiState = WATCHFACE_STATE;
showWatchFace(false);
} else {
alreadyInMenu = true;
}
break;
}
break;
case ESP_SLEEP_WAKEUP_EXT1: // button Press
@ -44,6 +57,7 @@ void Watchy::init(String datetime) {
default: // reset
RTC.config(datetime);
_bmaConfig();
gmtOffset = settings.gmtOffset;
RTC.read(currentTime);
showWatchFace(false); // full update on reset
vibMotor(75, 4);
@ -264,6 +278,7 @@ void Watchy::showMenu(byte menuIndex, bool partialRefresh) {
display.display(partialRefresh);
guiState = MAIN_MENU_STATE;
alreadyInMenu = false;
}
void Watchy::showFastMenu(byte menuIndex) {
@ -624,9 +639,10 @@ weatherData Watchy::getWeatherData(String cityID, String units, String lang,
currentWeather.weatherConditionCode =
int(responseObject["weather"][0]["id"]);
currentWeather.weatherDescription =
responseObject["weather"][0]["main"];
JSONVar::stringify(responseObject["weather"][0]["main"]);
// sync NTP during weather API call and use timezone of city
syncNTP(long(responseObject["timezone"]));
gmtOffset = int(responseObject["timezone"]);
syncNTP(gmtOffset);
} else {
// http error
}
@ -947,6 +963,8 @@ void Watchy::showSyncNTP() {
display.setTextColor(GxEPD_WHITE);
display.setCursor(0, 30);
display.println("Syncing NTP... ");
display.print("GMT offset: ");
display.println(gmtOffset);
display.display(false); // full refresh
if (connectWiFi()) {
if (syncNTP()) {
@ -984,7 +1002,7 @@ void Watchy::showSyncNTP() {
bool Watchy::syncNTP() { // NTP sync - call after connecting to WiFi and
// remember to turn it back off
return syncNTP(settings.gmtOffset,
return syncNTP(gmtOffset,
settings.ntpServer.c_str());
}

View File

@ -11,6 +11,7 @@
#include <Wire.h>
#include <Fonts/FreeMonoBold9pt7b.h>
#include "DSEG7_Classic_Bold_53.h"
#include "Display.h"
#include "WatchyRTC.h"
#include "BLE.h"
#include "bma.h"
@ -42,7 +43,7 @@ typedef struct watchySettings {
class Watchy {
public:
static WatchyRTC RTC;
static GxEPD2_BW<GxEPD2_154_D67, GxEPD2_154_D67::HEIGHT> display;
static GxEPD2_BW<WatchyDisplay, WatchyDisplay::HEIGHT> display;
tmElements_t currentTime;
watchySettings settings;