@growbox/sensors
Version:
An abstraction layer for a selection of raspberry-compatible sensors
35 lines (26 loc) • 1.05 kB
JavaScript
/**
* @author nstCactus
* @date 09/12/2017 15:30
*/
const AbstractAnalogSensor = require('./AbstractAnalogSensor');
/**
* A Flying Fish MH series soil moisture analog sensor
*/
class FlyingFishMhSeriesSoilMoistureAnalogSensor extends AbstractAnalogSensor {
constructor(name, uid, adcInstance, adcAddress) {
if (!(adcInstance instanceof 'AbstractAnalogToDigitalConverter')) {
throw new TypeError('The adcInstance parameter must be an instance of AbstractAnalogToDigitalConverter.');
}
name = `FlyingFishMhSeriesSoilMoisture_${adcInstance.getName()}_pin${adcAddress}`;
super(name, uid, adcInstance, adcAddress);
}
/**
* Read from the sensor to get the current a number between 0 and 1023 representing the soil moisture (the bigger the
* number, the dryer the soil is)
* @returns {Promise<number>} A promise that, when fulfilled, contains the value read from the sensor.
*/
read() {
return this.adcInstance.read(this.adcAddress);
}
}
module.exports = FlyingFishMhSeriesSoilMoistureAnalogSensor;