Make date string configurable

This commit is contained in:
Tyler Perkins 2021-12-21 16:47:35 -05:00
parent 14cf97ac33
commit 543c554456
3 changed files with 13 additions and 9 deletions

View File

@ -65,9 +65,9 @@ void def_overlay::update() {
_last_update = std::chrono::high_resolution_clock::now();
//get current date and time
std::time_t curr_time = std::chrono::system_clock::to_time_t(
std::chrono::system_clock::now());
date_time = std::ctime(&curr_time);
std::time_t curr_time = std::time(nullptr);
std::strftime(date_time, sizeof(date_time),
DEF_OVERLAY_DATE_STRING, std::localtime(&curr_time));
}
///////////////////////////////////////
@ -114,12 +114,12 @@ void def_overlay::update_texture() {
//show the date and time
TTF_SizeText(board::getFont({ "Roboto_Mono/RobotoMono-Medium.ttf", 50 }),
date_time.c_str(),
date_time,
&tgt.w, &tgt.h);
tgt.x = SCREEN_WIDTH - tgt.w + 25;
tgt.x = SCREEN_WIDTH - tgt.w - 5;
tgt.y = -5;
SDL_RenderCopy(board::getRenderer(),
board::getString(date_time.c_str(),
board::getString(std::string(date_time),
{ "Roboto_Mono/RobotoMono-Medium.ttf", 50 }), NULL, &tgt);

View File

@ -30,7 +30,7 @@ namespace dashboard::panel {
void update_texture();
void initTexture();
std::string date_time;
char date_time [100];
std::chrono::time_point<std::chrono::high_resolution_clock> _last_update;
std::chrono::milliseconds _update_interval;

View File

@ -10,8 +10,8 @@
namespace dashboard::panel {
//How long should we wait between updates? in ms
//Default 10 s
constexpr size_t DEF_OVERLAY_UPDATE_INTERVAL = 500;
//Default 1s
constexpr size_t DEF_OVERLAY_UPDATE_INTERVAL = 1000;
//Height of the bar on the top and bottom, in pixels
constexpr size_t DEF_OVERLAY_BAR_HEIGHT = 60;
@ -26,4 +26,8 @@ namespace dashboard::panel {
constexpr uint8_t DEF_OVERLAY_BAR_GREEN = 0xD3;
constexpr uint8_t DEF_OVERLAY_BAR_BLUE = 0xD3;
constexpr uint8_t DEF_OVERLAY_BAR_ALPHA = 0x7F;
//for more on how this string format works, refer to
//https://en.cppreference.com/w/cpp/chrono/c/strftime
constexpr char DEF_OVERLAY_DATE_STRING[] = "%a %R %p";
}