Enable buttons and the display.
Kind-of-sort-of usable-ish.
This commit is contained in:
141
Time.h
141
Time.h
@@ -79,4 +79,145 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class WallClockTime {
|
||||
|
||||
// TODO: Implement a saturating counter?
|
||||
|
||||
public:
|
||||
WallClockTime()
|
||||
: m_hours(0)
|
||||
, m_minutes(0)
|
||||
, m_seconds(0)
|
||||
{}
|
||||
|
||||
WallClockTime(uint8_t hours, uint8_t minutes, uint8_t seconds)
|
||||
: m_hours(hours)
|
||||
, m_minutes(minutes)
|
||||
, m_seconds(seconds)
|
||||
{}
|
||||
|
||||
static inline uint8_t hour24_to_hour12(uint8_t hour24) {
|
||||
if (hour24 == 0) {
|
||||
return 12;
|
||||
} else if (hour24 > 12) {
|
||||
return hour24 - 12;
|
||||
} else {
|
||||
return hour24;
|
||||
}
|
||||
}
|
||||
|
||||
static inline uint8_t hour24_is_am(uint8_t hour24) {
|
||||
return hour24 >= 12;
|
||||
}
|
||||
|
||||
inline uint8_t get_hours_12() const {
|
||||
return hour24_to_hour12(m_hours);
|
||||
}
|
||||
|
||||
inline uint8_t get_hours_12_tens() const {
|
||||
return get_hours_12() / 10;
|
||||
}
|
||||
|
||||
inline uint8_t get_hours_12_ones() const {
|
||||
return get_hours_12() % 10;
|
||||
}
|
||||
|
||||
inline bool get_is_pm() const {
|
||||
return m_hours >= 12;
|
||||
}
|
||||
|
||||
inline uint8_t get_hours_24() const {
|
||||
return m_hours;
|
||||
}
|
||||
|
||||
inline uint8_t get_hours_24_ones() const {
|
||||
return m_hours % 10;
|
||||
}
|
||||
|
||||
inline uint8_t get_hours_24_tens() const {
|
||||
return m_hours / 10;
|
||||
}
|
||||
|
||||
inline uint8_t get_minutes() const {
|
||||
return m_minutes;
|
||||
}
|
||||
|
||||
inline uint8_t get_minutes_ones() const {
|
||||
return m_minutes % 10;
|
||||
}
|
||||
|
||||
inline uint8_t get_minutes_tens() const {
|
||||
return m_minutes / 10;
|
||||
}
|
||||
|
||||
inline uint8_t get_seconds() const {
|
||||
return m_seconds;
|
||||
}
|
||||
|
||||
inline uint8_t get_seconds_ones() const {
|
||||
return m_seconds % 10;
|
||||
}
|
||||
|
||||
inline uint8_t get_seconds_tens() const {
|
||||
return m_seconds / 10;
|
||||
}
|
||||
|
||||
inline void increment_hours() {
|
||||
m_hours++;
|
||||
if (m_hours >= 24) {
|
||||
m_hours = 0;
|
||||
}
|
||||
}
|
||||
|
||||
inline void increment_minutes() {
|
||||
m_minutes++;
|
||||
if (m_minutes >= 60) {
|
||||
m_minutes = 0;
|
||||
}
|
||||
}
|
||||
|
||||
inline void increment_seconds() {
|
||||
m_seconds++;
|
||||
if (m_seconds >= 60) {
|
||||
m_seconds = 0;
|
||||
}
|
||||
}
|
||||
|
||||
inline void decrement_hours() {
|
||||
if (m_hours == 0) {
|
||||
m_hours = 23;
|
||||
} else {
|
||||
m_hours--;
|
||||
}
|
||||
}
|
||||
|
||||
inline void decrement_minutes() {
|
||||
if (m_minutes == 0) {
|
||||
m_minutes = 59;
|
||||
} else {
|
||||
m_minutes--;
|
||||
}
|
||||
}
|
||||
|
||||
inline void decrement_seconds() {
|
||||
if (m_seconds == 0) {
|
||||
m_seconds = 59;
|
||||
} else {
|
||||
m_seconds--;
|
||||
}
|
||||
}
|
||||
|
||||
inline void toggle_am_pm() {
|
||||
if (m_hours < 12) {
|
||||
m_hours += 12;
|
||||
} else {
|
||||
m_hours -= 12;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
uint8_t m_hours;
|
||||
uint8_t m_minutes;
|
||||
uint8_t m_seconds;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user