| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- # -*- coding:UTF-8 -*-
- import LCD_1in44
- import LCD_Config
- import threading
- from PIL import Image,ImageDraw,ImageFont,ImageColor
- import time
- class RaDisplay:
- __on = False
- __menu = None
- def __init__(self):
- self.__initDisplay()
- self.logoThread = threading.Thread(target = self.__showLogo)
- self.lock = threading.Lock()
- self.logoThread.start()
- def setMenu(self, Menu):
- self.__menu = Menu
- def setCamera(self, Camera):
- self.__camera = Camera
- def On(self):
- self.autoThread = threading.Thread(target = self.__autoRefreshThread)
- self.__on = True
- self.__camera.startCamera()
- self.lock = threading.Lock()
- self.autoThread.start()
- def Off(self):
- self.__on = False
- self.autoThread.join()
- self.__camera.stopCamera()
- def isVisible(self):
- return self.__on
- def waitForLogoEnd(self):
- self.logoThread.join()
- del self.logoThread
- def __initDisplay(self):
- self.disp = LCD_1in44.LCD()
- Lcd_ScanDir = LCD_1in44.SCAN_DIR_DFT #SCAN_DIR_DFT = D2U_L2R
- self.disp.LCD_Init(Lcd_ScanDir)
- self.disp.LCD_Clear()
- def __showLogo(self):
- with self.lock:
- image = Image.open('img/logo.bmp')
- self.disp.LCD_ShowImage(image,0,0)
- time.sleep(2.4)
- self.RequestUpdate()
-
- def RequestUpdate(self):
- if self.__menu is not None and self.__menu.isVisible() == True:
- frame = self.__menu.getFrame()
- if frame is not False:
- self.Update(frame)
- elif self.__on == True and self.__camera is not None:
- frame = self.__camera.getFrame()
- if frame is not None:
- img = Image.fromarray(frame)
- img = img.crop((420,0,1080,1080))
- img = img.resize((128,128))
- if self.__camera.isRecording() == True:
- draw = ImageDraw.Draw(img)
- draw.ellipse((100, 100, 120, 120), fill="red")
- #img = img.crop((0,0,128,128))
- self.Update(img)
- else:
- image = Image.new("RGB", (128, 128), "BLACK")
- self.Update(image)
- def __autoRefreshThread(self):
- with self.lock:
- while self.__on:
- time.sleep(0.05)
- self.RequestUpdate()
- self.RequestUpdate()
- def Update(self, img : Image):
- self.disp.LCD_ShowImage(img,0 ,0)
- def draw_recording_indicator(self, image):
- """
- Zeichnet einen roten Kreis auf dem Display als Indikator für laufende Aufnahmen.
- """
- image = Image.new("RGB", (self.LCD.width, self.LCD.height)) # Leeres Bild erstellen
- draw = ImageDraw.Draw(image) # Zeichnen-Objekt erstellen
-
- # Koordinaten für das Zeichnen des roten Kreises (untere rechte Ecke)
- circle_x = self.LCD.width - 12
- circle_y = self.LCD.height - 12
- circle_radius = 6
-
- # Kreis zeichnen
- draw.ellipse((circle_x - circle_radius, circle_y - circle_radius,
- circle_x + circle_radius, circle_y + circle_radius), fill="red")
-
- self.LCD.LCD_ShowImage(image) # Bild auf dem Display anzeigen
|