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
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
class LCD16x2(PluginBase): MAX_LINE = 2 MAX_POSITION = 16 qtcb_pressed = pyqtSignal(int) qtcb_released = pyqtSignal(int) def __init__(self, *args): super().__init__(BrickletLCD16x2, *args) self.lcd = self.device # the firmware version of a EEPROM Bricklet can (under common circumstances) # not change during the lifetime of an EEPROM Bricklet plugin. therefore, # it's okay to make final decisions based on it here self.has_custom_character = self.firmware_version >= (2, 0, 1) self.qtcb_pressed.connect(self.cb_pressed) self.lcd.register_callback(self.lcd.CALLBACK_BUTTON_PRESSED, self.qtcb_pressed.emit) self.qtcb_released.connect(self.cb_released) self.lcd.register_callback(self.lcd.CALLBACK_BUTTON_RELEASED, self.qtcb_released.emit) self.line_label = QLabel('Line:') self.line_combo = QComboBox() for i in range(LCD16x2.MAX_LINE): self.line_combo.addItem(str(i)) self.pos_label = QLabel('Position:') self.pos_combo = QComboBox() for i in range(LCD16x2.MAX_POSITION): self.pos_combo.addItem(str(i)) self.line_pos_layout = QHBoxLayout() self.line_pos_layout.addWidget(self.line_label) self.line_pos_layout.addWidget(self.line_combo) self.line_pos_layout.addWidget(self.pos_label) self.line_pos_layout.addWidget(self.pos_combo) self.line_pos_layout.addStretch() self.text_label = QLabel('Text:') self.text_edit = QLineEdit() self.text_edit.setMaxLength(LCD16x2.MAX_POSITION) self.text_button = QPushButton('Send Text') self.text_layout = QHBoxLayout() self.text_layout.addWidget(self.text_label) self.text_layout.addWidget(self.text_edit) self.text_layout.addWidget(self.text_button) self.clear_button = QPushButton("Clear Display") self.bl_button = QPushButton() self.cursor_button = QPushButton() self.blink_button = QPushButton() self.onofflayout = QHBoxLayout() self.onofflayout.addWidget(self.bl_button) self.onofflayout.addWidget(self.cursor_button) self.onofflayout.addWidget(self.blink_button) self.b0_label = QLabel('Button 0: Released,') self.b1_label = QLabel('Button 1: Released,') self.b2_label = QLabel('Button 2: Released') self.buttonlayout = QHBoxLayout() self.buttonlayout.addWidget(self.b0_label) self.buttonlayout.addWidget(self.b1_label) self.buttonlayout.addWidget(self.b2_label) self.cursor_button.clicked.connect(self.cursor_clicked) self.blink_button.clicked.connect(self.blink_clicked) self.clear_button.clicked.connect(self.clear_clicked) self.bl_button.clicked.connect(self.bl_clicked) self.text_button.clicked.connect(self.text_clicked) if self.has_custom_character: line = QFrame() line.setObjectName("line") line.setFrameShape(QFrame.HLine) line.setFrameShadow(QFrame.Sunken) self.scribble_widget = ScribbleWidget(5, 8, 25, QColor(Qt.white), QColor(Qt.blue)) self.char_index_label = QLabel('Index:') self.char_index_combo = QComboBox() self.char_index_combo.currentIndexChanged.connect(self.char_index_changed) for i in range(8): self.char_index_combo.addItem(str(i)) self.char_index_layout = QHBoxLayout() self.char_index_layout.addStretch() self.char_index_layout.addWidget(self.char_index_label) self.char_index_layout.addWidget(self.char_index_combo) self.char_index_layout.addStretch() self.char_index_save = QPushButton('Save Character') self.char_index_save.clicked.connect(self.char_index_save_clicked) self.char_show = QPushButton('Show all Custom Characters on LCD') self.char_show.clicked.connect(self.show_clicked) self.char_save_layout = QVBoxLayout() self.char_save_layout.addStretch() self.char_save_layout.addLayout(self.char_index_layout) self.char_save_layout.addWidget(self.char_index_save) self.char_save_layout.addWidget(self.char_show) help_label = QLabel('Use "\\0, \\1, ..., \\7" in text field to show custom characters.') help_label.setWordWrap(True) self.char_save_layout.addWidget(help_label) self.char_save_layout.addStretch() grid_stretch_layout = QHBoxLayout() grid_stretch_layout.addWidget(QLabel('Custom Character:')) grid_stretch_layout.addWidget(self.scribble_widget) grid_stretch_layout.addLayout(self.char_save_layout) grid_stretch_layout.addStretch() self.char_main_layout = QHBoxLayout() self.char_main_layout.addStretch() self.char_main_layout.addLayout(grid_stretch_layout) self.char_main_layout.addStretch() layout = QVBoxLayout(self) layout.addLayout(self.line_pos_layout) layout.addLayout(self.text_layout) layout.addWidget(self.clear_button) layout.addLayout(self.onofflayout) layout.addLayout(self.buttonlayout) if self.has_custom_character: layout.addWidget(line) layout.addLayout(self.char_main_layout) layout.addStretch(1) def is_backlight_on_async(self, on): if on: self.bl_button.setText('Backlight Off') else: self.bl_button.setText('Backlight On') def get_config_async(self, config): cursor, blink = config if cursor: self.cursor_button.setText('Cursor Off') else: self.cursor_button.setText('Cursor On') if blink: self.blink_button.setText('Blink Off') else: self.blink_button.setText('Blink On') def start(self): async_call(self.lcd.is_backlight_on, None, self.is_backlight_on_async, self.increase_error_count) async_call(self.lcd.get_config, None, self.get_config_async, self.increase_error_count) def stop(self): pass def destroy(self): pass @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletLCD16x2.DEVICE_IDENTIFIER def cb_pressed(self, button): if button == 0: self.b0_label.setText('Button 0: Pressed,') elif button == 1: self.b1_label.setText('Button 1: Pressed,') elif button == 2: self.b2_label.setText('Button 2: Pressed') def cb_released(self, button): if button == 0: self.b0_label.setText('Button 0: Released,') elif button == 1: self.b1_label.setText('Button 1: Released,') elif button == 2: self.b2_label.setText('Button 2: Released') def bl_clicked(self): if self.bl_button.text().replace('&', '') == 'Backlight On': async_call(self.lcd.backlight_on, None, None, self.increase_error_count) self.bl_button.setText('Backlight Off') else: async_call(self.lcd.backlight_off, None, None, self.increase_error_count) self.bl_button.setText('Backlight On') def get_config(self): cursor = self.cursor_button.text().replace('&', '') == 'Cursor Off' blink = self.blink_button.text().replace('&', '') == 'Blink Off' return (cursor, blink) def cursor_clicked(self): cursor, blink = self.get_config() async_call(self.lcd.set_config, (not cursor, blink), None, self.increase_error_count) if cursor: self.cursor_button.setText('Cursor On') else: self.cursor_button.setText('Cursor Off') def blink_clicked(self): cursor, blink = self.get_config() async_call(self.lcd.set_config, (cursor, not blink), None, self.increase_error_count) if blink: self.blink_button.setText('Blink On') else: self.blink_button.setText('Blink Off') def clear_clicked(self): async_call(self.lcd.clear_display, None, None, self.increase_error_count) def text_clicked(self): line = int(self.line_combo.currentText()) position = int(self.pos_combo.currentText()) text = self.text_edit.text() if self.has_custom_character: for i in range(8): text = text.replace('\\' + str(i), chr(i + 8)) async_call(self.lcd.write_line, (line, position, unicode_to_ks0066u(text)), None, self.increase_error_count) def char_index_save_clicked(self): char = [0] * 8 img = self.scribble_widget.image() for j in range(img.height()): for i in range(img.width() - 1, -1, -1): if img.pixel(i, j) == self.scribble_widget.foreground_color().rgb(): char[j] |= 1 << (4 - i) index = int(self.char_index_combo.currentText()) async_call(self.lcd.set_custom_character, (index, char), None, self.increase_error_count) def show_clicked(self): async_call(self.lcd.clear_display, None, None, self.increase_error_count) line1 = '0:{0} 1:{1} 2:{2} 3:{3}'.format(chr(8), chr(9), chr(10), chr(11)) line2 = '4:{0} 5:{1} 6:{2} 7:{3}'.format(chr(12), chr(13), chr(14), chr(15)) async_call(self.lcd.write_line, (0, 0, line1), None, self.increase_error_count) async_call(self.lcd.write_line, (1, 0, line2), None, self.increase_error_count) def custom_character_async(self, characters): r = [] g = [] b = [] for j in range(self.scribble_widget.image().height()): for i in range(self.scribble_widget.image().width() - 1, -1, -1): if characters[j] & (1 << i): r.append(255) g.append(255) b.append(255) else: r.append(0) g.append(0) b.append(255) self.scribble_widget.array_draw(r, g, b) def char_index_changed(self, index): async_call(self.lcd.get_custom_character, index, self.custom_character_async, self.increase_error_count)
class LCD16x2(PluginBase): MAX_LINE = 2 MAX_POSITION = 16 qtcb_pressed = pyqtSignal(int) qtcb_released = pyqtSignal(int) def __init__(self, *args): super().__init__(BrickletLCD16x2, *args) self.lcd = self.device # the firmware version of a EEPROM Bricklet can (under common circumstances) # not change during the lifetime of an EEPROM Bricklet plugin. therefore, # it's okay to make final decisions based on it here self.has_custom_character = self.firmware_version >= (2, 0, 1) self.qtcb_pressed.connect(self.cb_pressed) self.lcd.register_callback(self.lcd.CALLBACK_BUTTON_PRESSED, self.qtcb_pressed.emit) self.qtcb_released.connect(self.cb_released) self.lcd.register_callback(self.lcd.CALLBACK_BUTTON_RELEASED, self.qtcb_released.emit) self.line_label = QLabel('Line:') self.line_combo = QComboBox() for i in range(LCD16x2.MAX_LINE): self.line_combo.addItem(str(i)) self.pos_label = QLabel('Position:') self.pos_combo = QComboBox() for i in range(LCD16x2.MAX_POSITION): self.pos_combo.addItem(str(i)) self.line_pos_layout = QHBoxLayout() self.line_pos_layout.addWidget(self.line_label) self.line_pos_layout.addWidget(self.line_combo) self.line_pos_layout.addWidget(self.pos_label) self.line_pos_layout.addWidget(self.pos_combo) self.line_pos_layout.addStretch() self.text_label = QLabel('Text:') self.text_edit = QLineEdit() self.text_edit.setMaxLength(LCD16x2.MAX_POSITION) self.text_button = QPushButton('Send Text') self.text_layout = QHBoxLayout() self.text_layout.addWidget(self.text_label) self.text_layout.addWidget(self.text_edit) self.text_layout.addWidget(self.text_button) self.clear_button = QPushButton("Clear Display") self.bl_button = QPushButton() self.cursor_button = QPushButton() self.blink_button = QPushButton() self.onofflayout = QHBoxLayout() self.onofflayout.addWidget(self.bl_button) self.onofflayout.addWidget(self.cursor_button) self.onofflayout.addWidget(self.blink_button) self.b0_label = QLabel('Button 0: Released,') self.b1_label = QLabel('Button 1: Released,') self.b2_label = QLabel('Button 2: Released') self.buttonlayout = QHBoxLayout() self.buttonlayout.addWidget(self.b0_label) self.buttonlayout.addWidget(self.b1_label) self.buttonlayout.addWidget(self.b2_label) self.cursor_button.clicked.connect(self.cursor_clicked) self.blink_button.clicked.connect(self.blink_clicked) self.clear_button.clicked.connect(self.clear_clicked) self.bl_button.clicked.connect(self.bl_clicked) self.text_button.clicked.connect(self.text_clicked) if self.has_custom_character: line = QFrame() line.setObjectName("line") line.setFrameShape(QFrame.HLine) line.setFrameShadow(QFrame.Sunken) self.scribble_widget = ScribbleWidget(5, 8, 25, QColor(Qt.white), QColor(Qt.blue)) self.char_index_label = QLabel('Index:') self.char_index_combo = QComboBox() self.char_index_combo.currentIndexChanged.connect( self.char_index_changed) for i in range(8): self.char_index_combo.addItem(str(i)) self.char_index_layout = QHBoxLayout() self.char_index_layout.addStretch() self.char_index_layout.addWidget(self.char_index_label) self.char_index_layout.addWidget(self.char_index_combo) self.char_index_layout.addStretch() self.char_index_save = QPushButton('Save Character') self.char_index_save.clicked.connect(self.char_index_save_clicked) self.char_show = QPushButton('Show all Custom Characters on LCD') self.char_show.clicked.connect(self.show_clicked) self.char_save_layout = QVBoxLayout() self.char_save_layout.addStretch() self.char_save_layout.addLayout(self.char_index_layout) self.char_save_layout.addWidget(self.char_index_save) self.char_save_layout.addWidget(self.char_show) help_label = QLabel( 'Use "\\0, \\1, ..., \\7" in text field to show custom characters.' ) help_label.setWordWrap(True) self.char_save_layout.addWidget(help_label) self.char_save_layout.addStretch() grid_stretch_layout = QHBoxLayout() grid_stretch_layout.addWidget(QLabel('Custom Character:')) grid_stretch_layout.addWidget(self.scribble_widget) grid_stretch_layout.addLayout(self.char_save_layout) grid_stretch_layout.addStretch() self.char_main_layout = QHBoxLayout() self.char_main_layout.addStretch() self.char_main_layout.addLayout(grid_stretch_layout) self.char_main_layout.addStretch() layout = QVBoxLayout(self) layout.addLayout(self.line_pos_layout) layout.addLayout(self.text_layout) layout.addWidget(self.clear_button) layout.addLayout(self.onofflayout) layout.addLayout(self.buttonlayout) if self.has_custom_character: layout.addWidget(line) layout.addLayout(self.char_main_layout) layout.addStretch(1) def is_backlight_on_async(self, on): if on: self.bl_button.setText('Backlight Off') else: self.bl_button.setText('Backlight On') def get_config_async(self, config): cursor, blink = config if cursor: self.cursor_button.setText('Cursor Off') else: self.cursor_button.setText('Cursor On') if blink: self.blink_button.setText('Blink Off') else: self.blink_button.setText('Blink On') def start(self): async_call(self.lcd.is_backlight_on, None, self.is_backlight_on_async, self.increase_error_count) async_call(self.lcd.get_config, None, self.get_config_async, self.increase_error_count) def stop(self): pass def destroy(self): pass @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletLCD16x2.DEVICE_IDENTIFIER def cb_pressed(self, button): if button == 0: self.b0_label.setText('Button 0: Pressed,') elif button == 1: self.b1_label.setText('Button 1: Pressed,') elif button == 2: self.b2_label.setText('Button 2: Pressed') def cb_released(self, button): if button == 0: self.b0_label.setText('Button 0: Released,') elif button == 1: self.b1_label.setText('Button 1: Released,') elif button == 2: self.b2_label.setText('Button 2: Released') def bl_clicked(self): if self.bl_button.text().replace('&', '') == 'Backlight On': async_call(self.lcd.backlight_on, None, None, self.increase_error_count) self.bl_button.setText('Backlight Off') else: async_call(self.lcd.backlight_off, None, None, self.increase_error_count) self.bl_button.setText('Backlight On') def get_config(self): cursor = self.cursor_button.text().replace('&', '') == 'Cursor Off' blink = self.blink_button.text().replace('&', '') == 'Blink Off' return (cursor, blink) def cursor_clicked(self): cursor, blink = self.get_config() async_call(self.lcd.set_config, (not cursor, blink), None, self.increase_error_count) if cursor: self.cursor_button.setText('Cursor On') else: self.cursor_button.setText('Cursor Off') def blink_clicked(self): cursor, blink = self.get_config() async_call(self.lcd.set_config, (cursor, not blink), None, self.increase_error_count) if blink: self.blink_button.setText('Blink On') else: self.blink_button.setText('Blink Off') def clear_clicked(self): async_call(self.lcd.clear_display, None, None, self.increase_error_count) def text_clicked(self): line = int(self.line_combo.currentText()) position = int(self.pos_combo.currentText()) text = self.text_edit.text() if self.has_custom_character: for i in range(8): text = text.replace('\\' + str(i), chr(i + 8)) async_call(self.lcd.write_line, (line, position, unicode_to_ks0066u(text)), None, self.increase_error_count) def char_index_save_clicked(self): char = [0] * 8 img = self.scribble_widget.image() for j in range(img.height()): for i in range(img.width() - 1, -1, -1): if img.pixel( i, j) == self.scribble_widget.foreground_color().rgb(): char[j] |= 1 << (4 - i) index = int(self.char_index_combo.currentText()) async_call(self.lcd.set_custom_character, (index, char), None, self.increase_error_count) def show_clicked(self): async_call(self.lcd.clear_display, None, None, self.increase_error_count) line1 = '0:{0} 1:{1} 2:{2} 3:{3}'.format(chr(8), chr(9), chr(10), chr(11)) line2 = '4:{0} 5:{1} 6:{2} 7:{3}'.format(chr(12), chr(13), chr(14), chr(15)) async_call(self.lcd.write_line, (0, 0, line1), None, self.increase_error_count) async_call(self.lcd.write_line, (1, 0, line2), None, self.increase_error_count) def custom_character_async(self, characters): r = [] g = [] b = [] for j in range(self.scribble_widget.image().height()): for i in range(self.scribble_widget.image().width() - 1, -1, -1): if characters[j] & (1 << i): r.append(255) g.append(255) b.append(255) else: r.append(0) g.append(0) b.append(255) self.scribble_widget.array_draw(r, g, b) def char_index_changed(self, index): async_call(self.lcd.get_custom_character, index, self.custom_character_async, self.increase_error_count)
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
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
class RGBLEDMatrix(COMCUPluginBase, Ui_RGBLEDMatrix): qtcb_frame_started = pyqtSignal(int) STATE_IDLE = 0 STATE_COLOR_GRADIENT = 3 STATE_COLOR_DOT = 4 STATE_COLOR_SCRIBBLE = 5 def __init__(self, *args): COMCUPluginBase.__init__(self, BrickletRGBLEDMatrix, *args) self.setupUi(self) self.rgb_led_matrix = self.device self.color_button = QColorButton() self.below_scribble_layout.insertWidget(2, self.color_button) self.scribble_widget = ScribbleWidget(8, 8, 35, self.color_button.color(), QColor(Qt.black)) def set_state_scribble(): self.state = self.STATE_COLOR_SCRIBBLE self.scribble_widget.scribbling_started.connect(set_state_scribble) self.scribble_layout.insertWidget(1, self.scribble_widget) self.qtcb_frame_started.connect(self.cb_frame_started) self.color_button.colorChanged.connect(self.color_changed) self.button_clear_drawing.clicked.connect( self.scribble_widget.clear_image) self.button_drawing.clicked.connect(self.drawing_clicked) self.button_color.clicked.connect(self.color_clicked) self.button_gradient.clicked.connect(self.gradient_clicked) self.button_dot.clicked.connect(self.dot_clicked) self.box_frame_duration.valueChanged.connect( self.frame_duration_changed) self.state = self.STATE_IDLE self.gradient_counter = 0 self.dot_counter = 0 self.dot_direction = 1 self.voltage = 0 self.cbe_supply_voltage = CallbackEmulator( self, self.rgb_led_matrix.get_supply_voltage, None, self.cb_supply_voltage, self.increase_error_count) def set_rgb(self, r, g, b): async_call(self.rgb_led_matrix.set_red, r, None, self.increase_error_count) async_call(self.rgb_led_matrix.set_green, g, None, self.increase_error_count) async_call(self.rgb_led_matrix.set_blue, b, None, self.increase_error_count) def cb_supply_voltage(self, voltage): self.label_voltage.setText(str(voltage / 1000.0) + 'V') def cb_frame_started(self): if self.state == self.STATE_COLOR_GRADIENT: self.render_color_gradient() elif self.state == self.STATE_COLOR_DOT: self.render_color_dot() elif self.state == self.STATE_COLOR_SCRIBBLE: self.render_color_scribble() def color_changed(self): self.scribble_widget.set_foreground_color(self.color_button.color()) def frame_duration_changed(self, duration): async_call(self.rgb_led_matrix.set_frame_duration, duration, None, self.increase_error_count) def drawing_clicked(self): old_state = self.state self.state = self.STATE_COLOR_SCRIBBLE if old_state == self.STATE_IDLE: self.render_color_scribble() def color_clicked(self): old_state = self.state self.state = self.STATE_COLOR_SCRIBBLE self.scribble_widget.fill_image(self.color_button.color()) if old_state == self.STATE_IDLE: self.render_color_scribble() def gradient_clicked(self): old_state = self.state self.state = self.STATE_COLOR_GRADIENT if old_state == self.STATE_IDLE: self.render_color_gradient() def dot_clicked(self): self.dot_counter = 0 self.dot_direction = 1 old_state = self.state self.state = self.STATE_COLOR_DOT if old_state == self.STATE_IDLE: self.render_color_dot() def render_color_scribble(self): r = [] g = [] b = [] for i in range(8): for j in range(8): color = QColor(self.scribble_widget.image().pixel(j, i)) r.append(color.red()) g.append(color.green()) b.append(color.blue()) self.set_rgb(r, g, b) def render_color_gradient(self): self.gradient_counter += NUM_LEDS * self.box_speed.value( ) / 100.0 / 4.0 ra = [] ga = [] ba = [] range_leds = list(range(NUM_LEDS)) range_leds = range_leds[ int(self.gradient_counter) % NUM_LEDS:] + range_leds[:int(self.gradient_counter) % NUM_LEDS] range_leds = reversed(range_leds) for i in range_leds: r, g, b = colorsys.hsv_to_rgb(1.0 * i / NUM_LEDS, 1, 0.2) ra.append(int(r * 255)) ga.append(int(g * 255)) ba.append(int(b * 255)) self.scribble_widget.array_draw(ra, ga, ba, 4) self.set_rgb(ra, ga, ba) def render_color_dot(self): color = self.color_button.color() r = color.red() g = color.green() b = color.blue() self.dot_counter = self.dot_counter % NUM_LEDS index = self.dot_counter line = self.dot_counter // 8 if line % 2: index = line * 8 + (7 - (self.dot_counter % 8)) r_val = [0] * NUM_LEDS g_val = [0] * NUM_LEDS b_val = [0] * NUM_LEDS r_val[index] = r g_val[index] = g b_val[index] = b self.scribble_widget.array_draw(r_val, g_val, b_val) self.set_rgb(r_val, g_val, b_val) self.dot_counter += self.dot_direction * self.box_speed.value() if self.dot_counter >= NUM_LEDS: self.dot_direction = -1 self.dot_counter = NUM_LEDS - 1 elif self.dot_counter < 0: self.dot_direction = 1 self.dot_counter = 0 def start(self): self.rgb_led_matrix.register_callback( self.rgb_led_matrix.CALLBACK_FRAME_STARTED, self.qtcb_frame_started.emit) self.cbe_supply_voltage.set_period(250) async_call(self.rgb_led_matrix.set_frame_duration, self.box_frame_duration.value(), None, self.increase_error_count) def stop(self): self.rgb_led_matrix.register_callback( self.rgb_led_matrix.CALLBACK_FRAME_STARTED, None) self.cbe_supply_voltage.set_period(0) async_call(self.rgb_led_matrix.set_frame_duration, 0, None, self.increase_error_count) def destroy(self): pass @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletRGBLEDMatrix.DEVICE_IDENTIFIER
class RGBLEDMatrix(COMCUPluginBase, Ui_RGBLEDMatrix): qtcb_frame_started = pyqtSignal(int) STATE_IDLE = 0 STATE_COLOR_GRADIENT = 3 STATE_COLOR_DOT = 4 STATE_COLOR_SCRIBBLE = 5 def __init__(self, *args): COMCUPluginBase.__init__(self, BrickletRGBLEDMatrix, *args) self.setupUi(self) self.rgb_led_matrix = self.device self.color_button = QColorButton() self.below_scribble_layout.insertWidget(2, self.color_button) self.scribble_widget = ScribbleWidget(8, 8, 35, self.color_button.color(), QColor(Qt.black)) def set_state_scribble(): self.state = self.STATE_COLOR_SCRIBBLE self.scribble_widget.scribbling_started.connect(set_state_scribble) self.scribble_layout.insertWidget(1, self.scribble_widget) self.qtcb_frame_started.connect(self.cb_frame_started) self.color_button.colorChanged.connect(self.color_changed) self.button_clear_drawing.clicked.connect(self.scribble_widget.clear_image) self.button_drawing.clicked.connect(self.drawing_clicked) self.button_color.clicked.connect(self.color_clicked) self.button_gradient.clicked.connect(self.gradient_clicked) self.button_dot.clicked.connect(self.dot_clicked) self.box_frame_duration.valueChanged.connect(self.frame_duration_changed) self.state = self.STATE_IDLE self.gradient_counter = 0 self.dot_counter = 0 self.dot_direction = 1 self.voltage = 0 self.cbe_supply_voltage = CallbackEmulator(self.rgb_led_matrix.get_supply_voltage, None, self.cb_supply_voltage, self.increase_error_count) def set_rgb(self, r, g, b): async_call(self.rgb_led_matrix.set_red, r, None, self.increase_error_count) async_call(self.rgb_led_matrix.set_green, g, None, self.increase_error_count) async_call(self.rgb_led_matrix.set_blue, b, None, self.increase_error_count) def cb_supply_voltage(self, voltage): self.label_voltage.setText(str(voltage / 1000.0) + 'V') def cb_frame_started(self): if self.state == self.STATE_COLOR_GRADIENT: self.render_color_gradient() elif self.state == self.STATE_COLOR_DOT: self.render_color_dot() elif self.state == self.STATE_COLOR_SCRIBBLE: self.render_color_scribble() def color_changed(self): self.scribble_widget.set_foreground_color(self.color_button.color()) def frame_duration_changed(self, duration): async_call(self.rgb_led_matrix.set_frame_duration, duration, None, self.increase_error_count) def drawing_clicked(self): old_state = self.state self.state = self.STATE_COLOR_SCRIBBLE if old_state == self.STATE_IDLE: self.render_color_scribble() def color_clicked(self): old_state = self.state self.state = self.STATE_COLOR_SCRIBBLE self.scribble_widget.fill_image(self.color_button.color()) if old_state == self.STATE_IDLE: self.render_color_scribble() def gradient_clicked(self): old_state = self.state self.state = self.STATE_COLOR_GRADIENT if old_state == self.STATE_IDLE: self.render_color_gradient() def dot_clicked(self): self.dot_counter = 0 self.dot_direction = 1 old_state = self.state self.state = self.STATE_COLOR_DOT if old_state == self.STATE_IDLE: self.render_color_dot() def render_color_scribble(self): r = [] g = [] b = [] for i in range(8): for j in range(8): color = QColor(self.scribble_widget.image().pixel(j, i)) r.append(color.red()) g.append(color.green()) b.append(color.blue()) self.set_rgb(r, g, b) def render_color_gradient(self): self.gradient_counter += NUM_LEDS * self.box_speed.value() / 100.0 / 4.0 ra = [] ga = [] ba = [] range_leds = list(range(NUM_LEDS)) range_leds = range_leds[int(self.gradient_counter) % NUM_LEDS:] + range_leds[:int(self.gradient_counter) % NUM_LEDS] range_leds = reversed(range_leds) for i in range_leds: r, g, b = colorsys.hsv_to_rgb(1.0*i/NUM_LEDS, 1, 0.2) ra.append(int(r*255)) ga.append(int(g*255)) ba.append(int(b*255)) self.scribble_widget.array_draw(ra, ga, ba, 4) self.set_rgb(ra, ga, ba) def render_color_dot(self): color = self.color_button.color() r = color.red() g = color.green() b = color.blue() self.dot_counter = self.dot_counter % NUM_LEDS index = self.dot_counter line = self.dot_counter // 8 if line % 2: index = line*8 + (7 - (self.dot_counter % 8)) r_val = [0]*NUM_LEDS g_val = [0]*NUM_LEDS b_val = [0]*NUM_LEDS r_val[index] = r g_val[index] = g b_val[index] = b self.scribble_widget.array_draw(r_val, g_val, b_val) self.set_rgb(r_val, g_val, b_val) self.dot_counter += self.dot_direction * self.box_speed.value() if self.dot_counter >= NUM_LEDS: self.dot_direction = -1 self.dot_counter = NUM_LEDS - 1 elif self.dot_counter < 0: self.dot_direction = 1 self.dot_counter = 0 def start(self): self.rgb_led_matrix.register_callback(self.rgb_led_matrix.CALLBACK_FRAME_STARTED, self.qtcb_frame_started.emit) self.cbe_supply_voltage.set_period(250) async_call(self.rgb_led_matrix.set_frame_duration, self.box_frame_duration.value(), None, self.increase_error_count) def stop(self): self.rgb_led_matrix.register_callback(self.rgb_led_matrix.CALLBACK_FRAME_STARTED, None) self.cbe_supply_voltage.set_period(0) async_call(self.rgb_led_matrix.set_frame_duration, 0, None, self.increase_error_count) def destroy(self): pass @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletRGBLEDMatrix.DEVICE_IDENTIFIER
class EPaper296x128(COMCUPluginBase, Ui_EPaper296x128): def __init__(self, *args): COMCUPluginBase.__init__(self, BrickletEPaper296x128, *args) self.setupUi(self) self.epaper = self.device self.scribble_widget = ScribbleWidget(WIDTH, HEIGHT, 2, QColor(Qt.white), QColor(Qt.black), enable_grid=False) self.image_button_layout.insertWidget(0, self.scribble_widget) self.draw_button.clicked.connect(self.draw_clicked) self.send_button.clicked.connect(self.send_clicked) self.fill_black_button.clicked.connect(lambda: self.fill_clicked(0)) self.fill_white_button.clicked.connect(lambda: self.fill_clicked(1)) self.fill_red_button.clicked.connect(lambda: self.fill_clicked(2)) self.color_radio_black.toggled.connect(self.radio_toggled) self.color_radio_white.toggled.connect(self.radio_toggled) self.color_radio_red.toggled.connect(self.radio_toggled) self.display_type = self.epaper.DISPLAY_TYPE_BLACK_WHITE_RED def radio_toggled(self): if self.color_radio_black.isChecked(): self.scribble_widget.set_foreground_color(QColor(Qt.black)) elif self.color_radio_white.isChecked(): self.scribble_widget.set_foreground_color(QColor(Qt.white)) elif self.color_radio_red.isChecked(): if self.display_type == self.epaper.DISPLAY_TYPE_BLACK_WHITE_RED: self.scribble_widget.set_foreground_color(QColor(Qt.red)) else: self.scribble_widget.set_foreground_color(QColor(Qt.darkGray)) def fill_clicked(self, color): self.epaper.fill_display(color) self.start() def send_clicked(self): pos_x = self.posx_spinbox.value() pos_y = self.posy_spinbox.value() font = self.font_combo.currentIndex() color = self.color_combo.currentIndex() orien = self.orientation_combo.currentIndex() text = self.text_edit.text() self.epaper.draw_text(pos_x, pos_y, font, color, orien, text) self.start() def draw_clicked(self): bw = [False] * WIDTH * HEIGHT red = [False] * WIDTH * HEIGHT for i in range(HEIGHT): for j in range(WIDTH): if QColor(self.scribble_widget.image().pixel(j, i)) == Qt.white: bw[i * WIDTH + j] = True if QColor(self.scribble_widget.image().pixel(j, i)) in (Qt.red, Qt.darkGray): red[i * WIDTH + j] = True self.epaper.write_black_white(0, 0, WIDTH - 1, HEIGHT - 1, bw) self.epaper.write_color(0, 0, WIDTH - 1, HEIGHT - 1, red) self.epaper.draw() def read_black_white_async(self, pixels): for i in range(HEIGHT): for j in range(WIDTH): if pixels[i * WIDTH + j]: self.scribble_widget.image().setPixel(j, i, 0xFFFFFF) else: self.scribble_widget.image().setPixel(j, i, 0) async_call(self.epaper.read_color, (0, 0, WIDTH - 1, HEIGHT - 1), self.read_color_async, self.increase_error_count) def read_color_async(self, pixels): if pixels: for i in range(HEIGHT): for j in range(WIDTH): if pixels[i * WIDTH + j]: if self.display_type == self.epaper.DISPLAY_TYPE_BLACK_WHITE_RED: self.scribble_widget.image().setPixel(j, i, 0xFF0000) else: self.scribble_widget.image().setPixel(j, i, 0x808080) self.scribble_widget.update() def get_display_type_async(self, display_type): self.display_type = display_type if display_type == self.epaper.DISPLAY_TYPE_BLACK_WHITE_RED: color = 'Red' else: color = 'Grey' self.fill_red_button.setText('Fill ' + color) self.color_radio_red.setText(color) self.color_combo.removeItem(2) self.color_combo.insertItem(2, color) def start(self): async_call(self.epaper.get_display_type, None, self.get_display_type_async, self.increase_error_count) async_call(self.epaper.read_black_white, (0, 0, WIDTH - 1, HEIGHT - 1), self.read_black_white_async, self.increase_error_count) def stop(self): pass def destroy(self): pass @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletEPaper296x128.DEVICE_IDENTIFIER