示例#1
0
class Humidity(PluginBase):
    qtcb_humidity = pyqtSignal(int)

    def __init__(self, ipcon, uid, version):
        PluginBase.__init__(self, ipcon, uid, "Humidity Bricklet", version)

        self.hum = BrickletHumidity(uid, ipcon)

        self.qtcb_humidity.connect(self.cb_humidity)
        self.hum.register_callback(self.hum.CALLBACK_HUMIDITY, self.qtcb_humidity.emit)

        self.humidity_label = HumidityLabel("Humidity: ")

        self.current_value = None

        plot_list = [["", Qt.red, self.get_current_value]]
        self.plot_widget = PlotWidget("Relative Humidity [%RH]", plot_list)

        layout_h = QHBoxLayout()
        layout_h.addStretch()
        layout_h.addWidget(self.humidity_label)
        layout_h.addStretch()

        layout = QVBoxLayout(self)
        layout.addLayout(layout_h)
        layout.addWidget(self.plot_widget)

    def start(self):
        async_call(self.hum.get_humidity, None, self.cb_humidity, self.increase_error_count)
        async_call(self.hum.set_humidity_callback_period, 100, None, self.increase_error_count)

        self.plot_widget.stop = False

    def stop(self):
        async_call(self.hum.set_humidity_callback_period, 0, None, self.increase_error_count)

        self.plot_widget.stop = True

    def get_url_part(self):
        return "humidity"

    @staticmethod
    def has_device_identifier(device_identifier):
        return device_identifier == BrickletHumidity.DEVICE_IDENTIFIER

    def get_current_value(self):
        return self.current_value

    def cb_humidity(self, humidity):
        self.current_value = humidity / 10.0
        self.humidity_label.setText(str(humidity / 10.0))
示例#2
0
    def __init__(self, ipcon, uid, version):
        PluginBase.__init__(self, ipcon, uid, "Humidity Bricklet", version)

        self.hum = BrickletHumidity(uid, ipcon)

        self.qtcb_humidity.connect(self.cb_humidity)
        self.hum.register_callback(self.hum.CALLBACK_HUMIDITY, self.qtcb_humidity.emit)

        self.humidity_label = HumidityLabel("Humidity: ")

        self.current_value = None

        plot_list = [["", Qt.red, self.get_current_value]]
        self.plot_widget = PlotWidget("Relative Humidity [%RH]", plot_list)

        layout_h = QHBoxLayout()
        layout_h.addStretch()
        layout_h.addWidget(self.humidity_label)
        layout_h.addStretch()

        layout = QVBoxLayout(self)
        layout.addLayout(layout_h)
        layout.addWidget(self.plot_widget)