UNPKG

@growbox/sensors

Version:

An abstraction layer for a selection of raspberry-compatible sensors

48 lines (37 loc) 1.16 kB
/** * @author nstCactus * @date 09/12/2017 15:00 */ const AbstractSensor = require('../sensors/AbstractSensor'); /** {WeakMap<string>} The human-readable name of the ADC component */ const _name = new WeakMap(); /** {WeakMap<string>} A unique identifier for the ADC component */ const _uid = new WeakMap(); /** * An abstract class to represent an ADC (analog to digital converter) component */ class AbstractAnalogToDigitalConverter { constructor(name, uid) { if (this.constructor === AbstractSensor) { throw new TypeError('Abstract class "AbstractAnalogToDigitalConverter" cannot be instantiated directly.'); } if (this.read === undefined) { throw new TypeError('Classes extending the "AbstractAnalogToDigitalConverter" abstract class must implement the "read" method.'); } _name.set(this, name); _uid.set(this, uid); } /** * @returns {string} the name of the sensor */ get name() { return _name.get(this); } /** * @returns {string} the unique identifier (UID) of the sensor */ get uid() { return _uid.get(this); } } module.exports = AbstractAnalogToDigitalConverter;