Skip to content

Commit

Permalink
Restrict time-related meters to textual display (Text+LED mode)
Browse files Browse the repository at this point in the history
This disables graphing and bar mode display for:
* ClockMeter
* DateMeter
* DateTimeMeter
* UptimeMeter

Co-authored-by: Benny Baumann <[email protected]>
Co-authored-by: Kang-Che Sung <[email protected]>
  • Loading branch information
Explorer09 and BenBE committed May 2, 2024
1 parent 9f315bb commit c75e4d7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 27 deletions.
6 changes: 3 additions & 3 deletions ClockMeter.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ static void ClockMeter_updateValues(Meter* this) {

struct tm result;
const struct tm* lt = localtime_r(&host->realtime.tv_sec, &result);
this->values[0] = lt->tm_hour * 60 + lt->tm_min;
strftime(this->txtBuffer, sizeof(this->txtBuffer), "%H:%M:%S", lt);
}

Expand All @@ -37,8 +36,9 @@ const MeterClass ClockMeter_class = {
},
.updateValues = ClockMeter_updateValues,
.defaultMode = TEXT_METERMODE,
.maxItems = 1,
.total = 1440, /* 24*60 */
.supportedModes = (1 << TEXT_METERMODE) | (1 << LED_METERMODE),
.maxItems = 0,
.total = 0.0,
.attributes = ClockMeter_attributes,
.name = "Clock",
.uiName = "Clock",
Expand Down
12 changes: 3 additions & 9 deletions DateMeter.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,6 @@ static void DateMeter_updateValues(Meter* this) {

struct tm result;
const struct tm* lt = localtime_r(&host->realtime.tv_sec, &result);
this->values[0] = lt->tm_yday;
int year = lt->tm_year + 1900;
if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) {
this->total = 366;
} else {
this->total = 365;
}
strftime(this->txtBuffer, sizeof(this->txtBuffer), "%F", lt);
}

Expand All @@ -43,8 +36,9 @@ const MeterClass DateMeter_class = {
},
.updateValues = DateMeter_updateValues,
.defaultMode = TEXT_METERMODE,
.maxItems = 1,
.total = 365,
.supportedModes = (1 << TEXT_METERMODE) | (1 << LED_METERMODE),
.maxItems = 0,
.total = 0.0,
.attributes = DateMeter_attributes,
.name = "Date",
.uiName = "Date",
Expand Down
12 changes: 3 additions & 9 deletions DateTimeMeter.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,6 @@ static void DateTimeMeter_updateValues(Meter* this) {

struct tm result;
const struct tm* lt = localtime_r(&host->realtime.tv_sec, &result);
int year = lt->tm_year + 1900;
if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) {
this->total = 366;
} else {
this->total = 365;
}
this->values[0] = lt->tm_yday;
strftime(this->txtBuffer, sizeof(this->txtBuffer), "%F %H:%M:%S", lt);
}

Expand All @@ -43,8 +36,9 @@ const MeterClass DateTimeMeter_class = {
},
.updateValues = DateTimeMeter_updateValues,
.defaultMode = TEXT_METERMODE,
.maxItems = 1,
.total = 365,
.supportedModes = (1 << TEXT_METERMODE) | (1 << LED_METERMODE),
.maxItems = 0,
.total = 0.0,
.attributes = DateTimeMeter_attributes,
.name = "DateTime",
.uiName = "Date and Time",
Expand Down
10 changes: 4 additions & 6 deletions UptimeMeter.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ static void UptimeMeter_updateValues(Meter* this) {
int minutes = (totalseconds / 60) % 60;
int hours = (totalseconds / 3600) % 24;
int days = (totalseconds / 86400);
this->values[0] = days;
if (days > this->total) {
this->total = days;
}

char daysbuf[32];
if (days > 100) {
xSnprintf(daysbuf, sizeof(daysbuf), "%d days(!), ", days);
Expand All @@ -53,8 +50,9 @@ const MeterClass UptimeMeter_class = {
},
.updateValues = UptimeMeter_updateValues,
.defaultMode = TEXT_METERMODE,
.maxItems = 1,
.total = 100.0,
.supportedModes = (1 << TEXT_METERMODE) | (1 << LED_METERMODE),
.maxItems = 0,
.total = 0.0,
.attributes = UptimeMeter_attributes,
.name = "Uptime",
.uiName = "Uptime",
Expand Down

0 comments on commit c75e4d7

Please sign in to comment.