From aed9bbc35d28c42174dbcfa12f49bf33543cab3f Mon Sep 17 00:00:00 2001 From: Tyler Perkins Date: Sun, 19 Sep 2021 18:23:02 -0400 Subject: [PATCH] Networked text loading 1 --- src/board.cpp | 2 ++ src/config.def.hpp | 5 ++++- src/main.cpp | 1 + src/panel/weather.cpp | 31 +++++++++++++++++++++++++++---- src/panel/weather.hpp | 8 ++++++-- src/panel/weather_config.hpp | 3 +-- 6 files changed, 41 insertions(+), 9 deletions(-) diff --git a/src/board.cpp b/src/board.cpp index 676620e..72740a6 100644 --- a/src/board.cpp +++ b/src/board.cpp @@ -359,6 +359,7 @@ void board::start(){ //SDL_RenderClear(_renderer); //PLACEHOLDER, cycle color + /* { static uint8_t red = 0; static bool up = true; @@ -378,6 +379,7 @@ void board::start(){ red --; } } + */ //END PLACEHOLDER diff --git a/src/config.def.hpp b/src/config.def.hpp index 787fbd2..178465c 100644 --- a/src/config.def.hpp +++ b/src/config.def.hpp @@ -119,5 +119,8 @@ struct FONT_SIZE_STRING { const FONT_SIZE _font_size; }; static const FONT_SIZE_STRING CONST_STRINGS[] = { - { "Test string 12345", { "Roboto_Mono/RobotoMono-Medium.ttf", 24 } }, + //Weather strings + { "Today's Weather", { "Roboto_Mono/RobotoMono-Medium.ttf", 24 } }, + { "Sunny" , { "Roboto_Mono/RobotoMono-Medium.ttf", 24 } }, + { "Rainy" , { "Roboto_Mono/RobotoMono-Medium.ttf", 24 } }, }; diff --git a/src/main.cpp b/src/main.cpp index c920780..5da5d42 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,6 +18,7 @@ int main(int argc, char** argv){ if(_board.init() != 0){ std::cerr << "Due to errors, " << argv[0] << " was unable to start, quitting!" << std::endl; + return -1; } _board.start(); diff --git a/src/panel/weather.cpp b/src/panel/weather.cpp index 005a654..c16cf63 100644 --- a/src/panel/weather.cpp +++ b/src/panel/weather.cpp @@ -5,6 +5,7 @@ // #include "weather.hpp" +#include "weather_config.hpp" using namespace dashboard::panel; @@ -16,6 +17,9 @@ weather::weather(){ _time_on_screen = WEATHER_DEFAULT_ON_SCREEN_TIME; _update_interval = std::chrono::milliseconds{UPDATE_INTERVAL}; _last_update = std::chrono::high_resolution_clock::now(); + _rss = rss_utils::rss(WEATHER_URL_SOURCE); + + update(); } weather::~weather(){ @@ -27,15 +31,32 @@ weather::~weather(){ /////////////////////////////////////////////////////////////////////////////// void weather::draw(){ - std::cerr << "WEATHER DRAW FUNC\n"; - std::cerr << "url_source : " << WEATHER_URL_SOURCE << "\n"; - //check if its time to update - if((std::chrono::high_resolution_clock::now() - _last_update) > _update_interval){ + if((std::chrono::high_resolution_clock::now() - _last_update) + > _update_interval){ //TODO multithread this update(); } + //TODO add this all to one canvas thing? + //BEGIN GRAPHICS + SDL_Rect tgt; + tgt.x = 50; + tgt.y = 50; + TTF_SizeText(board::getFont({ "Roboto_Mono/RobotoMono-Medium.ttf", 24 }), + _rss.getTitle().c_str(), + &tgt.w, &tgt.h); + + SDL_RenderCopy(board::getRenderer(), + board::getString(_rss.getTitle(), + { "Roboto_Mono/RobotoMono-Medium.ttf", 24 }), NULL, &tgt ); + + + + //END GRAPHICS + + SDL_RenderPresent(board::getRenderer()); + } /////////////////////////////////////////////////////////////////////////////// @@ -47,4 +68,6 @@ void weather::update() { _last_update = std::chrono::high_resolution_clock::now(); //fetch updates + _rss.update(); + } diff --git a/src/panel/weather.hpp b/src/panel/weather.hpp index 8a0d914..c01a4b3 100644 --- a/src/panel/weather.hpp +++ b/src/panel/weather.hpp @@ -8,8 +8,8 @@ #include "panel.hpp" -#include "weather_config.hpp" #include +#include "../util/rss.hpp" #include #include @@ -26,8 +26,12 @@ namespace dashboard::panel { void draw(); private: + void update(); + + rss_utils::rss _rss; std::chrono::time_point _last_update; std::chrono::milliseconds _update_interval; - void update(); }; } + +#include "../board.hpp" diff --git a/src/panel/weather_config.hpp b/src/panel/weather_config.hpp index 7045848..35aa03b 100644 --- a/src/panel/weather_config.hpp +++ b/src/panel/weather_config.hpp @@ -16,6 +16,5 @@ namespace dashboard::panel { //How long should we wait between updates? in ms //Default 1 hour - constexpr int UPDATE_INTERVAL = 3600000; + constexpr size_t UPDATE_INTERVAL = 3600000; } -