JoyPi-RGB-Matrix-RaspberryPi 1.0.0__py3-none-any.whl → 1.0.2__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.
@@ -1,13 +1,14 @@
1
1
  from ._RGBW import RGBW
2
2
  from ._PixelStrip import PixelStrip
3
3
  import time
4
+ import busio
4
5
 
5
6
  class RGB_Matrix:
6
7
  """
7
8
  New version using the I2C-based PixelStrip instead of rpi_ws281x.
8
9
  """
9
10
 
10
- def __init__(self, bus = None, bus_id = 1, i2c_adress = 0x66, count = 64, brightness = 10,
11
+ def __init__(self, i2c: busio.I2C, i2c_adress = 0x66, count = 64, brightness = 10,
11
12
  right_border = [7,15,23,31,39,47,55,63], left_border = [0,8,16,24,32,40,48,56]):
12
13
  """
13
14
  initiliaze LED matrix
@@ -26,8 +27,7 @@ class RGB_Matrix:
26
27
  self.LEFT_BORDER = left_border
27
28
 
28
29
  # Create the I2C-based PixelStrip instance
29
- self.strip = PixelStrip(num=self.LED_COUNT, brightness=self.LED_BRIGHTNESS,
30
- bus = bus, bus_id = bus_id, i2c_adress=i2c_adress)
30
+ self.strip = PixelStrip(num=self.LED_COUNT, i2c=i2c, brightness=self.LED_BRIGHTNESS, i2c_adress=i2c_adress)
31
31
  self.strip.begin()
32
32
 
33
33
  def clean(self):
@@ -51,7 +51,7 @@ class RGB_Matrix:
51
51
 
52
52
  :param colour: RGBW value 32 bit integer
53
53
  """
54
- for i in range(self.strip.numPixels()):
54
+ for i in range(self.strip.getNumPixels()):
55
55
  self.strip.setPixelColor(i, colour)
56
56
  self.strip.show()
57
57
 
@@ -59,7 +59,7 @@ class RGB_Matrix:
59
59
  """
60
60
  turn all LEDs in matrix off
61
61
  """
62
- for i in range(self.strip.numPixels()):
62
+ for i in range(self.strip.getNumPixels()):
63
63
  self.strip.setPixelColor(i, RGBW(0, 0, 0, 0))
64
64
  self.strip.show()
65
65
 
@@ -86,7 +86,7 @@ class RGB_Matrix:
86
86
  :param iterations: iterations of animation
87
87
  """
88
88
  for j in range(256 * iterations):
89
- for i in range(self.strip.numPixels()):
89
+ for i in range(self.strip.getNumPixels()):
90
90
  self.strip.setPixelColor(i, self.wheel((i + j) & 255))
91
91
  self.strip.show()
92
92
  time.sleep(wait_ms / 1000.0)
@@ -98,7 +98,7 @@ class RGB_Matrix:
98
98
  :param color: RGB value to set pixels to
99
99
  :param wait_ms: time between each pixel
100
100
  """
101
- for i in range(self.strip.numPixels()):
101
+ for i in range(self.strip.getNumPixels()):
102
102
  self.strip.setPixelColor(i, color)
103
103
  self.strip.show()
104
104
  time.sleep(wait_ms / 1000.0)
@@ -113,11 +113,11 @@ class RGB_Matrix:
113
113
  """
114
114
  for j in range(iterations):
115
115
  for q in range(3):
116
- for i in range(0, self.strip.numPixels(), 3):
116
+ for i in range(0, self.strip.getNumPixels(), 3):
117
117
  self.strip.setPixelColor(i + q, color)
118
118
  self.strip.show()
119
119
  time.sleep(wait_ms / 1000.0)
120
- for i in range(0, self.strip.numPixels(), 3):
120
+ for i in range(0, self.strip.getNumPixels(), 3):
121
121
  self.strip.setPixelColor(i + q, 0)
122
122
 
123
123
  def demo1(self):
@@ -151,4 +151,19 @@ class RGB_Matrix:
151
151
  self.strip.setPixelColor(i, RGBW(255, 0, 0, 0))
152
152
  self.strip.show()
153
153
  except KeyboardInterrupt:
154
- self.clean()
154
+ self.clean()
155
+
156
+ def setBrightness(self, brightness):
157
+ """
158
+ Set brightness of all pixels
159
+
160
+ :param brightness: brightness level (0-255)
161
+ """
162
+ self.strip.setBrightness(brightness)
163
+ self.strip.show()
164
+
165
+ def getPixelNum(self):
166
+ """
167
+ Get number of pixels in matrix
168
+ """
169
+ return self.strip.getNumPixels()
@@ -1,6 +1,7 @@
1
1
  from ._LEDTransferData import LEDTransferData
2
2
  from enum import Enum
3
- import smbus2
3
+ import busio
4
+ from adafruit_bus_device import i2c_device
4
5
  import time
5
6
 
6
7
  class FunctionEnum(Enum):
@@ -16,26 +17,25 @@ class FunctionEnum(Enum):
16
17
  SETPIXELCOLOR = 1
17
18
  FILL = 2
18
19
  SETBRIGHTNESS = 3
19
- WHITEOVERRAINBOW = 4
20
- GAMMA8 = 5
21
- GAMMA32 = 6
22
- NUMPIXEL = 7
23
- COLORHSV = 8
24
- CLEAR = 9
25
- SENDDATA2SHOW = 10
26
- SENDALLPIXRGB0 = 11
27
- SENDALLPIXRGB1 = 12
28
- SENDALLPIXRGB2 = 13
29
- SENDALLPIXRGB3 = 14
30
- SENDALLPIXRGB4 = 15
31
- SENDALLPIXRGB5 = 16
20
+ GAMMA8 = 4
21
+ GAMMA32 = 5
22
+ NUMPIXEL = 6
23
+ COLORHSV = 7
24
+ CLEAR = 8
25
+ SENDDATA2SHOW = 9
26
+ SENDALLPIXRGB0 = 10
27
+ SENDALLPIXRGB1 = 11
28
+ SENDALLPIXRGB2 = 12
29
+ SENDALLPIXRGB3 = 13
30
+ SENDALLPIXRGB4 = 14
31
+ SENDALLPIXRGB5 = 15
32
32
 
33
33
  class PixelStrip:
34
34
  """
35
35
  Controls a strip of LEDs (WS281x / SK6812) via I2C.
36
36
  """
37
37
 
38
- def __init__(self, num, brightness=255, bus = None, bus_id = 1, i2c_adress = 0x66):
38
+ def __init__(self, num, i2c: busio.I2C, brightness=255, i2c_adress = 0x66):
39
39
  """
40
40
  initilize LED controll class
41
41
 
@@ -43,8 +43,8 @@ class PixelStrip:
43
43
  :param brightness: brightness of all pixels
44
44
  """
45
45
  self.num = num
46
- self.bus = bus if bus is not None else smbus2.SMBus(bus_id)
47
- self.Address = i2c_adress
46
+ self.address = i2c_adress
47
+ self.device = i2c_device.I2CDevice(i2c, self.address)
48
48
  self.transfer_data = LEDTransferData()
49
49
  self.transfer_data.setBright(brightness)
50
50
 
@@ -61,25 +61,45 @@ class PixelStrip:
61
61
 
62
62
  :param cmd: block of data to send
63
63
  """
64
- self.bus.write_block_data(
65
- self.Address, cmd, [
66
- self.transfer_data.func,
67
- self.transfer_data.pos,
68
- self.transfer_data.r,
69
- self.transfer_data.g,
70
- self.transfer_data.b,
71
- self.transfer_data.w,
72
- self.transfer_data.c,
73
- self.transfer_data.bright,
74
- self.transfer_data.first,
75
- self.transfer_data.count,
76
- self.transfer_data.data,
77
- self.transfer_data.data1
78
- ]
79
- )
64
+ data = bytes([
65
+ cmd & 0xFF,
66
+ 0x0C,
67
+ self.transfer_data.func & 0xFF,
68
+ self.transfer_data.pos & 0xFF,
69
+ self.transfer_data.r & 0xFF,
70
+ self.transfer_data.g & 0xFF,
71
+ self.transfer_data.b & 0xFF,
72
+ self.transfer_data.w & 0xFF,
73
+ self.transfer_data.c & 0xFF,
74
+ self.transfer_data.bright & 0xFF,
75
+ self.transfer_data.first & 0xFF,
76
+ self.transfer_data.count & 0xFF,
77
+ self.transfer_data.data & 0xFF,
78
+ self.transfer_data.data1 & 0xFF,
79
+ ])
80
+ with self.device as bus_device:
81
+ bus_device.write(data)
80
82
  time.sleep(0.003) # Hardware timing delay
81
83
  self.transfer_data.clean()
82
84
 
85
+ def _write(self, cmd, data):
86
+ """
87
+ Send a command byte followed by a data block
88
+ """
89
+ buffer = bytes([cmd & 0xFF, len(data) & 0xFF] + [value & 0xFF for value in data])
90
+ with self.device as bus_device:
91
+ bus_device.write(buffer)
92
+ time.sleep(0.003)
93
+
94
+ def _read(self):
95
+ """
96
+ Read one byte from the I2C device
97
+ """
98
+ data = bytearray(1)
99
+ with self.device as bus_device:
100
+ bus_device.readinto(data)
101
+ return data[0]
102
+
83
103
  def __len__(self):
84
104
  """
85
105
  Return the total number of pixels
@@ -205,11 +225,7 @@ class PixelStrip:
205
225
  for i in range(6):
206
226
  start = 32 * i
207
227
  end = start + 32
208
- self.bus.write_block_data(
209
- self.Address,
210
- FunctionEnum.SENDALLPIXRGB0.value + i,
211
- rgb[start:end]
212
- )
228
+ self._write( FunctionEnum.SENDALLPIXRGB0.value + i, rgb[start:end])
213
229
 
214
230
  def fill(self, r=0, g=0, b=0, w=0, first=0, end=64):
215
231
  """
@@ -252,7 +268,7 @@ class PixelStrip:
252
268
  self.transfer_data.setFunc(FunctionEnum.SETBRIGHTNESS.value)
253
269
  self.send(0x00)
254
270
 
255
- def numPixels(self):
271
+ def getNumPixels(self):
256
272
  """
257
273
  Return the number of pixels in this strip
258
274
  """
@@ -267,7 +283,7 @@ class PixelStrip:
267
283
  self.transfer_data.setFunc(FunctionEnum.GAMMA8.value)
268
284
  self.transfer_data.setData(x)
269
285
  self.send(0x01)
270
- return self.bus.read_byte(self.Address)
286
+ return self._read()
271
287
 
272
288
  def getGamma32(self, x):
273
289
  """
@@ -278,9 +294,9 @@ class PixelStrip:
278
294
  self.transfer_data.setFunc(FunctionEnum.GAMMA32.value)
279
295
  self.transfer_data.setData(x)
280
296
  self.send(0x01)
281
- return self.bus.read_byte(self.Address)
297
+ return self._read()
282
298
 
283
- def ColorHSV(self, x):
299
+ def getColorHSV(self, x):
284
300
  """
285
301
  Converts an HSV color value into the device-specific RGB format.
286
302
 
@@ -289,4 +305,4 @@ class PixelStrip:
289
305
  self.transfer_data.setFunc(FunctionEnum.COLORHSV.value)
290
306
  self.transfer_data.setData(x)
291
307
  self.send(0x01)
292
- return self.bus.read_byte(self.Address)
308
+ return self._read()
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: JoyPi_RGB_Matrix_RaspberryPi
3
- Version: 1.0.0
3
+ Version: 1.0.2
4
4
  Summary: This library enables usage of RGB matrix with RP2040 microcontroller chip on the Raspberry Pi.
5
5
  Project-URL: Homepage, https://github.com/joy-it/JoyPi_RGB_Matrix_RaspberryPi
6
6
  Project-URL: Issues, https://github.com/joy-it/JoyPi_RGB_Matrix_RaspberryPi/issues
@@ -20,13 +20,15 @@ This library enables usage of RGB matrix with RP2040 microcontroller chip on the
20
20
  ## Installation
21
21
  You can install this library from PyPI.
22
22
  To install it for the current user on your Raspberry Pi, use the following command:
23
- ```
24
- pip install JoyPi_RGB_Matrix_RaspberryPi
23
+ ```bash
24
+ pip install JoyPi-RGB-Matrix-RaspberryPi
25
25
  ```
26
26
 
27
27
  ## Library Guide
28
28
  - `LEDMatrix( count = 64, brightness = 10, right_border = [7,15,23,31,39,47,55,63], left_border = [0,8,16,24,32,40,48,56])`- initialize LED matrix with default values for Joy-Pi
29
29
  - `clean()` - clears the LED matrix
30
+ - `setBrightness(brightness)` - set brightness to a certain level (0-255)
31
+ - `getPixelNum()` - returns number of pixel of led matrix
30
32
  - `setPixel(position, colour)` - sets specific pixel to a selected colour
31
33
  - `RGB_on(colour)` - sets the complete matrix to one selected colour
32
34
  - `RGB_off()` - turns the complete matrix off
@@ -0,0 +1,9 @@
1
+ JoyPi_RGB_Matrix_RaspberryPi/RGB_Matrix.py,sha256=1gmJGBovYm2o-J4rjJfhAq4wofTCCYSn65Phth2vAK8,5468
2
+ JoyPi_RGB_Matrix_RaspberryPi/_LEDTransferData.py,sha256=pFT0s87GIUvcorLBMoP6SaVyG1a4VFFd3ZFemH0SvIw,4612
3
+ JoyPi_RGB_Matrix_RaspberryPi/_PixelStrip.py,sha256=Yqy-M1nz0EuEEyvW0_ZasFrRZ0HQLK1QlhyVP1Za_Fg,10077
4
+ JoyPi_RGB_Matrix_RaspberryPi/_RGBW.py,sha256=EcaedZUnIVB30MQiqcV5YPxvjxWJKUdMZLnERE1nLho,1577
5
+ JoyPi_RGB_Matrix_RaspberryPi/__init__.py,sha256=TmM6J8HmbztmrjNjyOO3-xGrS1FeNlc0TZKVW7do4mA,62
6
+ joypi_rgb_matrix_raspberrypi-1.0.2.dist-info/METADATA,sha256=0awiueBo8K7N2x7Td2qP44ZKShFlarO0Xb4L9EWnFIw,2187
7
+ joypi_rgb_matrix_raspberrypi-1.0.2.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
8
+ joypi_rgb_matrix_raspberrypi-1.0.2.dist-info/licenses/LICENSE,sha256=huySC1quQxrIchKLo7iaLAiFssUwfkKHjAEcXDJ5XXk,1085
9
+ joypi_rgb_matrix_raspberrypi-1.0.2.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.28.0
2
+ Generator: hatchling 1.32.4
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -1,9 +0,0 @@
1
- JoyPi_RGB_Matrix_RaspberryPi/RGB_Matrix.py,sha256=u3bVOw9-weDAANFtf3VnPQMWbJRDDDm86cMlezzUvbM,5114
2
- JoyPi_RGB_Matrix_RaspberryPi/_LEDTransferData.py,sha256=pFT0s87GIUvcorLBMoP6SaVyG1a4VFFd3ZFemH0SvIw,4612
3
- JoyPi_RGB_Matrix_RaspberryPi/_PixelStrip.py,sha256=Ogmkn6v5e2GfzOG2qiYrwVhBVukL4JRTNMklIsXcEEI,9584
4
- JoyPi_RGB_Matrix_RaspberryPi/_RGBW.py,sha256=EcaedZUnIVB30MQiqcV5YPxvjxWJKUdMZLnERE1nLho,1577
5
- JoyPi_RGB_Matrix_RaspberryPi/__init__.py,sha256=TmM6J8HmbztmrjNjyOO3-xGrS1FeNlc0TZKVW7do4mA,62
6
- joypi_rgb_matrix_raspberrypi-1.0.0.dist-info/METADATA,sha256=-UXhIi_ysnCUTmjU3gak8aByBLDyoZNLuxRF9LQ6X-M,2051
7
- joypi_rgb_matrix_raspberrypi-1.0.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
8
- joypi_rgb_matrix_raspberrypi-1.0.0.dist-info/licenses/LICENSE,sha256=huySC1quQxrIchKLo7iaLAiFssUwfkKHjAEcXDJ5XXk,1085
9
- joypi_rgb_matrix_raspberrypi-1.0.0.dist-info/RECORD,,