Exemplo n.º 1
0
    def __init__(self, ipcon, uid, version):
        PluginBase.__init__(self, ipcon, uid, 'Dual Button Bricklet', version)
        
        self.setupUi(self)

        self.button = BrickletDualButton(uid, ipcon)
        
        self.qtcb_state_changed.connect(self.cb_state_changed)
        self.button.register_callback(self.button.CALLBACK_STATE_CHANGED,
                                      self.qtcb_state_changed.emit)
        
        self.led_r = DualButton.OFF
        self.led_l = DualButton.OFF
        self.button_r = DualButton.RELEASED
        self.button_l = DualButton.RELEASED
        
        self.button_led_on_button_r.pressed.connect(self.on_button_r_pressed)
        self.button_led_on_button_l.pressed.connect(self.on_button_l_pressed)
        self.button_led_off_button_r.pressed.connect(self.off_button_r_pressed)
        self.button_led_off_button_l.pressed.connect(self.off_button_l_pressed)
        self.button_toggle_button_r.pressed.connect(self.toggle_button_r_pressed)
        self.button_toggle_button_l.pressed.connect(self.toggle_button_l_pressed)
        
        self.count = 0
Exemplo n.º 2
0
class DualButton(PluginBase, Ui_DualButton):
    qtcb_state_changed = pyqtSignal(int, int, int, int)
    
    AT_ON = 0
    AT_OFF = 1
    ON = 2
    OFF = 3
    
    PRESSED = 0
    RELEASED = 1
    
    def __init__(self, ipcon, uid, version):
        PluginBase.__init__(self, ipcon, uid, 'Dual Button Bricklet', version)
        
        self.setupUi(self)

        self.button = BrickletDualButton(uid, ipcon)
        
        self.qtcb_state_changed.connect(self.cb_state_changed)
        self.button.register_callback(self.button.CALLBACK_STATE_CHANGED,
                                      self.qtcb_state_changed.emit)
        
        self.led_r = DualButton.OFF
        self.led_l = DualButton.OFF
        self.button_r = DualButton.RELEASED
        self.button_l = DualButton.RELEASED
        
        self.button_led_on_button_r.pressed.connect(self.on_button_r_pressed)
        self.button_led_on_button_l.pressed.connect(self.on_button_l_pressed)
        self.button_led_off_button_r.pressed.connect(self.off_button_r_pressed)
        self.button_led_off_button_l.pressed.connect(self.off_button_l_pressed)
        self.button_toggle_button_r.pressed.connect(self.toggle_button_r_pressed)
        self.button_toggle_button_l.pressed.connect(self.toggle_button_l_pressed)
        
        self.count = 0
        
    def on_button_l_pressed(self):
        self.led_l = DualButton.ON
        self.button.set_led_state(DualButton.ON, self.led_r)
        self.update_buttons()
        
    def on_button_r_pressed(self):
        self.led_r = DualButton.ON
        self.button.set_led_state(self.led_l, DualButton.ON)
        self.update_buttons()
        
    def off_button_l_pressed(self):
        self.led_l = DualButton.OFF
        self.button.set_led_state(DualButton.OFF, self.led_r)
        self.update_buttons()
    
    def off_button_r_pressed(self):
        self.led_r = DualButton.OFF
        self.button.set_led_state(self.led_l, DualButton.OFF)
        self.update_buttons()
        
    def toggle_button_l_pressed(self):
        self.led_l = DualButton.AT_OFF
        self.button.set_led_state(DualButton.AT_OFF, self.led_r)
        self.update_buttons()
    
    def toggle_button_r_pressed(self):
        self.led_r = DualButton.AT_OFF
        self.button.set_led_state(self.led_l, DualButton.AT_OFF)
        self.update_buttons()
        
    def update_buttons(self):
        if self.led_r == DualButton.ON:
            self.button_toggle_button_r.setEnabled(True)
            self.button_led_on_button_r.setEnabled(False)
            self.button_led_off_button_r.setEnabled(True)
        elif self.led_r == DualButton.OFF:
            self.button_toggle_button_r.setEnabled(True)
            self.button_led_on_button_r.setEnabled(True)
            self.button_led_off_button_r.setEnabled(False)
        elif self.led_r in (DualButton.AT_OFF, DualButton.AT_ON):
            self.button_toggle_button_r.setEnabled(False)
            self.button_led_on_button_r.setEnabled(True)
            self.button_led_off_button_r.setEnabled(True)
            
        if self.led_l == DualButton.ON:
            self.button_toggle_button_l.setEnabled(True)
            self.button_led_on_button_l.setEnabled(False)
            self.button_led_off_button_l.setEnabled(True)
        elif self.led_l == DualButton.OFF:
            self.button_toggle_button_l.setEnabled(True)
            self.button_led_on_button_l.setEnabled(True)
            self.button_led_off_button_l.setEnabled(False)
        elif self.led_l in (DualButton.AT_OFF, DualButton.AT_ON):
            self.button_toggle_button_l.setEnabled(False)
            self.button_led_on_button_l.setEnabled(True)
            self.button_led_off_button_l.setEnabled(True)
            
    def cb_state_changed(self, button_l, button_r, led_l, led_r):
        self.count += 1
        self.get_led_state_async((led_l, led_r))
        self.get_button_state_async((button_l, button_r))
    
    def get_led_state_async(self, led):
        self.led_l, self.led_r = led
        
        self.update_buttons()
    
    def get_button_state_async(self, button):
        self.button_l, self.button_r = button
        led_text_button_l = ''
        led_text_button_r = ''
        
        if self.led_l in (DualButton.ON, DualButton.AT_ON):
            led_text_button_l = ', LED On'
        else:
            led_text_button_l = ', LED Off'
            
        if self.led_r in (DualButton.ON, DualButton.AT_ON):
            led_text_button_r = ', LED On'
        else:
            led_text_button_r = ', LED Off'
            
        if self.button_l == DualButton.RELEASED:
            self.label_status_button_l.setText('Released' + led_text_button_l)
        else:
            self.label_status_button_l.setText('Pressed' + led_text_button_l)
            
        if self.button_r == DualButton.RELEASED:
            self.label_status_button_r.setText('Released' + led_text_button_r)
        else:
            self.label_status_button_r.setText('Pressed' + led_text_button_r)

    def start(self):
        async_call(self.button.get_led_state, None, self.get_led_state_async, self.increase_error_count)
        async_call(self.button.get_button_state, None, self.get_button_state_async, self.increase_error_count)
        
    def stop(self):
        pass

    def get_url_part(self):
        return 'dual_button'

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