Пример #1
0
    def write_line(self, line, position, text):
        """
        Writes text to a specific line with a specific position.
        The text can have a maximum of 22 characters.

        For example: (1, 10, "Hello") will write *Hello* in the middle of the
        second line of the display.

        The display uses a special 5x7 pixel charset. You can view the characters
        of the charset in Brick Viewer.

        If automatic draw is enabled (default) the text is directly written to
        the screen. Only pixels that have actually changed are updated on the screen,
        the rest stays the same.

        If automatic draw is disabled the text is written to an internal buffer and
        the buffer is transferred to the display only after :func:`Draw Buffered Frame`
        is called. This can be used to avoid flicker when drawing a complex frame in
        multiple steps.

        Automatic draw can be configured with the :func:`Set Display Configuration`
        function.
        """
        self.check_validity()

        line = int(line)
        position = int(position)
        text = create_string(text)

        self.ipcon.send_request(self, BrickletOLED128x64V2.FUNCTION_WRITE_LINE,
                                (line, position, text), 'B B 22s', 0, '')
Пример #2
0
    def set_string_chunk(self, string_id, offset, buffer):
        """
        Sets a chunk of up to 58 bytes in a string object beginning at ``offset``.

        Returns the resulting error code.
        """
        string_id = int(string_id)
        offset = int(offset)
        buffer = create_string(buffer)

        return self.ipcon.send_request(self, BrickRED.FUNCTION_SET_STRING_CHUNK, (string_id, offset, buffer), 'H I 58s', 'B')
Пример #3
0
    def allocate_string(self, length_to_reserve, buffer, session_id):
        """
        Allocates a new string object, reserves ``length_to_reserve`` bytes memory
        for it and sets up to the first 60 bytes. Set ``length_to_reserve`` to the
        length of the string that should be stored in the string object.

        Returns the object ID of the new string object and the resulting error code.
        """
        length_to_reserve = int(length_to_reserve)
        buffer = create_string(buffer)
        session_id = int(session_id)

        return AllocateString(*self.ipcon.send_request(self, BrickRED.FUNCTION_ALLOCATE_STRING, (length_to_reserve, buffer, session_id), 'I 58s H', 'B H'))
Пример #4
0
    def set_default_text(self, line, text):
        """
        Sets the default text for lines 0-3. The max number of characters
        per line is 20.

        The default text is shown on the LCD, if the default text counter
        expires, see :func:`Set Default Text Counter`.

        .. versionadded:: 2.0.2$nbsp;(Plugin)
        """
        line = int(line)
        text = create_string(text)

        self.ipcon.send_request(self, BrickletLCD20x4.FUNCTION_SET_DEFAULT_TEXT, (line, text), 'B 20s', '')
Пример #5
0
    def morse_code(self, morse):
        """
        Sets morse code that will be played by the piezo buzzer. The morse code
        is given as a string consisting of "." (dot), "-" (minus) and " " (space)
        for *dits*, *dahs* and *pauses*. Every other character is ignored.

        For example: If you set the string "...---...", the piezo buzzer will beep
        nine times with the durations "short short short long long long short
        short short".
        """
        morse = create_string(morse)

        self.ipcon.send_request(self, BrickletPiezoBuzzer.FUNCTION_MORSE_CODE,
                                (morse, ), '60s', '')
Пример #6
0
    def set_default_text(self, line, text):
        """
        Sets the default text for lines 0-3. The max number of characters
        per line is 20.

        The default text is shown on the LCD, if the default text counter
        expires, see :func:`Set Default Text Counter`.

        .. versionadded:: 2.0.2$nbsp;(Plugin)
        """
        line = int(line)
        text = create_string(text)

        self.ipcon.send_request(self, BrickletLCD20x4.FUNCTION_SET_DEFAULT_TEXT, (line, text), 'B 20s', '')
Пример #7
0
    def morse_code(self, morse):
        """
        Sets morse code that will be played by the piezo buzzer. The morse code
        is given as a string consisting of "." (dot), "-" (minus) and " " (space)
        for *dits*, *dahs* and *pauses*. Every other character is ignored.

        For example: If you set the string "...---...", the piezo buzzer will beep
        nine times with the durations "short short short long long long short
        short short".

        The maximum string size is 60.
        """
        morse = create_string(morse)

        self.ipcon.send_request(self, BrickletPiezoBuzzer.FUNCTION_MORSE_CODE, (morse,), '60s', '')
