Skip to content

Commit

Permalink
Update temperature.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
THEb0nny committed Jun 26, 2024
1 parent 125547b commit 72e38ed
Showing 1 changed file with 30 additions and 13 deletions.
43 changes: 30 additions & 13 deletions libs/nxt-temperature-sensor/temperature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const enum NXTTempSensorMode {

namespace sensors {

const MODE_SWITCH_DELAY = 100;

//% fixedInstances
export class NXTTemperatureSensor extends internal.IICSensor {

Expand All @@ -22,9 +24,35 @@ namespace sensors {
return DAL.DEVICE_TYPE_NXT_TEMPERATURE;
}

setMode(m: NXTTempSensorMode) {
this._setMode(m);
}

_setMode(m: number) {
let v = m | 0;
this.mode = v;
if (!this.isActive()) return;
if (this.realmode != this.mode) {
this.realmode = v;
if (m == NXTTempSensorMode.Celsius) {
this.transaction(1, [76, NXTTempSensorMode.Celsius], 0);
} else if (m == NXTTempSensorMode.Fahrenheit) {
this.transaction(1, [76, NXTTempSensorMode.Fahrenheit], 0);
}
pause(MODE_SWITCH_DELAY);
}
}

/**
* Gets the current temp mode
*/
tempMode() {
return <NXTTempSensorMode>this.mode;
}

_IICId() {
// return 'LEGO';
return 'LEGOTemp.';
// return 'LEGO';
return 'LEGOTemp.';
}

_query() {
Expand All @@ -47,17 +75,6 @@ namespace sensors {

}

setMode(m: number) {
this._setMode(m);
}

/**
* Gets the current temp mode
*/
tempMode() {
return <NXTTempSensorMode>this.mode;
}

/**
* Measure the ambient or reflected light value from 0 (darkest) to 100 (brightest). For raw reflection values, the range can be from 0 to 4095.
* @param sensor the color sensor port
Expand Down

0 comments on commit 72e38ed

Please sign in to comment.