Exemplo n.º 1
0
    def __init__(self, ipcon, uid, version):
        PluginBase.__init__(self, ipcon, uid, 'Rotary Encoder Bricklet', version)

        self.re = BrickletRotaryEncoder(uid, ipcon)
        
        self.qtcb_count.connect(self.cb_count)
        self.re.register_callback(self.re.CALLBACK_COUNT,
                                  self.qtcb_count.emit)

        self.qtcb_pressed.connect(self.cb_pressed)
        self.re.register_callback(self.re.CALLBACK_PRESSED,
                                  self.qtcb_pressed.emit)
        
        self.qtcb_released.connect(self.cb_released)
        self.re.register_callback(self.re.CALLBACK_RELEASED,
                                  self.qtcb_released.emit)
        
        self.count_label = CountLabel('Count: 0')
        self.reset_button = QPushButton('Reset Count')
        self.reset_button.pressed.connect(self.reset_pressed)
        
        self.encoder_frame = EncoderFrame(self)
        self.encoder_frame.setMinimumSize(220, 220)
        self.encoder_frame.setMaximumSize(220, 220)
        self.encoder_frame.set_count(0)
        
        layout_h1 = QHBoxLayout()
        layout_h1.addStretch()
        layout_h1.addWidget(self.count_label)
        layout_h1.addStretch()
        
        layout_h2 = QHBoxLayout()
        layout_h2.addStretch()
        layout_h2.addWidget(self.encoder_frame)
        layout_h2.addStretch()
        
        layout_h3 = QHBoxLayout()
        layout_h3.addStretch()
        layout_h3.addWidget(self.reset_button)
        layout_h3.addStretch()

        layout = QVBoxLayout(self)
        layout.addLayout(layout_h1)
        layout.addLayout(layout_h2)
        layout.addLayout(layout_h3)
        layout.addStretch()
Exemplo n.º 2
0
class RotaryEncoder(PluginBase):
    qtcb_count = pyqtSignal(int)
    qtcb_pressed = pyqtSignal()
    qtcb_released = pyqtSignal()
    
    def __init__(self, ipcon, uid, version):
        PluginBase.__init__(self, ipcon, uid, 'Rotary Encoder Bricklet', version)

        self.re = BrickletRotaryEncoder(uid, ipcon)
        
        self.qtcb_count.connect(self.cb_count)
        self.re.register_callback(self.re.CALLBACK_COUNT,
                                  self.qtcb_count.emit)

        self.qtcb_pressed.connect(self.cb_pressed)
        self.re.register_callback(self.re.CALLBACK_PRESSED,
                                  self.qtcb_pressed.emit)
        
        self.qtcb_released.connect(self.cb_released)
        self.re.register_callback(self.re.CALLBACK_RELEASED,
                                  self.qtcb_released.emit)
        
        self.count_label = CountLabel('Count: 0')
        self.reset_button = QPushButton('Reset Count')
        self.reset_button.pressed.connect(self.reset_pressed)
        
        self.encoder_frame = EncoderFrame(self)
        self.encoder_frame.setMinimumSize(220, 220)
        self.encoder_frame.setMaximumSize(220, 220)
        self.encoder_frame.set_count(0)
        
        layout_h1 = QHBoxLayout()
        layout_h1.addStretch()
        layout_h1.addWidget(self.count_label)
        layout_h1.addStretch()
        
        layout_h2 = QHBoxLayout()
        layout_h2.addStretch()
        layout_h2.addWidget(self.encoder_frame)
        layout_h2.addStretch()
        
        layout_h3 = QHBoxLayout()
        layout_h3.addStretch()
        layout_h3.addWidget(self.reset_button)
        layout_h3.addStretch()

        layout = QVBoxLayout(self)
        layout.addLayout(layout_h1)
        layout.addLayout(layout_h2)
        layout.addLayout(layout_h3)
        layout.addStretch()
        
    def cb_released(self):
        self.encoder_frame.set_pressed(False)

    def cb_pressed(self):
        self.encoder_frame.set_pressed(True)
        
    def cb_count(self, count):
        self.count_label.setText(str(count))
        self.encoder_frame.set_count(count)
        
    def reset_pressed(self):
        async_call(self.re.get_count, True, None, self.increase_error_count)
        self.cb_count(0)

    def start(self):
        async_call(self.re.set_count_callback_period, 100, None, self.increase_error_count)
        async_call(self.re.get_count, False, self.cb_count, self.increase_error_count)
        
    def stop(self):
        async_call(self.re.set_count_callback_period, 0, None, self.increase_error_count)

    def get_url_part(self):
        return 'rotary_encoder'

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