idotmatrix-api-client 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- idotmatrix/__init__.py +15 -0
- idotmatrix/apps/__init__.py +0 -0
- idotmatrix/apps/digital_picture_frame.py +541 -0
- idotmatrix/client.py +284 -0
- idotmatrix/connection_manager.py +702 -0
- idotmatrix/const.py +30 -0
- idotmatrix/fonts/16-ErbosDraco1StOpenNbpRegular-l5wX.ttf +0 -0
- idotmatrix/fonts/16-MinecraftStandard.otf +0 -0
- idotmatrix/fonts/16-MinecraftStandardBoldOblique.otf +0 -0
- idotmatrix/fonts/16-PixelOperator8-Bold.ttf +0 -0
- idotmatrix/fonts/16-PixelOperator8.ttf +0 -0
- idotmatrix/fonts/16-PixelifySans-Regular.ttf +0 -0
- idotmatrix/fonts/16-PressStart2P-Regular.ttf +0 -0
- idotmatrix/fonts/16-dogica.ttf +0 -0
- idotmatrix/fonts/16-dogicabold.ttf +0 -0
- idotmatrix/fonts/16-dogicapixel.ttf +0 -0
- idotmatrix/fonts/16-dogicapixelbold.ttf +0 -0
- idotmatrix/fonts/16_32-HomeVideo-BLG6G.ttf +0 -0
- idotmatrix/fonts/16_32-HomeVideoBold-R90Dv.ttf +0 -0
- idotmatrix/fonts/16_32-MayfairNbpBold-gAA4.ttf +0 -0
- idotmatrix/fonts/32-Jersey10-Regular.ttf +0 -0
- idotmatrix/fonts/CC-BY-SA-4.0-License.txt +428 -0
- idotmatrix/fonts/ErbosDraco-License.txt +3 -0
- idotmatrix/fonts/HomeVideo-License.txt +2 -0
- idotmatrix/fonts/Jersey10-Regular-License.txt +93 -0
- idotmatrix/fonts/MayfairNbpBold-License.txt +3 -0
- idotmatrix/fonts/MinecraftStandard-License.txt +5 -0
- idotmatrix/fonts/PixelOperator-License.txt +121 -0
- idotmatrix/fonts/PixelifySans-License.txt +93 -0
- idotmatrix/fonts/PressStart2P-Regular-License.txt +93 -0
- idotmatrix/fonts/Rain-DRM3-License.txt +44 -0
- idotmatrix/fonts/Rain-DRM3.otf +0 -0
- idotmatrix/fonts/dogica_license.txt +94 -0
- idotmatrix/modules/__init__.py +64 -0
- idotmatrix/modules/chronograph.py +50 -0
- idotmatrix/modules/clock.py +101 -0
- idotmatrix/modules/common.py +176 -0
- idotmatrix/modules/countdown.py +70 -0
- idotmatrix/modules/eco.py +63 -0
- idotmatrix/modules/effect.py +79 -0
- idotmatrix/modules/fullscreen_color.py +55 -0
- idotmatrix/modules/gif.py +403 -0
- idotmatrix/modules/graffiti.py +71 -0
- idotmatrix/modules/image.py +383 -0
- idotmatrix/modules/music_sync.py +67 -0
- idotmatrix/modules/scoreboard.py +38 -0
- idotmatrix/modules/system.py +65 -0
- idotmatrix/modules/text.py +232 -0
- idotmatrix/protocol.py +52 -0
- idotmatrix/screensize.py +8 -0
- idotmatrix/transport.py +137 -0
- idotmatrix/util/__init__.py +0 -0
- idotmatrix/util/color_utils.py +64 -0
- idotmatrix/util/command_ack.py +23 -0
- idotmatrix/util/device_info.py +38 -0
- idotmatrix/util/device_material.py +16 -0
- idotmatrix/util/file_watch.py +57 -0
- idotmatrix/util/image_utils.py +139 -0
- idotmatrix/util/upload_ack.py +42 -0
- idotmatrix_api_client-0.2.0.dist-info/METADATA +375 -0
- idotmatrix_api_client-0.2.0.dist-info/RECORD +63 -0
- idotmatrix_api_client-0.2.0.dist-info/WHEEL +4 -0
- idotmatrix_api_client-0.2.0.dist-info/licenses/LICENSE +674 -0
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
from datetime import datetime
|
|
3
|
+
from typing import Optional
|
|
4
|
+
|
|
5
|
+
from idotmatrix import protocol
|
|
6
|
+
from idotmatrix.modules import IDotMatrixModule
|
|
7
|
+
from idotmatrix.protocol import build_command
|
|
8
|
+
from idotmatrix.util.device_info import DeviceInfo, parse_device_info
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class CommonModule(IDotMatrixModule):
|
|
12
|
+
"""
|
|
13
|
+
This class contains generic Bluetooth functions for the iDotMatrix.
|
|
14
|
+
Based on the BleProtocolN.java file of the iDotMatrix Android App.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
logging = logging.getLogger(__name__)
|
|
18
|
+
|
|
19
|
+
async def freeze_screen(self):
|
|
20
|
+
"""
|
|
21
|
+
Freezes or unfreezes the screen.
|
|
22
|
+
|
|
23
|
+
Returns:
|
|
24
|
+
bytearray: Command to be sent to the device.
|
|
25
|
+
"""
|
|
26
|
+
data = build_command(protocol.FREEZE_SCREEN)
|
|
27
|
+
await self._send_bytes(data=data, response=True)
|
|
28
|
+
|
|
29
|
+
async def turn_off(self):
|
|
30
|
+
"""
|
|
31
|
+
Turns the screen off.
|
|
32
|
+
|
|
33
|
+
Returns:
|
|
34
|
+
bytearray: Command to be sent to the device.
|
|
35
|
+
"""
|
|
36
|
+
data = build_command(protocol.SCREEN_ON_OFF, 0)
|
|
37
|
+
await self._send_bytes(data=data, response=True)
|
|
38
|
+
|
|
39
|
+
async def turn_on(self):
|
|
40
|
+
"""
|
|
41
|
+
Turns the screen on.
|
|
42
|
+
|
|
43
|
+
Returns:
|
|
44
|
+
bytearray: Command to be sent to the device.
|
|
45
|
+
"""
|
|
46
|
+
data = build_command(protocol.SCREEN_ON_OFF, 1)
|
|
47
|
+
await self._send_bytes(data=data)
|
|
48
|
+
|
|
49
|
+
async def set_screen_state(self, is_on: bool):
|
|
50
|
+
"""
|
|
51
|
+
Sets the screen state to on or off.
|
|
52
|
+
|
|
53
|
+
Args:
|
|
54
|
+
is_on (bool): True = on, False = off.
|
|
55
|
+
"""
|
|
56
|
+
|
|
57
|
+
data = build_command(protocol.SCREEN_ON_OFF, 1 if is_on else 0)
|
|
58
|
+
await self._send_bytes(data=data)
|
|
59
|
+
|
|
60
|
+
async def set_screen_flipped(self, flip: bool = True):
|
|
61
|
+
"""
|
|
62
|
+
Rotates the screen 180 degrees.
|
|
63
|
+
|
|
64
|
+
Args:
|
|
65
|
+
flip (bool): False = normal, True = rotated. Defaults to True.
|
|
66
|
+
"""
|
|
67
|
+
data = build_command(protocol.SCREEN_FLIP, 1 if flip else 0)
|
|
68
|
+
await self._send_bytes(data=data, response=True)
|
|
69
|
+
|
|
70
|
+
async def set_brightness(self, brightness_percent: int):
|
|
71
|
+
"""
|
|
72
|
+
Set screen brightness. Range 5-100 (%).
|
|
73
|
+
|
|
74
|
+
Args:
|
|
75
|
+
brightness_percent (int): Set the brightness in percent.
|
|
76
|
+
"""
|
|
77
|
+
if brightness_percent not in range(5, 101):
|
|
78
|
+
raise ValueError("Common.setBrightness parameter brightness_percent is not in range between 5 and 100")
|
|
79
|
+
data = build_command(protocol.BRIGHTNESS, brightness_percent)
|
|
80
|
+
await self._send_bytes(data=data, response=True)
|
|
81
|
+
|
|
82
|
+
async def set_speed(self, speed: int):
|
|
83
|
+
"""
|
|
84
|
+
Sets the speed of ? - not referenced anywhere in the iDotMatrix Android App.
|
|
85
|
+
|
|
86
|
+
Args:
|
|
87
|
+
speed (int): Set the speed.
|
|
88
|
+
"""
|
|
89
|
+
data = build_command(protocol.SET_SPEED, speed)
|
|
90
|
+
await self._send_bytes(data=data)
|
|
91
|
+
|
|
92
|
+
async def set_time(self, time: datetime):
|
|
93
|
+
"""
|
|
94
|
+
Sets the date and time of the device.
|
|
95
|
+
|
|
96
|
+
Args:
|
|
97
|
+
time (datetime): The datetime object representing the date and time to set. Accuracy is to the second.
|
|
98
|
+
|
|
99
|
+
The device answers with information about itself, see `get_device_info`.
|
|
100
|
+
"""
|
|
101
|
+
await self._send_bytes(data=self._create_set_time_command(time), response=True)
|
|
102
|
+
|
|
103
|
+
async def get_device_info(self, time: Optional[datetime] = None) -> Optional[DeviceInfo]:
|
|
104
|
+
"""
|
|
105
|
+
Asks the device about itself: the firmware version, the type of its screen and whether it is protected by a
|
|
106
|
+
password. The device only tells that as the answer to the set time command, so this sets its time as well.
|
|
107
|
+
|
|
108
|
+
Args:
|
|
109
|
+
time (datetime, optional): The time to set on the device. Defaults to the current time.
|
|
110
|
+
Returns:
|
|
111
|
+
Optional[DeviceInfo]: The information, or None if the device did not answer.
|
|
112
|
+
"""
|
|
113
|
+
command = self._create_set_time_command(time or datetime.now())
|
|
114
|
+
notification = await self._connection_manager.request(command, response=True)
|
|
115
|
+
return parse_device_info(notification) if notification else None
|
|
116
|
+
|
|
117
|
+
@staticmethod
|
|
118
|
+
def _create_set_time_command(time: datetime) -> bytearray:
|
|
119
|
+
year = time.year
|
|
120
|
+
month = time.month
|
|
121
|
+
day = time.day
|
|
122
|
+
hour = time.hour
|
|
123
|
+
minute = time.minute
|
|
124
|
+
second = time.second
|
|
125
|
+
if not (0 <= month <= 12):
|
|
126
|
+
raise ValueError("Common.setTime parameter month is not in range between 1 and 12")
|
|
127
|
+
if not (0 <= day <= 31):
|
|
128
|
+
raise ValueError("Common.setTime parameter day is not in range between 1 and 31")
|
|
129
|
+
if not (0 <= hour <= 23):
|
|
130
|
+
raise ValueError("Common.setTime parameter hour is not in range between 0 and 23")
|
|
131
|
+
if not (0 <= minute <= 59):
|
|
132
|
+
raise ValueError("Common.setTime parameter minute is not in range between 0 and 59")
|
|
133
|
+
if not (0 <= second <= 59):
|
|
134
|
+
raise ValueError("Common.setTime parameter second is not in range between 0 and 59")
|
|
135
|
+
|
|
136
|
+
return build_command(
|
|
137
|
+
protocol.SET_TIME, year % 100, month, day, datetime(year, month, day).weekday() + 1, hour, minute, second)
|
|
138
|
+
|
|
139
|
+
async def set_joint(self, mode: int):
|
|
140
|
+
"""
|
|
141
|
+
Currently no idea what this is doing.
|
|
142
|
+
|
|
143
|
+
Args:
|
|
144
|
+
mode (int): Set the joint mode.
|
|
145
|
+
"""
|
|
146
|
+
data = build_command(protocol.SET_JOINT, mode)
|
|
147
|
+
await self._send_bytes(data=data)
|
|
148
|
+
|
|
149
|
+
async def set_password(self, password: int):
|
|
150
|
+
"""
|
|
151
|
+
Setting password: 6 digits in range 000000..999999. Reset device to clear.
|
|
152
|
+
|
|
153
|
+
Args:
|
|
154
|
+
password (int): Password.
|
|
155
|
+
"""
|
|
156
|
+
pwd_high = (password // 10000) % 256
|
|
157
|
+
pwd_mid = (password // 100) % 100 % 256
|
|
158
|
+
pwd_low = password % 100 % 256
|
|
159
|
+
data = build_command(protocol.SET_PASSWORD, 1, pwd_high, pwd_mid, pwd_low)
|
|
160
|
+
await self._send_bytes(data=data)
|
|
161
|
+
|
|
162
|
+
async def reset(self):
|
|
163
|
+
"""
|
|
164
|
+
Sends a command that resets the device and its internals.
|
|
165
|
+
Can fix issues that appear over time.
|
|
166
|
+
|
|
167
|
+
Note:
|
|
168
|
+
Credits to 8none1 for finding this method:
|
|
169
|
+
https://github.com/8none1/idotmatrix/commit/1a08e1e9b82d78427ab1c896c24c2a7fb45bc2f0
|
|
170
|
+
"""
|
|
171
|
+
reset_packets = [
|
|
172
|
+
[
|
|
173
|
+
bytes(build_command(protocol.RESET))
|
|
174
|
+
]
|
|
175
|
+
]
|
|
176
|
+
await self._send_packets(packets=reset_packets, response=True)
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
|
|
3
|
+
from idotmatrix import protocol
|
|
4
|
+
from idotmatrix.modules import IDotMatrixModule
|
|
5
|
+
from idotmatrix.protocol import build_command
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class CountdownModule(IDotMatrixModule):
|
|
9
|
+
"""This class contains the management of the Countdown of the iDotMatrix device."""
|
|
10
|
+
|
|
11
|
+
logging = logging.getLogger(__name__)
|
|
12
|
+
|
|
13
|
+
async def stop(self):
|
|
14
|
+
"""
|
|
15
|
+
Disables the countdown.
|
|
16
|
+
"""
|
|
17
|
+
await self._set_mode(mode=0, minutes=0, seconds=0)
|
|
18
|
+
|
|
19
|
+
async def start(self, minutes: int, seconds: int = 0):
|
|
20
|
+
"""
|
|
21
|
+
Starts the countdown with the given minutes and seconds.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
minutes (int): minutes to count down from
|
|
25
|
+
seconds (int): seconds to count down from
|
|
26
|
+
"""
|
|
27
|
+
await self._set_mode(mode=1, minutes=minutes, seconds=seconds)
|
|
28
|
+
|
|
29
|
+
async def pause(self):
|
|
30
|
+
"""
|
|
31
|
+
Pauses the countdown.
|
|
32
|
+
"""
|
|
33
|
+
await self._set_mode(mode=2, minutes=0, seconds=0)
|
|
34
|
+
|
|
35
|
+
async def restart(self):
|
|
36
|
+
"""
|
|
37
|
+
Restarts the countdown with the given minutes and seconds.
|
|
38
|
+
"""
|
|
39
|
+
await self._set_mode(mode=3, minutes=0, seconds=0)
|
|
40
|
+
|
|
41
|
+
async def _set_mode(
|
|
42
|
+
self, mode: int, minutes: int, seconds: int
|
|
43
|
+
):
|
|
44
|
+
"""
|
|
45
|
+
Sets the countdown (and activates or disables it)
|
|
46
|
+
|
|
47
|
+
Args:
|
|
48
|
+
mode (int): mode of the countdown. 0 = disable, 1 = start, 2 = pause, 3 = restart
|
|
49
|
+
minutes (int): minutes to count down from
|
|
50
|
+
seconds (int): seconds to count down from
|
|
51
|
+
"""
|
|
52
|
+
if mode not in range(0, 4):
|
|
53
|
+
raise ValueError("Countdown.setMode expects parameter mode to be between 0 and 3")
|
|
54
|
+
# TODO: check for valid range of minutes
|
|
55
|
+
if seconds > 59 or seconds < 0:
|
|
56
|
+
raise ValueError("Countdown.setMode expects parameter seconds to be between 0 and 59")
|
|
57
|
+
if minutes > 59 or minutes < 0:
|
|
58
|
+
raise ValueError("Countdown.setMode expects parameter minutes to be between 0 and 59")
|
|
59
|
+
|
|
60
|
+
data = self._create_payload(
|
|
61
|
+
mode=mode,
|
|
62
|
+
minutes=minutes,
|
|
63
|
+
seconds=seconds,
|
|
64
|
+
)
|
|
65
|
+
await self._send_bytes(data=data)
|
|
66
|
+
|
|
67
|
+
@staticmethod
|
|
68
|
+
def _create_payload(mode: int, minutes: int, seconds: int) -> bytearray:
|
|
69
|
+
data = build_command(protocol.COUNTDOWN, mode % 256, minutes % 256, seconds % 256)
|
|
70
|
+
return data
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
|
|
3
|
+
from idotmatrix import protocol
|
|
4
|
+
from idotmatrix.modules import IDotMatrixModule
|
|
5
|
+
from idotmatrix.protocol import build_command
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class EcoModule(IDotMatrixModule):
|
|
9
|
+
"""
|
|
10
|
+
This class contains code for the eco-mode of the iDotMatrix device.
|
|
11
|
+
With this class you can change the brightness automatically depending on the time.
|
|
12
|
+
Based on the BleProtocolN.java file of the iDotMatrix Android App.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
logging = logging.getLogger(__name__)
|
|
16
|
+
|
|
17
|
+
async def set_mode(
|
|
18
|
+
self,
|
|
19
|
+
enabled: bool = True,
|
|
20
|
+
start_hour: int = 22, start_minute: int = 0,
|
|
21
|
+
end_hour: int = 6, end_minute: int = 0,
|
|
22
|
+
eco_brightness: int = 10,
|
|
23
|
+
):
|
|
24
|
+
"""
|
|
25
|
+
Sets the eco-mode settings of the device.
|
|
26
|
+
eco-mode lowers the brightness of the display to the given amount
|
|
27
|
+
between the given start and end time.
|
|
28
|
+
|
|
29
|
+
Args:
|
|
30
|
+
enabled (int): whether to enable the eco-mode feature or not
|
|
31
|
+
start_hour (int): hour to start eco-mode
|
|
32
|
+
start_minute (int): minute to start eco-mode
|
|
33
|
+
end_hour (int): hour to end eco-mode
|
|
34
|
+
end_minute (int): minute to end eco-mode
|
|
35
|
+
eco_brightness (int): the brightness of the screen when in eco-mode. Set to 0 to disable eco-mode.
|
|
36
|
+
"""
|
|
37
|
+
if not (0 <= start_hour < 24) or not (0 <= end_hour < 24):
|
|
38
|
+
raise ValueError("start_hour and end_hour must be between 0 and 23")
|
|
39
|
+
if not (0 <= start_minute < 60) or not (0 <= end_minute < 60):
|
|
40
|
+
raise ValueError("start_minute and end_minute must be between 0 and 59")
|
|
41
|
+
if not (0 <= eco_brightness < 256):
|
|
42
|
+
raise ValueError("eco_brightness must be between 0 and 255")
|
|
43
|
+
|
|
44
|
+
data = self._compute_payload(
|
|
45
|
+
enabled=1 if enabled else 0,
|
|
46
|
+
start_hour=start_hour,
|
|
47
|
+
start_minute=start_minute,
|
|
48
|
+
end_hour=end_hour,
|
|
49
|
+
end_minute=end_minute,
|
|
50
|
+
eco_brightness=eco_brightness,
|
|
51
|
+
)
|
|
52
|
+
await self._send_bytes(data=data)
|
|
53
|
+
|
|
54
|
+
@staticmethod
|
|
55
|
+
def _compute_payload(
|
|
56
|
+
enabled: int,
|
|
57
|
+
start_hour: int, start_minute: int,
|
|
58
|
+
end_hour: int, end_minute: int,
|
|
59
|
+
eco_brightness: int) -> bytearray:
|
|
60
|
+
data = build_command(
|
|
61
|
+
protocol.ECO, int(enabled) % 256, int(start_hour) % 256, int(start_minute) % 256,
|
|
62
|
+
int(end_hour) % 256, int(end_minute) % 256, int(eco_brightness) % 256)
|
|
63
|
+
return data
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
from enum import Enum
|
|
3
|
+
from typing import List, Tuple
|
|
4
|
+
|
|
5
|
+
from idotmatrix import protocol
|
|
6
|
+
from idotmatrix.modules import IDotMatrixModule
|
|
7
|
+
from idotmatrix.protocol import build_command
|
|
8
|
+
from idotmatrix.util import color_utils
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class EffectStyle(Enum):
|
|
12
|
+
"""Enum for the different effect styles."""
|
|
13
|
+
|
|
14
|
+
GRADIENT_HORIZONTAL_RAINBOW = 0
|
|
15
|
+
RANDOM_COLORED_PIXELS_ON_BLACK = 1
|
|
16
|
+
RANDOM_WHITE_PIXELS_ON_CHANGING_BACKGROUND = 2
|
|
17
|
+
VERTICAL_RAINBOW = 3
|
|
18
|
+
DIAGONAL_RIGHT_RAINBOW = 4
|
|
19
|
+
DIAGONAL_LEFT_RAINBOW_ON_BLACK = 5
|
|
20
|
+
RANDOM_COLORED_PIXELS = 6
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class EffectModule(IDotMatrixModule):
|
|
24
|
+
"""This class contains the Effect controls for the iDotMatrix device."""
|
|
25
|
+
|
|
26
|
+
logging = logging.getLogger(__name__)
|
|
27
|
+
|
|
28
|
+
async def show(
|
|
29
|
+
self,
|
|
30
|
+
style: EffectStyle | int,
|
|
31
|
+
colors: List[Tuple[int, int, int] | int | str],
|
|
32
|
+
):
|
|
33
|
+
"""
|
|
34
|
+
Set the effect mode of the device.
|
|
35
|
+
|
|
36
|
+
Args:
|
|
37
|
+
style (int): Style of the effect 0-6.
|
|
38
|
+
colors (list[tuple[int, int, int]]): list of red, green, blue tuples 2-7.
|
|
39
|
+
"""
|
|
40
|
+
if isinstance(style, EffectStyle):
|
|
41
|
+
style = style.value
|
|
42
|
+
|
|
43
|
+
if style not in range(0, 7):
|
|
44
|
+
raise ValueError("effect.setMode expects parameter style to be between 0 and 6")
|
|
45
|
+
|
|
46
|
+
if len(colors) not in range(2, 8):
|
|
47
|
+
raise ValueError("effect.setMode expects parameter rgb_values to be a list of tuples to be between 2 and 7")
|
|
48
|
+
|
|
49
|
+
colors = color_utils.parse_color_rgb_list(colors)
|
|
50
|
+
|
|
51
|
+
data = self._compute_payload(style=style, rgb_values=colors)
|
|
52
|
+
await self._send_bytes(data=data)
|
|
53
|
+
|
|
54
|
+
@staticmethod
|
|
55
|
+
def _compute_payload(style: int, rgb_values: List[Tuple[int, int, int]]) -> bytearray:
|
|
56
|
+
"""
|
|
57
|
+
Computes the payload for the effect mode command.
|
|
58
|
+
|
|
59
|
+
Args:
|
|
60
|
+
style (int): The effect style, must be between 0 and 6.
|
|
61
|
+
rgb_values (list[tuple[int, int, int]]): List of RGB tuples, each tuple contains red, green, and blue values.
|
|
62
|
+
"""
|
|
63
|
+
processed_rgb_values = [
|
|
64
|
+
(r % 256, g % 256, b % 256)
|
|
65
|
+
for rgb in rgb_values
|
|
66
|
+
for r, g, b in [rgb + (255,) * (3 - len(rgb))]
|
|
67
|
+
]
|
|
68
|
+
|
|
69
|
+
data = build_command(
|
|
70
|
+
protocol.EFFECT,
|
|
71
|
+
style % 256,
|
|
72
|
+
90,
|
|
73
|
+
len(processed_rgb_values) % 256,
|
|
74
|
+
*[component for rgb in processed_rgb_values for component in rgb],
|
|
75
|
+
# the length byte is not the length of the message, but the app does it that way and the device accepts it
|
|
76
|
+
length=6 + len(processed_rgb_values),
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
return data
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
from typing import Tuple
|
|
3
|
+
|
|
4
|
+
from idotmatrix import protocol
|
|
5
|
+
from idotmatrix.modules import IDotMatrixModule
|
|
6
|
+
from idotmatrix.protocol import build_command
|
|
7
|
+
from idotmatrix.util import color_utils
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class FullscreenColorModule(IDotMatrixModule):
|
|
11
|
+
"""
|
|
12
|
+
This class contains the management of the iDotMatrix fullscreen color mode.
|
|
13
|
+
Based on the BleProtocolN.java file of the iDotMatrix Android App.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
logging = logging.getLogger(__name__)
|
|
17
|
+
|
|
18
|
+
async def show_color(
|
|
19
|
+
self, color: Tuple[int, int, int] | int | str
|
|
20
|
+
):
|
|
21
|
+
"""
|
|
22
|
+
Sets the fullscreen color of the screen of the device.
|
|
23
|
+
Args:
|
|
24
|
+
color (tuple or str): Color in RGB format as a tuple of three integers (r, g, b) or a string in hex format (#RRGGBB or 0xRRGGBB).
|
|
25
|
+
"""
|
|
26
|
+
color = color_utils.parse_color_rgb(color)
|
|
27
|
+
await self._show_color_rgb(*color)
|
|
28
|
+
|
|
29
|
+
async def _show_color_rgb(
|
|
30
|
+
self, r: int = 0, g: int = 0, b: int = 0
|
|
31
|
+
):
|
|
32
|
+
"""
|
|
33
|
+
Sets the fullscreen color of the screen of the device
|
|
34
|
+
|
|
35
|
+
Args:
|
|
36
|
+
r (int, optional): color red. Defaults to 0.
|
|
37
|
+
g (int, optional): color green. Defaults to 0.
|
|
38
|
+
b (int, optional): color blue. Defaults to 0.
|
|
39
|
+
"""
|
|
40
|
+
if r not in range(0, 256):
|
|
41
|
+
raise ValueError("FullscreenColor.setMode expects parameter r to be between 0 and 255")
|
|
42
|
+
if g not in range(0, 256):
|
|
43
|
+
raise ValueError("FullscreenColor.setMode expects parameter g to be between 0 and 255")
|
|
44
|
+
if b not in range(0, 256):
|
|
45
|
+
raise ValueError("FullscreenColor.setMode expects parameter b to be between 0 and 255")
|
|
46
|
+
|
|
47
|
+
data = self._create_payload(
|
|
48
|
+
r=r, g=g, b=b
|
|
49
|
+
)
|
|
50
|
+
await self._send_bytes(data=data, response=True)
|
|
51
|
+
|
|
52
|
+
@staticmethod
|
|
53
|
+
def _create_payload(r, g, b) -> bytearray:
|
|
54
|
+
data = build_command(protocol.FULLSCREEN_COLOR, int(r) % 256, int(g) % 256, int(b) % 256)
|
|
55
|
+
return data
|