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

@ -359,6 +359,7 @@ void board::start(){
//SDL_RenderClear(_renderer); //SDL_RenderClear(_renderer);
//PLACEHOLDER, cycle color //PLACEHOLDER, cycle color
/*
{ {
static uint8_t red = 0; static uint8_t red = 0;
static bool up = true; static bool up = true;
@ -378,6 +379,7 @@ void board::start(){
red --; red --;
} }
} }
*/
//END PLACEHOLDER //END PLACEHOLDER

View File

@ -119,5 +119,8 @@ struct FONT_SIZE_STRING {
const FONT_SIZE _font_size; const FONT_SIZE _font_size;
}; };
static const FONT_SIZE_STRING CONST_STRINGS[] = { 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 } },
}; };

View File

@ -18,6 +18,7 @@ int main(int argc, char** argv){
if(_board.init() != 0){ if(_board.init() != 0){
std::cerr << "Due to errors, " << argv[0] std::cerr << "Due to errors, " << argv[0]
<< " was unable to start, quitting!" << std::endl; << " was unable to start, quitting!" << std::endl;
return -1;
} }
_board.start(); _board.start();

View File

@ -5,6 +5,7 @@
// //
#include "weather.hpp" #include "weather.hpp"
#include "weather_config.hpp"
using namespace dashboard::panel; using namespace dashboard::panel;
@ -16,6 +17,9 @@ weather::weather(){
_time_on_screen = WEATHER_DEFAULT_ON_SCREEN_TIME; _time_on_screen = WEATHER_DEFAULT_ON_SCREEN_TIME;
_update_interval = std::chrono::milliseconds{UPDATE_INTERVAL}; _update_interval = std::chrono::milliseconds{UPDATE_INTERVAL};
_last_update = std::chrono::high_resolution_clock::now(); _last_update = std::chrono::high_resolution_clock::now();
_rss = rss_utils::rss(WEATHER_URL_SOURCE);
update();
} }
weather::~weather(){ weather::~weather(){
@ -27,15 +31,32 @@ weather::~weather(){
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
void weather::draw(){ void weather::draw(){
std::cerr << "WEATHER DRAW FUNC\n";
std::cerr << "url_source : " << WEATHER_URL_SOURCE << "\n";
//check if its time to update //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 //TODO multithread this
update(); 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(); _last_update = std::chrono::high_resolution_clock::now();
//fetch updates //fetch updates
_rss.update();
} }

View File

@ -8,8 +8,8 @@
#include "panel.hpp" #include "panel.hpp"
#include "weather_config.hpp"
#include <chrono> #include <chrono>
#include "../util/rss.hpp"
#include <SDL.h> #include <SDL.h>
#include <SDL2/SDL_image.h> #include <SDL2/SDL_image.h>
@ -26,8 +26,12 @@ namespace dashboard::panel {
void draw(); void draw();
private: private:
void update();
rss_utils::rss _rss;
std::chrono::time_point<std::chrono::high_resolution_clock> _last_update; std::chrono::time_point<std::chrono::high_resolution_clock> _last_update;
std::chrono::milliseconds _update_interval; 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 //How long should we wait between updates? in ms
//Default 1 hour //Default 1 hour
constexpr int UPDATE_INTERVAL = 3600000; constexpr size_t UPDATE_INTERVAL = 3600000;
} }