Added debug gui
This commit is contained in:
		| @@ -7,7 +7,10 @@ ScreenY = 40 | ||||
| Serial = "/dev/ttyACM0" | ||||
|  | ||||
| # kills app after some seconds if it sends no data | ||||
| NoDataTimeout = 10 | ||||
| NoDataTimeout = 20 | ||||
|  | ||||
| UseGui = True | ||||
| GuiScaleFactor = 10 | ||||
|  | ||||
| # first app is always running in IDLE     | ||||
| Apps = [ | ||||
|   | ||||
							
								
								
									
										34
									
								
								main.py
									
									
									
									
									
								
							
							
						
						
									
										34
									
								
								main.py
									
									
									
									
									
								
							| @@ -6,6 +6,35 @@ import threading | ||||
| import json | ||||
| from bottle import route, run | ||||
| import time | ||||
| if config.UseGui: | ||||
|     import pygame | ||||
|  | ||||
|     class Gui(threading.Thread): | ||||
|         def __init__(self): | ||||
|             super().__init__() | ||||
|             self.data = b"\x00"*config.ScreenX*config.ScreenY*3 | ||||
|  | ||||
|         def setData(self, data): | ||||
|             self.data = data | ||||
|  | ||||
|         def run(self): | ||||
|             sf = config.GuiScaleFactor | ||||
|             screen = pygame.display.set_mode((sf*config.ScreenX, sf*config.ScreenY)) | ||||
|             pygame.display.set_caption("Pixelserver - GUI Vis") | ||||
|             while True: | ||||
|                 for event in pygame.event.get(): | ||||
|                     if event.type == pygame.QUIT: | ||||
|                         sys.exit(0) | ||||
|                 screen.fill((0, 255, 0)) | ||||
|                 for x in range(config.ScreenX): | ||||
|                     for y in range(config.ScreenY): | ||||
|                         i = x+y*config.ScreenX | ||||
|                         r = (self.data[i*3+0]) | ||||
|                         g = (self.data[i*3+1]) | ||||
|                         b = (self.data[i*3+2]) | ||||
|  | ||||
|                         pygame.draw.rect(screen, (r, g, b), pygame.Rect(sf*x, sf*y, sf, sf)) | ||||
|                 pygame.display.flip() | ||||
|  | ||||
| class SerialWriter(threading.Thread): | ||||
|     def __init__(self): | ||||
| @@ -62,6 +91,9 @@ class AppRunner(threading.Thread): | ||||
|         self.last_update = time.time() | ||||
|         self.watchdog = WatchDog(lambda: self.appTimedOut(), lambda: self.terminateApp()) | ||||
|         self.watchdog.start() | ||||
|         if config.UseGui: | ||||
|             self.gui = Gui() | ||||
|             self.gui.start() | ||||
|  | ||||
|     def requestApp(self, app, param=""): | ||||
|         with self.lock: | ||||
| @@ -101,6 +133,8 @@ class AppRunner(threading.Thread): | ||||
|                 data = os.read(oshandle, config.ScreenX*config.ScreenY*3) | ||||
|                 self.last_update = time.time() | ||||
|                 self.serial.setData(data) | ||||
|                 if config.UseGui: | ||||
|                     self.gui.setData(data) | ||||
|             except: | ||||
|                 pass | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 deckensteuerung
					deckensteuerung