| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- const { TempSensor, Channel } = require('./sensor')
- const { Controller } = require('./controller')
- const { Scanner } = require('./scanner')
-
- const unitScale = {
- dC: { unit: 'degree', scale: 'celcius' },
- dF: { unit: 'degree', scale: 'fahrenheit' },
- mV: { unit: 'volt', scale: 'millivolt' },
- V: { unit: 'volt', scale: 'volt' }
- }
-
- /**
- * Create a sensor and readout channel as -67 to 257 degrees fahrenheit
- */
- const tempController = new Controller({
- type: 'temp',
- channel: new Channel({ name: 'temperature_channel_00', min: -67, max: 257, interval: 10, unit: unitScale.dF.unit, scale: unitScale.dF.scale }),
- sensor: new TempSensor({ name: 'temperature_sensor_00', min: -67, max: 257, interval: 10, unit: unitScale.dF.unit, scale: unitScale.dF.scale })
- })
- console.log(tempController.readout) // { value: 78, unit: 'degrees' scale: 'fahrenheit' }
-
- /**
- * Create a 0-5v sensor and interpolate readout as -67 to 257 degrees fahrenheit
- */
- const manualTempController = new Controller({
- type: 'temp',
- channel: new Channel({ name: 'temperature_channel_01', min: -67, max: 257, interval: 10, unit: unitScale.dF.unit, scale: unitScale.dF.scale }),
- sensor: new TempSensor({ name: 'temperature_sensor_01', min: 0, max: 5, interval: 100, unit: unitScale.mV.unit, scale: unitScale.mV.scale })
- })
- console.log(manualTempController.readout) // { value: 78, unit: 'degrees' scale: 'fahrenheit' }
-
- /**
- * A Scanner is made up of controllers
- * A Controller is made up of an output Channel and input Sensor
- */
- const mySystem = new Scanner({ controllers: [ tempController, manualTempController ] })
- console.log(mySystem.readAll())
- /**
- * Example: console.log(mySystem.readAll())
- * temperature_channel_00: Reading({ value: 78, unit: 'degrees' scale: 'fahrenheit' }),
- * temperature_channel_01: Reading({ value: 78, unit: 'degrees' scale: 'fahrenheit' }),
- */
-
- module.exports = {
- unitScale
- }
|