Example #1
0
class OLED128x64V2(COMCUPluginBase, Ui_OLED128x64V2):
    def __init__(self, *args):
        COMCUPluginBase.__init__(self, BrickletOLED128x64V2, *args)

        self.setupUi(self)

        self.oled = self.device

        self.scribble_widget = ScribbleWidget(128,
                                              64,
                                              5,
                                              QColor(Qt.white),
                                              QColor(Qt.black),
                                              enable_grid=False)
        self.image_button_layout.insertWidget(0, self.scribble_widget)

        self.contrast_syncer = SliderSpinSyncer(
            self.contrast_slider, self.contrast_spin,
            lambda value: self.new_configuration())
        self.char_syncer = SliderSpinSyncer(self.char_slider, self.char_spin,
                                            self.char_slider_changed)

        self.draw_button.clicked.connect(self.draw_clicked)
        self.clear_button.clicked.connect(self.clear_clicked)
        self.send_button.clicked.connect(self.send_clicked)
        self.clear_display_button.clicked.connect(self.clear_display_clicked)
        self.invert_checkbox.stateChanged.connect(self.new_configuration)

        self.current_char_value = -1

        self.write_line_response_expected = None

    def char_slider_changed(self, value):
        if value != self.current_char_value:
            self.current_char_value = value
            self.write_chars(value)
            self.char_slider.setValue(value)

    def new_configuration(self):
        contrast = self.contrast_slider.value()
        invert = self.invert_checkbox.isChecked()
        self.oled.set_display_configuration(contrast, invert, True)

    def write_chars(self, value):
        if value > 248:
            value = 248
        for j in range(8):
            start = ""
            if value + j < 10:
                start = "  "
            elif value + j < 100:
                start = " "
            async_call(
                self.oled.write_line,
                (j, 8, start + str(value + j) + ": " + chr(value + j) + '\0'),
                None, self.increase_error_count)

    def clear_display_clicked(self):
        self.oled.clear_display()

    def clear_clicked(self):
        self.scribble_widget.clear_image()

    def send_clicked(self):
        line = int(self.line_combobox.currentText())
        pos = int(self.pos_combobox.currentText())
        text = self.text_edit.text()
        self.oled.write_line(line, pos, text)

    def draw_clicked(self):
        data = []

        for i in range(64):
            for j in range(128):
                if QColor(self.scribble_widget.image().pixel(j,
                                                             i)) == Qt.white:
                    data.append(True)
                else:
                    data.append(False)

        async_call(self.oled.write_pixels, (0, 0, 127, 63, data), None,
                   self.increase_error_count)

    def get_display_configuration_async(self, conf):
        self.contrast_slider.setValue(conf.contrast)
        self.invert_checkbox.setChecked(conf.invert)

    def read_pixels_async(self, pixels):
        for i in range(64):
            for j in range(128):
                if pixels[i * 128 + j]:
                    self.scribble_widget.image().setPixel(j, i, 0xFFFFFF)
                else:
                    self.scribble_widget.image().setPixel(j, i, 0)

        self.scribble_widget.update()

    def start(self):
        # Use response expected for write_line function, to make sure that the
        # data queue can't fill up while you move the slider around.
        self.write_line_response_expected = self.oled.get_response_expected(
            self.oled.FUNCTION_WRITE_LINE)
        self.oled.set_response_expected(self.oled.FUNCTION_WRITE_LINE, True)

        async_call(self.oled.get_display_configuration, None,
                   self.get_display_configuration_async,
                   self.increase_error_count)
        async_call(self.oled.read_pixels, (0, 0, 127, 63),
                   self.read_pixels_async, self.increase_error_count)

    def stop(self):
        if self.write_line_response_expected != None:
            self.oled.set_response_expected(self.oled.FUNCTION_WRITE_LINE,
                                            self.write_line_response_expected)

    def destroy(self):
        pass

    @staticmethod
    def has_device_identifier(device_identifier):
        return device_identifier == BrickletOLED128x64V2.DEVICE_IDENTIFIER
