Skip to content

Commit

Permalink
Enable dynamic scale for Load average meter
Browse files Browse the repository at this point in the history
The default "total" will still equals to number of CPUs.

Signed-off-by: Kang-Che Sung <[email protected]>
  • Loading branch information
Explorer09 committed Jul 30, 2021
1 parent ad0ead8 commit 7bb6d27
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions LoadAverageMeter.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ static void LoadAverageMeter_updateValues(Meter* this) {
this->curItems = 1;

// change bar color and total based on value
if (this->total < -((double)this->pl->cpuCount)) {
this->total = -((double)this->pl->cpuCount);
}
if (this->values[0] < 1.0) {
this->curAttributes = OK_attributes;
this->total = 1.0;
} else if (this->values[0] < this->pl->cpuCount) {
this->curAttributes = Medium_attributes;
this->total = this->pl->cpuCount;
} else {
this->curAttributes = High_attributes;
this->total = 2 * this->pl->cpuCount;
}

xSnprintf(this->txtBuffer, sizeof(this->txtBuffer), "%.2f/%.2f/%.2f", this->values[0], this->values[1], this->values[2]);
Expand All @@ -76,15 +76,16 @@ static void LoadMeter_updateValues(Meter* this) {
Platform_getLoadAverage(&this->values[0], &five, &fifteen);

// change bar color and total based on value
if (this->total < -((double)this->pl->cpuCount)) {
this->total = -((double)this->pl->cpuCount);
}

if (this->values[0] < 1.0) {
this->curAttributes = OK_attributes;
this->total = 1.0;
} else if (this->values[0] < this->pl->cpuCount) {
this->curAttributes = Medium_attributes;
this->total = this->pl->cpuCount;
} else {
this->curAttributes = High_attributes;
this->total = 2 * this->pl->cpuCount;
}

xSnprintf(this->txtBuffer, sizeof(this->txtBuffer), "%.2f", this->values[0]);
Expand All @@ -108,7 +109,7 @@ const MeterClass LoadAverageMeter_class = {
.updateValues = LoadAverageMeter_updateValues,
.defaultMode = TEXT_METERMODE,
.maxItems = 3,
.total = 100.0,
.total = -1.0,
.attributes = LoadAverageMeter_attributes,
.name = "LoadAverage",
.uiName = "Load average",
Expand All @@ -125,7 +126,7 @@ const MeterClass LoadMeter_class = {
.updateValues = LoadMeter_updateValues,
.defaultMode = TEXT_METERMODE,
.maxItems = 1,
.total = 100.0,
.total = -1.0,
.attributes = LoadMeter_attributes,
.name = "Load",
.uiName = "Load",
Expand Down

0 comments on commit 7bb6d27

Please sign in to comment.