From 235887d86055c1a48e682d2a5dc745898257e6f9 Mon Sep 17 00:00:00 2001 From: Bodmer Date: Mon, 23 Apr 2018 20:05:50 +0100 Subject: [PATCH] Update weather station example Corrected jpeg render fn to handle any width image Minor tweaks Remove version number from sketch name, put in settings.h --- .../ArialRoundedMTBold_36.h | 2 +- .../ArialRoundedMtBold_14.h | 0 .../GfxUi.cpp | 37 +++++++++++-------- .../GfxUi.h | 0 .../SPIFFS_Support.ino | 0 .../WebResource.cpp | 0 .../WebResource.h | 0 .../settings.h | 22 +++++++---- .../weather-station.ino} | 1 + 9 files changed, 38 insertions(+), 24 deletions(-) rename examples/320 x 240/{weather-station-v8 => weather-station}/ArialRoundedMTBold_36.h (99%) rename examples/320 x 240/{weather-station-v8 => weather-station}/ArialRoundedMtBold_14.h (100%) rename examples/320 x 240/{weather-station-v8 => weather-station}/GfxUi.cpp (94%) rename examples/320 x 240/{weather-station-v8 => weather-station}/GfxUi.h (100%) rename examples/320 x 240/{weather-station-v8 => weather-station}/SPIFFS_Support.ino (100%) rename examples/320 x 240/{weather-station-v8 => weather-station}/WebResource.cpp (100%) rename examples/320 x 240/{weather-station-v8 => weather-station}/WebResource.h (100%) rename examples/320 x 240/{weather-station-v8 => weather-station}/settings.h (78%) rename examples/320 x 240/{weather-station-v8/weather-station-v8.ino => weather-station/weather-station.ino} (99%) diff --git a/examples/320 x 240/weather-station-v8/ArialRoundedMTBold_36.h b/examples/320 x 240/weather-station/ArialRoundedMTBold_36.h similarity index 99% rename from examples/320 x 240/weather-station-v8/ArialRoundedMTBold_36.h rename to examples/320 x 240/weather-station/ArialRoundedMTBold_36.h index 767147c..a171dbe 100644 --- a/examples/320 x 240/weather-station-v8/ArialRoundedMTBold_36.h +++ b/examples/320 x 240/weather-station/ArialRoundedMTBold_36.h @@ -22,7 +22,7 @@ See more at http://blog.squix.ch // In case of problems make sure that you are using the font file with the correct version! // Bodmer fix: End character is 0x7D not 0x7E, so bug in last line of the file corrected -// this avoids screen corruption if ~ is printer +// this avoids screen corruption if ~ is printed // Bodmer change: '`' changed to tiny degree symbol (typically this character is on top left key of a QWERTY keyboard) diff --git a/examples/320 x 240/weather-station-v8/ArialRoundedMtBold_14.h b/examples/320 x 240/weather-station/ArialRoundedMtBold_14.h similarity index 100% rename from examples/320 x 240/weather-station-v8/ArialRoundedMtBold_14.h rename to examples/320 x 240/weather-station/ArialRoundedMtBold_14.h diff --git a/examples/320 x 240/weather-station-v8/GfxUi.cpp b/examples/320 x 240/weather-station/GfxUi.cpp similarity index 94% rename from examples/320 x 240/weather-station-v8/GfxUi.cpp rename to examples/320 x 240/weather-station/GfxUi.cpp index e222adf..c425abb 100644 --- a/examples/320 x 240/weather-station-v8/GfxUi.cpp +++ b/examples/320 x 240/weather-station/GfxUi.cpp @@ -275,30 +275,35 @@ void GfxUi::jpegRender(int xpos, int ypos) { int mcu_x = JpegDec.MCUx * mcu_w + xpos; int mcu_y = JpegDec.MCUy * mcu_h + ypos; - // check if the image block size needs to be changed for the right and bottom edges + // check if the image block size needs to be changed for the right edge if (mcu_x + mcu_w <= max_x) win_w = mcu_w; else win_w = min_w; + + // check if the image block size needs to be changed for the bottom edge if (mcu_y + mcu_h <= max_y) win_h = mcu_h; else win_h = min_h; - // calculate how many pixels must be drawn - uint32_t mcu_pixels = win_w * win_h; + // copy pixels into a contiguous block + if (win_w != mcu_w) + { + uint16_t *cImg; + int p = 0; + cImg = pImg + win_w; + for (int h = 1; h < win_h; h++) + { + p += mcu_w; + for (int w = 0; w < win_w; w++) + { + *cImg = *(pImg + w + p); + cImg++; + } + } + } // draw image MCU block only if it will fit on the screen if ( ( mcu_x + win_w) <= _tft->width() && ( mcu_y + win_h) <= _tft->height()) - { -#ifdef USE_SPI_BUFFER - // Now set a MCU bounding window on the TFT to push pixels into (x, y, x + width - 1, y + height - 1) - _tft->setWindow(mcu_x, mcu_y, mcu_x + win_w - 1, mcu_y + win_h - 1); - // Write all MCU pixels to the TFT window - uint8_t *pImg8 = (uint8_t*)pImg; // Convert 16 bit pointer to an 8 bit pointer - _tft->pushColors(pImg8, mcu_pixels*2); // Send bytes via 64 byte SPI port buffer -#else - // Now set a MCU bounding window on the TFT to push pixels into (x, y, x + width - 1, y + height - 1) - _tft->setAddrWindow(mcu_x, mcu_y, mcu_x + win_w - 1, mcu_y + win_h - 1); - // Write all MCU pixels to the TFT window - while (mcu_pixels--) _tft->pushColor(*pImg++); -#endif + { + _tft->pushImage(mcu_x, mcu_y, win_w, win_h, pImg); } else if ( ( mcu_y + win_h) >= _tft->height()) JpegDec.abort(); diff --git a/examples/320 x 240/weather-station-v8/GfxUi.h b/examples/320 x 240/weather-station/GfxUi.h similarity index 100% rename from examples/320 x 240/weather-station-v8/GfxUi.h rename to examples/320 x 240/weather-station/GfxUi.h diff --git a/examples/320 x 240/weather-station-v8/SPIFFS_Support.ino b/examples/320 x 240/weather-station/SPIFFS_Support.ino similarity index 100% rename from examples/320 x 240/weather-station-v8/SPIFFS_Support.ino rename to examples/320 x 240/weather-station/SPIFFS_Support.ino diff --git a/examples/320 x 240/weather-station-v8/WebResource.cpp b/examples/320 x 240/weather-station/WebResource.cpp similarity index 100% rename from examples/320 x 240/weather-station-v8/WebResource.cpp rename to examples/320 x 240/weather-station/WebResource.cpp diff --git a/examples/320 x 240/weather-station-v8/WebResource.h b/examples/320 x 240/weather-station/WebResource.h similarity index 100% rename from examples/320 x 240/weather-station-v8/WebResource.h rename to examples/320 x 240/weather-station/WebResource.h diff --git a/examples/320 x 240/weather-station-v8/settings.h b/examples/320 x 240/weather-station/settings.h similarity index 78% rename from examples/320 x 240/weather-station-v8/settings.h rename to examples/320 x 240/weather-station/settings.h index 4a4618c..d4d97c2 100644 --- a/examples/320 x 240/weather-station-v8/settings.h +++ b/examples/320 x 240/weather-station/settings.h @@ -18,22 +18,30 @@ SOFTWARE. See more at http://blog.squix.ch Adapted by Bodmer to use the faster TFT_ILI9341_ESP library: -https://github.com/Bodmer/TFT_ILI9341_ESP +https://github.com/Bodmer/TFT_eSPI +Version 9 */ +// *************************************************************************************** +// WARNING - READ THIS +// +// 3M Flash Size MUST be allocated to SPIFFS using the IDE Tools menu option or else the +// ESP8266 may crash or do strange things (due to lack of error checks in SPIFFS library?) +// *************************************************************************************** +// // Setup const int UPDATE_INTERVAL_SECS = 10 * 60; // Update every 10 minutes -// Pins for the TFT interface are defined in the User_Config.h file inside the TFT_ILI9341_ESP library +// Pins for the TFT interface are defined in the User_Config.h file inside the TFT_eSPI library // TimeClient settings const float UTC_OFFSET = 1; -// Wunderground Settings, EDIT TO SUIT YOUR LOCATION +// Wunderground Settings, EDIT to suit your Wunderground key and location const boolean IS_METRIC = true; // Temperature only? Wind speed units appear to stay in mph. To do: investigate <<<<<<<<<<<<<<<<<<<<<<<<< -const String WUNDERGRROUND_API_KEY = ""; -//const String WUNDERGRROUND_API_KEY = "1c265fajf48s0a82"; // Random key example showing how the above line should look +//const String WUNDERGRROUND_API_KEY = "WUNDERGROUND KEY HERE"; + const String WUNDERGRROUND_API_KEY = "1c265fajf48s0a82"; // Random key example showing how the above line should look // For language codes see https://www.wunderground.com/weather/api/d/docs?d=language-support&_ga=1.55148395.1951311424.1484425551 const String WUNDERGRROUND_LANGUAGE = "EN"; // Language EN = English @@ -53,8 +61,8 @@ const String WUNDERGROUND_CITY = "Base_Naval"; // City, "London", "FL/Boca_Raton #define WIND_SPEED_UNITS " kph" //Thingspeak Settings - not used, no need to populate this at the moment -const String THINGSPEAK_CHANNEL_ID = ""; -const String THINGSPEAK_API_READ_KEY = ""; +const String THINGSPEAK_CHANNEL_ID = "CHANNEL_ID_HERE"; +const String THINGSPEAK_API_READ_KEY = "API_READ_KEY_HERE"; // List, so that the downloader knows what to fetch String wundergroundIcons [] = {"chanceflurries","chancerain","chancesleet","chancesnow","clear","cloudy","flurries","fog","hazy","mostlycloudy","mostlysunny","partlycloudy","partlysunny","rain","sleet","snow","sunny","tstorms","unknown"}; diff --git a/examples/320 x 240/weather-station-v8/weather-station-v8.ino b/examples/320 x 240/weather-station/weather-station.ino similarity index 99% rename from examples/320 x 240/weather-station-v8/weather-station-v8.ino rename to examples/320 x 240/weather-station/weather-station.ino index 4a84d28..ab3cfad 100644 --- a/examples/320 x 240/weather-station-v8/weather-station-v8.ino +++ b/examples/320 x 240/weather-station/weather-station.ino @@ -30,6 +30,7 @@ New smart WU splash startup screen and updated progress messages Display does not need to be blanked between updates Icons nudged about slightly to add wind direction + speed + Barometric pressure added */ #define SERIAL_MESSAGES