Add panel boilerplate and weather boilerplate

This commit is contained in:
Tyler Perkins
2021-09-19 17:16:59 -04:00
parent fdd40d31cc
commit f3409daff9
7 changed files with 174 additions and 9 deletions

View File

@@ -17,7 +17,7 @@
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_ttf.h>
namespace dashboard {
namespace dashboard::panel {
class panel {
public:
panel() = default;

50
src/panel/weather.cpp Normal file
View 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
View 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();
};
}

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