nope/modules/tinkerforge/bricklets/thermocouple.brick.factory.ts
2021-05-13 10:00:34 +02:00

57 lines
1.5 KiB
TypeScript

/**
* @author Martin Karkowski
* @email m.karkowski@zema.de
* @create date 2021-05-13 07:49:23
* @modify date 2021-05-13 08:08:00
* @desc [description]
*/
import * as Tinkerforge from "tinkerforge";
import { NopeObservable } from "../../../lib/observables/nopeObservable";
import { INopeDispatcher } from "../../../lib/types/nope/nopeDispatcher.interface";
import { GenericBrick } from "../src/genericBrick.module";
import { BRICKS } from "../src/identifiers";
import { TinkerForgeConnector } from "../src/TinkerForgeConnector";
import { IDeviceConfiguration } from "../type/interfaces";
export default async function (
_dispatcher: INopeDispatcher,
UID: string,
ipcon: TinkerForgeConnector,
config: IDeviceConfiguration
) {
const sensor = new ThermoCoupleSensor(_dispatcher, UID, ipcon);
return sensor;
}
export class ThermoCoupleSensor extends GenericBrick {
public value = new NopeObservable<number>();
constructor(
_dispatcher: INopeDispatcher,
UID: string,
ipcon: TinkerForgeConnector
) {
super(
_dispatcher,
UID,
ipcon,
BRICKS.THERMOCOUPLE_BRICK,
"BrickletTemperature"
);
}
async init(): Promise<void> {
await super.init();
const _this = this;
this.instance.on(
Tinkerforge.BrickletThermocouple.CALLBACK_TEMPERATURE,
// Callback function for temperature callback
(_temperature) => {
// Temperature in [°C]
_this.value.setContent(_temperature / 100);
}
);
}
}