Esempio n. 1
0
class Moisture(PluginBase):
    qtcb_moisture = pyqtSignal(int)
    
    def __init__(self, ipcon, uid, version):
        PluginBase.__init__(self, ipcon, uid, 'Moisture Bricklet', version)

        self.moisture = BrickletMoisture(uid, ipcon)
        
        self.qtcb_moisture.connect(self.cb_moisture)
        self.moisture.register_callback(self.moisture.CALLBACK_MOISTURE,
                                        self.qtcb_moisture.emit) 
        
        self.moisture_label = MoistureLabel()
        self.current_value = None
        
        plot_list = [['', Qt.red, self.get_current_value]]
        self.plot_widget = PlotWidget('Moisture', plot_list)
        
        layout_h = QHBoxLayout()
        layout_h.addStretch()
        layout_h.addWidget(self.moisture_label)
        layout_h.addStretch()

        layout = QVBoxLayout(self)
        layout.addLayout(layout_h)
        layout.addWidget(self.plot_widget)
        
        
    def get_current_value(self):
        return self.current_value

    def cb_moisture(self, moisture):
        self.current_value = moisture
        self.moisture_label.setText(str(moisture))

    def start(self):
        async_call(self.moisture.get_moisture_value, None, self.cb_moisture, self.increase_error_count)
        async_call(self.moisture.set_moisture_callback_period, 100, None, self.increase_error_count)
        
        self.plot_widget.stop = False
        
    def stop(self):
        async_call(self.moisture.set_moisture_callback_period, 0, None, self.increase_error_count)
        
        self.plot_widget.stop = True

    def get_url_part(self):
        return 'moisture'

    @staticmethod
    def has_device_identifier(device_identifier):
        return device_identifier == BrickletMoisture.DEVICE_IDENTIFIER
Esempio n. 2
0
    def __init__(self, ipcon, uid, version):
        PluginBase.__init__(self, ipcon, uid, 'Moisture Bricklet', version)

        self.moisture = BrickletMoisture(uid, ipcon)
        
        self.qtcb_moisture.connect(self.cb_moisture)
        self.moisture.register_callback(self.moisture.CALLBACK_MOISTURE,
                                        self.qtcb_moisture.emit) 
        
        self.moisture_label = MoistureLabel()
        self.current_value = None
        
        plot_list = [['', Qt.red, self.get_current_value]]
        self.plot_widget = PlotWidget('Moisture', plot_list)
        
        layout_h = QHBoxLayout()
        layout_h.addStretch()
        layout_h.addWidget(self.moisture_label)
        layout_h.addStretch()

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