Skip to content

Commit a1312c3

Browse files
committed
Enable dynamic scale for Load average meter
The default "total" will still equals to number of CPUs. Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
1 parent 9feae7b commit a1312c3

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

LoadAverageMeter.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ static void LoadAverageMeter_updateValues(Meter* this) {
4444
this->curItems = 1;
4545

4646
// change bar color and total based on value
47+
if (this->total < -((double)this->pl->cpuCount)) {
48+
this->total = -((double)this->pl->cpuCount);
49+
}
4750
if (this->values[0] < 1.0) {
4851
this->curAttributes = OK_attributes;
49-
this->total = 1.0;
5052
} else if (this->values[0] < this->pl->cpuCount) {
5153
this->curAttributes = Medium_attributes;
52-
this->total = this->pl->cpuCount;
5354
} else {
5455
this->curAttributes = High_attributes;
55-
this->total = 2 * this->pl->cpuCount;
5656
}
5757

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

7878
// change bar color and total based on value
79+
if (this->total < -((double)this->pl->cpuCount)) {
80+
this->total = -((double)this->pl->cpuCount);
81+
}
82+
7983
if (this->values[0] < 1.0) {
8084
this->curAttributes = OK_attributes;
81-
this->total = 1.0;
8285
} else if (this->values[0] < this->pl->cpuCount) {
8386
this->curAttributes = Medium_attributes;
84-
this->total = this->pl->cpuCount;
8587
} else {
8688
this->curAttributes = High_attributes;
87-
this->total = 2 * this->pl->cpuCount;
8889
}
8990

9091
xSnprintf(this->txtBuffer, sizeof(this->txtBuffer), "%.2f", this->values[0]);
@@ -108,7 +109,7 @@ const MeterClass LoadAverageMeter_class = {
108109
.updateValues = LoadAverageMeter_updateValues,
109110
.defaultMode = TEXT_METERMODE,
110111
.maxItems = 3,
111-
.total = 100.0,
112+
.total = -1.0,
112113
.attributes = LoadAverageMeter_attributes,
113114
.name = "LoadAverage",
114115
.uiName = "Load average",
@@ -125,7 +126,7 @@ const MeterClass LoadMeter_class = {
125126
.updateValues = LoadMeter_updateValues,
126127
.defaultMode = TEXT_METERMODE,
127128
.maxItems = 1,
128-
.total = 100.0,
129+
.total = -1.0,
129130
.attributes = LoadMeter_attributes,
130131
.name = "Load",
131132
.uiName = "Load",

0 commit comments

Comments
 (0)