Skip to content

Emulator prototype #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/__pycache__/
78 changes: 78 additions & 0 deletions Emulator/glowbitEmulator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import sys
sys.path.insert(0, '../glowbit')
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()


9 changes: 9 additions & 0 deletions Emulator/testMatrix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
try:
import glowbitEmulator as glowbit
except:
import glowbit

matrix = glowbit.matrix8x8(3, 3)

matrix.demo()

10 changes: 7 additions & 3 deletions glowbit/glowbit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down