| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- /**
- * @type {Reading}
- */
- class Reading {
- constructor({ onRead, unit, min, max }) {
- this._val = onRead
- this.unit = unit
- this.max = max
- this.min = min
- this.created = Date.now()
- }
- /**
- * Reach out and grabs the value
- * from some sensor
- */
- get val() {
- return this._val()
- }
- }
-
- /**
- * @type {Channel}
- */
- class Channel {
- constructor({ interval = 1, reader = null }) {
- this._interval = interval
- this._reader = reader
- }
- get interval() {
- return this._interval
- }
- get val() {
- return this._reader.val
- }
- get unit() {
- return this._reader.unit
- }
- get aboveRange() {
- return this._reader.val > this._reader.max
- }
- get belowRange() {
- return this._reader.val < this._reader.min
- }
- get inRange() {
- return this._reader.val && !this.aboveRange && !this.belowRange
- ? true
- : false
- }
- /** Always return a new Reading instance with new Channel instances */
- update() {
- const reader = new Reading({
- // !: Setup the callback to return a sensor value
- onRead: this._reader._val,
- unit: this._reader.unit,
- max: this._reader.max,
- min: this._reader.min,
- })
-
- const chan = new Channel({ interval: this.interval, reader })
- return chan
- }
- }
-
- export { Channel, Reading }
|