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

Method constructor

modules/drivers/sensors/tmp117/tmp117.js:61–101  ·  view source on GitHub ↗
(options)

Source from the content-addressed store, hash-verified

59 #status;
60
61 constructor(options) {
62 const io = this.#io = new options.sensor.io({
63 hz: 400_000,
64 address: 0x48,
65 ...options.sensor
66 });
67
68 this.#onError = options.onError;
69
70 let conf = io.readUint16(Register.TMP117_CHIPID, true);
71 if (0x117 != (conf & 0x0fff)) {
72 this.#onError?.("unexpected sensor");
73 this.#io.close();
74 this.#io = undefined;
75 return;
76 }
77
78 conf = io.readUint16(Register.TMP117_CONF, true);
79 conf |= ConfigMask.SOFT_RESET; // softreset
80 io.writeUint16(Register.TMP117_CONF, conf, true);
81
82 const {alert, onAlert} = options;
83 if (alert && onAlert) {
84 this.#onAlert = options.onAlert;
85 this.#monitor = new alert.io({
86 mode: alert.io.InputPullUp,
87 ...alert,
88 edge: alert.io.Falling,
89 onReadable: () => this.#onAlert()
90 });
91 }
92
93 // Reset to default: DataSheet 7.6.3
94 io.writeUint16(Register.TMP117_CONF, 0b0000_0010_0010_0000, true);
95
96 // DataSheet 7.6.4, 7.6.5
97 io.writeUint16(Register.TMP117_THI, 0b0110_0000_0000_0000, true);
98 io.writeUint16(Register.TMP117_TLO, 0b1000_0000_0000_0000, true);
99
100 this.#status = "ready";
101 }
102 configure(options) {
103 const io = this.#io;
104 let conf = io.readUint16(Register.TMP117_CONF, true);

Callers

nothing calls this directly

Calls 4

closeMethod · 0.65
readUint16Method · 0.45
#onErrorMethod · 0.45
writeUint16Method · 0.45

Tested by

no test coverage detected