Skip to content

Other Commands

set_fun_mode

Enable or disable fun mode.

Parameters:

Name Type Description Default
enable bool

Boolean or equivalent, enables (True) or disables (False) fun mode.

False
Source code in src/pypixelcolor/commands/set_fun_mode.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
def set_fun_mode(enable : bool = False):
    """
    Enable or disable fun mode.

    Args:
        enable: Boolean or equivalent, enables (True) or disables (False) fun mode.
    """

    # Convert bool
    if isinstance(enable, str):
        enable = enable.lower() in ("true", "1", "yes", "on")

    # Build payload using bytes
    payload = bytes([
        5,                        # Command length
        0,                        # Reserved
        4,                        # Command ID
        1,                        # Command type ID
        1 if bool(enable) else 0  # Fun mode value
    ])

    return single_window_plan("set_fun_mode", payload)

set_pixel

Defines the color of a specific pixel.

Parameters:

Name Type Description Default
x int

X coordinate of the pixel (0-...).

required
y int

Y coordinate of the pixel (0-...).

required
color str

Color in hexadecimal format (e.g., 'FF0000' for red).

required
Source code in src/pypixelcolor/commands/set_fun_mode.py
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
def set_pixel(x: int, y: int, color: str, device_info: Optional[DeviceInfo] = None):
    """
    Defines the color of a specific pixel.

    Args:
        x: X coordinate of the pixel (0-...).
        y: Y coordinate of the pixel (0-...).
        color: Color in hexadecimal format (e.g., 'FF0000' for red).
    """

    # Validate coordinates range if device info is provided
    if device_info and not (0 <= int(x) <= device_info.width - 1 and 0 <= int(y) <= device_info.height - 1):
            raise ValueError(f"Invalid coordinates range. Range are x[0:{device_info.width-1}] y[0:{device_info.height-1}]")

    # Validate color format
    if (not (isinstance(color, str)) 
        and len(color) == 6 
        and all(c in '0123456789abcdefABCDEF' for c in color)):
            raise ValueError("Color must be a 6-character hexadecimal string.")

    # Build payload using bytes
    payload = bytes([
        10,                       # Command length
        0,                        # Reserved
        5,                        # Command ID
        1,                        # Command type ID
        0,                        # Reserved
        int(color[0:2], 16),      # Red
        int(color[2:4], 16),      # Green
        int(color[4:6], 16),      # Blue
        int(x),                   # X coordinate
        int(y)                    # Y coordinate
    ])

    return single_window_plan("set_pixel", payload, requires_ack=False)

set_rhythm_mode

Set the rhythm mode of the device.

Parameters:

Name Type Description Default
style int

The style of the rhythm mode (0-4).

0
l1 int

Level 1 (0-15).

0
l2 int

Level 2 (0-15).

0
l3 int

Level 3 (0-15).

0
l4 int

Level 4 (0-15).

0
l5 int

Level 5 (0-15).

0
l6 int

Level 6 (0-15).

0
l7 int

Level 7 (0-15).

0
l8 int

Level 8 (0-15).

0
l9 int

Level 9 (0-15).

0
l10 int

Level 10 (0-15).

0
l11 int

Level 11 (0-15).

0

Raises:

Type Description
ValueError

If style is not in 0..4 or any level is not in 0..15.

Source code in src/pypixelcolor/commands/set_rhythm_mode.py
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
def set_rhythm_mode(style=0, l1 : int = 0, l2 : int = 0, l3 : int = 0, l4 : int = 0, l5 : int = 0, l6 : int = 0, l7 : int = 0, l8 : int = 0, l9 : int = 0, l10 : int = 0, l11 : int = 0):
    """Set the rhythm mode of the device.

    Args:
        style (int): The style of the rhythm mode (0-4).
        l1 (int): Level 1 (0-15).
        l2 (int): Level 2 (0-15).
        l3 (int): Level 3 (0-15).
        l4 (int): Level 4 (0-15).
        l5 (int): Level 5 (0-15).
        l6 (int): Level 6 (0-15).
        l7 (int): Level 7 (0-15).
        l8 (int): Level 8 (0-15).
        l9 (int): Level 9 (0-15).
        l10 (int): Level 10 (0-15).
        l11 (int): Level 11 (0-15).

    Raises:
        ValueError: If ``style`` is not in 0..4 or any level is not in 0..15.
    """

    # Validation
    if not (0 <= int(style) <= 4):
        raise ValueError(f"rhythm mode style must be between 0 and 4, got {style}")

    levels = [int(v) for v in [l1, l2, l3, l4, l5, l6, l7, l8, l9, l10, l11]]
    for idx, lv in enumerate(levels, start=1):
        if not (0 <= lv <= 15):
            raise ValueError(f"level {idx} must be between 0 and 15, got {lv}")

    # Build payload
    payload = bytes([
        16,     # Command length
        0,      # Reserved
        1,      # Command ID
        2,      # Command type ID
        int(style),
    ])
    payload += bytes(levels)

    return single_window_plan("set_rhythm_mode", payload, requires_ack=True)

set_rhythm_mode_2

Set the rhythm mode of the device (alternative version).

Parameters:

Name Type Description Default
style int

The style of the rhythm mode. Allowed values are 0 or 1.

0
t int

Animation time (0-7).

0

Returns:

Name Type Description
bytes

Byte sequence for the command payload used to set the rhythm mode.

Raises:

Type Description
ValueError

If style is not in 0..1 or t is not in 0..7.

Source code in src/pypixelcolor/commands/set_rhythm_mode.py
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
def set_rhythm_mode_2(style: int = 0, t: int = 0):
    """Set the rhythm mode of the device (alternative version).

    Args:
        style (int): The style of the rhythm mode. Allowed values are 0 or 1.
        t (int): Animation time (0-7).

    Returns:
        bytes: Byte sequence for the command payload used to set the rhythm mode.

    Raises:
        ValueError: If ``style`` is not in 0..1 or ``t`` is not in 0..7.
    """

    # Validation
    if not (0 <= int(style) <= 1):
        raise ValueError(f"rhythm mode style must be between 0 and 1, got {style}")

    if not (0 <= int(t) <= 7):
        raise ValueError(f"Level (t) must be between 0 and 7, got {t}")

    # Build payload using bytes
    payload = bytes([
        6,              # Command length
        0,              # Reserved
        0,              # Command ID
        2,              # Command type ID
        int(t),         # Animation time
        int(style)      # Style
    ])

    return single_window_plan("set_rhythm_mode_2", payload)