basic implementation done #16

pull/1/head
Thomas Ballmann 4 years ago
parent cffb1fdab5
commit 529e2a53ef

@ -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}

@ -4,5 +4,6 @@
void setupFaceCalendar();
void loopFaceCalendar();
bool updateCalendarData();
#endif

@ -33,6 +33,8 @@ struct faceWeatherData
int forecast_4_max;
};
extern faceWeatherData weatherData;
void setupFaceWeather();
void loopFaceWeather();

@ -1,5 +1,6 @@
#include <HTTPClient.h>
#include <SPIFFS.h>
#include <ArduinoJson.h>
#include <pngle.h>
#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 <Fonts/FreeMono12pt7b.h> // weekday - month year
#include <Fonts/FreeSans24pt7b.h> // current day
#include <Fonts/FreeSansBold24pt7b.h> // 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()

Loading…
Cancel
Save