-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimePanel.cpp
More file actions
98 lines (93 loc) · 2.8 KB
/
Copy pathTimePanel.cpp
File metadata and controls
98 lines (93 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
* This file is part of the Eclipse2024 project. It is subject to the GPLv3
* license terms in the LICENSE file found in the top-level directory of this
* distribution and at
* https://github.com/jjackowski/eclipse2024/blob/master/LICENSE.
* No part of the Eclipse2024 project, including this file, may be copied,
* modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*
* Copyright (C) 2024 Jeff Jackowski
*/
#include "TimePanel.hpp"
#include <duds/time/planetary/Planetary.hpp>
#include <duds/ui/graphics/BppFontPool.hpp>
#include <duds/hardware/devices/clocks/LinuxClock.hpp>
extern duds::ui::graphics::BppFontPool FontPool;
// ordered by size-step
static const std::string fontNames[] = {
"Time-large",
"Time-medium",
"Time-medium",
"Time-small",
"Time-tiny",
"Time-tiny",
};
TimePanel::TimePanel(Token) : nextSec(duds::time::interstellar::SecondTime::min()) { }
void TimePanel::updateTime(const duds::data::Measurement::TimeSample &ts) {
// using timestamp here is a shortcut, but should work fine
if (duds::time::interstellar::SecondTime(ts.value) >= nextSec) {
// compute and store the time of the next second
//nextSec += duds::time::interstellar::Seconds(1);
nextSec = duds::time::interstellar::SecondTime(ts.value) +
duds::time::interstellar::Seconds(1);
// get the new day in computer's set time zone
std::time_t tt = duds::time::planetary::earth->timeUtc(
ts.value
);
std::tm ltime;
localtime_r(&tt, <ime);
// clear rendered time images
for (int i = 0; i < 4; ++i) {
outputs[i].reset();
}
if (ltime.tm_min != time.tm_min) {
outputs[4].reset();
}
time = ltime;
}
}
const duds::ui::graphics::BppImage *TimePanel::render(
duds::ui::graphics::ImageLocation &offset,
duds::ui::graphics::ImageDimensions &dim,
duds::ui::graphics::PanelMargins &margin,
int sizeStep
) {
assert(sizeStep < 5);
// does it need to be rendered?
if (!outputs[sizeStep]) {
std::ostringstream oss;
// don't show seconds?
if ((sizeStep == 2) || (sizeStep > 4)) {
// time not set?
if (time.tm_year < 100) {
oss << "??:??";
} else {
oss << std::setfill('0') << std::setw(1) << time.tm_hour << ':'
<< std::setw(2) << time.tm_min;
}
} else {
char sep;
if (blink && (time.tm_sec & 1)) {
sep = ' ';
} else {
sep = ':';
}
// time not set?
if (time.tm_year < 100) {
oss << "??" << sep << "??" << sep << "??";
} else {
oss << std::setfill('0') << std::setw(1) << time.tm_hour << sep
<< std::setw(2) << time.tm_min << sep << std::setw(2) <<
time.tm_sec;
}
}
outputs[sizeStep] = FontPool.render(fontNames[sizeStep], oss.str());
}
dim = outputs[sizeStep]->dimensions();
if (sizeStep >= 3) {
// the last column will be empty; don't show it
--dim.w;
}
return outputs[sizeStep].get();
}