Пример #8
0
    def write_line(self, line, position, text):
        """
        Writes text to a specific line (0 to 7) with a specific position
        (0 to 21). The text can have a maximum of 22 characters.

        For example: (1, 10, "Hello") will write *Hello* in the middle of the
        second line of the display.

        The display uses a special 5x7 pixel charset. You can view the characters
        of the charset in Brick Viewer.
        """
        line = int(line)
        position = int(position)
        text = create_string(text)

        self.ipcon.send_request(self, BrickletOLED128x64V2.FUNCTION_WRITE_LINE, (line, position, text), 'B B 22s', '')
Пример #9
0
    def write_line(self, line, position, text):
        """
        Writes text to a specific line (0 to 7) with a specific position
        (0 to 21). The text can have a maximum of 22 characters.

        For example: (1, 10, "Hello") will write *Hello* in the middle of the
        second line of the display.

        The display uses a special 5x7 pixel charset. You can view the characters
        of the charset in Brick Viewer.
        """
        line = int(line)
        position = int(position)
        text = create_string(text)

        self.ipcon.send_request(self, BrickletOLED128x64V2.FUNCTION_WRITE_LINE,
                                (line, position, text), 'B B 22s', '')
Пример #10
0
    def draw_text(self, position_x, position_y, font, color, orientation, text):
        """
        Draws a text with up to 50 characters at the pixel position (x, y).

        You can use one of 9 different font sizes and draw the text in
        black/white/red|gray. The text can be drawn horizontal or vertical.

        This function writes the pixels into the black/white/red|gray pixel buffer, to draw the buffer
        to the display use :func:`Draw`.
        """
        position_x = int(position_x)
        position_y = int(position_y)
        font = int(font)
        color = int(color)
        orientation = int(orientation)
        text = create_string(text)

        self.ipcon.send_request(self, BrickletEPaper296x128.FUNCTION_DRAW_TEXT, (position_x, position_y, font, color, orientation, text), 'H B B B B 50s', '')
Пример #11
0
    def draw_text(self, position_x, position_y, font, color, orientation, text):
        """
        Draws a text with up to 50 characters at the pixel position (x, y).

        The x values have to be within the range of 0 to 295 and the y
        values have to be within the range of 0 to 127.

        You can use one of 9 different font sizes and draw the text in
        black/white/red|gray. The text can be drawn horizontal or vertical.
        """
        position_x = int(position_x)
        position_y = int(position_y)
        font = int(font)
        color = int(color)
        orientation = int(orientation)
        text = create_string(text)

        self.ipcon.send_request(self, BrickletEPaper296x128.FUNCTION_DRAW_TEXT, (position_x, position_y, font, color, orientation, text), 'H B B B B 50s', '')
Пример #12
0
    def morse_code(self, morse, frequency):
        """
        Sets morse code that will be played by the piezo buzzer. The morse code
        is given as a string consisting of "." (dot), "-" (minus) and " " (space)
        for *dits*, *dahs* and *pauses*. Every other character is ignored.
        The second parameter is the frequency (see :func:`Beep`).

        For example: If you set the string "...---...", the piezo buzzer will beep
        nine times with the durations "short short short long long long short
        short short".

        The maximum string size is 60.
        """
        morse = create_string(morse)
        frequency = int(frequency)

        self.ipcon.send_request(self, BrickletPiezoSpeaker.FUNCTION_MORSE_CODE,
                                (morse, frequency), '60s H', '')
Пример #13
0
    def write_line(self, line, position, text):
        """
        Writes text to a specific line (0 to 5) with a specific position
        (0 to 12). The text can have a maximum of 13 characters.

        For example: (1, 4, "Hello") will write *Hello* in the middle of the
        second line of the display.

        You can draw to the display with :func:`Write` and then add text to it
        afterwards.

        The display uses a special 5x7 pixel charset. You can view the characters
        of the charset in Brick Viewer.
        """
        line = int(line)
        position = int(position)
        text = create_string(text)

        self.ipcon.send_request(self, BrickletOLED64x48.FUNCTION_WRITE_LINE, (line, position, text), 'B B 13s', '')
Пример #14
0
    def write_line(self, line, position, text):
        """
        Writes text to a specific line (0 to 3) with a specific position
        (0 to 19). The text can have a maximum of 20 characters.

        For example: (0, 7, "Hello") will write *Hello* in the middle of the
        first line of the display.

        The display uses a special charset that includes all ASCII characters except
        backslash and tilde. The LCD charset also includes several other non-ASCII characters, see
        the `charset specification <https://github.com/Tinkerforge/lcd-20x4-bricklet/raw/master/datasheets/standard_charset.pdf>`__
        for details. The Unicode example above shows how to specify non-ASCII characters
        and how to translate from Unicode to the LCD charset.
        """
        line = int(line)
        position = int(position)
        text = create_string(text)

        self.ipcon.send_request(self, BrickletLCD20x4.FUNCTION_WRITE_LINE, (line, position, text), 'B B 20s', '')
