From 84b8c25b3c7b8ab7e1406c46beeae8bf0d58d6fe Mon Sep 17 00:00:00 2001 From: "Mr.Servo" Date: Thu, 30 Jan 2025 17:13:46 +0100 Subject: [PATCH 1/5] [LCD4linux] v5.0-r25 bugfix for Display AX206 (480x320) - new display name '**AX206**' (former '**Pearl**' 480x320) - bugfixed code for **DPF-displays** (e.g. Pearl & AX206) HINT: **LCD4linux** is still working under Python2 and Python3 --- lcd4linux/src/Photoframe.py | 135 +++++++++++++++------------ lcd4linux/src/dpf.py | 12 +-- lcd4linux/src/module.py | 22 ++--- lcd4linux/src/plugin.py | 181 ++++++++++++++++++++---------------- 4 files changed, 189 insertions(+), 161 deletions(-) diff --git a/lcd4linux/src/Photoframe.py b/lcd4linux/src/Photoframe.py index 234bc7e..8bb1639 100644 --- a/lcd4linux/src/Photoframe.py +++ b/lcd4linux/src/Photoframe.py @@ -5,11 +5,12 @@ from usb.util import get_string from PIL import Image from struct import pack -from six.moves import cStringIO as StringIO +from six import ensure_binary +from six.moves import cStringIO def write_jpg2frame(dev, pic): - """Attach header to picture, pad with zeros if necessary, and send to frame""" + # Attach header to picture, pad with zeros if necessary, and send to frame # create header and stack before picture # middle 4 bytes have size of picture rawdata = b"\xa5\x5a\x18\x04" + pack('= 2: - d = d[1] - else: - d = None + d = d[1] if len(d) >= 2 else None else: d = None else: d = list(list(find(idVendor=device['idVendor'], idProduct=device['idProduct'], find_all=True)) + list(find(idVendor=device2['idVendor'], idProduct=device2['idProduct'], find_all=True)))[0] - except: + except Exception: from traceback import format_exc print("[LCD4linux] find exception") print("Error: %s" % format_exc()) @@ -108,9 +110,9 @@ def find_device(Anzahl, device, device2): return d -def init_device(Anzahl, device0, device1): - """First try Mini Monitor mode, then Mass storage mode""" - dev = find_device(Anzahl, device0, device1) +def init_device(anzahl, device0, device1): + # First try Mini Monitor mode, then Mass storage mode + dev = find_device(anzahl, device0, device1) if dev is not None: ## found it, trying to init it @@ -124,7 +126,7 @@ def init_device(Anzahl, device0, device1): ts = time() while True: # may need to burn some time - dev = find_device(Anzahl, device0, device1) + dev = find_device(anzahl, device0, device1) if dev is not None and dev.idProduct == device0["idProduct"]: #switching successful break @@ -140,20 +142,35 @@ def init_device(Anzahl, device0, device1): def frame_init(dev): - """Init device so it stays in Mini Monitor mode""" + # Init device so it stays in Mini Monitor mode # this is the minimum required to keep the frame in Mini Monitor mode!!! -# dev.ctrl_transfer(0xc0, 4 ) -# dev.ctrl_transfer(0xc0, 0x01, 0x00, 0x00, 0x09, 0x04 ) + # dev.ctrl_transfer(0xc0, 4 ) + # dev.ctrl_transfer(0xc0, 0x01, 0x00, 0x00, 0x09, 0x04 ) dev.ctrl_transfer(0xc0, 0x01, 0x00, 0x00, 0x02) def frame_switch(dev): - """Switch device from Mass Storage to Mini Monitor""" + CTRL_TYPE_VENDOR = (2 << 5) + CTRL_IN = 0x80 + CTRL_RECIPIENT_DEVICE = 0 try: - sleep(0.5) + time.sleep(0.5) + s = "\x00" * 251 dev.ctrl_transfer(0x00 | 0x80, 0x06, 0xfe, 0xfe, 0xfe) - except: +# dev.ctrl_transfer(0x00|0x80, 0x06, 0xfe, 0xfe, s, 0xfe ) +# dev.ctrl_transfer(CTRL_TYPE_VENDOR | CTRL_IN | CTRL_RECIPIENT_DEVICE, 0x04, 0x00, 0x00, 1) +# result = dev.ctrl_transfer(CTRL_TYPE_VENDOR | CTRL_IN | CTRL_RECIPIENT_DEVICE, 0x04, 0x00, 0x00, 1) +# expect(result, [ 0x03 ]) +# result = dev.ctrl_transfer(CTRL_TYPE_VENDOR | CTRL_IN | CTRL_RECIPIENT_DEVICE, 0x01, 0x00, 0x00, 2) +# expect(result, [ 0x09, 0x04 ]) +# result = dev.ctrl_transfer(CTRL_TYPE_VENDOR | CTRL_IN | CTRL_RECIPIENT_DEVICE, 0x02, 0x00, 0x00, 1) +# expect(result, [ 0x46 ]) + # settling of the bus and frame takes about 0.42 sec + # give it some extra time, but then still make sure it has settled + except Exception: print("[LCD4linux] switching ERROR") +# from traceback import format_exc +# print format_exc() finally: sleep(2) @@ -161,25 +178,21 @@ def frame_switch(dev): def name(dev): try: return get_string(dev, 1) - except: + except Exception: try: return get_string(dev, 256, 2) - except: + except Exception: return None def main(): global dev, known_devices_list - known_devices_list = get_known_devices() - # define which frame to use, here use Samsung SPF-87H device0 = known_devices_list[0] # Mini Monitor mode device1 = known_devices_list[1] # Mass Storage mode - dev = init_device(1, device0, device1) print("Frame is in Mini Monitor mode and initialized. Sending pictures now") - image = Image.open("mypicture.jpg") #manipulations to consider: # convert @@ -187,8 +200,8 @@ def main(): # rotate # crop image = image.resize((800, 480)) - output = StringIO.StringIO() - image.save(output, "JPEG", quality=94) + output = cStringIO() + image.save(ensure_binary(output), "JPEG", quality=94) pic = output.getvalue() output.close() write_jpg2frame(dev, pic) diff --git a/lcd4linux/src/dpf.py b/lcd4linux/src/dpf.py index e21c569..ef692d2 100644 --- a/lcd4linux/src/dpf.py +++ b/lcd4linux/src/dpf.py @@ -2,7 +2,7 @@ from six import PY2 try: from . import dpflib -except: +except Exception: print("[LCD4linux] dpflib-Error") PROPERTY_BRIGHTNESS = 0x01 @@ -15,7 +15,7 @@ def setBacklight(dev, value): try: dev.setProperty(PROPERTY_BRIGHTNESS, value) return True - except: + except Exception: print("[LCD4linux] Error set Backlight") return False @@ -29,7 +29,7 @@ def showImage(dev, image): else: dev.showRGBAImage(0, 0, x, y, ir.tobytes()) return True - except: + except Exception: print("[LCD4linux] Error writing DPF Device") return False @@ -37,9 +37,9 @@ def showImage(dev, image): def open(usb): try: d = dpflib.open(usb) - d.setProperty(PROPERTY_ORIENTATION, 1) +# d.setProperty(PROPERTY_ORIENTATION, 1) print("[LCD4linux] open %s" % usb) - except: + except Exception: d = None print("[LCD4linux] open Error: %s" % usb) return d @@ -49,5 +49,5 @@ def close(dev): try: if dev is not None: dev.close() - except: + except Exception: pass diff --git a/lcd4linux/src/module.py b/lcd4linux/src/module.py index 4d5a0b6..042d170 100644 --- a/lcd4linux/src/module.py +++ b/lcd4linux/src/module.py @@ -79,14 +79,14 @@ def getHold(self): return L4Lelement.Hold def setHold(self, H): - print("[LCD4linuxE] Hold: %s" % H) + print("[LCD4linuxE] hold: %s" % H) L4Lelement.Hold = H def getHoldKey(self): return L4Lelement.HoldKey def setHoldKey(self, H=False): - print("[LCD4linuxE] HoldKey: %s" % H) + print("[LCD4linuxE] holdkey: %s" % H) L4Lelement.HoldKey = H def getFont(self, F="0"): @@ -102,19 +102,15 @@ def getScreen(self): return L4Lelement.Screen def setScreen(self, S, Lcd="", Hold=False): - if Lcd != "": - if len(str(Lcd)) > 1 or int(Lcd) > 3: - Lcd = "1" + if Lcd != "" and len(str(Lcd)) > 1 or int(Lcd) > 3: + Lcd = "1" L4Lelement.Screen = str(S) L4Lelement.LCD = str(Lcd) L4Lelement.Hold = Hold L4Lelement.Refresh = True - def resetBrightness(self, AKT=""): - if len(AKT) == 3: - L4Lelement.BrightAkt = AKT - else: - L4Lelement.Bright = [-1, -1, -1] + def resetBrightness(self, AKT=[0, 0, 0]): + L4Lelement.Bright = [-1, -1, -1] def setBrightness(self, LCD, BRI=-1): if int(LCD) < 1 or int(LCD) > 3: @@ -145,14 +141,13 @@ def getstatusoutput(cmd): sts = pipe.close() if sts is None: sts = 0 - if text[-1:] == '\n': + if text.endswith == '\n': text = text[:-1] except Exception: sts = 1 text = "- -" print("[LCD4linux] Error on os-call") - finally: - return sts, text + return sts, text def L4LVtest(VV): @@ -172,6 +167,7 @@ def L4LVtest(VV): if O != "": try: f = open(L4Linfo % (O, P)) + B = f.readline() OO = f.readline().strip().split()[1].startswith(VV[1:]) f.close() except Exception: diff --git a/lcd4linux/src/plugin.py b/lcd4linux/src/plugin.py index 1648467..8a22448 100644 --- a/lcd4linux/src/plugin.py +++ b/lcd4linux/src/plugin.py @@ -35,7 +35,7 @@ from icalendar import vDatetime, Calendar as iCalendar from imaplib import IMAP4_SSL, IMAP4 from math import pi, floor, cos -from mutagen.id3 import ID3 +from mutagen.id3 import ID3 # type: ignore from mutagen.mp3 import MP3 from mutagen.flac import FLAC from mutagen.easyid3 import EasyID3 @@ -176,7 +176,7 @@ get_backend(find_library=lambda x: "/lib64/libusb-1.0.so.0") print("[LCD4linux] libusb found :-)", getEnigmaVersionString()) USBok = True -Version = "V5.0-r24" +Version = "V5.0-r25" L4LElist = L4Lelement() L4LdoThread = True LCD4enigma2config = resolveFilename(SCOPE_CONFIG) # /etc/enigma2/ @@ -314,7 +314,7 @@ TimeSelect = [("1", _("5s")), ("2", _("10s")), ("3", _("15s")), ("4", _("20s")), ("6", _("30s")), ("8", _("40s")), ("10", _("50s")), ("12", _("1min")), ("24", _("2min")), ("36", _("3min")), ("48", _("4min")), ("60", _("5min")), ("120", _("10min")), ("240", _("20min")), ("360", _("30min")), ("720", _("60min")), ("1440", _("2h")), ("2160", _("3h")), ("3600", _("5h"))] LCDSelect = [("1", _("LCD 1")), ("2", _("LCD 2")), ("12", _("LCD 1+2")), ("3", _("LCD 3")), ("13", _("LCD 1+3")), ("23", _("LCD 2+3")), ("123", _("LCD 1+2+3"))] LCDSwitchSelect = [("0", _("LCD 1-3")), ("1", _("LCD 1")), ("2", _("LCD 2")), ("3", _("LCD 3"))] -LCDType = [("11", _("Pearl (or compatible LCD) 320x240")), ("12", _("Pearl (or compatible LCD) 240x320")), ("121", _("Corby@Pearl 128x128")), ("122", _("Pearl (or compatible LCD) 480x320")), ("123", _("Pearl (or compatible LCD) 800x480")), +LCDType = [("11", _("Pearl (or compatible LCD) 320x240")), ("12", _("Pearl (or compatible LCD) 240x320")), ("121", _("Corby@Pearl 128x128")), ("122", _("AX206 (or compatible LCD) 480x320")), ("123", _("AX206 (or compatible LCD) 800x480")), ("210", _("Samsung SPF-72H 800x480")), ("23", _("Samsung SPF-75H/76H 800x480")), ("24", _("Samsung SPF-87H 800x480")), ("25", _("Samsung SPF-87H old 800x480")), ("26", _("Samsung SPF-83H 800x600")), ("29", _("Samsung SPF-85H/86H 800x600")), ("212", _("Samsung SPF-85P/86P 800x600")), ("28", _("Samsung SPF-105P 1024x600")), ("27", _("Samsung SPF-107H 1024x600")), ("213", _("Samsung SPF-107H old 1024x600")), ("211", _("Samsung SPF-700T 800x600")), ("215", _("Samsung SPF-800P 800x480")), ("214", _("Samsung SPF-1000P 1024x600")), ("430", _("Internal TFT-LCD 400x240")), ("50", _("Internal Box-Skin-LCD")), @@ -2555,7 +2555,7 @@ def setPopText(w): PopText[1] = Code_utf8(w) -def resetWetter(wetter): +def resetWetter(): global wwwWetter global PICwetter wwwWetter = ["", ""] @@ -2698,8 +2698,7 @@ def getFB2(check): def BRI(w1, w2): - gb = L4LElist.getBrightness(w2, False) - return w1 if gb == -1 else gb + return int(w1) if L4LElist.getBrightness(w2, False) == -1 else int(L4LElist.getBrightness(w2, False)) def virtBRI(LCD): @@ -2844,7 +2843,7 @@ def ICSdownloads(): nextmonth = today + timedelta(mdays[today.month]) # 2012-01-23 nextmonth2 = today + timedelta(mdays[today.month] - 3) # save Month+1 if days to long DTstart = str(Icomp.decoded("dtstart")) - if strftime("%Y-%m") == DTstart[:7] or nextmonth.strftime("%Y-%m") == DTstart[:7] or nextmonth2.strftime("%Y-%m") == DTstart[:7]: + if DTstart.startswith(strftime("%Y-%m")) or DTstart.startswith(nextmonth.strftime("%Y-%m")) or DTstart.startswith(nextmonth2.strftime("%Y-%m")): D = DTstart[:10] inew = [Code_utf8(Icomp.get('summary')), Icomp.decoded("dtstart"), name[1]] Doppel = False @@ -2886,9 +2885,9 @@ def getResolution(t, r): if int(LCD4linux.xmlOffset.value) != 0: MAX_W -= (int(LCD4linux.xmlOffset.value) * 2) MAX_H -= (int(LCD4linux.xmlOffset.value) * 2) - elif t[1:] == "1": + elif t.endswith("1"): MAX_W, MAX_H = 320, 240 - elif t[1:] == "2": + elif t.endswith("2"): MAX_W, MAX_H = 240, 320 elif t[1:] in ["3", "4", "5", "10", "15"]: MAX_W, MAX_H = 800, 480 @@ -2896,21 +2895,21 @@ def getResolution(t, r): MAX_W, MAX_H = 800, 600 elif t[1:] in ["7", "8", "13", "14"]: MAX_W, MAX_H = 1024, 600 - elif t[1:] == "17": + elif t.endswith("17"): MAX_W, MAX_H = 220, 176 - elif t[1:] == "18": + elif t.endswith("18"): MAX_W, MAX_H = 255, 64 - elif t[1:] == "22": + elif t.endswith("22"): MAX_W, MAX_H = 480, 320 - elif t[1:] == "23": + elif t.endswith("23"): MAX_W, MAX_H = 800, 480 - elif t[1:] == "30": + elif t.endswith("30"): MAX_W, MAX_H = 400, 240 elif t == "320": MAX_W, MAX_H = LCD4linux.SizeW.value, LCD4linux.SizeH.value elif t == "420": MAX_W, MAX_H = LCD4linux.SizeW2.value, LCD4linux.SizeH2.value - elif t[1:] == "21": + elif t.endswith("21"): MAX_W, MAX_H = 128, 128 else: MAX_W, MAX_H = 132, 64 @@ -3130,9 +3129,9 @@ def writeHelligkeit(hell, night, STOP): global AktHelligkeit global AktNight R = "" - h1 = BRI(hell[0], 1) - h2 = BRI(hell[1], 2) - h3 = BRI(hell[2], 3) + h1 = BRI(int(hell[0]), 1) + h2 = BRI(int(hell[1]), 2) + h3 = BRI(int(hell[2]), 3) if isOffTime(L4LMoon, L4LSun, L4LMoon, L4LSun): if int(night[0]) != 0: h1 = max(h1 - int(night[0]), 0) @@ -3151,7 +3150,7 @@ def writeHelligkeit(hell, night, STOP): return R AktHelligkeit = [h1, h2, h3] + L4LElist.getBrightness(0, False) L4LElist.resetBrightness([h1, h2, h3]) - L4log("write Bright", AktHelligkeit) + L4log("write Bright: %s" % AktHelligkeit) if SamsungDevice is not None and LCD4linux.LCDType1.value[0] == "1": if dpf.setBacklight(SamsungDevice, h1 if h1 < 8 else 7) == False: dpf.close(SamsungDevice) @@ -4303,12 +4302,12 @@ def __init__(self, cmd): system(cmd + " >/dev/null 2>&1") ShellRunning = False - def cmdFinished(self, data): + def cmdFinished(self): global ShellRunning ShellRunning = False L4log("Shell Stop") - def dataAvail(self, data): + def dataAvail(self): global ShellRunning ShellRunning = False L4log("Shell Data") @@ -4472,10 +4471,10 @@ def getDpfDevice(): if USBok == False: return if LCD4linux.LCDType1.value[0] == "1" and SamsungDevice is None: - L4log("get DPF Device...") + L4log("get DPF1 Device...") if find_dev(1, 0x1908, 0x0102) == True: try: - L4log("open DPF Device0...") + L4log("open DPF1 Device0...") SamsungDevice = dpf.open("usb0") except Exception: L4log("open Error DPF1 Device0") @@ -4517,7 +4516,7 @@ def getDpfDevice(): L4log("open Error DPF3 Device1") SamsungDevice3 = None else: - L4log("DPF2 Device1 not found") + L4log("DPF3 Device1 not found") else: if find_dev(1, 0x1908, 0x0102) == True: try: @@ -4720,16 +4719,15 @@ def __init__(self, cmd): global GrabRunning GrabRunning = True L4logE("Grab Run") - system(cmd + " >/dev/null 2>&1") - self.cmdFinished("") + self.cmdFinished() - def cmdFinished(self, data): + def cmdFinished(self): global GrabRunning L4logE("Grab Stop") GrabRunning = False - def dataAvail(self, data): + def dataAvail(self): pass # Grab @@ -7929,7 +7927,7 @@ def dirSelected(self, dir, dir1): return if dir + dir1 != "" and dir1.endswith("/"): sel = self["config"].getCurrent()[1] - if dir1[-1:] != "/": + if not dir1.endswith("/"): dir1 += "/" if sel == LCD4linux.PiconPath: LCD4linux.PiconPath.value = dir1 @@ -8110,19 +8108,19 @@ def selectionChanged(self): rmFiles(join(LCD4linux.Picon2Cache.value, "*.png")) if LCD4linux.WetterApi.isChanged(): L4log("Weather API was changed to %s" % LCD4linux.WetterApi.value) - resetWetter(None) + resetWetter() if self.SaveWetter != LCD4linux.WetterCity.value: self.SaveWetter = LCD4linux.WetterCity.value LCD4linux.WetterCoords.value = "0,0" LCD4linux.WetterCoords.save() L4log("Weather city was changed from '%s' to '%s'" % (self.SaveWetter, LCD4linux.WetterCity.value)) - resetWetter(0) + resetWetter() if self.SaveWetter2 != LCD4linux.Wetter2City.value: self.SaveWetter2 = LCD4linux.Wetter2City.value LCD4linux.Wetter2Coords.value = "0,0" LCD4linux.Wetter2Coords.save() L4log("Weather2 city was changed from '%s' to '%s'" % (self.SaveWetter2, LCD4linux.Wetter2City.value)) - resetWetter(1) + resetWetter() if LCD4linux.WetterIconZoom.isChanged() or LCD4linux.WetterRain.isChanged() or LCD4linux.WetterRainZoom.isChanged() or LCD4linux.WetterRainColor.isChanged() or LCD4linux.WetterRainColor2.isChanged() or LCD4linux.WetterRainColor2use.isChanged() or LCD4linux.WetterLine.isChanged() or LCD4linux.WetterTrendArrows.isChanged() or LCD4linux.WetterExtra.isChanged() or LCD4linux.WetterExtraColorFeel.isChanged() or LCD4linux.WetterExtraColorCity.isChanged() or LCD4linux.WetterExtraZoom.isChanged() or LCD4linux.WetterExtraFeel.isChanged() or LCD4linux.WetterWind.isChanged() or LCD4linux.WetterWindLines.isChanged() or LCD4linux.WetterLowColor.isChanged() or LCD4linux.WetterHighColor.isChanged() or LCD4linux.WetterTransparenz.isChanged() or LCD4linux.WetterHumColor.isChanged() or LCD4linux.WetterExtra.isChanged(): PICwetter = [None, None] if LCD4linux.WetterZoom.isChanged() or LCD4linux.StandbyWetterZoom.isChanged() or LCD4linux.MPWetterZoom.isChanged() or LCD4linux.WetterType.isChanged() or LCD4linux.StandbyWetterType.isChanged() or LCD4linux.MPWetterType.isChanged() or LCD4linux.WetterColor.isChanged() or LCD4linux.StandbyWetterColor.isChanged() or LCD4linux.MPWetterColor.isChanged() or LCD4linux.WetterFont.isChanged() or LCD4linux.MPWetterFont.isChanged() or LCD4linux.StandbyWetterFont.isChanged() or LCD4linux.WetterShadow.isChanged() or LCD4linux.StandbyWetterShadow.isChanged() or LCD4linux.MPWetterShadow.isChanged(): @@ -9152,10 +9150,10 @@ def ServiceChange(self): self.LsreftoString = sref.toString() if self.LsreftoString is not None: self.LsrefFile = self.LsreftoString[self.LsreftoString.rfind(":") + 1:] - if self.LsrefFile[:1] != "/": + if self.LsrefFile.endswith("/"): tsref = self.LsreftoString[:-len(self.LsrefFile) - 1] tsref = tsref[tsref.rfind(":") + 1:] - if tsref[:1] == "/": + if tsref.starts("/"): self.LsrefFile = tsref else: self.LsrefFile = "" @@ -9171,7 +9169,7 @@ def ServiceChange(self): self.Lchannel_name = info and Code_utf8(info.getName(ref)) self.Lchannel_name2 = info and info.getName(ref) self.Lcommand = "" - if self.LsrefFile[:1] == "/" and isfile("%s.meta" % self.LsrefFile): + if self.LsrefFile.startswith("/") and isfile("%s.meta" % self.LsrefFile): try: with open("%s.meta" % self.LsrefFile, "r") as f: service_name = f.readline().strip() @@ -9507,14 +9505,14 @@ def rcKeyPressed(self, key, flag): self.restartTimer() if LCD4linux.KeySwitch.value == True: if flag == 3: - if LCD4linux.KeyScreen.value[-1:] == "1" and key == self.k: + if LCD4linux.KeyScreen.value.endswith("1") and key == self.k: ScreenTime = 9999 L4logE("Restart at Scr-longkey") NextScreen(True) LCD4linux.ScreenActive.value = ScreenActive[0] self.Refresh = "1" self.restartTimer() - elif LCD4linux.KeyOff.value[-1:] == "1" and key == self.ko: + elif LCD4linux.KeyOff.value.endswith("1") and key == self.ko: LCDon = True if LCDon == False else False L4logE("Restart at Off-longkey") self.Refresh = "1" @@ -9525,16 +9523,16 @@ def rcKeyPressed(self, key, flag): self.KeyTime = time() if self.KeyDoppel == key and flag == 0: self.KeyDoppel = 0 - if LCD4linux.KeyOff.value[-1:] != "1" and key == self.ko: # PREVIOUS + if not LCD4linux.KeyOff.value.endswith("1") and key == self.ko: # PREVIOUS LCDon = True if LCDon == False else False - L4logE("Restart at Off-doublekey", key) + L4logE("Restart at Off-doublekey %s" % key) self.Refresh = "1" self.restartTimer() - elif LCD4linux.KeyScreen.value[-1:] != "1" and key == self.k: # FORWARD / INFO + elif not LCD4linux.KeyScreen.value.endswith("1") and key == self.k: # FORWARD / INFO ScreenTime = 9999 NextScreen(True) LCD4linux.ScreenActive.value = ScreenActive[0] - L4logE("Restart at Scr-doublekey", key) + L4logE("Restart at Scr-doublekey %s" % key) self.Refresh = "1" self.restartTimer() elif flag == 0: @@ -11006,7 +11004,7 @@ def putWetter(workaround, draw, im): WetterZoom[ConfigWWW] = ConfigZoom POSX, POSY = 1, 0 Wmulti = ConfigZoom / 10.0 - largesize = ConfigType[0] != "3" + largesize = not ConfigType.startswith("3") trendarrows = LCD4linux.WetterTrendArrows.value MAX_Wr = 0 if trendarrows else int(12 * Wmulti) # reduce width of current weather frame when trendarrows are missing if ConfigType.startswith("2"): @@ -11056,7 +11054,7 @@ def putWetter(workaround, draw, im): image_Back = self.im[im].crop((POSXs, ConfigPos, POSXs + MAX_W, ConfigPos + MAX_H)) self.im[Wim].paste(image_Back, (0, 0)) self.draw[Wim] = ImageDraw.Draw(self.im[Wim]) - if ConfigType != "3" and ConfigType[0] != "4": + if ConfigType != "3" and not ConfigType.startswith("4"): i = 0 for curr in self.WWeek[ConfigWWW]: if (i < 4 and ConfigType in ["1", "2", "5"]) or (i < 5 and ConfigType in ["11", "21", "51"]) or (i < 2 and ConfigType in ["12", "22"]): @@ -11152,7 +11150,7 @@ def putWetter(workaround, draw, im): POSY += int(54 * Wmulti) else: POSX += int(54 * Wmulti) - if ConfigType[0] != "5": + if not ConfigType.startswith("5"): if LCD4linux.WetterLine.value == "true": self.draw[Wim].line((POSX, 1, POSX, POSY + int(60 * Wmulti)), fill=ConfigColor) elif LCD4linux.WetterLine.value == "trueLong": @@ -11191,12 +11189,18 @@ def putWetter(workaround, draw, im): Feel = "" else: if trendarrows: - Feelarrow = "●" if OldFeel == -88 else "▲" if OldFeel < float(Feel) else "▼" + if OldFeel == -88: + Feelarrow = "●" + else: + Feelarrow = "▲" if OldFeel < float(Feel) else "▼" OldFeel = float(cleanFeel) Feel = "%s%s" % (Feelarrow, Feel) Feel += "°" if trendarrows: - Temparrow = "●" if OldTemp_c == -88 else "▲" if OldTemp_c < float(Temp_c) else "▼" + if OldTemp_c == -88: + Temparrow = "●" + else: + Temparrow = "▲" if OldTemp_c < float(Temp_c) else "▼" OldTemp_c = float(cleanTemp_c) Temp_c = "%s%s" % (Temparrow, Temp_c) Temp_c += "°" @@ -11239,14 +11243,19 @@ def putWetter(workaround, draw, im): font = ImageFont.truetype(ConfigFont, int(((int(LCD4linux.WetterExtraZoom.value) - 100) / 20.0 + 8) * Wmulti), encoding='unic') ShadowText(Wim, POSX - minus5, POSYs, "%s %s" % (Locname, Wtime), font, LCD4linux.WetterExtraColorCity.value, ConfigShadow) if trendarrows: - Humarrow = "●" if OldHum == -88 else "▲" if OldHum < float(cleanHum) else "▼" + if OldHum == -88: + Humarrow = "●" + else: + Humarrow = "▲" if OldHum < float(cleanHum) else "▼" OldHum = float(cleanHum) Hum = "%s%s" % (Humarrow, Hum) if trendarrows: - Windarrow = "●" if OldWind == -88 else "▲" if OldWind < float(cleanWind[0]) else "▼" + if OldWind == -88: + Windarrow = "●" + else: + Windarrow = "▲" if OldWind < float(cleanWind[0]) else "▼" OldWind = float(cleanWind[0]) Wind = "%s%s" % (Windarrow, Wind) - font = ImageFont.truetype(ConfigFont, int(13 * Wmulti), encoding='unic') if LCD4linux.WetterWindLines.value == "2": Wind = (Wind.split(" ", 2)) @@ -11293,11 +11302,13 @@ def putWetter(workaround, draw, im): font = ImageFont.truetype(ConfigFont, int((18 if largesize else 14) * Wmulti), encoding='unic') w, h = getFsize(Hum, font) if not PY3: # for equal results, 'w' needs an correction under Python 2 - w = int(w * (0.72 if trendarrows else 0.98)) if largesize else int(w * (0.72 if trendarrows else 0.98)) + if largesize: + w = int(w * (0.72 if trendarrows else 0.98)) + else: + w = int(w * (0.72 if trendarrows else 0.98)) PX = MAX_Wc - int(w) PY = POSY + int((40 if largesize else 44) * Wmulti) ShadowText(Wim, PX, PY, Hum, font, LCD4linux.WetterHumColor.value, ConfigShadow) - PICwetter[ConfigWWW] = 1 counter = 20 while PICwetter[ConfigWWW] == "wait" and counter > 0: @@ -11443,14 +11454,20 @@ def putMoon(workaround, draw, im): if ConfigInfo[2] == "1": MoonDist = MoonDistance() if ConfigTrends: - MoonDistarrow = "●" if OldMoonDist == -88 else "▲" if OldMoonDist < MoonDist else "▼" + if OldMoonDist == -88: + MoonDistarrow = "●" + else: + MoonDistarrow = "▲" if OldMoonDist < MoonDist else "▼" OldMoonDist = MoonDist INFOS += "%s%s km" % (MoonDistarrow, round(MoonDist)) if ConfigInfo[1] == "1": illum = 100 - abs((cos(pi * POS) + 0j) ** 1.7 * 100) illum = abs(illum - 1) / .99 if illum - 1 > 0 else 0.0 if ConfigTrends: - illumarrow = "●" if Oldillum in [-88, 0] else "▲" if float(Oldillum) < illum else "▼" + if Oldillum in [-88, 0]: + illumarrow = "●" + else: + illumarrow = "▲" if float(Oldillum) < illum else "▼" Oldillum = illum INFOS += "- %s%s %%" % (illumarrow, round(illum, 1)) if INFOS != "": @@ -11650,7 +11667,7 @@ def putClock(workaround, draw, im): self.ClockName[ConfigNum] = [int(ConfigAnalog), y] self.im[im].paste(self.ClockIm[ConfigNum], (POSX, ConfigPos), self.ClockIm[ConfigNum]) # Weekday in or underneath clockface - if ConfigType[:3] == "521": + if ConfigType.startswith("521"): if "+" in ConfigType: # means weekday in combination with date now = Code_utf8(_(strftime("%A"))) font = ImageFont.truetype(ConfigFont, int(y / 6), encoding='unic') @@ -11692,7 +11709,7 @@ def putClock(workaround, draw, im): self.im[im].paste(pil_image, (POSX + int((x - x1) / 2), ConfigPos + int((y - y1) / 2)), pil_image) # Seconds: Due to the bad refresh rates, the second hand was deliberately not programmed! # Date underneath clockface - if ConfigType[:2] == "52": + if ConfigType.startswith("52"): now = strftime(_("%d.%m.%Y")) font = ImageFont.truetype(ConfigFont, int(y / 6), encoding='unic') w, h = getFsize(now, font) @@ -11908,14 +11925,14 @@ def __init__(self, cmd): GrabTVRunning = True L4logE("GrabTV Run") system(cmd + " >/dev/null 2>&1") - self.cmdFinished("") + self.cmdFinished() - def cmdFinished(self, data): + def cmdFinished(self): global GrabTVRunning L4logE("GrabTV Stop") GrabTVRunning = False - def dataAvail(self, data): + def dataAvail(self): pass def doGrabTVthread(x, y, lcd, vidosd): @@ -12018,7 +12035,7 @@ def putTimer(workaround, draw, im): TL = self.Ltimer_list if ConfigBox == 0 else self.wwwBoxTimer TL = sorted(TL, key=lambda x: x.begin, reverse=False) for timerlist in TL: - if timerlist.disabled == 0 and timerlist.justplay == 0 and str(timerlist.service_ref)[:3] != "-1:": + if timerlist.disabled == 0 and timerlist.justplay == 0 and not str(timerlist.service_ref).startswith("-1:"): if timercount < int(ConfigLines): a = int(config.recording.margin_before.value) * 60 if ConfigType == "0" else 0 b = int(config.recording.margin_after.value) * 60 if ConfigType == "0" else 0 @@ -12277,20 +12294,20 @@ def putProgress(workaround, draw, im): POSX = getSplit(ConfigSplit, ConfigAlign, MAX_W, ProgressBar) if self.LsreftoString is not None: Minutes, Prozent = (" min", " %") if ConfigMinutes else ("", "") - if ConfigType[1:] == "1": + if ConfigType.endswith("1"): ms = 1.5 - elif ConfigType[1:] == "2": + elif ConfigType.endswith("2"): ms = 2 else: ms = 1 font = ImageFont.truetype(ConfigFont, int(ConfigSize * ms) + 8, encoding='unic') # 5 -# if self.Lpath and ":0:" not in self.Lpath and "//" not in self.Lpath: - if self.Llength is not None and self.Llength[0] != -1: # Movie +# if self.Lpath and ":0:" not in self.Lpath and "//" not in self.Lpath: # Movie + if self.Llength is not None and self.Llength[0] != -1: isVideoPlaying = 1 try: length = self.Llength position = self.Lposition - if (length and position) and (length[1] > 0): + if length and length[1] > 0 and position: if ConfigType[0] in ["2", "4", "6", "8", "9", "A"]: if ConfigType[0] in ["8", "9", "A"] or length[0] == 1: dur = int(position[1] / 90000) @@ -12460,7 +12477,7 @@ def putProgress(workaround, draw, im): isData = True if isData == True and ConfigBorder != "off": event_run = min(max(event_run, 0), ProgressBar) - if ConfigBorder[:4] == "true": + if ConfigBorder.startswith("true"): if ConfigColorBG == "0": # don't fill (=transparency) self.draw[draw].rectangle((POSX + 9, ConfigPos, POSX + ProgressBar + 11, ConfigPos + ConfigSize), outline=ConfigColor) else: @@ -12645,7 +12662,7 @@ def putSat(workaround, draw, im): x = int(float(CS) / yy * xx) imW = imW.resize((x, CS)) POSX = getSplit(ConfigSplit, ConfigAlign, MAX_W, x) - if ConfigType[1:] == "A": + if ConfigType.endswith("A"): ShadowText(draw, POSX, ConfigPos + int(ConfigSize / 4), Code_utf8(orbital), font, ConfigColor, ConfigShadow) POSX += w if str(LCD4linux.PiconTransparenz.value) == "2": @@ -12655,9 +12672,9 @@ def putSat(workaround, draw, im): self.im[im].paste(imW, (POSX, ConfigPos)) if not PY3: # correction for Python 2 POSX += x - if ConfigType[1:] == "C": + if ConfigType.endswith("C"): ShadowText(draw, POSX, ConfigPos + int(ConfigSize / 4), Code_utf8(orbital), font, ConfigColor, ConfigShadow) - if ConfigType[1:] == "B": + if ConfigType.endswith("B"): ShadowText(draw, POSX - int((x - w) / 2), ConfigPos + CS, Code_utf8(orbital), font, ConfigColor, ConfigShadow) except Exception: pass @@ -12792,20 +12809,20 @@ def putDescription(workaround, draw, im): event_name = "" if self.LEventsDesc is not None and len(self.LEventsDesc) > 0: if self.LEventsDesc[0][4]: - if self.LEventsDesc[0][5] != "" and (ConfigType[0] == "1" or (ConfigType[0] == "2" and self.LEventsDesc[0][6] == "")): + if self.LEventsDesc[0][5] != "" and (ConfigType.startswith("1") or (ConfigType.startswith("2") and self.LEventsDesc[0][6] == "")): event_name += self.LEventsDesc[0][5] + "\n" if self.LEventsDesc[0][6] != "" and (ConfigType[1] == "1" or (ConfigType[1] == "2" and self.LEventsDesc[0][5] == "")): event_name += self.LEventsDesc[0][6] if event_name == "": if self.LShortDescription is not None and self.LExtendedDescription is not None: - if self.LShortDescription != "" and (ConfigType[0] == "1" or (ConfigType[0] == "2" and self.LExtendedDescription == "")): + if self.LShortDescription != "" and (ConfigType.startswith("1") or (ConfigType.startswith("2") and self.LExtendedDescription == "")): event_name += self.LShortDescription + "\n" if self.LExtendedDescription != "" and (ConfigType[1] == "1" or (ConfigType[1] == "2" and self.LShortDescription == "")): event_name += self.LExtendedDescription if self.LsreftoString is not None and event_name == "": sreffile = self.LsrefFile datei = "%s.txt" % splitext(sreffile)[0] - if sreffile[:1] == "/" and isfile(datei): + if sreffile.startswith("/") and isfile(datei): try: event_name = open(datei, "r").readline().strip() except Exception: @@ -13135,10 +13152,10 @@ def putDev(workaround, draw, im): lx = getSplit(ConfigSplit, ConfigAlign, MAX_W, (w + 20) * co) Bproz = 0 for l in ConfigList: - if l not in DeviceRemove and (isdir(l) == True or l[:3] == "RAM"): + if l not in DeviceRemove and (isdir(l) == True or l.startswith("RAM")): L4logE("Device", l) G = F = B = B1pixel = B2pixel = 0 - if l[:3] == "RAM": + if l.startswith("RAM"): G, F, B = getMem() Bproz = int(F * 100 / G) if F > 0 else 0 B1pixel = ((2 * h) * Bproz / 100) @@ -13178,8 +13195,8 @@ def putDev(workaround, draw, im): Einh = "T" ShadowText(draw, lx + 20, ly, "%.1f" % Fe, font, ConfigColor, ConfigShadow) ShadowText(draw, lx + 20, ly + h, "%sB" % Einh, font, ConfigColor, ConfigShadow) - self.draw[draw].rectangle((lx + 8, ly, lx + 18, ly + (2 * h)), outline=LCD4linux.DevBarColor.value, fill=LCD4linux.DevFullColor.value if (Fproz < int(ConfigWarning) and l[:3] != "RAM") else LCD4linux.DevBarColor.value) - if l[:3] == "RAM": + self.draw[draw].rectangle((lx + 8, ly, lx + 18, ly + (2 * h)), outline=LCD4linux.DevBarColor.value, fill=LCD4linux.DevFullColor.value if (Fproz < int(ConfigWarning) and not l.startswith("RAM")) else LCD4linux.DevBarColor.value) + if l.startswith("RAM"): self.draw[draw].rectangle((lx + 8, ly, lx + 18, ly + B1pixel), outline=LCD4linux.DevBackColor.value, fill=LCD4linux.DevBackColor.value) self.draw[draw].rectangle((lx + 8, ly + B1pixel, lx + 14, ly + B1pixel + B2pixel), outline=LCD4linux.DevBackColor.value, fill=LCD4linux.DevBackColor.value) else: @@ -13666,7 +13683,7 @@ def putMail(workaround, draw, im): PopCheck = CP if len(PopMail[CP]) > 0: PopCheck = PopMail[CP][0][2] - if ConfigType[:1] == "A" or (ConfigType[:1] == "B" and PopCheck != PopMailUid[CP][0]): + if ConfigType.startswith("A") or (ConfigType.startswith("B") and PopCheck != PopMailUid[CP][0]): NM = 0 for e in PopMail[CP]: if e[2] != PopMailUid[CP][0]: @@ -13699,7 +13716,7 @@ def putMail(workaround, draw, im): font = ImageFont.truetype(ConfigFont, ConfigSize, encoding='unic') c = int(ConfigSize / 4) for M in PopMail[CP]: - if i >= int(ConfigLines) or (ConfigType[1:] == "2" and M[2] == PopMailUid[CP][0]): + if i >= int(ConfigLines) or (ConfigType.endswith("2") and M[2] == PopMailUid[CP][0]): break i += 1 self.draw[draw].ellipse((POSX, POSY + int(ConfigSize / 2) - c, POSX + (2 * c), POSY + int(ConfigSize / 2) + c), fill=ConfigColor) @@ -14060,7 +14077,7 @@ def putNetatmoIllu(workaround, draw, im): staerke = staerkeVal2 dis_reason = Code_utf8(self.dis_reason[ConfigStation]) if ConfigType.startswith("0"): - if ConfigType[1:] == "9": + if ConfigType.endswith("9"): S = 1.5 if ConfigSize <= 10 else 1.0 ZW = str(staerkeValOrg) # Value font = ImageFont.truetype(FONT, int(ConfigSize * S), encoding='unic') @@ -14087,7 +14104,7 @@ def putNetatmoIllu(workaround, draw, im): except Exception: L4log("Error Knob") L4log("Error:", format_exc()) - if ConfigType[1:] == "9": + if ConfigType.endswith("9"): ZW = str(int(staerkeValOrg)) font = ImageFont.truetype(FONT, int(ConfigSize / 3), encoding='unic') w, h = getFsize(ZW, font) @@ -14186,7 +14203,8 @@ def putCalendar(workaround, draw, im): if ConfigLayout in ["0", "2"]: if datetime.now().day == day[0]: self.draw[4].rectangle((PX1 - w1, POSY, PX1 + w1, POSY + h), fill=ConfigBackColor) - ShadowText(4, PX, POSY, Tag, font, ConfigColor if day[1] < 5 else LCD4linux.CalSaColor.value if day[1] == 5 else LCD4linux.CalSuColor.value, ConfigShadow) + CalSaSuColor = LCD4linux.CalSaColor.value if day[1] == 5 else LCD4linux.CalSuColor.value + ShadowText(4, PX, POSY, Tag, font, ConfigColor if day[1] < 5 else CalSaSuColor, ConfigShadow) if ConfigLayout in ["0"] and ICS.get(ICStag, None) is not None: self.draw[4].rectangle((PX1 - w1, POSY, PX1 + w1, POSY + h), outline=CC[int(ICS[ICStag][0][2])]) if int(LCD4linux.CalLine.value) > 1: @@ -14199,7 +14217,8 @@ def putCalendar(workaround, draw, im): if int(LCD4linux.CalLine.value) > 1: self.draw[4].rectangle((PX1 - w1, POSY + h, PX1 + w1, POSY + h), outline=ConfigBackColor) else: - ShadowText(4, PX, POSY, Tag, font, ConfigColor if day[1] < 5 else LCD4linux.CalSaColor.value if day[1] == 5 else LCD4linux.CalSuColor.value, ConfigShadow) + CalSaSuColor = LCD4linux.CalSaColor.value if day[1] == 5 else LCD4linux.CalSuColor.value + ShadowText(4, PX, POSY, Tag, font, ConfigColor if day[1] < 5 else CalSaSuColor, ConfigShadow) if ConfigLayout in ["1", "2"] and ICS.get(ICStag, None) is not None: self.draw[4].rectangle((PX1 - w1, POSY + h, PX1 + w1, POSY + h), outline=CC[int(ICS[ICStag][0][2])]) if int(LCD4linux.CalLine.value) > 1: From 0b582fdaf7a06ec4fdd032a3f1ea56008bdfecc3 Mon Sep 17 00:00:00 2001 From: "Mr.Servo" Date: Sat, 1 Feb 2025 19:16:50 +0100 Subject: [PATCH 2/5] [LCD4linux] v5.0-r25 two files reverted --- lcd4linux/src/Photoframe.py | 135 ++++++++++++++++-------------------- lcd4linux/src/module.py | 22 +++--- 2 files changed, 74 insertions(+), 83 deletions(-) diff --git a/lcd4linux/src/Photoframe.py b/lcd4linux/src/Photoframe.py index 8bb1639..234bc7e 100644 --- a/lcd4linux/src/Photoframe.py +++ b/lcd4linux/src/Photoframe.py @@ -5,12 +5,11 @@ from usb.util import get_string from PIL import Image from struct import pack -from six import ensure_binary -from six.moves import cStringIO +from six.moves import cStringIO as StringIO def write_jpg2frame(dev, pic): - # Attach header to picture, pad with zeros if necessary, and send to frame + """Attach header to picture, pad with zeros if necessary, and send to frame""" # create header and stack before picture # middle 4 bytes have size of picture rawdata = b"\xa5\x5a\x18\x04" + pack('= 2 else None + if len(d) >= 2: + d = d[1] + else: + d = None else: d = None else: d = list(list(find(idVendor=device['idVendor'], idProduct=device['idProduct'], find_all=True)) + list(find(idVendor=device2['idVendor'], idProduct=device2['idProduct'], find_all=True)))[0] - except Exception: + except: from traceback import format_exc print("[LCD4linux] find exception") print("Error: %s" % format_exc()) @@ -110,9 +108,9 @@ def find_device(anzahl, device, device2): return d -def init_device(anzahl, device0, device1): - # First try Mini Monitor mode, then Mass storage mode - dev = find_device(anzahl, device0, device1) +def init_device(Anzahl, device0, device1): + """First try Mini Monitor mode, then Mass storage mode""" + dev = find_device(Anzahl, device0, device1) if dev is not None: ## found it, trying to init it @@ -126,7 +124,7 @@ def init_device(anzahl, device0, device1): ts = time() while True: # may need to burn some time - dev = find_device(anzahl, device0, device1) + dev = find_device(Anzahl, device0, device1) if dev is not None and dev.idProduct == device0["idProduct"]: #switching successful break @@ -142,35 +140,20 @@ def init_device(anzahl, device0, device1): def frame_init(dev): - # Init device so it stays in Mini Monitor mode + """Init device so it stays in Mini Monitor mode""" # this is the minimum required to keep the frame in Mini Monitor mode!!! - # dev.ctrl_transfer(0xc0, 4 ) - # dev.ctrl_transfer(0xc0, 0x01, 0x00, 0x00, 0x09, 0x04 ) +# dev.ctrl_transfer(0xc0, 4 ) +# dev.ctrl_transfer(0xc0, 0x01, 0x00, 0x00, 0x09, 0x04 ) dev.ctrl_transfer(0xc0, 0x01, 0x00, 0x00, 0x02) def frame_switch(dev): - CTRL_TYPE_VENDOR = (2 << 5) - CTRL_IN = 0x80 - CTRL_RECIPIENT_DEVICE = 0 + """Switch device from Mass Storage to Mini Monitor""" try: - time.sleep(0.5) - s = "\x00" * 251 + sleep(0.5) dev.ctrl_transfer(0x00 | 0x80, 0x06, 0xfe, 0xfe, 0xfe) -# dev.ctrl_transfer(0x00|0x80, 0x06, 0xfe, 0xfe, s, 0xfe ) -# dev.ctrl_transfer(CTRL_TYPE_VENDOR | CTRL_IN | CTRL_RECIPIENT_DEVICE, 0x04, 0x00, 0x00, 1) -# result = dev.ctrl_transfer(CTRL_TYPE_VENDOR | CTRL_IN | CTRL_RECIPIENT_DEVICE, 0x04, 0x00, 0x00, 1) -# expect(result, [ 0x03 ]) -# result = dev.ctrl_transfer(CTRL_TYPE_VENDOR | CTRL_IN | CTRL_RECIPIENT_DEVICE, 0x01, 0x00, 0x00, 2) -# expect(result, [ 0x09, 0x04 ]) -# result = dev.ctrl_transfer(CTRL_TYPE_VENDOR | CTRL_IN | CTRL_RECIPIENT_DEVICE, 0x02, 0x00, 0x00, 1) -# expect(result, [ 0x46 ]) - # settling of the bus and frame takes about 0.42 sec - # give it some extra time, but then still make sure it has settled - except Exception: + except: print("[LCD4linux] switching ERROR") -# from traceback import format_exc -# print format_exc() finally: sleep(2) @@ -178,21 +161,25 @@ def frame_switch(dev): def name(dev): try: return get_string(dev, 1) - except Exception: + except: try: return get_string(dev, 256, 2) - except Exception: + except: return None def main(): global dev, known_devices_list + known_devices_list = get_known_devices() + # define which frame to use, here use Samsung SPF-87H device0 = known_devices_list[0] # Mini Monitor mode device1 = known_devices_list[1] # Mass Storage mode + dev = init_device(1, device0, device1) print("Frame is in Mini Monitor mode and initialized. Sending pictures now") + image = Image.open("mypicture.jpg") #manipulations to consider: # convert @@ -200,8 +187,8 @@ def main(): # rotate # crop image = image.resize((800, 480)) - output = cStringIO() - image.save(ensure_binary(output), "JPEG", quality=94) + output = StringIO.StringIO() + image.save(output, "JPEG", quality=94) pic = output.getvalue() output.close() write_jpg2frame(dev, pic) diff --git a/lcd4linux/src/module.py b/lcd4linux/src/module.py index 042d170..4d5a0b6 100644 --- a/lcd4linux/src/module.py +++ b/lcd4linux/src/module.py @@ -79,14 +79,14 @@ def getHold(self): return L4Lelement.Hold def setHold(self, H): - print("[LCD4linuxE] hold: %s" % H) + print("[LCD4linuxE] Hold: %s" % H) L4Lelement.Hold = H def getHoldKey(self): return L4Lelement.HoldKey def setHoldKey(self, H=False): - print("[LCD4linuxE] holdkey: %s" % H) + print("[LCD4linuxE] HoldKey: %s" % H) L4Lelement.HoldKey = H def getFont(self, F="0"): @@ -102,15 +102,19 @@ def getScreen(self): return L4Lelement.Screen def setScreen(self, S, Lcd="", Hold=False): - if Lcd != "" and len(str(Lcd)) > 1 or int(Lcd) > 3: - Lcd = "1" + if Lcd != "": + if len(str(Lcd)) > 1 or int(Lcd) > 3: + Lcd = "1" L4Lelement.Screen = str(S) L4Lelement.LCD = str(Lcd) L4Lelement.Hold = Hold L4Lelement.Refresh = True - def resetBrightness(self, AKT=[0, 0, 0]): - L4Lelement.Bright = [-1, -1, -1] + def resetBrightness(self, AKT=""): + if len(AKT) == 3: + L4Lelement.BrightAkt = AKT + else: + L4Lelement.Bright = [-1, -1, -1] def setBrightness(self, LCD, BRI=-1): if int(LCD) < 1 or int(LCD) > 3: @@ -141,13 +145,14 @@ def getstatusoutput(cmd): sts = pipe.close() if sts is None: sts = 0 - if text.endswith == '\n': + if text[-1:] == '\n': text = text[:-1] except Exception: sts = 1 text = "- -" print("[LCD4linux] Error on os-call") - return sts, text + finally: + return sts, text def L4LVtest(VV): @@ -167,7 +172,6 @@ def L4LVtest(VV): if O != "": try: f = open(L4Linfo % (O, P)) - B = f.readline() OO = f.readline().strip().split()[1].startswith(VV[1:]) f.close() except Exception: From f0e39166ddf2242e2e760c556124e84fad9faa86 Mon Sep 17 00:00:00 2001 From: "Mr.Servo" Date: Sun, 2 Feb 2025 17:28:48 +0100 Subject: [PATCH 3/5] [LCD4linux] v5.0-r25 bugfixed - bugfixed troubles with some Samsung-Displays - some general bugfixes HINT: **LCD4linux** is still working under Python2 and Python3 --- lcd4linux/src/Photoframe.py | 128 ++++++++++++++++++++---------------- lcd4linux/src/module.py | 29 ++++---- lcd4linux/src/plugin.py | 15 +++-- 3 files changed, 91 insertions(+), 81 deletions(-) diff --git a/lcd4linux/src/Photoframe.py b/lcd4linux/src/Photoframe.py index 234bc7e..920c45b 100644 --- a/lcd4linux/src/Photoframe.py +++ b/lcd4linux/src/Photoframe.py @@ -5,11 +5,12 @@ from usb.util import get_string from PIL import Image from struct import pack +from six import ensure_binary from six.moves import cStringIO as StringIO def write_jpg2frame(dev, pic): - """Attach header to picture, pad with zeros if necessary, and send to frame""" + # Attach header to picture, pad with zeros if necessary, and send to frame # create header and stack before picture # middle 4 bytes have size of picture rawdata = b"\xa5\x5a\x18\x04" + pack('= 2: - d = d[1] - else: - d = None + d = d[1] if len(d) >= 2 else None else: d = None else: d = list(list(find(idVendor=device['idVendor'], idProduct=device['idProduct'], find_all=True)) + list(find(idVendor=device2['idVendor'], idProduct=device2['idProduct'], find_all=True)))[0] - except: + except Exception: from traceback import format_exc print("[LCD4linux] find exception") print("Error: %s" % format_exc()) @@ -108,9 +110,9 @@ def find_device(Anzahl, device, device2): return d -def init_device(Anzahl, device0, device1): - """First try Mini Monitor mode, then Mass storage mode""" - dev = find_device(Anzahl, device0, device1) +def init_device(anzahl, device0, device1): + # First try Mini Monitor mode, then Mass storage mode + dev = find_device(anzahl, device0, device1) if dev is not None: ## found it, trying to init it @@ -124,7 +126,7 @@ def init_device(Anzahl, device0, device1): ts = time() while True: # may need to burn some time - dev = find_device(Anzahl, device0, device1) + dev = find_device(anzahl, device0, device1) if dev is not None and dev.idProduct == device0["idProduct"]: #switching successful break @@ -140,20 +142,36 @@ def init_device(Anzahl, device0, device1): def frame_init(dev): - """Init device so it stays in Mini Monitor mode""" + # Init device so it stays in Mini Monitor mode # this is the minimum required to keep the frame in Mini Monitor mode!!! -# dev.ctrl_transfer(0xc0, 4 ) -# dev.ctrl_transfer(0xc0, 0x01, 0x00, 0x00, 0x09, 0x04 ) + # dev.ctrl_transfer(0xc0, 4 ) + # dev.ctrl_transfer(0xc0, 0x01, 0x00, 0x00, 0x09, 0x04 ) dev.ctrl_transfer(0xc0, 0x01, 0x00, 0x00, 0x02) def frame_switch(dev): - """Switch device from Mass Storage to Mini Monitor""" + # Switch device from Mass Storage to Mini Monitor + CTRL_TYPE_VENDOR = (2 << 5) + CTRL_IN = 0x80 + CTRL_RECIPIENT_DEVICE = 0 try: sleep(0.5) + s = "\x00" * 251 dev.ctrl_transfer(0x00 | 0x80, 0x06, 0xfe, 0xfe, 0xfe) - except: + # dev.ctrl_transfer(0x00 | 0x80, 0x06, 0xfe, 0xfe, s, 0xfe ) + # dev.ctrl_transfer(CTRL_TYPE_VENDOR | CTRL_IN | CTRL_RECIPIENT_DEVICE, 0x04, 0x00, 0x00, 1) + # result = dev.ctrl_transfer(CTRL_TYPE_VENDOR | CTRL_IN | CTRL_RECIPIENT_DEVICE, 0x04, 0x00, 0x00, 1) + # expect(result, [ 0x03 ]) + # result = dev.ctrl_transfer(CTRL_TYPE_VENDOR | CTRL_IN | CTRL_RECIPIENT_DEVICE, 0x01, 0x00, 0x00, 2) + # expect(result, [ 0x09, 0x04 ]) + # result = dev.ctrl_transfer(CTRL_TYPE_VENDOR | CTRL_IN | CTRL_RECIPIENT_DEVICE, 0x02, 0x00, 0x00, 1) + # expect(result, [ 0x46 ]) + # settling of the bus and frame takes about 0.42 sec + # give it some extra time, but then still make sure it has settled + except Exception: print("[LCD4linux] switching ERROR") + # from traceback import format_exc + # print format_exc() finally: sleep(2) @@ -161,25 +179,21 @@ def frame_switch(dev): def name(dev): try: return get_string(dev, 1) - except: + except Exception: try: return get_string(dev, 256, 2) - except: + except Exception: return None def main(): global dev, known_devices_list - known_devices_list = get_known_devices() - # define which frame to use, here use Samsung SPF-87H device0 = known_devices_list[0] # Mini Monitor mode device1 = known_devices_list[1] # Mass Storage mode - dev = init_device(1, device0, device1) print("Frame is in Mini Monitor mode and initialized. Sending pictures now") - image = Image.open("mypicture.jpg") #manipulations to consider: # convert diff --git a/lcd4linux/src/module.py b/lcd4linux/src/module.py index 4d5a0b6..9d7466b 100644 --- a/lcd4linux/src/module.py +++ b/lcd4linux/src/module.py @@ -79,14 +79,14 @@ def getHold(self): return L4Lelement.Hold def setHold(self, H): - print("[LCD4linuxE] Hold: %s" % H) + print("[LCD4linuxE] hold: %s" % H) L4Lelement.Hold = H def getHoldKey(self): return L4Lelement.HoldKey def setHoldKey(self, H=False): - print("[LCD4linuxE] HoldKey: %s" % H) + print("[LCD4linuxE] holdkey: %s" % H) L4Lelement.HoldKey = H def getFont(self, F="0"): @@ -102,25 +102,20 @@ def getScreen(self): return L4Lelement.Screen def setScreen(self, S, Lcd="", Hold=False): - if Lcd != "": - if len(str(Lcd)) > 1 or int(Lcd) > 3: - Lcd = "1" + if Lcd != "" and (len(str(Lcd)) > 1 or int(Lcd) > 3): + Lcd = "1" L4Lelement.Screen = str(S) L4Lelement.LCD = str(Lcd) L4Lelement.Hold = Hold L4Lelement.Refresh = True - def resetBrightness(self, AKT=""): - if len(AKT) == 3: - L4Lelement.BrightAkt = AKT - else: - L4Lelement.Bright = [-1, -1, -1] + def resetBrightness(self, AKT=[]): + L4Lelement.BrightAkt = AKT if len(AKT) == 3 else [-1, -1, -1] def setBrightness(self, LCD, BRI=-1): - if int(LCD) < 1 or int(LCD) > 3: - return - L4Lelement.Bright[int(LCD) - 1] = int(BRI) - L4Lelement.Refresh = True + if int(LCD) > 0 and int(LCD) < 4: + L4Lelement.Bright[int(LCD) - 1] = int(BRI) + L4Lelement.Refresh = True def getBrightness(self, LCD=0, ORG=True): if int(LCD) > 0 and int(LCD) < 4: @@ -145,14 +140,13 @@ def getstatusoutput(cmd): sts = pipe.close() if sts is None: sts = 0 - if text[-1:] == '\n': + if text.endswith == '\n': text = text[:-1] except Exception: sts = 1 text = "- -" print("[LCD4linux] Error on os-call") - finally: - return sts, text + return sts, text def L4LVtest(VV): @@ -172,6 +166,7 @@ def L4LVtest(VV): if O != "": try: f = open(L4Linfo % (O, P)) + B = f.readline() OO = f.readline().strip().split()[1].startswith(VV[1:]) f.close() except Exception: diff --git a/lcd4linux/src/plugin.py b/lcd4linux/src/plugin.py index 8a22448..c370e07 100644 --- a/lcd4linux/src/plugin.py +++ b/lcd4linux/src/plugin.py @@ -2698,7 +2698,8 @@ def getFB2(check): def BRI(w1, w2): - return int(w1) if L4LElist.getBrightness(w2, False) == -1 else int(L4LElist.getBrightness(w2, False)) + gb = L4LElist.getBrightness(w2, False) + return int(w1) if gb == -1 else gb def virtBRI(LCD): @@ -3129,9 +3130,9 @@ def writeHelligkeit(hell, night, STOP): global AktHelligkeit global AktNight R = "" - h1 = BRI(int(hell[0]), 1) - h2 = BRI(int(hell[1]), 2) - h3 = BRI(int(hell[2]), 3) + h1 = BRI(hell[0], 1) + h2 = BRI(hell[1], 2) + h3 = BRI(hell[2], 3) if isOffTime(L4LMoon, L4LSun, L4LMoon, L4LSun): if int(night[0]) != 0: h1 = max(h1 - int(night[0]), 0) @@ -9150,10 +9151,10 @@ def ServiceChange(self): self.LsreftoString = sref.toString() if self.LsreftoString is not None: self.LsrefFile = self.LsreftoString[self.LsreftoString.rfind(":") + 1:] - if self.LsrefFile.endswith("/"): + if self.LsrefFile.startswith("/"): tsref = self.LsreftoString[:-len(self.LsrefFile) - 1] tsref = tsref[tsref.rfind(":") + 1:] - if tsref.starts("/"): + if tsref.startswith("/"): self.LsrefFile = tsref else: self.LsrefFile = "" @@ -12307,7 +12308,7 @@ def putProgress(workaround, draw, im): try: length = self.Llength position = self.Lposition - if length and length[1] > 0 and position: + if length and (length[1] > 0 and position): if ConfigType[0] in ["2", "4", "6", "8", "9", "A"]: if ConfigType[0] in ["8", "9", "A"] or length[0] == 1: dur = int(position[1] / 90000) From 046bcdea4357e10f6ae47938211cdd7c5cbbbbc1 Mon Sep 17 00:00:00 2001 From: "Mr.Servo" Date: Mon, 3 Feb 2025 09:10:35 +0100 Subject: [PATCH 4/5] [LCD4linux] v5.0-r25 tiny bugfix in 'resetBrightness' - 'resetBrightness' corrected acc. original version V5.2-r0 - tiny code improvements --- lcd4linux/src/module.py | 7 +++++-- lcd4linux/src/plugin.py | 10 +++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lcd4linux/src/module.py b/lcd4linux/src/module.py index 9d7466b..a68668c 100644 --- a/lcd4linux/src/module.py +++ b/lcd4linux/src/module.py @@ -110,7 +110,10 @@ def setScreen(self, S, Lcd="", Hold=False): L4Lelement.Refresh = True def resetBrightness(self, AKT=[]): - L4Lelement.BrightAkt = AKT if len(AKT) == 3 else [-1, -1, -1] + if len(AKT) == 3: + L4Lelement.BrightAkt = AKT + else: + L4Lelement.Bright = [-1, -1, -1] def setBrightness(self, LCD, BRI=-1): if int(LCD) > 0 and int(LCD) < 4: @@ -119,7 +122,7 @@ def setBrightness(self, LCD, BRI=-1): def getBrightness(self, LCD=0, ORG=True): if int(LCD) > 0 and int(LCD) < 4: - return L4Lelement.Bright[int(LCD) - 1] if ORG == False else L4Lelement.BrightAkt[int(LCD) - 1] + return [L4Lelement.Bright[int(LCD) - 1]] if ORG == False else [L4Lelement.BrightAkt[int(LCD) - 1]] else: return L4Lelement.Bright if ORG == False else L4Lelement.BrightAkt diff --git a/lcd4linux/src/plugin.py b/lcd4linux/src/plugin.py index c370e07..af15dfe 100644 --- a/lcd4linux/src/plugin.py +++ b/lcd4linux/src/plugin.py @@ -2698,13 +2698,13 @@ def getFB2(check): def BRI(w1, w2): - gb = L4LElist.getBrightness(w2, False) + gb = int(L4LElist.getBrightness(w2, False)[0]) return int(w1) if gb == -1 else gb def virtBRI(LCD): global AktNight - vb = BRI(L4LElist.getBrightness(LCD), LCD) + vb = BRI(L4LElist.getBrightness(LCD)[0], LCD) if vb < 1: return 0 elif vb == 10: @@ -5103,11 +5103,11 @@ def MailDecode(Sdecode): Date = "" for R in mailserver.retr(M)[1]: if str(R).upper().startswith("FROM:"): - From = R[R.find(" "):].strip() + From = R[str(R).find(" "):].strip() elif str(R).upper().startswith("SUBJECT:"): - Subj = R[R.find(" "):].strip() + Subj = R[str(R).find(" "):].strip() elif str(R).upper().startswith("DATE:") and LCD4linux.MailShowDate.value == True: - Date = R[R.find(" "):].strip() + Date = R[str(R).find(" "):].strip() Date = "- %s" % str(Date).split("+")[0].split(",")[-1].strip() if From != "" and Subj != "": break From 891216ed16b41a900c023fb6583cecf1e96926f3 Mon Sep 17 00:00:00 2001 From: "Mr.Servo" Date: Wed, 5 Feb 2025 08:26:41 +0100 Subject: [PATCH 5/5] [LCD4linux] v5.0-r25 bugfix for AX206 displays - bugfixed troubles with AX206 displays HINT: **LCD4linux** is still working under Python2 and Python3 --- lcd4linux/src/plugin.py | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/lcd4linux/src/plugin.py b/lcd4linux/src/plugin.py index af15dfe..6ded4bd 100644 --- a/lcd4linux/src/plugin.py +++ b/lcd4linux/src/plugin.py @@ -2886,9 +2886,10 @@ def getResolution(t, r): if int(LCD4linux.xmlOffset.value) != 0: MAX_W -= (int(LCD4linux.xmlOffset.value) * 2) MAX_H -= (int(LCD4linux.xmlOffset.value) * 2) - elif t.endswith("1"): + # ATTENTION: must not be changed to 'endswith()' under any circumstances + elif t[1:] == "1": MAX_W, MAX_H = 320, 240 - elif t.endswith("2"): + elif t[1:] == "2": MAX_W, MAX_H = 240, 320 elif t[1:] in ["3", "4", "5", "10", "15"]: MAX_W, MAX_H = 800, 480 @@ -2896,21 +2897,21 @@ def getResolution(t, r): MAX_W, MAX_H = 800, 600 elif t[1:] in ["7", "8", "13", "14"]: MAX_W, MAX_H = 1024, 600 - elif t.endswith("17"): + elif t[1:] == "17": MAX_W, MAX_H = 220, 176 - elif t.endswith("18"): + elif t[1:] == "18": MAX_W, MAX_H = 255, 64 - elif t.endswith("22"): + elif t[1:] == "22": MAX_W, MAX_H = 480, 320 - elif t.endswith("23"): + elif t[1:] == "23": MAX_W, MAX_H = 800, 480 - elif t.endswith("30"): + elif t[1:] == "30": MAX_W, MAX_H = 400, 240 elif t == "320": MAX_W, MAX_H = LCD4linux.SizeW.value, LCD4linux.SizeH.value elif t == "420": MAX_W, MAX_H = LCD4linux.SizeW2.value, LCD4linux.SizeH2.value - elif t.endswith("21"): + elif t[1:] == "21": MAX_W, MAX_H = 128, 128 else: MAX_W, MAX_H = 132, 64 @@ -9506,14 +9507,14 @@ def rcKeyPressed(self, key, flag): self.restartTimer() if LCD4linux.KeySwitch.value == True: if flag == 3: - if LCD4linux.KeyScreen.value.endswith("1") and key == self.k: + if LCD4linux.KeyScreen.value[-1:] == "1" and key == self.k: ScreenTime = 9999 L4logE("Restart at Scr-longkey") NextScreen(True) LCD4linux.ScreenActive.value = ScreenActive[0] self.Refresh = "1" self.restartTimer() - elif LCD4linux.KeyOff.value.endswith("1") and key == self.ko: + elif LCD4linux.KeyOff.value[-1:] == "1" and key == self.ko: LCDon = True if LCDon == False else False L4logE("Restart at Off-longkey") self.Refresh = "1" @@ -9524,12 +9525,12 @@ def rcKeyPressed(self, key, flag): self.KeyTime = time() if self.KeyDoppel == key and flag == 0: self.KeyDoppel = 0 - if not LCD4linux.KeyOff.value.endswith("1") and key == self.ko: # PREVIOUS + if LCD4linux.KeyOff.value[-1:] != "1" and key == self.ko: # PREVIOUS LCDon = True if LCDon == False else False L4logE("Restart at Off-doublekey %s" % key) self.Refresh = "1" self.restartTimer() - elif not LCD4linux.KeyScreen.value.endswith("1") and key == self.k: # FORWARD / INFO + elif LCD4linux.KeyScreen.value[-1:] != "1" and key == self.k: # FORWARD / INFO ScreenTime = 9999 NextScreen(True) LCD4linux.ScreenActive.value = ScreenActive[0] @@ -12295,9 +12296,9 @@ def putProgress(workaround, draw, im): POSX = getSplit(ConfigSplit, ConfigAlign, MAX_W, ProgressBar) if self.LsreftoString is not None: Minutes, Prozent = (" min", " %") if ConfigMinutes else ("", "") - if ConfigType.endswith("1"): + if ConfigType[1:] == "1": ms = 1.5 - elif ConfigType.endswith("2"): + elif ConfigType[1:] == "2": ms = 2 else: ms = 1 @@ -12663,7 +12664,7 @@ def putSat(workaround, draw, im): x = int(float(CS) / yy * xx) imW = imW.resize((x, CS)) POSX = getSplit(ConfigSplit, ConfigAlign, MAX_W, x) - if ConfigType.endswith("A"): + if ConfigType[1:] == "A": ShadowText(draw, POSX, ConfigPos + int(ConfigSize / 4), Code_utf8(orbital), font, ConfigColor, ConfigShadow) POSX += w if str(LCD4linux.PiconTransparenz.value) == "2": @@ -12673,9 +12674,9 @@ def putSat(workaround, draw, im): self.im[im].paste(imW, (POSX, ConfigPos)) if not PY3: # correction for Python 2 POSX += x - if ConfigType.endswith("C"): + if ConfigType[1:] == "C": ShadowText(draw, POSX, ConfigPos + int(ConfigSize / 4), Code_utf8(orbital), font, ConfigColor, ConfigShadow) - if ConfigType.endswith("B"): + if ConfigType[1:] == "B": ShadowText(draw, POSX - int((x - w) / 2), ConfigPos + CS, Code_utf8(orbital), font, ConfigColor, ConfigShadow) except Exception: pass @@ -13717,7 +13718,7 @@ def putMail(workaround, draw, im): font = ImageFont.truetype(ConfigFont, ConfigSize, encoding='unic') c = int(ConfigSize / 4) for M in PopMail[CP]: - if i >= int(ConfigLines) or (ConfigType.endswith("2") and M[2] == PopMailUid[CP][0]): + if i >= int(ConfigLines) or (ConfigType[1:] == "2" and M[2] == PopMailUid[CP][0]): break i += 1 self.draw[draw].ellipse((POSX, POSY + int(ConfigSize / 2) - c, POSX + (2 * c), POSY + int(ConfigSize / 2) + c), fill=ConfigColor) @@ -14078,7 +14079,7 @@ def putNetatmoIllu(workaround, draw, im): staerke = staerkeVal2 dis_reason = Code_utf8(self.dis_reason[ConfigStation]) if ConfigType.startswith("0"): - if ConfigType.endswith("9"): + if ConfigType[1:] == "9": S = 1.5 if ConfigSize <= 10 else 1.0 ZW = str(staerkeValOrg) # Value font = ImageFont.truetype(FONT, int(ConfigSize * S), encoding='unic') @@ -14105,7 +14106,7 @@ def putNetatmoIllu(workaround, draw, im): except Exception: L4log("Error Knob") L4log("Error:", format_exc()) - if ConfigType.endswith("9"): + if ConfigType[1:] == "9": ZW = str(int(staerkeValOrg)) font = ImageFont.truetype(FONT, int(ConfigSize / 3), encoding='unic') w, h = getFsize(ZW, font)