final-changes

This commit is contained in:
Dmitriy Antipov
2023-05-13 22:53:44 +03:00
parent d6d4479889
commit 333b487bb6
6 changed files with 46 additions and 27 deletions

View File

@ -87,11 +87,18 @@ namespace sensors {
|| this.mode == ColorSensorMode.AmbientLightIntensity
|| this.mode == ColorSensorMode.ReflectedLightIntensity)
return this.getNumber(NumberFormat.UInt8LE, 0)
if (this.mode == ColorSensorMode.RefRaw || this.mode == ColorSensorMode.RgbRaw)
if (this.mode == ColorSensorMode.RefRaw)
return this.getNumber(NumberFormat.UInt16LE, 0)
return 0
}
_queryArr(): number[] {
if (this.mode == ColorSensorMode.RgbRaw) {
return [this.getNumber(NumberFormat.UInt16LE, 0), this.getNumber(NumberFormat.UInt16LE, 2), this.getNumber(NumberFormat.UInt16LE, 4)];
}
return [0, 0, 0];
}
_info(): string {
switch (this.mode) {
case ColorSensorMode.Color:
@ -106,11 +113,23 @@ namespace sensors {
case ColorSensorMode.AmbientLightIntensity:
case ColorSensorMode.ReflectedLightIntensity:
return `${this._query()}%`;
case ColorSensorMode.RgbRaw:
return "array";
default:
return this._query().toString();
}
}
_infoArr(): string[] {
switch (this.mode) {
case ColorSensorMode.RgbRaw:
const queryArr = this._queryArr().map(number => number.toString());
return queryArr;
default:
return ["0", "0", "0"];
}
}
_update(prev: number, curr: number) {
if (this.calibrating) return; // simply ignore data updates while calibrating
if (this.mode == ColorSensorMode.Color || this.mode == ColorSensorMode.RgbRaw || this.mode == ColorSensorMode.RefRaw)

View File

@ -400,6 +400,10 @@ void cUiUpdatePower(void)
return this._query().toString();
}
_infoArr(): string[] {
return [this._query().toString()];
}
_update(prev: number, curr: number) {
}

View File

@ -272,7 +272,14 @@ namespace brick {
const x = (si.port() - 1) * col + 2;
const inf = si._info();
if (screenMode != ScreenMode.Ports) return;
if (inf) screen.print(inf, x, h - 2 * lineHeight8, 1, inf.length > 4 ? image.font5 : image.font8);
if (inf == "array") {
let infArr = si._infoArr();
for (let data = 0, str = Math.min(infArr.length + 1, 4); data < Math.min(infArr.length, 3); data++, str--) {
screen.print(infArr[data], x, h - str * lineHeight8, 1, infArr[data].length > 4 ? image.font5 : image.font8);
}
} else if (inf) {
screen.print(inf, x, h - 2 * lineHeight8, 1, inf.length > 4 ? image.font5 : image.font8);
}
}
}