From 529e2a53ef858d5398757920a627b36c3b597e49 Mon Sep 17 00:00:00 2001 From: Thomas Ballmann Date: Sun, 8 Mar 2020 18:07:37 +0100 Subject: [PATCH] basic implementation done #16 --- data/calendarPhoto.json | 1 + include/faceCalendar.h | 1 + include/faceWeather.h | 2 + src/faceCalendar.cpp | 93 ++++++++++++++++++++++++++++++++++------- 4 files changed, 81 insertions(+), 16 deletions(-) create mode 100644 data/calendarPhoto.json diff --git a/data/calendarPhoto.json b/data/calendarPhoto.json new file mode 100644 index 0000000..cc5d9fb --- /dev/null +++ b/data/calendarPhoto.json @@ -0,0 +1 @@ +{"id":"skdmXL-OnFA","created_at":"2020-02-20T14:10:50-05:00","updated_at":"2020-03-07T00:04:37-05:00","promoted_at":"2020-02-21T04:57:02-05:00","width":3648,"height":5472,"color":"#DCDDDD","description":"Rio de Janeiro","alt_description":"brown wooden hallway with white walls","urls":{"raw":"https://images.unsplash.com/photo-1582225764554-a82806fe9f30?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjExMDM0OH0","full":"https://images.unsplash.com/photo-1582225764554-a82806fe9f30?ixlib=rb-1.2.1&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjExMDM0OH0","regular":"https://images.unsplash.com/photo-1582225764554-a82806fe9f30?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=1080&fit=max&ixid=eyJhcHBfaWQiOjExMDM0OH0","small":"https://images.unsplash.com/photo-1582225764554-a82806fe9f30?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjExMDM0OH0","thumb":"https://images.unsplash.com/photo-1582225764554-a82806fe9f30?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=200&fit=max&ixid=eyJhcHBfaWQiOjExMDM0OH0"},"links":{"self":"https://api.unsplash.com/photos/skdmXL-OnFA","html":"https://unsplash.com/photos/skdmXL-OnFA","download":"https://unsplash.com/photos/skdmXL-OnFA/download","download_location":"https://api.unsplash.com/photos/skdmXL-OnFA/download"},"categories":[],"likes":89,"liked_by_user":false,"current_user_collections":[],"user":{"id":"uFFemR6e1vs","updated_at":"2020-03-08T10:32:04-04:00","username":"tiomp","name":"Marcos Paulo Prado","first_name":"Marcos Paulo","last_name":"Prado","twitter_username":null,"portfolio_url":"http://bit.ly/2sEQFpE","bio":"CHECK MY INSTAGRAM LINK ABOVE FOR MORE CONTENT AND PHOTOGRAPHY HACKS","location":"Toronto","links":{"self":"https://api.unsplash.com/users/tiomp","html":"https://unsplash.com/@tiomp","photos":"https://api.unsplash.com/users/tiomp/photos","likes":"https://api.unsplash.com/users/tiomp/likes","portfolio":"https://api.unsplash.com/users/tiomp/portfolio","following":"https://api.unsplash.com/users/tiomp/following","followers":"https://api.unsplash.com/users/tiomp/followers"},"profile_image":{"small":"https://images.unsplash.com/profile-1572910425876-25d44d080554image?ixlib=rb-1.2.1&q=80&fm=jpg&crop=faces&cs=tinysrgb&fit=crop&h=32&w=32","medium":"https://images.unsplash.com/profile-1572910425876-25d44d080554image?ixlib=rb-1.2.1&q=80&fm=jpg&crop=faces&cs=tinysrgb&fit=crop&h=64&w=64","large":"https://images.unsplash.com/profile-1572910425876-25d44d080554image?ixlib=rb-1.2.1&q=80&fm=jpg&crop=faces&cs=tinysrgb&fit=crop&h=128&w=128"},"instagram_username":"tio.mp","total_collections":0,"total_likes":233,"total_photos":254,"accepted_tos":true},"exif":{"make":"Canon","model":"Canon EOS 6D","exposure_time":"1/100","aperture":"4","focal_length":"28.0","iso":160},"location":{"title":"Rio de Janeiro, RJ, Brasil","name":"Rio de Janeiro, RJ, Brasil","city":"Rio de Janeiro","country":"Brasil","position":{"latitude":-22.9068467,"longitude":-43.1728965}},"views":374852,"downloads":895} \ No newline at end of file diff --git a/include/faceCalendar.h b/include/faceCalendar.h index a430a5d..e868d01 100644 --- a/include/faceCalendar.h +++ b/include/faceCalendar.h @@ -4,5 +4,6 @@ void setupFaceCalendar(); void loopFaceCalendar(); +bool updateCalendarData(); #endif \ No newline at end of file diff --git a/include/faceWeather.h b/include/faceWeather.h index 1056ef9..a20b298 100644 --- a/include/faceWeather.h +++ b/include/faceWeather.h @@ -33,6 +33,8 @@ struct faceWeatherData int forecast_4_max; }; +extern faceWeatherData weatherData; + void setupFaceWeather(); void loopFaceWeather(); diff --git a/src/faceCalendar.cpp b/src/faceCalendar.cpp index 8ec8eb3..db925f6 100644 --- a/src/faceCalendar.cpp +++ b/src/faceCalendar.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include "faceCalendar.h" #include "display.h" @@ -7,20 +8,25 @@ #include "tools.h" #include "image.h" #include "download.h" +#include "faceWeather.h" +#include "faceWeatherIcons.h" #include // weekday - month year +#include // current day #include // current day -void downloadRandomePicture(); +bool downloadRandomePicture(); void showFaceCalendar(); void display_calender(); void display_picture(); void display_time(); +const char faceCalendarPicutreJson[] = "/calendarPhoto.json"; const char faceCalendarPicture[] = "/calendarPhoto.png"; void setupFaceCalendar() { + downloadRandomePicture(); } void loopFaceCalendar() @@ -42,25 +48,67 @@ void showFaceCalendar() displayFlush(); } -void downloadRandomePicture() +bool downloadRandomePicture() { - // https://images.unsplash.com/photo-1580886349729-1bd109928600?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjExMDM0OH0&w=640&h=200&fm=png&fit=crop - // https://images.unsplash.com/photo-1580886349729-1bd109928600?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjExMDM0OH0&w=390&h=384&fm=png&fit=crop&colorquant=2 - // https://images.unsplash.com/photo-1581307385098-a0338263e357?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjExMDM0OH0&w=640&h=384&fm=png&fit=crop&duotone=000000,FFFFFF - // final filter: &w=390&h=384&fm=png&fit=crop&duotone=000000,FFFFFF - Serial.println("TODO download new image"); + // download json file + Serial.println(" download json"); + String randomUrl = "https://api.unsplash.com/photos/random"; + randomUrl += "&client_id=6cb16f348161f1c3e6bf21172c398893beec2d8d3ccf740bff4e72feac507422"; - // TODO download json file + if (true) // downloadFile(randomUrl, faceCalendarPicutreJson) + { + Serial.println(" read json"); + + File file = SPIFFS.open(faceCalendarPicutreJson); + if (!file) + { + Serial.print("Failed to open file: "); + Serial.println(faceCalendarPicutreJson); + + return false; + } + + StaticJsonDocument<5000> docPicutre; // Use arduinojson.org/v6/assistant to compute the capacity. + DeserializationError error = deserializeJson(docPicutre, file); + file.close(); + if (error) + { + Serial.print("Failed to read file: "); + Serial.println(faceCalendarPicutreJson); + + Serial.println(error.c_str()); + + return false; + } + + //String pictureUrl = "https://images.unsplash.com/photo-1582910587039-b4f085805c86?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjExMDM0OH0"; + String pictureUrl = docPicutre["urls"]["raw"]; + pictureUrl += "&w=390&h=384"; // size + pictureUrl += "&fm=png"; // format + pictureUrl += "&fit=crop"; // crop to needed size + pictureUrl += "&duotone=000000,FFFFFF"; // grayscale to save bytes + + //downloadFile(pictureUrl, faceCalendarPicture); - String pictureUrl = "https://images.unsplash.com/photo-1582910587039-b4f085805c86?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjExMDM0OH0"; - pictureUrl += "&w=390&h=384"; // size - pictureUrl += "&fm=png"; // format - pictureUrl += "&fit=crop"; // crop to needed size - pictureUrl += "&duotone=000000,FFFFFF"; // grayscale to save bytes + return true; + } + + return false; +} + +/** + * download and update calendar data + */ +bool updateCalendarData() +{ + if (downloadRandomePicture()) + { + //readWeatherData(); - downloadFile(pictureUrl, faceCalendarPicture); // /face/calendar/bg.png + return true; + } - Serial.println("TODO download new image ---- done"); + return false; } void display_calender() @@ -127,8 +175,21 @@ void display_calender() } } - // TODO current weather + // current weather display.drawLine(15, 320, sideWidth - 15, 320, GxEPD_WHITE); + + // icon + const unsigned char *icon = getIconById(weatherData.current_icon, 64); + if (icon) + { + display.drawInvertedBitmap(72, 325, icon, 64, 64, GxEPD_WHITE); + } + + // temperature + display.setFont(&FreeSans24pt7b); + display.setTextSize(1); + display.setCursor(150, 367); + display.println(weatherData.current_temp); } void display_picture()