Exemplo n.º 1
0
    def initialize_input(self):
        from adafruit_extended_bus import ExtendedI2C
        from anyleaf import OrpSensor, CalPtOrp

        self.sensor = OrpSensor(
            ExtendedI2C(self.input_dev.i2c_bus),
            self.input_dev.period,
            address=int(str(self.input_dev.i2c_location), 16)
        )

        # `default_value` above doesn't set the default in the database: custom options will initialize to None.
        if self.get_custom_option("cal_v"):
            cal_v = self.get_custom_option("cal_v")
        else:
            cal_v = 0.4
        if self.get_custom_option("cal_orp"):
            cal_orp = self.get_custom_option("cal_orp")
        else:
            cal_orp = 400.0

        # Load cal data from the database.
        self.sensor.calibrate_all(CalPtOrp(
            cal_v,
            cal_orp,
        ))
Exemplo n.º 2
0
class InputModule(AbstractInput):
    """A sensor support class that monitors AnyLeaf sensor pH or ORP"""

    def __init__(self, input_dev, testing=False):
        super(InputModule, self).__init__(input_dev, testing=testing, name=__name__)

        self.sensor = None

        self.cal_v = None
        self.cal_orp = None

        if not testing:
            self.initialize_input()

    def initialize_input(self):
        from adafruit_extended_bus import ExtendedI2C
        from anyleaf import OrpSensor, CalPtOrp

        self.sensor = OrpSensor(
            ExtendedI2C(self.input_dev.i2c_bus),
            self.input_dev.period,
            address=int(str(self.input_dev.i2c_location), 16))

        # Load cal data from the database
        self.sensor.calibrate_all(CalPtOrp(self.cal_v, self.cal_orp,))

    def calibrate(self, args_dict):
        """ Auto-calibrate """
        if 'calibration_orp' not in args_dict:
            self.logger.error("Cannot conduct calibration without a buffer ORP value")
            return
        if not isinstance(args_dict['calibration_orp'], float) and not isinstance(args_dict['calibration_orp'], int):
            self.logger.error("buffer value does not represent a number: '{}', type: {}".format(
                args_dict['calibration_orp'], type(args_dict['calibration_orp'])))
            return

        # For this session
        v = self.sensor.calibrate(args_dict['calibration_orp'])

        # For future sessions
        self.set_custom_option("cal_orp", args_dict['calibration_orp'])
        self.set_custom_option("cal_v", v)

    def clear_calibrate_slots(self, args_dict):
        self.delete_custom_option("cal_v")
        self.delete_custom_option("cal_orp")
        self.setup_custom_options(
            INPUT_INFORMATION['custom_options'], self.input_dev)

    def get_measurement(self):
        """ Gets the measurement """
        self.return_dict = copy.deepcopy(measurements_dict)

        if not self.sensor:
            self.logger.error("Input not set up")
            return

        self.value_set(0, self.sensor.read())

        return self.return_dict
Exemplo n.º 3
0
    def initialize_input(self):
        from adafruit_extended_bus import ExtendedI2C
        from anyleaf import OrpSensor, CalPtOrp

        self.sensor = OrpSensor(
            ExtendedI2C(self.input_dev.i2c_bus),
            self.input_dev.period,
            address=int(str(self.input_dev.i2c_location), 16))

        # Load cal data from the database
        self.sensor.calibrate_all(CalPtOrp(self.cal_v, self.cal_orp,))