Add panel boilerplate and weather boilerplate
This commit is contained in:
parent
fdd40d31cc
commit
f3409daff9
@ -370,12 +370,64 @@ int board::init(){
|
|||||||
// This is where most of the logic lives
|
// This is where most of the logic lives
|
||||||
void board::start(){
|
void board::start(){
|
||||||
initConstResources();
|
initConstResources();
|
||||||
|
//get Panel size
|
||||||
|
const size_t panel_count = sizeof(PANELS) / sizeof(PANELS[0]);
|
||||||
|
size_t i = 0;
|
||||||
|
|
||||||
|
//timing, for dealing with framerates
|
||||||
|
auto start = std::chrono::high_resolution_clock::now();
|
||||||
|
static const std::chrono::nanoseconds s{1000000000};
|
||||||
|
|
||||||
|
//frame counter
|
||||||
|
static unsigned long long int fcount = 0;
|
||||||
|
|
||||||
SDL_Log("Starting main loop...\n");
|
SDL_Log("Starting main loop...\n");
|
||||||
for(;;){
|
for(;;){
|
||||||
|
start = std::chrono::high_resolution_clock::now();
|
||||||
|
fcount++;
|
||||||
|
|
||||||
|
//check if we can loop back over
|
||||||
|
if(i > panel_count)
|
||||||
|
i = 0;
|
||||||
|
|
||||||
|
//SDL_RenderClear(_renderer);
|
||||||
|
|
||||||
|
//PLACEHOLDER, cycle color
|
||||||
|
{
|
||||||
|
static uint8_t red = 0;
|
||||||
|
static bool up = true;
|
||||||
|
|
||||||
|
SDL_SetRenderDrawColor(_renderer, red,
|
||||||
|
BOARD_GREEN, BOARD_BLUE, SDL_ALPHA_OPAQUE);
|
||||||
|
|
||||||
|
SDL_RenderClear(_renderer);
|
||||||
|
|
||||||
|
if(up){
|
||||||
|
if(red == 254)
|
||||||
|
up = false;
|
||||||
|
red++;
|
||||||
|
} else {
|
||||||
|
if(red == 1)
|
||||||
|
up = true;
|
||||||
|
red --;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//END PLACEHOLDER
|
||||||
|
|
||||||
|
|
||||||
|
//call draw on the current panel
|
||||||
|
PANELS[i]->draw();
|
||||||
|
|
||||||
|
std::cerr << "Current frame: " << fcount << "\n";
|
||||||
|
|
||||||
|
SDL_RenderPresent(_renderer);
|
||||||
|
|
||||||
|
|
||||||
|
//wait for frame
|
||||||
|
std::this_thread::sleep_for((s / MAX_FRAMERATE) -
|
||||||
|
std::chrono::duration_cast<std::chrono::nanoseconds>(
|
||||||
|
std::chrono::high_resolution_clock::now() - start));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////
|
///////////////////////////////////////
|
||||||
|
@ -9,10 +9,13 @@
|
|||||||
#include "config.hpp"
|
#include "config.hpp"
|
||||||
|
|
||||||
#include "util/lru.hpp"
|
#include "util/lru.hpp"
|
||||||
|
#include "panel/panel.hpp"
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <chrono>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
#include <SDL2/SDL_image.h>
|
#include <SDL2/SDL_image.h>
|
||||||
@ -29,7 +32,6 @@ namespace dashboard {
|
|||||||
bool operator< (const font_and_size&) const;
|
bool operator< (const font_and_size&) const;
|
||||||
bool operator>=(const font_and_size&) const;
|
bool operator>=(const font_and_size&) const;
|
||||||
bool operator<=(const font_and_size&) const;
|
bool operator<=(const font_and_size&) const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct string_and_font {
|
struct string_and_font {
|
||||||
@ -126,7 +128,6 @@ namespace dashboard {
|
|||||||
SDL_Texture* setImage (const std::string&);
|
SDL_Texture* setImage (const std::string&);
|
||||||
TTF_Font* setFont (const font_and_size&);
|
TTF_Font* setFont (const font_and_size&);
|
||||||
|
|
||||||
//TODO make set* functions that accept SDL_*_Wrapper objects
|
|
||||||
SDL_Texture* setString(const string_and_font&, const SDL_Texture_Wrapper&);
|
SDL_Texture* setString(const string_and_font&, const SDL_Texture_Wrapper&);
|
||||||
SDL_Texture* setImage (const std::string&, const SDL_Texture_Wrapper&);
|
SDL_Texture* setImage (const std::string&, const SDL_Texture_Wrapper&);
|
||||||
TTF_Font* setFont (const font_and_size&, const SDL_Font_Wrapper&);
|
TTF_Font* setFont (const font_and_size&, const SDL_Font_Wrapper&);
|
||||||
@ -138,11 +139,12 @@ namespace dashboard {
|
|||||||
inline static std::unordered_map<string_and_font, SDL_Texture_Wrapper,
|
inline static std::unordered_map<string_and_font, SDL_Texture_Wrapper,
|
||||||
string_and_font_hash> _strings;
|
string_and_font_hash> _strings;
|
||||||
|
|
||||||
static clortox::LRUCache<string_and_font,
|
inline static clortox::LRUCache<string_and_font,
|
||||||
SDL_Texture_Wrapper, string_and_font_hash> _dynamic_strings;
|
SDL_Texture_Wrapper, string_and_font_hash> _dynamic_strings;
|
||||||
|
|
||||||
//TODO: Dynamic images?
|
//TODO: Dynamic images?
|
||||||
//TODO: Dynamic Fonts?
|
//TODO: Dynamic Fonts?
|
||||||
|
|
||||||
|
|
||||||
//local pointers to the globals
|
//local pointers to the globals
|
||||||
SDL_Window* _window;
|
SDL_Window* _window;
|
||||||
|
@ -71,6 +71,16 @@ constexpr int IMG_FLAGS = 0
|
|||||||
//| IMG_INIT_TIF
|
//| IMG_INIT_TIF
|
||||||
;
|
;
|
||||||
|
|
||||||
|
// PANELS
|
||||||
|
// A list of all panels to be displayed, in order
|
||||||
|
// Be sure to include the panel definition below, then add it to the system
|
||||||
|
#include "panel/panel.hpp"
|
||||||
|
#include "panel/weather.hpp"
|
||||||
|
static dashboard::panel::panel* PANELS[] = {
|
||||||
|
new dashboard::panel::weather(),
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
// DATA_DIR
|
// DATA_DIR
|
||||||
// Where all resources will be
|
// Where all resources will be
|
||||||
// Keep this as DATA to use the install dir set in the makefile
|
// Keep this as DATA to use the install dir set in the makefile
|
||||||
@ -81,9 +91,6 @@ constexpr char DATA_DIR[] = DATA_ ;
|
|||||||
// Keep this a DATA_IMG_ to use the DATA_IMG dir defined in the makefile
|
// Keep this a DATA_IMG_ to use the DATA_IMG dir defined in the makefile
|
||||||
constexpr char DATA_IMG[] = DATA_IMG_;
|
constexpr char DATA_IMG[] = DATA_IMG_;
|
||||||
|
|
||||||
//TODO: Add directory prefix for each of these, and change it so it doesnt use
|
|
||||||
//that whole path as the key for the file
|
|
||||||
|
|
||||||
// IMAGE_LOCATIONS
|
// IMAGE_LOCATIONS
|
||||||
// Locations of all static images used
|
// Locations of all static images used
|
||||||
static const char* IMAGE_LOCATIONS[] = {
|
static const char* IMAGE_LOCATIONS[] = {
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
#include <SDL2/SDL_image.h>
|
#include <SDL2/SDL_image.h>
|
||||||
#include <SDL2/SDL_ttf.h>
|
#include <SDL2/SDL_ttf.h>
|
||||||
|
|
||||||
namespace dashboard {
|
namespace dashboard::panel {
|
||||||
class panel {
|
class panel {
|
||||||
public:
|
public:
|
||||||
panel() = default;
|
panel() = default;
|
||||||
|
50
src/panel/weather.cpp
Normal file
50
src/panel/weather.cpp
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Tyler Perkins
|
||||||
|
// 19-9-21
|
||||||
|
// weather panel
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "weather.hpp"
|
||||||
|
|
||||||
|
using namespace dashboard::panel;
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Constructors ///////////////////////////////////////////////////////////////
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
weather::~weather(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Draw function //////////////////////////////////////////////////////////////
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
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){
|
||||||
|
//TODO multithread this
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Helper functions ///////////////////////////////////////////////////////////
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
void weather::update() {
|
||||||
|
std::cerr << "WEATHER::UPDATE\n";
|
||||||
|
_last_update = std::chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
|
//fetch updates
|
||||||
|
}
|
33
src/panel/weather.hpp
Normal file
33
src/panel/weather.hpp
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Tyler Perkins
|
||||||
|
// 19-9-21
|
||||||
|
// weather panel
|
||||||
|
//
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "panel.hpp"
|
||||||
|
|
||||||
|
#include "weather_config.hpp"
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
|
#include <SDL.h>
|
||||||
|
#include <SDL2/SDL_image.h>
|
||||||
|
#include <SDL2/SDL_ttf.h>
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
namespace dashboard::panel {
|
||||||
|
class weather : public panel {
|
||||||
|
public:
|
||||||
|
weather();
|
||||||
|
~weather();
|
||||||
|
|
||||||
|
void draw();
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::chrono::time_point<std::chrono::high_resolution_clock> _last_update;
|
||||||
|
std::chrono::milliseconds _update_interval;
|
||||||
|
void update();
|
||||||
|
};
|
||||||
|
}
|
21
src/panel/weather_config.hpp
Normal file
21
src/panel/weather_config.hpp
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Tyler Perkins
|
||||||
|
// 19-9-21
|
||||||
|
// weather panel configuration
|
||||||
|
//
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace dashboard::panel {
|
||||||
|
//New York RSS feed
|
||||||
|
static const char* WEATHER_URL_SOURCE = "http://rss.accuweather.com/rss/liveweather_rss.asp?locCode=10007";
|
||||||
|
|
||||||
|
//Default time the slide is shown on screen, in ms
|
||||||
|
//Default 5s
|
||||||
|
constexpr size_t WEATHER_DEFAULT_ON_SCREEN_TIME = 5000;
|
||||||
|
|
||||||
|
//How long should we wait between updates? in ms
|
||||||
|
//Default 1 hour
|
||||||
|
constexpr int UPDATE_INTERVAL = 3600000;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user