-
Notifications
You must be signed in to change notification settings - Fork 0
/
wiring.php
63 lines (48 loc) · 2.22 KB
/
wiring.php
1
2
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
// I used 5V WS2812B Eco Led Panels 8x32 pixel density
//*********************************************************************
// Because I find python array handling to be an abomination (c) 2021
//*********************************************************************
// This spits out a python array definition of the pixels to STDOUT
$number_of_panels = 4; // How many panels you have?
$matrix_pixelsy = 8; // Vertical pixel density of a panel
$matrix_pixelsx = 32; // Horizontal pixel density of a panel
// Use this for later to contain my panels / pixels
$panels = [];
// Create all the pixels (in numerical order starting at 0
// Pixel density: ($matrix_pixelsy * $matrixpixelsx * $number_of_panels)
for ($panel = 0;$panel < $number_of_panels;$panel++) {
for ($pixel = 0;$pixel < ($matrix_pixelsx * $matrix_pixelsy);$pixel++) {
$panels[$panel][] = $pixel + ($panel * $matrix_pixelsx * $matrix_pixelsy);
}
}
/********************************/
/* This is where the fun begins */
/********************************/
// Start spitting out the (python) matrix definition file
// python and its "tabs" (tsk tsk) what problem does this solve again?
print "def getMatrix():\n\treturn[\n";
// Since I stacked my panels VERITCALLY I need to array chunk my
// pixels into {$matrix_pixelsy} slices (across the top) (thanks PHP!)
foreach($panels as $panel=>$pixels) {
$panelpixel[$panel] = array_chunk($pixels,$matrix_pixelsy);
}
// Now go through each panelpixel array on the X axis and spit out the chain of
// "zigzag" - chained panels. this should also work with chained strings where applicable
for ($x =0; $x < $matrix_pixelsx;$x++) {
foreach($panelpixel as $panel=>$pixels) {
print "# {$panel}\n";
// Even rows keep "sane" and print straight
if ($x % 2 == 0) {
$pixels[$x] = $pixels[$x];
}
// Odd Rows we need to reverse these and start at the "rightmost" edge and go backwards
else {
$pixels[$x] = array_reverse($pixels[$x]);
}
// Print all my pixels out (thanks php!) with commas and newlines formatted for python3
print join(',',$pixels[$x]).",\n";
}
}
print "\t]\n";
// That's it!