Update configs to allocate correctly

This commit is contained in:
Tyler Perkins 2021-10-02 14:14:58 -04:00
parent aed9bbc35d
commit 51b9e6401f
9 changed files with 107 additions and 33 deletions

View File

@ -24,6 +24,7 @@ Depends on
optional dependencies
---------------------
- Weather/RSS
- rapidxml
- libcurl

BIN
img/rainy.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

BIN
img/sunny.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

View File

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

49
src/config.cpp Normal file
View File

@ -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]);

View File

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

View File

@ -26,5 +26,8 @@ namespace dashboard::panel {
virtual void draw() = 0;
size_t _time_on_screen = 0;
protected:
SDL_Texture* _texture;
};
}

View File

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

View File

@ -27,6 +27,7 @@ namespace dashboard::panel {
private:
void update();
void update_texture();
rss_utils::rss _rss;
std::chrono::time_point<std::chrono::high_resolution_clock> _last_update;