Ejemplo n.º 1
0
class AmbientLight(PluginBase):
    qtcb_illuminance = pyqtSignal(int)
    
    def __init__(self, ipcon, uid, version):
        PluginBase.__init__(self, ipcon, uid, 'Ambient Light Bricklet', version)
        
        self.al = BrickletAmbientLight(uid, ipcon)
        
        self.qtcb_illuminance.connect(self.cb_illuminance)
        self.al.register_callback(self.al.CALLBACK_ILLUMINANCE,
                                  self.qtcb_illuminance.emit) 
        
        self.illuminance_label = IlluminanceLabel('Illuminance: ')
        self.alf = AmbientLightFrame()
        
        self.current_value = None

        plot_list = [['', Qt.red, self.get_current_value]]
        self.plot_widget = PlotWidget('Illuminance [lx]', plot_list)
        
        layout_h = QHBoxLayout()
        layout_h.addStretch()
        layout_h.addWidget(self.illuminance_label)
        layout_h.addWidget(self.alf)
        layout_h.addStretch()

        layout = QVBoxLayout(self)
        layout.addLayout(layout_h)
        layout.addWidget(self.plot_widget)
        
    def start(self):
        async_call(self.al.get_illuminance, None, self.cb_illuminance, self.increase_error_count)
        async_call(self.al.set_illuminance_callback_period, 100, None, self.increase_error_count)
        
        self.plot_widget.stop = False
        
    def stop(self):
        async_call(self.al.set_illuminance_callback_period, 0, None, self.increase_error_count)
        
        self.plot_widget.stop = True

    def get_url_part(self):
        return 'ambient_light'

    @staticmethod
    def has_device_identifier(device_identifier):
        return device_identifier == BrickletAmbientLight.DEVICE_IDENTIFIER
    
    def get_current_value(self):
        return self.current_value

    def cb_illuminance(self, illuminance):
        self.current_value = illuminance/10.0
        self.illuminance_label.setText(str(self.current_value))        
        
        value = illuminance*255/9000
        self.alf.set_color(value, value, value)
Ejemplo n.º 2
0
    def __init__(self, ipcon, uid, version):
        PluginBase.__init__(self, ipcon, uid, 'Ambient Light Bricklet', version)
        
        self.al = BrickletAmbientLight(uid, ipcon)
        
        self.qtcb_illuminance.connect(self.cb_illuminance)
        self.al.register_callback(self.al.CALLBACK_ILLUMINANCE,
                                  self.qtcb_illuminance.emit) 
        
        self.illuminance_label = IlluminanceLabel('Illuminance: ')
        self.alf = AmbientLightFrame()
        
        self.current_value = None

        plot_list = [['', Qt.red, self.get_current_value]]
        self.plot_widget = PlotWidget('Illuminance [lx]', plot_list)
        
        layout_h = QHBoxLayout()
        layout_h.addStretch()
        layout_h.addWidget(self.illuminance_label)
        layout_h.addWidget(self.alf)
        layout_h.addStretch()

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