MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / constructor

Method constructor

modules/drivers/sensors/tmp102/tmp102.js:46–82  ·  view source on GitHub ↗
(options)

Source from the content-addressed store, hash-verified

44 #status;
45
46 constructor(options) {
47 let io, monitor;
48 try {
49 io = new options.sensor.io({
50 hz: 400_000,
51 address: 0x48,
52 ...options.sensor
53 });
54
55 const {alert, onAlert} = options;
56 if (alert && onAlert) {
57 this.#onAlert = onAlert;
58 monitor = new alert.io({
59 mode: alert.io.InputPullUp,
60 ...alert,
61 edge: alert.io.Falling,
62 onReadable: () => this.#onAlert()
63 });
64 }
65
66 // reset to default values (7.5.3 of datasheet)
67 io.writeUint16(Register.CONFIG, 0b0110_0000_1010_0000, true);
68
69 // THigh = +80C TLow = +75C (7.5.4)
70 io.writeUint16(Register.TEMP_HIGH, 0b0101_0000_0000_0000, true);
71 io.writeUint16(Register.TEMP_LOW, 0b0100_1011_0000_0000, true);
72
73 this.#io = io;
74 io.monitor = monitor;
75 this.#status = true;
76 }
77 catch (e) {
78 io?.close();
79 monitor?.close();
80 throw e;
81 }
82 }
83
84 configure(options) {
85 const io = this.#io;

Callers

nothing calls this directly

Calls 2

closeMethod · 0.65
writeUint16Method · 0.45

Tested by

no test coverage detected