Пример #15
0
    def write_line(self, line, position, text):
        """
        Writes text to a specific line (0 to 3) with a specific position
        (0 to 19). The text can have a maximum of 20 characters.

        For example: (0, 7, "Hello") will write *Hello* in the middle of the
        first line of the display.

        The display uses a special charset that includes all ASCII characters except
        backslash and tilde. The LCD charset also includes several other non-ASCII characters, see
        the `charset specification <https://github.com/Tinkerforge/lcd-20x4-bricklet/raw/master/datasheets/standard_charset.pdf>`__
        for details. The Unicode example above shows how to specify non-ASCII characters
        and how to translate from Unicode to the LCD charset.
        """
        line = int(line)
        position = int(position)
        text = create_string(text)

        self.ipcon.send_request(self, BrickletLCD20x4.FUNCTION_WRITE_LINE, (line, position, text), 'B B 20s', '')
Пример #16
0
    def write_line(self, line, position, text):
        """
        Writes text to a specific line (0 to 5) with a specific position
        (0 to 12). The text can have a maximum of 13 characters.

        For example: (1, 4, "Hello") will write *Hello* in the middle of the
        second line of the display.

        You can draw to the display with :func:`Write` and then add text to it
        afterwards.

        The display uses a special 5x7 pixel charset. You can view the characters
        of the charset in Brick Viewer.
        """
        line = int(line)
        position = int(position)
        text = create_string(text)

        self.ipcon.send_request(self, BrickletOLED64x48.FUNCTION_WRITE_LINE, (line, position, text), 'B B 13s', '')
Пример #17
0
    assert (create_char_list(b'a') == ['a'])  # bytes
    assert (create_char_list(b'ab') == ['a', 'b'])  # bytes
    assert (create_char_list([b'a']) == ['a'])  # bytes
    assert (create_char_list([b'a', b'b']) == ['a', 'b'])  # bytes

assert (create_char_list(bytearray([])) == [])  # bytearray
assert (create_char_list(bytearray([97])) == ['a'])  # bytearray
assert (create_char_list(bytearray([97, 98])) == ['a', 'b'])  # bytearray
assert (create_char_list([97]) == ['a'])  # int
assert (create_char_list([97, 98]) == ['a', 'b'])  # int

#
# string
#

assert (create_string('') == '')  # str
assert (create_string('a') == 'a')  # str
assert (create_string('ab') == 'ab')  # str
assert (create_string([]) == '')
assert (create_string(['a']) == 'a')  # str
assert (create_string(['a', 'b']) == 'ab')  # str

if sys.hexversion < 0x03000000:
    assert (create_string(u'') == '')  # unicode
    assert (create_string(u'a') == 'a')  # unicode
    assert (create_string(u'ab') == 'ab')  # unicode
    assert (create_string([u'a']) == 'a')  # unicode
    assert (create_string([u'a', u'b']) == 'ab')  # unicode
else:
    assert (create_string(b'') == '')  # bytes
    assert (create_string(b'a') == 'a')  # bytes
Пример #18
0
    assert(create_char_list(b'a') == ['a']) # bytes
    assert(create_char_list(b'ab') == ['a', 'b']) # bytes
    assert(create_char_list([b'a']) == ['a']) # bytes
    assert(create_char_list([b'a', b'b']) == ['a', 'b']) # bytes

assert(create_char_list(bytearray([])) == []) # bytearray
assert(create_char_list(bytearray([97])) == ['a']) # bytearray
assert(create_char_list(bytearray([97, 98])) == ['a', 'b']) # bytearray
assert(create_char_list([97]) == ['a']) # int
assert(create_char_list([97, 98]) == ['a', 'b']) # int

#
# string
#

assert(create_string('') == '') # str
assert(create_string('a') == 'a') # str
assert(create_string('ab') == 'ab') # str
assert(create_string([]) == '')
assert(create_string(['a']) == 'a') # str
assert(create_string(['a', 'b']) == 'ab') # str

if sys.hexversion < 0x03000000:
    assert(create_string(u'') == '') # unicode
    assert(create_string(u'a') == 'a') # unicode
    assert(create_string(u'ab') == 'ab') # unicode
    assert(create_string([u'a']) == 'a') # unicode
    assert(create_string([u'a', u'b']) == 'ab') # unicode
else:
    assert(create_string(b'') == '') # bytes
    assert(create_string(b'a') == 'a') # bytes