diff --git a/README.md b/README.md index cbac9d3..78f06ee 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,9 @@ Depends on optional dependencies --------------------- -- rapidxml -- libcurl +- Weather/RSS + - rapidxml + - libcurl Building sdl2 on rpi -------------------- diff --git a/img/rainy.png b/img/rainy.png new file mode 100644 index 0000000..c1f1b80 Binary files /dev/null and b/img/rainy.png differ diff --git a/img/sunny.png b/img/sunny.png new file mode 100644 index 0000000..033a92e Binary files /dev/null and b/img/sunny.png differ diff --git a/src/board.cpp b/src/board.cpp index 72740a6..e8e618a 100644 --- a/src/board.cpp +++ b/src/board.cpp @@ -337,7 +337,6 @@ int board::init(){ void board::start(){ initConstResources(); //get Panel size - const size_t panel_count = sizeof(PANELS) / sizeof(PANELS[0]); size_t i = 0; //timing, for dealing with framerates @@ -353,13 +352,12 @@ void board::start(){ fcount++; //check if we can loop back over - if(i > panel_count) + if(i > PANELS_LENGTH) i = 0; - //SDL_RenderClear(_renderer); + SDL_RenderClear(_renderer); //PLACEHOLDER, cycle color - /* { static uint8_t red = 0; static bool up = true; @@ -379,12 +377,11 @@ void board::start(){ red --; } } - */ //END PLACEHOLDER //call draw on the current panel - PANELS[i]->draw(); + //PANELS[i]->draw(); if(fcount % 10 == 0) std::cerr << "Frame : " << fcount << "\n"; @@ -416,7 +413,7 @@ void board::initConstResources(){ SDL_Log("Static images directory prefix: %s\n", fullPath.c_str()); SDL_Log("Loading static images into working memory...\n"); for(unsigned int i = 0; - i < (sizeof(IMAGE_LOCATIONS)/sizeof(IMAGE_LOCATIONS[0])); ++i){ + i < IMAGE_LOCATIONS_LENGTH; ++i){ SDL_Texture_Wrapper tw(fullPath + IMAGE_LOCATIONS[0]); @@ -434,7 +431,7 @@ void board::initConstResources(){ SDL_Log("Static Fonts directory prefix: %s\n", fullPath.c_str()); SDL_Log("Loading fonts into working memory...\n"); for(unsigned int i = 0; - i < (sizeof(FONT_LOCATIONS)/sizeof(FONT_LOCATIONS[0])); ++i){ + i < FONT_LOCATIONS_LENGTH; ++i){ SDL_Font_Wrapper fw(fullPath + FONT_LOCATIONS[0]._name, FONT_LOCATIONS[0]._size); @@ -449,7 +446,7 @@ void board::initConstResources(){ std::cerr << "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n"; SDL_Log("Loading static strings into working memory...\n"); for(unsigned int i = 0; - i < (sizeof(CONST_STRINGS)/sizeof(CONST_STRINGS[0])); ++i){ + i < CONST_STRINGS_LENGTH; ++i){ SDL_Texture_Wrapper tw(CONST_STRINGS[i]._text, { CONST_STRINGS[i]._font_size._name, diff --git a/src/config.cpp b/src/config.cpp new file mode 100644 index 0000000..25c2b35 --- /dev/null +++ b/src/config.cpp @@ -0,0 +1,49 @@ +/////////////////////////////////////////////////////////////////////////////// +// Tyler Perkins +// 9-29-21 +// configuration file +// + +#include "config.hpp" + +// PANELS +// A list of all panels to be displayed, in order +dashboard::panel::panel* PANELS[] = { + new dashboard::panel::weather(), +}; +size_t PANELS_LENGTH = sizeof(PANELS)/sizeof(PANELS[0]); + +// IMAGE_LOCATIONS +// Locations of all static images used +const char* IMAGE_LOCATIONS[] = { + "bmp_24.png", + //Weather + "sunny.png", + "rainy.png", +}; +size_t IMAGE_LOCATIONS_LENGTH = sizeof(IMAGE_LOCATIONS)/sizeof(IMAGE_LOCATIONS[0]); + +// FONT_LOCATIONS +// Locations of all fonts used +//struct FONT_SIZE { +// const char* _name; +// const size_t _size; +//}; +const FONT_SIZE FONT_LOCATIONS[] = { + { "Roboto_Mono/RobotoMono-Medium.ttf", 24 }, +}; +size_t FONT_LOCATIONS_LENGTH = sizeof(FONT_LOCATIONS)/sizeof(FONT_LOCATIONS[0]); + +// CONST_STRINGS +// All constant strings +//struct FONT_SIZE_STRING { +// const char* _text; +// const FONT_SIZE _font_size; +//}; +const FONT_SIZE_STRING CONST_STRINGS[] = { + //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 } }, +}; +size_t CONST_STRINGS_LENGTH = sizeof(CONST_STRINGS)/sizeof(CONST_STRINGS[0]); diff --git a/src/config.def.hpp b/src/config.def.hpp index 178465c..82f1a8c 100644 --- a/src/config.def.hpp +++ b/src/config.def.hpp @@ -95,6 +95,9 @@ constexpr char DATA_IMG[] = DATA_IMG_; // Locations of all static images used static const char* IMAGE_LOCATIONS[] = { "bmp_24.png", + //Weather + "sunny.png", + "rainy.png", }; // FONT_DIR diff --git a/src/panel/panel.hpp b/src/panel/panel.hpp index b1dee5b..c63eec5 100644 --- a/src/panel/panel.hpp +++ b/src/panel/panel.hpp @@ -26,5 +26,8 @@ namespace dashboard::panel { virtual void draw() = 0; size_t _time_on_screen = 0; + + protected: + SDL_Texture* _texture; }; } diff --git a/src/panel/weather.cpp b/src/panel/weather.cpp index c16cf63..8f850c7 100644 --- a/src/panel/weather.cpp +++ b/src/panel/weather.cpp @@ -14,16 +14,22 @@ using namespace dashboard::panel; /////////////////////////////////////////////////////////////////////////////// weather::weather(){ + std::cerr << "WEATHER CONSTRUCTOR\n"; _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); + _texture = SDL_CreateTexture(board::getRenderer(), + SDL_PIXELFORMAT_RGBA8888, + SDL_TEXTUREACCESS_TARGET, + SCREEN_WIDTH, SCREEN_HEIGHT); + update(); } weather::~weather(){ - + std::cerr << "WEATHER DECONSTRUCTOR\n"; } /////////////////////////////////////////////////////////////////////////////// @@ -36,10 +42,42 @@ void weather::draw(){ > _update_interval){ //TODO multithread this update(); + + update_texture(); } - //TODO add this all to one canvas thing? - //BEGIN GRAPHICS + static SDL_Rect tgt = { 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT }; + + //SDL_RenderCopy(board::getRenderer(), _texture, NULL, + //&tgt); + + //TODO add this all to one texture + +} + +/////////////////////////////////////////////////////////////////////////////// +// Helper functions /////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// + +/////////////////////////////////////// +// Update the information of the obj +// This DOES NOT update the display +void weather::update() { + std::cerr << "WEATHER::UPDATE\n"; + _last_update = std::chrono::high_resolution_clock::now(); + + //fetch updates + _rss.update(); + +} + +/////////////////////////////////////// +// Update the texture that is being +// displayed, based on data in +// _rss +void weather::update_texture(){ + //SDL_SetRenderTarget(board::getRenderer(), _texture); + SDL_Rect tgt; tgt.x = 50; tgt.y = 50; @@ -51,23 +89,5 @@ void weather::draw(){ board::getString(_rss.getTitle(), { "Roboto_Mono/RobotoMono-Medium.ttf", 24 }), NULL, &tgt ); - - - //END GRAPHICS - - SDL_RenderPresent(board::getRenderer()); - -} - -/////////////////////////////////////////////////////////////////////////////// -// Helper functions /////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// - -void weather::update() { - std::cerr << "WEATHER::UPDATE\n"; - _last_update = std::chrono::high_resolution_clock::now(); - - //fetch updates - _rss.update(); - + //SDL_SetRenderTarget(board::getRenderer(), NULL); } diff --git a/src/panel/weather.hpp b/src/panel/weather.hpp index c01a4b3..d25f52d 100644 --- a/src/panel/weather.hpp +++ b/src/panel/weather.hpp @@ -27,6 +27,7 @@ namespace dashboard::panel { private: void update(); + void update_texture(); rss_utils::rss _rss; std::chrono::time_point _last_update;