Beispiel #1
0
    def _init_lcd(self, uid):
        try:
            self.lcd = BrickletLCD128x64(uid, self.ipcon)
            self.lcd.clear_display()
            self.lcd.remove_all_gui()
            LOGGER.info("LCD128x64 initialized")
        except TFConnectionError as error:
            LOGGER.error("LCD128x64 init failed: " + str(error.description))
            return

        self.lcd.set_gui_tab_selected_callback_configuration(
            GUI_READ_PERIOD, True)
        self.lcd.register_callback(BrickletLCD128x64.CALLBACK_GUI_TAB_SELECTED,
                                   self.cb_tab)
        self.lcd.set_gui_tab_configuration(
            self.lcd.CHANGE_TAB_ON_CLICK_AND_SWIPE, True)
        self.lcd.set_gui_tab_icon(0, CONTROL_ICON)
        self.lcd.set_gui_tab_icon(1, GRAPH_ICON)
        self.lcd.set_gui_tab_icon(2, SETTINGS_ICON)

        self.lcd.set_gui_button_pressed_callback_configuration(
            GUI_READ_PERIOD, True)
        self.lcd.register_callback(
            BrickletLCD128x64.CALLBACK_GUI_BUTTON_PRESSED, self.cb_button)

        # Set initial tab
        self.cb_tab(self.active_tab)
Beispiel #2
0
 def cb_enumerate(self, uid, connected_uid, position, hardware_version,
                  firmware_version, device_identifier, enumeration_type):
     if enumeration_type == IPConnection.ENUMERATION_TYPE_CONNECTED or \
        enumeration_type == IPConnection.ENUMERATION_TYPE_AVAILABLE:
         if device_identifier == BrickletLCD128x64.DEVICE_IDENTIFIER:
             try:
                 # Initialize newly enumerated LCD128x64 Bricklet
                 self.lcd = BrickletLCD128x64(uid, self.ipcon)
                 self.lcd.clear_display()
                 self.lcd.write_line(0, 0, "   Weather Station")
                 log.info('LCD 128x64 initialized')
             except Error as e:
                 log.error('LCD 128x64 init failed: ' + str(e.description))
                 self.lcd = None
         elif device_identifier == BrickletAirQuality.DEVICE_IDENTIFIER:
             try:
                 # Initialize newly enumaratedy Air Quality Bricklet and configure callbacks
                 self.air_quality = BrickletAirQuality(uid, self.ipcon)
                 self.air_quality.set_all_values_callback_configuration(
                     1000, False)
                 self.air_quality.register_callback(
                     self.air_quality.CALLBACK_ALL_VALUES,
                     self.cb_all_values)
                 log.info('Air Quality initialized')
             except Error as e:
                 log.error('Air Quality init failed: ' + str(e.description))
                 self.air_quality = None
from tinkerforge.bricklet_lcd_128x64 import BrickletLCD128x64

def draw_image(lcd, start_column, start_row, column_count, row_count, image):
    image_data = image.load()
    pixels = []

    # Convert image pixels into 8bit pages
    for row in range(row_count):
        for column in range(column_count):
            pixels.append(image_data[column, row] != 0)

    lcd.write_pixels(0, 0, WIDTH-1, HEIGHT-1, pixels)

if __name__ == "__main__":
    ipcon = IPConnection() # Create IP connection
    lcd = BrickletLCD128x64(UID, ipcon) # Create device object

    ipcon.connect(HOST, PORT) # Connect to brickd
    # Don't use device before ipcon is connected

    # Clear display
    lcd.clear_display()

    # Draw rotating line
    image = Image.new("1", (WIDTH, HEIGHT), 0)
    draw = ImageDraw.Draw(image)
    origin_x = WIDTH // 2
    origin_y = HEIGHT // 2
    length = HEIGHT // 2 - 2
    angle = 0
Beispiel #4
0
def cb_high_contrast_image(lcd, image):
    # Convert 8 bit thermal image into 1 bit image for LCD 128x64
    image_bw = []
    for x in image:
        image_bw.append(x > THRESHOLD)

    # Draw 1 bit image to to center of LCD 128x64
    lcd.write_pixels(24, 2, TI_WIDTH + 24 - 1, TI_HEIGHT + 2 - 1, image_bw)


if __name__ == "__main__":
    ipcon = IPConnection()  # Create IP connection

    # Create device objects
    ti = BrickletThermalImaging(UID_TI, ipcon)
    lcd = BrickletLCD128x64(UID_LCD, ipcon)

    ipcon.connect(HOST, PORT)  # Connect to brickd
    # Don't use device before ipcon is connected

    # Clear image
    lcd.clear_display()

    # Register high contrast image callback to function cb_high_contrast_image
    ti.register_callback(ti.CALLBACK_HIGH_CONTRAST_IMAGE,
                         lambda x: cb_high_contrast_image(lcd, x))

    # Enable high contrast image transfer for callback
    ti.set_image_transfer_config(
        ti.IMAGE_TRANSFER_CALLBACK_HIGH_CONTRAST_IMAGE)
 def __init__(self, UID_LCD, ipcon: IPConnection):
     self.display = BrickletLCD128x64(UID_LCD, ipcon)
Beispiel #6
0
 def __init__(self, UID_LCD, UID_PIEZO,
              ipcon: IPConnection):  # init function
     self.display = BrickletLCD128x64(UID_LCD, ipcon)
     self.sound = BrickletPiezoSpeakerV2(UID_PIEZO, ipcon)