Ejemplo n.º 1
0
class Temperature(PluginBase):
    qtcb_temperature = pyqtSignal(int)
    
    def __init__(self, ipcon, uid, version):
        PluginBase.__init__(self, ipcon, uid, 'Temperature Bricklet', version)
        
        self.tem = BrickletTemperature(uid, ipcon)
        
        self.qtcb_temperature.connect(self.cb_temperature)
        self.tem.register_callback(self.tem.CALLBACK_TEMPERATURE,
                                   self.qtcb_temperature.emit) 
        
        self.temperature_label = TemperatureLabel()
        
        self.current_value = None
        
        plot_list = [['', Qt.red, self.get_current_value]]
        self.plot_widget = PlotWidget('Temperature [%cC]' % 0xB0, plot_list)
        
        layout_h = QHBoxLayout()
        layout_h.addStretch()
        layout_h.addWidget(self.temperature_label)
        layout_h.addStretch()

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

    def start(self):
        async_call(self.tem.get_temperature, None, self.cb_temperature, self.increase_error_count)
        async_call(self.tem.set_temperature_callback_period, 100, None, self.increase_error_count)
        
        self.plot_widget.stop = False
        
    def stop(self):
        async_call(self.tem.set_temperature_callback_period, 0, None, self.increase_error_count)
        
        self.plot_widget.stop = True

    def get_url_part(self):
        return 'temperature'

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

    def get_current_value(self):
        return self.current_value

    def cb_temperature(self, temperature):
        self.current_value = temperature/100.0
        self.temperature_label.setText(str(temperature/100.0))
Ejemplo n.º 2
0
    def __init__(self, ipcon, uid, version):
        PluginBase.__init__(self, ipcon, uid, 'Temperature Bricklet', version)
        
        self.tem = BrickletTemperature(uid, ipcon)
        
        self.qtcb_temperature.connect(self.cb_temperature)
        self.tem.register_callback(self.tem.CALLBACK_TEMPERATURE,
                                   self.qtcb_temperature.emit) 
        
        self.temperature_label = TemperatureLabel()
        
        self.current_value = None
        
        plot_list = [['', Qt.red, self.get_current_value]]
        self.plot_widget = PlotWidget('Temperature [%cC]' % 0xB0, plot_list)
        
        layout_h = QHBoxLayout()
        layout_h.addStretch()
        layout_h.addWidget(self.temperature_label)
        layout_h.addStretch()

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