From fc0bea00de1c794ad441097be0f1f3c0431c042c Mon Sep 17 00:00:00 2001 From: Neil Roodyn Date: Sun, 29 Jan 2023 19:45:45 +1100 Subject: [PATCH 1/3] Add initial emulator script --- .gitignore | 1 + glowbit/glowbit.py | 10 +++-- glowbit/glowbitEmulator.py | 76 ++++++++++++++++++++++++++++++++++++++ glowbit/testMatrix.py | 9 +++++ 4 files changed, 93 insertions(+), 3 deletions(-) create mode 100644 .gitignore create mode 100644 glowbit/glowbitEmulator.py create mode 100644 glowbit/testMatrix.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a4a310f --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +glowbit/__pycache__/ diff --git a/glowbit/glowbit.py b/glowbit/glowbit.py index e3f58ad..13fddb6 100644 --- a/glowbit/glowbit.py +++ b/glowbit/glowbit.py @@ -7,8 +7,12 @@ import rp2 if _SYSNAME == 'Linux': - import rpi_ws281x as ws - + try: + import rpi_ws281x as ws + except: + print ("rpi_ws281x not installed") + ws = None + # Dummy ptr32() for within micropython.viper def ptr32(arg): return arg @@ -1498,7 +1502,7 @@ def __init__(self, tileRows = 1, tileCols = 1, pin = 18, brightness = 20, mapFun self.pixelsShow = self._pixelsShowPico self.ticks_ms = time.ticks_ms - if _SYSNAME == 'Linux': + if _SYSNAME == 'Linux' and ws is not None: self.strip = ws.PixelStrip(self.numLEDs, pin) self.strip.begin() self.pixelsShow = self._pixelsShowRPi diff --git a/glowbit/glowbitEmulator.py b/glowbit/glowbitEmulator.py new file mode 100644 index 0000000..e5f7e99 --- /dev/null +++ b/glowbit/glowbitEmulator.py @@ -0,0 +1,76 @@ +import glowbit +import os +from colorama import Fore, Back, Style +from time import sleep + +class WSE: + def PixelStrip(self, numLEDs: int, pin :int): + return self + + def begin(self): + return None + + def setPixelColor(self, x: int, colour: int): + return None + + def show(self): + return None + +ws = WSE() + +class matrix8x8(glowbit.matrix8x8): + + def __init__(self, tileRows = 1, tileCols = 1, pin = 18, brightness = 20, mapFunction = None, rateLimitFPS = -1, rateLimitCharactersPerSecond = -1, sm = 0): + self.tileRows = tileRows + self.tileCols = tileCols + self.numLEDs = tileRows*tileCols*64 + self.numLEDsX = tileCols*8 + self.numLEDsY = tileRows*8 + self.numCols = self.numLEDsX + self.numRows = self.numLEDsY + + self.strip = ws.PixelStrip(self.numLEDs, pin) + self.strip.begin() + self.pixelsShow = self._pixelsShowRPi + self.ticks_ms = self._ticks_ms_Linux + + super().__init__(tileRows, tileCols, pin, brightness, mapFunction, rateLimitFPS, rateLimitCharactersPerSecond, sm) + self.pixelsShow = self.draw + + def getColor(self, row: int, col: int): + colInt = self.ar[self.remap(col, row)] + r = (colInt&0xFF0000) >> 16 + g = (colInt&0xFF00)>> 8 + b = (colInt&0xFF) + # need a better way to do this + if (r >= 150 and g < 150 and b < 150): + return Fore.RED + if (r < 150 and g >= 150 and b < 150): + return Fore.GREEN + if (r < 150 and g < 150 and b >= 150): + return Fore.BLUE + if (r >= 150 and g >= 150 and b < 150): + return Fore.YELLOW + if (r >= 150 and g >= 150 and b >= 150): + return Fore.WHITE + if (r < 50 and g < 50 and b < 50): + return Fore.BLACK + return Fore.MAGENTA + + def draw(self): + os.system('cls' if os.name == 'nt' else 'clear') + for r in range (self.tileRows*8): + for c in range (self.tileCols*8): + col = self.getColor(r, c) + print(Back.BLACK + col + '■', end=' ') + print() + print(Style.RESET_ALL) + sleep(0.25) + + + def blankDisplay(self): + for i in range(int(len(self.ar))): + self.ar[i] = self.rgbColour(0,0,0) + self.pixelsShow() + + diff --git a/glowbit/testMatrix.py b/glowbit/testMatrix.py new file mode 100644 index 0000000..73e9ff4 --- /dev/null +++ b/glowbit/testMatrix.py @@ -0,0 +1,9 @@ +try: + import glowbitEmulator as glowbit +except: + import glowbit + +matrix = glowbit.matrix8x8(3, 3) + +matrix.demo() + From 7493b5816ad79967480df29ebb7f7fd6bef4e652 Mon Sep 17 00:00:00 2001 From: Neil Roodyn Date: Sun, 29 Jan 2023 19:54:51 +1100 Subject: [PATCH 2/3] Move into Emulator folder --- .gitignore | 2 +- {glowbit => Emulator}/glowbitEmulator.py | 2 ++ {glowbit => Emulator}/testMatrix.py | 0 3 files changed, 3 insertions(+), 1 deletion(-) rename {glowbit => Emulator}/glowbitEmulator.py (98%) rename {glowbit => Emulator}/testMatrix.py (100%) diff --git a/.gitignore b/.gitignore index a4a310f..61f2dc9 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -glowbit/__pycache__/ +**/__pycache__/ diff --git a/glowbit/glowbitEmulator.py b/Emulator/glowbitEmulator.py similarity index 98% rename from glowbit/glowbitEmulator.py rename to Emulator/glowbitEmulator.py index e5f7e99..cbbe06b 100644 --- a/glowbit/glowbitEmulator.py +++ b/Emulator/glowbitEmulator.py @@ -1,3 +1,5 @@ +import sys +sys.path.insert(0, '..') import glowbit import os from colorama import Fore, Back, Style diff --git a/glowbit/testMatrix.py b/Emulator/testMatrix.py similarity index 100% rename from glowbit/testMatrix.py rename to Emulator/testMatrix.py From 3bd5358316c2ecdd32b2751f6f929db5e4ced2c7 Mon Sep 17 00:00:00 2001 From: Neil Roodyn Date: Sun, 29 Jan 2023 19:56:04 +1100 Subject: [PATCH 3/3] fix path to glowbit scripts --- Emulator/glowbitEmulator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Emulator/glowbitEmulator.py b/Emulator/glowbitEmulator.py index cbbe06b..b12366b 100644 --- a/Emulator/glowbitEmulator.py +++ b/Emulator/glowbitEmulator.py @@ -1,5 +1,5 @@ import sys -sys.path.insert(0, '..') +sys.path.insert(0, '../glowbit') import glowbit import os from colorama import Fore, Back, Style