Skip to content

Commit 682ccec

Browse files
committed
Handle correctly 32bit channels
1 parent 204d90f commit 682ccec

File tree

6 files changed

+72
-21
lines changed

6 files changed

+72
-21
lines changed

pygdtf/__init__.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
from .utils import *
4242
from .value import * # type: ignore
4343

44-
__version__ = "1.4.3"
44+
__version__ = "1.4.4-dev5"
4545

4646
# Standard predefined colour spaces: R, G, B, W-P
4747
COLOR_SPACE_SRGB = ColorSpaceDefinition(
@@ -1696,8 +1696,8 @@ def as_dict(self):
16961696
"dmx": offset_value,
16971697
"offset": self.offset,
16981698
"attribute": self.attribute.str_link,
1699-
"default": self.default.get_value(),
1700-
"highlight": self.highlight.get_value()
1699+
"default": self.default.get_value(full=True),
1700+
"highlight": self.highlight.get_value(full=True)
17011701
if self.highlight is not None
17021702
else None,
17031703
"geometry": self.geometry,
@@ -1715,7 +1715,7 @@ def as_dict(self):
17151715
"offset": self.offset,
17161716
"attribute": "+" * idx + self.attribute.str_link,
17171717
"geometry": self.geometry,
1718-
"default": self.default.get_value(fine=True),
1718+
"default": self.default.get_value(full=True),
17191719
}
17201720
)
17211721
return dicts_list
@@ -1951,9 +1951,9 @@ def as_dict(self):
19511951
return {
19521952
"name": self.name,
19531953
"attribute": self.attribute.str_link,
1954-
"dmx_from": self.dmx_from.get_value(),
1955-
"dmx_to": self.dmx_to.get_value(),
1956-
"default": self.default.get_value(),
1954+
"dmx_from": self.dmx_from.get_value(full=True),
1955+
"dmx_to": self.dmx_to.get_value(full=True),
1956+
"default": self.default.get_value(full=True),
19571957
"real_fade": self.real_fade,
19581958
"physical_to": self.physical_to.value,
19591959
"physical_from": self.physical_from.value,
@@ -2142,8 +2142,8 @@ def __repr__(self):
21422142
def as_dict(self):
21432143
return {
21442144
"name": self.name,
2145-
"dmx_from": self.dmx_from.get_value(),
2146-
"dmx_to": self.dmx_to.get_value(),
2145+
"dmx_from": self.dmx_from.get_value(full=True),
2146+
"dmx_to": self.dmx_to.get_value(full=True),
21472147
"physical_from": self.physical_from.value,
21482148
"physical_to": self.physical_to.value,
21492149
"wheel_slot_index": self.wheel_slot_index,

pygdtf/utils/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ def _create_break_channel(offset, channel, geometry, offset_index):
219219
"dmx": offset,
220220
"offset": channel.offset,
221221
"attribute": "+" * offset_index + str(channel.logical_channels[0].attribute),
222-
"default": channel.default.get_value(fine=offset_index > 0),
223-
"highlight": channel.highlight.get_value()
222+
"default": channel.default.get_value(full=True),
223+
"highlight": channel.highlight.get_value(full=True)
224224
if channel.highlight is not None
225225
else None,
226226
"geometry": geometry.name,

pygdtf/value.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -252,16 +252,26 @@ def __str__(self):
252252
def __repr__(self):
253253
return f"Value: {self.value}, Byte count: {self.byte_count}"
254254

255-
def get_value(self, fine=False):
255+
def _get_byte(self, byte_index):
256+
if self.byte_count <= 0:
257+
return 0
258+
if byte_index < 0 or byte_index >= self.byte_count:
259+
return 0
260+
shift = (self.byte_count - 1 - byte_index) * 8
261+
return (self.value >> shift) & 0xFF
262+
263+
def get_value(self, fine=False, byte_index=None, full=False, components=False):
256264
if self.byte_count == 1:
257265
return self.value
258-
259-
msb = (self.value >> 8) & 0xFF
260-
lsb = self.value & 0xFF
261-
262-
if not fine:
263-
return msb
264-
return lsb
266+
if full:
267+
return self.value
268+
if components:
269+
return [self._get_byte(i) for i in range(self.byte_count)]
270+
if byte_index is not None:
271+
return self._get_byte(byte_index)
272+
if fine:
273+
return self._get_byte(self.byte_count - 1)
274+
return self._get_byte(0)
265275

266276

267277
class PhysicalValue:

tests/test1.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

tests/test2.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

tests/test_dmx_value.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import pygdtf
2+
3+
4+
def test_dmx_value_full_and_bytes():
5+
value = pygdtf.DmxValue("16909060/4") # 0x01_02_03_04
6+
assert value.get_value(full=True) == 16909060
7+
assert value.get_value() == 1
8+
assert value.get_value(fine=True) == 4
9+
assert value.get_value(components=True) == [1, 2, 3, 4]
10+
assert value.get_value(byte_index=1) == 2
11+
assert value.get_value(byte_index=2) == 3
12+
assert value.get_value(byte_index=3) == 4
13+
14+
15+
def test_channel_function_as_dict_full_values():
16+
channel_function = pygdtf.ChannelFunction(
17+
name="Test",
18+
attribute=pygdtf.NodeLink("Attributes", "Dimmer"),
19+
dmx_from=pygdtf.DmxValue("16909060/4"),
20+
dmx_to=pygdtf.DmxValue("16909061/4"),
21+
default=pygdtf.DmxValue("16909062/4"),
22+
)
23+
result = channel_function.as_dict()
24+
assert result["dmx_from"] == 16909060
25+
assert result["dmx_to"] == 16909061
26+
assert result["default"] == 16909062
27+
28+
29+
def test_dmx_channel_as_dict_byte_defaults():
30+
channel = pygdtf.DmxChannel(
31+
offset=[1, 2, 3, 4],
32+
default=pygdtf.DmxValue("16909060/4"),
33+
highlight=pygdtf.DmxValue("84281096/4"), # 0x05_06_07_08
34+
attribute=pygdtf.NodeLink("Attributes", "Dimmer"),
35+
logical_channels=[
36+
pygdtf.LogicalChannel(attribute=pygdtf.NodeLink("Attributes", "Dimmer"))
37+
],
38+
)
39+
result = channel.as_dict()
40+
assert [entry["default"] for entry in result] == [16909060, 16909060, 16909060, 16909060]
41+
assert result[0]["highlight"] == 84281096

0 commit comments

Comments
 (0)