Example #2
0
class OLED64x48(PluginBase, Ui_OLED64x48):
    def __init__(self, *args):
        PluginBase.__init__(self, BrickletOLED64x48, *args)

        self.setupUi(self)

        self.oled = self.device

        self.scribble_widget = ScribbleWidget(64,
                                              48,
                                              7,
                                              QColor(Qt.white),
                                              QColor(Qt.black),
                                              enable_grid=False)
        self.image_button_layout.insertWidget(0, self.scribble_widget)

        self.contrast_syncer = SliderSpinSyncer(
            self.contrast_slider, self.contrast_spin,
            lambda value: self.new_configuration())
        self.char_syncer = SliderSpinSyncer(self.char_slider, self.char_spin,
                                            self.char_slider_changed)

        self.draw_button.clicked.connect(self.draw_clicked)
        self.clear_button.clicked.connect(self.clear_clicked)
        self.send_button.clicked.connect(self.send_clicked)
        self.clear_display_button.clicked.connect(self.clear_display_clicked)
        self.invert_checkbox.stateChanged.connect(self.new_configuration)

        self.current_char_value = -1

    def char_slider_changed(self, value):
        if value != self.current_char_value:
            self.current_char_value = value
            self.write_chars(value)
            self.char_slider.setValue(value)

    def new_configuration(self):
        contrast = self.contrast_spin.value()
        invert = self.invert_checkbox.isChecked()
        self.oled.set_display_configuration(contrast, invert)

    def write_chars(self, value):
        if value > 250:
            value = 250
        for j in range(6):
            start = ""
            if value + j < 10:
                start = "  "
            elif value + j < 100:
                start = " "
            self.oled.write_line(
                j, 3, start + str(value + j) + ": " + chr(value + j) + '\0')

    def clear_display_clicked(self):
        self.oled.new_window(0, 63, 0, 5)
        self.oled.clear_display()

    def clear_clicked(self):
        self.scribble_widget.clear_image()

    def send_clicked(self):
        line = int(self.line_combobox.currentText())
        pos = int(self.pos_combobox.currentText())
        text = self.text_edit.text()
        self.oled.write_line(line, pos, text)

    def draw_clicked(self):
        lcd = []
        for i in range(6):
            lcd.append([])
            for j in range(64):
                page = 0
                for k in range(8):
                    if QColor(self.scribble_widget.image().pixel(
                            j, i * 8 + k)) == Qt.white:
                        page |= 1 << k

                lcd[i].append(page)

        self.oled.new_window(0, 63, 0, 5)
        for i in range(6):
            self.oled.write(lcd[i])

    def get_display_configuration_async(self, conf):
        self.contrast_slider.setValue(conf.contrast)
        self.invert_checkbox.setChecked(conf.invert)

    def start(self):
        async_call(self.oled.get_display_configuration, None,
                   self.get_display_configuration_async,
                   self.increase_error_count)

    def stop(self):
        pass

    def destroy(self):
        pass

    @staticmethod
    def has_device_identifier(device_identifier):
        return device_identifier == BrickletOLED64x48.DEVICE_IDENTIFIER
Example #3
0
class OLED128x64V2(COMCUPluginBase, Ui_OLED128x64V2):
    def __init__(self, *args):
        COMCUPluginBase.__init__(self, BrickletOLED128x64V2, *args)

        self.setupUi(self)

        self.oled = self.device

        self.scribble_widget = ScribbleWidget(128, 64, 5, QColor(Qt.white), QColor(Qt.black), enable_grid=False)
        self.image_button_layout.insertWidget(0, self.scribble_widget)

        self.contrast_syncer = SliderSpinSyncer(self.contrast_slider, self.contrast_spin, lambda value: self.new_configuration())
        self.char_syncer = SliderSpinSyncer(self.char_slider, self.char_spin, self.char_slider_changed)

        self.draw_button.clicked.connect(self.draw_clicked)
        self.clear_button.clicked.connect(self.clear_clicked)
        self.send_button.clicked.connect(self.send_clicked)
        self.clear_display_button.clicked.connect(self.clear_display_clicked)
        self.invert_checkbox.stateChanged.connect(self.new_configuration)

        self.current_char_value = -1

        self.write_line_response_expected = None

    def char_slider_changed(self, value):
        if value != self.current_char_value:
            self.current_char_value = value
            self.write_chars(value)
            self.char_slider.setValue(value)

    def new_configuration(self):
        contrast = self.contrast_slider.value()
        invert = self.invert_checkbox.isChecked()
        self.oled.set_display_configuration(contrast, invert, True)

    def write_chars(self, value):
        if value > 248:
            value = 248
        for j in range(8):
            start = ""
            if value + j < 10:
                start = "  "
            elif value + j < 100:
                start = " "
            async_call(self.oled.write_line, (j, 8, start + str(value + j) + ": " + chr(value + j) + '\0'), None, self.increase_error_count)

    def clear_display_clicked(self):
        self.oled.clear_display()

    def clear_clicked(self):
        self.scribble_widget.clear_image()

    def send_clicked(self):
        line = int(self.line_combobox.currentText())
        pos = int(self.pos_combobox.currentText())
        text = self.text_edit.text()
        self.oled.write_line(line, pos, text)

    def draw_clicked(self):
        data = []

        for i in range(64):
            for j in range(128):
                if QColor(self.scribble_widget.image().pixel(j, i)) == Qt.white:
                    data.append(True)
                else:
                    data.append(False)

        async_call(self.oled.write_pixels, (0, 0, 127, 63, data), None, self.increase_error_count)

    def get_display_configuration_async(self, conf):
        self.contrast_slider.setValue(conf.contrast)
        self.invert_checkbox.setChecked(conf.invert)

    def read_pixels_async(self, pixels):
        for i in range(64):
            for j in range(128):
                if pixels[i*128 + j]:
                    self.scribble_widget.image().setPixel(j, i, 0xFFFFFF)
                else:
                    self.scribble_widget.image().setPixel(j, i, 0)

        self.scribble_widget.update()

    def start(self):
        # Use response expected for write_line function, to make sure that the
        # data queue can't fill up while you move the slider around.
        self.write_line_response_expected = self.oled.get_response_expected(self.oled.FUNCTION_WRITE_LINE)
        self.oled.set_response_expected(self.oled.FUNCTION_WRITE_LINE, True)

        async_call(self.oled.get_display_configuration, None, self.get_display_configuration_async, self.increase_error_count)
        async_call(self.oled.read_pixels, (0, 0, 127, 63), self.read_pixels_async, self.increase_error_count)

    def stop(self):
        if self.write_line_response_expected != None:
            self.oled.set_response_expected(self.oled.FUNCTION_WRITE_LINE, self.write_line_response_expected)

    def destroy(self):
        pass

    @staticmethod
    def has_device_identifier(device_identifier):
        return device_identifier == BrickletOLED128x64V2.DEVICE_IDENTIFIER
