Networked text loading 1

This commit is contained in:
Tyler Perkins
2021-09-19 18:23:02 -04:00
parent bed1a1474c
commit aed9bbc35d
6 changed files with 41 additions and 9 deletions

View File

@@ -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();
}

View File

@@ -8,8 +8,8 @@
#include "panel.hpp"
#include "weather_config.hpp"
#include <chrono>
#include "../util/rss.hpp"
#include <SDL.h>
#include <SDL2/SDL_image.h>
@@ -26,8 +26,12 @@ namespace dashboard::panel {
void draw();
private:
void update();
rss_utils::rss _rss;
std::chrono::time_point<std::chrono::high_resolution_clock> _last_update;
std::chrono::milliseconds _update_interval;
void update();
};
}
#include "../board.hpp"

View File

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