threshold query api

This commit is contained in:
Peli de Halleux
2018-01-30 08:27:23 -08:00
parent 16c67f0e30
commit 188d5b3aa7
10 changed files with 68 additions and 13 deletions

View File

@ -432,11 +432,11 @@ namespace sensors {
export class ThresholdDetector {
public id: number;
private min: number;
private max: number;
private lowThreshold: number;
private highThreshold: number;
private level: number;
public min: number;
public max: number;
public lowThreshold: number;
public highThreshold: number;
public level: number;
public state: ThresholdState;
constructor(id: number, min = 0, max = 100, lowThreshold = 20, highThreshold = 80) {
@ -467,6 +467,14 @@ namespace sensors {
}
}
public threshold(t: ThresholdState): number {
switch(t) {
case ThresholdState.High: return this.highThreshold;
case ThresholdState.Low: return this.lowThreshold;
default: return (this.max - this.min) / 2;
}
}
public setLowThreshold(value: number) {
this.lowThreshold = this.clampValue(value);
this.highThreshold = Math.max(this.lowThreshold + 1, this.highThreshold);