From 328b4fb84bc4cbb126366c86f4132a4af6d1577b Mon Sep 17 00:00:00 2001 From: schneider <schneider@blinkenlichts.net> Date: Mon, 15 Jun 2020 16:27:45 +0200 Subject: [PATCH] fix(pycardium): Fix code style of some py/ modules --- pycardium/modules/py/ledfx.py | 4 +++- pycardium/modules/py/pov.py | 36 +++++++++++++++++++++-------------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/pycardium/modules/py/ledfx.py b/pycardium/modules/py/ledfx.py index 993fb0926..d03cacca2 100644 --- a/pycardium/modules/py/ledfx.py +++ b/pycardium/modules/py/ledfx.py @@ -75,7 +75,9 @@ def kitt( # set the color values to the LEDs by multiplying the given color # value with the corresponding brightness value in the kitt table - output = [[int(x * y) for y in rgb] for x in kitt_table[j : (j + used_leds)]] + output = [ + [int(x * y) for y in rgb] for x in kitt_table[j : (j + used_leds)] + ] else: used_leds = len(spectrum) diff --git a/pycardium/modules/py/pov.py b/pycardium/modules/py/pov.py index d82b56918..a666ffdc2 100644 --- a/pycardium/modules/py/pov.py +++ b/pycardium/modules/py/pov.py @@ -1,26 +1,27 @@ -#this script reads a BMP file and displays it as POV. For optimal results use a BMP that is 11 pixels wide. +# this script reads a BMP file and displays it as POV. For optimal results use a BMP that is 11 pixels wide. import leds -#default filename. Depending on how you want to run this, change it + +# default filename. Depending on how you want to run this, change it FILENAME = "Smiley.bmp" -#Determines the Frame Rate, currently not used. +# Determines the Frame Rate, currently not used. DELAY = 0 -#Determine Brightness Level. You might not wanna use the full values from the BMP +# Determine Brightness Level. You might not wanna use the full values from the BMP BRIGHTNESS = 1.0 - class BMPError(Exception): pass + class POV: def __init__(self, filename=FILENAME): self.filename = filename f = open("/" + self.filename, "rb") - if f.read(2) != b'BM': # check signature + if f.read(2) != b"BM": # check signature raise BMPError("Not BitMap file") - #turn into int.from_bytes - bmpFileSize = int.from_bytes(f.read(4), 'little') + # turn into int.from_bytes + bmpFileSize = int.from_bytes(f.read(4), "little") f.read(4) # Read & ignore creator bytes self.bmpImageOffset = self.read_le(f.read(4)) # Start of image data @@ -29,8 +30,10 @@ class POV: self.bmpHeight = self.read_le(f.read(4)) flip = False - print("Size: %d\nImage offset: %d\nHeader size: %d" % - (bmpFileSize, self.bmpImageOffset, headerSize)) + print( + "Size: %d\nImage offset: %d\nHeader size: %d" + % (bmpFileSize, self.bmpImageOffset, headerSize) + ) print("Width: %d\nHeight: %d" % (self.bmpWidth, self.bmpHeight)) if self.read_le(f.read(2)) != 1: @@ -45,21 +48,25 @@ class POV: print("Image OK!") self.rowSize = (self.bmpWidth * 3 + 3) & ~3 # 32-bit line boundary self.fileOffset = f.tell() - print("File Offset"+str(self.fileOffset)) + print("File Offset" + str(self.fileOffset)) f.close() self.read_image() - def correct_brightness(self, color): return int(pow((color * BRIGHTNESS) / 255, 2.7) * 255 + 0.5) + def getWidth(self): return self.bmpWidth + def setFileOffset(self, fileOffset): self.fileOffset = fileOffset + def getFileOffset(self): return self.fileOffset + def read_le(self, bytes): - return int.from_bytes(bytes, 'little') + return int.from_bytes(bytes, "little") + def read_image(self): self.imageArray = [] flip = True @@ -75,7 +82,7 @@ class POV: for col in range(self.bmpWidth): rgb = [f.read(1), f.read(1), f.read(1)] rgb = [int.from_bytes(x, "little") for x in rgb] - #rgb = [self.correct_brightness(x) for x in rgb] + # rgb = [self.correct_brightness(x) for x in rgb] rowArray += [rgb] self.imageArray += [rowArray] @@ -86,6 +93,7 @@ class POV: for i in self.imageArray: leds.set_all(i) + def play(imagename): myPov = POV(imagename) while True: -- GitLab