Example #4
0
class OLED128x64(PluginBase, Ui_OLED128x64):
    def __init__(self, *args):
        PluginBase.__init__(self, BrickletOLED128x64, *args)

        self.setupUi(self)

        self.oled = self.device

        self.scribble_widget = ScribbleWidget(128, 64, 5, QColor(Qt.white), QColor(Qt.black), enable_grid=False)
        self.image_button_layout.insertWidget(0, self.scribble_widget)

        self.contrast_syncer = SliderSpinSyncer(self.contrast_slider, self.contrast_spin, lambda value: self.new_configuration())
        self.char_syncer = SliderSpinSyncer(self.char_slider, self.char_spin, self.char_slider_changed)

        self.draw_button.clicked.connect(self.draw_clicked)
        self.clear_button.clicked.connect(self.clear_clicked)
        self.send_button.clicked.connect(self.send_clicked)
        self.clear_display_button.clicked.connect(self.clear_display_clicked)
        self.invert_checkbox.stateChanged.connect(self.new_configuration)

        self.current_char_value = -1

    def char_slider_changed(self, value):
        if value != self.current_char_value:
            self.current_char_value = value
            self.write_chars(value)
            self.char_slider.setValue(value)

    def new_configuration(self):
        contrast = self.contrast_slider.value()
        invert = self.invert_checkbox.isChecked()
        self.oled.set_display_configuration(contrast, invert)

    def write_chars(self, value):
        if value > 248:
            value = 248
        for j in range(8):
            start = ""
            if value + j < 10:
                start = "  "
            elif value + j < 100:
                start = " "
            self.oled.write_line(j, 8, start + str(value+j) + ": " + chr(value+j) + '\0')

    def clear_display_clicked(self):
        self.oled.new_window(0, 127, 0, 7)
        self.oled.clear_display()

    def clear_clicked(self):
        self.scribble_widget.clear_image()

    def send_clicked(self):
        line = int(self.line_combobox.currentText())
        pos = int(self.pos_combobox.currentText())
        text = self.text_edit.text()
        self.oled.write_line(line, pos, text)

    def draw_clicked(self):
        lcd_index = 0
        lcd = []
        for i in range(8):
            for j in range(128):
                page = 0
                for k in range(8):
                    if QColor(self.scribble_widget.image().pixel(j, i*8 + k)) == Qt.white:
                        page |= 1 << k

                if len(lcd) <= lcd_index:
                    lcd.append([])

                lcd[lcd_index].append(page)
                if len(lcd[lcd_index]) == 64:
                    lcd_index += 1

        self.oled.new_window(0, 127, 0, 7)
        for i in range(len(lcd)):
            self.oled.write(lcd[i])

    def get_display_configuration_async(self, conf):
        self.contrast_slider.setValue(conf.contrast)
        self.invert_checkbox.setChecked(conf.invert)

    def start(self):
        async_call(self.oled.get_display_configuration, None, self.get_display_configuration_async, self.increase_error_count)

    def stop(self):
        pass

    def destroy(self):
        pass

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