Stefan Schuermans commited on 2019-06-21 16:22:49
Showing 1 changed files, with 94 additions and 0 deletions.
| ... | ... |
@@ -0,0 +1,94 @@ |
| 1 |
+#! /usr/bin/env python3 |
|
| 2 |
+ |
|
| 3 |
+import sys |
|
| 4 |
+ |
|
| 5 |
+ |
|
| 6 |
+def read_leds(filename): |
|
| 7 |
+ leds = {}
|
|
| 8 |
+ err = 0 |
|
| 9 |
+ with open(filename, "r") as f: |
|
| 10 |
+ for line in f: |
|
| 11 |
+ fields = line.split() |
|
| 12 |
+ ledno = int(fields[0]) |
|
| 13 |
+ led = {
|
|
| 14 |
+ "ledno": ledno, |
|
| 15 |
+ "x": int(fields[1]), |
|
| 16 |
+ "y": int(fields[2]), |
|
| 17 |
+ "type": fields[3], |
|
| 18 |
+ "copies": [] |
|
| 19 |
+ } |
|
| 20 |
+ if led["type"] == "-": |
|
| 21 |
+ led["copies"].append({"x": led["x"] - 1, "y": led["y"]})
|
|
| 22 |
+ led["copies"].append({"x": led["x"] + 1, "y": led["y"]})
|
|
| 23 |
+ elif led["type"] == "|": |
|
| 24 |
+ led["copies"].append({"x": led["x"], "y": led["y"] - 1})
|
|
| 25 |
+ led["copies"].append({"x": led["x"], "y": led["y"] + 1})
|
|
| 26 |
+ elif led["type"] == "/": |
|
| 27 |
+ led["copies"].append({"x": led["x"] - 1, "y": led["y"] + 1})
|
|
| 28 |
+ led["copies"].append({"x": led["x"] + 1, "y": led["y"] - 1})
|
|
| 29 |
+ elif led["type"] == "\\": |
|
| 30 |
+ led["copies"].append({"x": led["x"] - 1, "y": led["y"] - 1})
|
|
| 31 |
+ led["copies"].append({"x": led["x"] + 1, "y": led["y"] + 1})
|
|
| 32 |
+ else: |
|
| 33 |
+ print( |
|
| 34 |
+ "led {:d} unknown type \"{:s}\"".format(ledno,
|
|
| 35 |
+ led["type"]), |
|
| 36 |
+ file=sys.stderr) |
|
| 37 |
+ leds[ledno] = led |
|
| 38 |
+ # assign indices |
|
| 39 |
+ leds2 = [] |
|
| 40 |
+ for ledno in sorted(leds): |
|
| 41 |
+ led = leds[ledno] |
|
| 42 |
+ idx = len(leds2) |
|
| 43 |
+ led["idx"] = idx |
|
| 44 |
+ leds2.append(led) |
|
| 45 |
+ return leds2 |
|
| 46 |
+ |
|
| 47 |
+ |
|
| 48 |
+def output(leds): |
|
| 49 |
+ cnt = 0 |
|
| 50 |
+ for led in leds: |
|
| 51 |
+ cnt += 1 + len(led["copies"]) |
|
| 52 |
+ print(" FixedPixel fixed[] = new FixedPixel [{:d}];".format(cnt))
|
|
| 53 |
+ i = 0 |
|
| 54 |
+ for led in leds: |
|
| 55 |
+ print(" fixed[{:d}] = new FixedPixel( {:d}, {:d}, 2, (byte)0 );".
|
|
| 56 |
+ format(i, led["y"], led["x"])) |
|
| 57 |
+ i += 1 |
|
| 58 |
+ for cpy in led["copies"]: |
|
| 59 |
+ print( |
|
| 60 |
+ " fixed[{:d}] = new FixedPixel( {:d}, {:d}, 2, (byte)0 );".
|
|
| 61 |
+ format(i, cpy["y"], cpy["x"])) |
|
| 62 |
+ i += 1 |
|
| 63 |
+ print(" setFixed( fixed );")
|
|
| 64 |
+ print(" ContentPixel content[] = new ContentPixel [{:d}];".format(
|
|
| 65 |
+ len(leds))) |
|
| 66 |
+ for led in leds: |
|
| 67 |
+ print(" content[{:d}] = new ContentPixel( {:d}, {:d}, 1 );".format(
|
|
| 68 |
+ led["idx"], led["y"], led["x"])) |
|
| 69 |
+ print(" setContent( content );")
|
|
| 70 |
+ cnt = 0 |
|
| 71 |
+ for led in leds: |
|
| 72 |
+ cnt += 1 + 2 * len(led["copies"]) |
|
| 73 |
+ print(" CopyPixel copies[] = new CopyPixel [{:d}];".format(cnt))
|
|
| 74 |
+ i = 0 |
|
| 75 |
+ for led in leds: |
|
| 76 |
+ print(" copies[{:d}] = new CopyPixel( {:d}, {:d}, 0, {:d} );".
|
|
| 77 |
+ format(i, led["y"], led["x"], led["idx"])) |
|
| 78 |
+ i += 1 |
|
| 79 |
+ for cpy in led["copies"]: |
|
| 80 |
+ for chan in range(2): |
|
| 81 |
+ print( |
|
| 82 |
+ " copies[{:d}] = new CopyPixel( {:d}, {:d}, {:d}, {:d} );".
|
|
| 83 |
+ format(i, cpy["y"], cpy["x"], chan, led["idx"])) |
|
| 84 |
+ i += 1 |
|
| 85 |
+ print(" setCopies( copies );")
|
|
| 86 |
+ |
|
| 87 |
+ |
|
| 88 |
+def main(): |
|
| 89 |
+ leds = read_leds("ledno_x_y_type.txt")
|
|
| 90 |
+ output(leds) |
|
| 91 |
+ |
|
| 92 |
+ |
|
| 93 |
+if __name__ == "__main__": |
|
| 94 |
+ sys.exit(main()) |
|
| 0 | 95 |