RaDisplay.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. # -*- coding:UTF-8 -*-
  2. import LCD_1in44
  3. import LCD_Config
  4. import threading
  5. from PIL import Image,ImageDraw,ImageFont,ImageColor
  6. import time
  7. class RaDisplay:
  8. __on = False
  9. def __init__(self, Components):
  10. """
  11. Initialisiert das RaDisplay
  12. :param Components: RaComponents Element
  13. :type Components: RaComponents
  14. """
  15. self.components = Components
  16. self.__initDisplay()
  17. self.logoThread = threading.Thread(target = self.__showLogo)
  18. self.lock = threading.Lock()
  19. self.logoThread.start()
  20. def setCamera(self, Camera):
  21. self.__camera = Camera
  22. def On(self):
  23. if self.__on == True:
  24. return
  25. print("Display: On")
  26. self.autoThread = threading.Thread(target = self.__autoRefreshThread)
  27. self.__on = True
  28. if self.components.Camera!=None:
  29. self.components.Camera.startCamera()
  30. self.lock = threading.Lock()
  31. self.disp.LCD_Backlight(True)
  32. self.autoThread.start()
  33. def Off(self):
  34. if self.__on == False:
  35. return
  36. print("Display: Off")
  37. self.disp.LCD_Backlight(False)
  38. print("Display: Off1")
  39. self.__on = False
  40. self.autoThread.join()
  41. print("Display: Off2")
  42. if self.components.Camera!=None:
  43. self.components.Camera.stopCamera()
  44. print("Display: Off3")
  45. def isVisible(self):
  46. return self.__on
  47. def waitForLogoEnd(self):
  48. self.logoThread.join()
  49. del self.logoThread
  50. def __initDisplay(self):
  51. self.disp = LCD_1in44.LCD()
  52. Lcd_ScanDir = LCD_1in44.SCAN_DIR_DFT #SCAN_DIR_DFT = D2U_L2R
  53. self.disp.LCD_Init(Lcd_ScanDir)
  54. self.disp.LCD_Clear()
  55. def __showLogo(self):
  56. with self.lock:
  57. self.On()
  58. image = Image.open('img/logo.bmp')
  59. self.disp.LCD_ShowImage(image,0,0)
  60. time.sleep(3.4)
  61. self.RequestUpdate()
  62. self.Off()
  63. def RequestUpdate(self):
  64. if self.components.Menu is not None and self.components.Menu.isVisible() == True:
  65. frame = self.components.Menu.getFrame()
  66. if frame is not False:
  67. self.Update(frame)
  68. elif self.__on == True and self.components.Camera is not None:
  69. frame = self.components.Camera.getFrame()
  70. if frame is not None:
  71. img = Image.fromarray(frame)
  72. img = img.crop((420,0,1080,1080))
  73. img = img.resize((128,128))
  74. if self.components.Camera.isRecording() == True:
  75. draw = ImageDraw.Draw(img)
  76. draw.ellipse((100, 100, 120, 120), fill="red")
  77. #img = img.crop((0,0,128,128))
  78. self.Update(img)
  79. else:
  80. image = Image.new("RGB", (128, 128), "BLACK")
  81. self.Update(image)
  82. def __autoRefreshThread(self):
  83. with self.lock:
  84. while self.__on:
  85. time.sleep(0.05)
  86. self.RequestUpdate()
  87. self.RequestUpdate()
  88. def Update(self, img : Image):
  89. self.disp.LCD_ShowImage(img,0 ,0)
  90. def draw_recording_indicator(self, image):
  91. """
  92. Zeichnet einen roten Kreis auf dem Display als Indikator für laufende Aufnahmen.
  93. """
  94. image = Image.new("RGB", (self.LCD.width, self.LCD.height)) # Leeres Bild erstellen
  95. draw = ImageDraw.Draw(image) # Zeichnen-Objekt erstellen
  96. # Koordinaten für das Zeichnen des roten Kreises (untere rechte Ecke)
  97. circle_x = self.LCD.width - 12
  98. circle_y = self.LCD.height - 12
  99. circle_radius = 6
  100. # Kreis zeichnen
  101. draw.ellipse((circle_x - circle_radius, circle_y - circle_radius,
  102. circle_x + circle_radius, circle_y + circle_radius), fill="red")
  103. self.LCD.LCD_ShowImage(image) # Bild auf dem Display anzeigen