From 6c44fd9eb9c0d8d5fac4273650ff960b3c3bc5c0 Mon Sep 17 00:00:00 2001 From: Tasos Sahanidis Date: Fri, 23 Jun 2023 15:39:03 +0300 Subject: [PATCH] scripts: add nxp_rgb_count.py --- scripts/nxp_rgb_count.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 scripts/nxp_rgb_count.py diff --git a/scripts/nxp_rgb_count.py b/scripts/nxp_rgb_count.py new file mode 100755 index 00000000..48e1ecf5 --- /dev/null +++ b/scripts/nxp_rgb_count.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python3 +import sys + +# Reads an NXP (single colour) frame from stdin and returns the index of the first led that's fully on +# Args are indices to ignore (for buttons that can not be turned off) +ignore = set([int(x) for x in sys.argv[1:]]) +cmdi = 0 +leds = [] +while cmdi < 3: + expected = f"7f 0{cmdi + 1} " + cmd = input().lower().strip() + if not cmd.startswith(expected): + print("Try again. Expecting " + expected) + continue + + cmdi += 1 + + cmdl = cmd.split(" ") + leds += cmdl[4:] + +for i in range(len(leds)): + if len(leds[i]) != 2: + print(f"Invalid data at {i}") + elif leds[i] == "ff": + if i in ignore: + continue + print(f"LED found at {i} {hex(i)}") + break