class RunMatchScreen(Screen): #screen is run as a state machine # State Description # ------ -------------------------- # 0 Waiting to start the match # 1 Match has started autonomous # 2 Match is between autonomous and teleop # 3 Match has started teleop # 4 Match has started end-game # 5 Match is over # def __init__(self,name,bigScreen): Screen.__init__(self,name) self.clock = HDMIClock(self.screen,BLACK) self.state = 0 self.bigScreen = bigScreen self.bigStopped = False def _enter(self): self.state = 0 self.clock.setTime(2,30) self.clock.run() self.bigScreen.clockSet(2,30) self.bigScreen.clockRun() def _process(self): self.clock.update() if self.clock.time == 140: self.bigScreen.clockColor(BLUE) if not self.bigStopped and self.clock.time == 130: self.bigScreen.clockStop() self.bigScreen.clockSet(self.clock.time) # make sure in sync self.bigStopped = True return True # tells screen that a redraw is necessary # # _state0() - implements the state zero # def _state0(self): # clear the big screen pass # # stateEnter() - using the current state, prepare the screen for that # state. # def stateEnter(self): if state == 0: # entering the initial state, there is a big button in the middle self._state0() # used to assign teams if Remote Control is on.
def __init__(self,role,hdmiComm,framebuffer="/dev/fb0"): self.role = role self.comm = hdmiComm self.framebuffer = framebuffer if self.role == "client": print("going init on HDMI...") self._initHDMI() print("done") StatsDisplay.init() self.clock = HDMIClock(pygame.display.get_surface(),BLACK) print("done with HDMI clock as well") self.teamFontSize = 60 self.teamFont = pygame.font.SysFont('arial', self.teamFontSize, bold=True) # just go into listen/dispatch loop #print("enter listen loop") while 1: self.clientListen() self.clock.update() pygame.display.update()
class HDMI: def __init__(self,role,hdmiComm,framebuffer="/dev/fb0"): self.role = role self.comm = hdmiComm self.framebuffer = framebuffer if self.role == "client": print("going init on HDMI...") self._initHDMI() print("done") StatsDisplay.init() self.clock = HDMIClock(pygame.display.get_surface(),BLACK) print("done with HDMI clock as well") self.teamFontSize = 60 self.teamFont = pygame.font.SysFont('arial', self.teamFontSize, bold=True) # just go into listen/dispatch loop #print("enter listen loop") while 1: self.clientListen() self.clock.update() pygame.display.update() # # _initHDMI() - initializes the HDMI display from the framebuffer # Note that the framebuffer device is passed in to the # this routine and has no default. We have a good # guess on the RPi as to what this will be, but don't # know on other devices. # (/dev/fb0 is HDMI screen on the RPi) # We go straight after the fbcon on RPi. The others # could be directfb or svgalib. # def _initHDMI(self): if not os.getenv("DISPLAY"): print("going real hdmi...") os.putenv("SDL_FBDEV", self.framebuffer) # should switch these to os.environ os.putenv('SDL_VIDEODRIVER', "fbcon") alarm(1) # gets us out of the VT_WAITACTIVE bug else: os.environ['SDL_VIDEO_WINDOW_POS'] = "%d,%d" % (500,0) try: pygame.display.init() pygame.init() except pygame.error: print("failed on opening frame buffer") return False # couldn't init HDMI if os.getenv("DISPLAY"): self.screenSize = (800,600) self.screen = pygame.display.set_mode(self.screenSize,pygame.DOUBLEBUF) pygame.display.set_caption("HDMI Simulation") else: mymodes = pygame.display.list_modes() for mode in mymodes: print(mode) g = gcd(mode[0],mode[1]) print((mode[0]/g,mode[1]/g)) self.screenSize = (pygame.display.Info().current_w, pygame.display.Info().current_h) #self.screenSize = (800,600) print "Framebuffer size: %d x %d" % (self.screenSize[0], self.screenSize[1]) print("going for screen") self.screen = pygame.display.set_mode(self.screenSize, pygame.FULLSCREEN) alarm(0) #self.screen = pygame.display.get_surface() print("good") print("ready to fill") self.screen.fill((128,128,128)) print("ready to font init") pygame.font.init() print("ready to set invisible mouse") pygame.mouse.set_visible(0) print("updating") pygame.display.update() # # end() - the command that tells this HDMI client to shut down - it doesn't # do anything important, just clears the screen. The dispatcher # special-cases "end" # def end(self): if self.role == "server": self._command("END") else: self.cls() # the caller needs to notice the END and end things pygame.quit() exit() def fill(self,r,g,b,fade=0): if self.role == "server": self._command("FILL",r,g,b,fade) else: fill = self.screen.copy() fill.fill((int(r), int(g), int(b))) utils._showImage(fill,(0,0),1,float(fade)) #self._showImage(fill,(0,0),1,float(fade)) #self.screen.fill((int(r), int(g), int(b))) #pygame.display.update() def cls(self): if self.role == "server": self._command("CLS") else: self.screen.fill((255, 255, 255)) pygame.display.update() def showImage(self,image,position,fade=0): if self.role == "server": self._command("SI",image,position,fade) else: utils.showImage(image,position,fade) def cteam(self,position,number,ping,rBat,pBat,stats=True): if self.role == "server": self._command("CTEAM",position,number,ping,rBat,pBat,stats) else: StatsDisplay.display(self.screen,self.screenSize,position,number,ping,rBat,pBat,stats) # # clockSet(mins,secs) - routines to control the clock # clockColor(r,g,b) # clockRun() # clockStop() # def clockSet(self,mins,secs=None): if self.role == "server": self._command("CSET",mins,secs) else: if secs is None: print("clockSet() called with secs as None") self.clock.setTime(mins,secs) def clockColor(self,color): if self.role == "server": self._command("CCOLOR",color) else: self.clock.setColor(color) def clockRun(self): if self.role == "server": self._command("CRUN") else: self.clock.run() def clockStop(self): if self.role == "server": self._command("CSTOP") else: self.clock.stop() def init(self): if self.role == "server": self._command("INIT") else: self._initHDMI(framebuffer) # initialize the display self.cls() def _command(self,*args): self.comm.put(args) # includes the command def _dispatch(self,cmd,args): #print("dispatching " + cmd) for c in HDMI.commandTable: if cmd == c[0]: c[1](self,*args) return print("BAD COMMAND") # # clientListen() - listens for incoming requests and dispatches them # Should only be called by the client. # Commands have a command, followed by a tab, followed # by tab-separated arguments. # def clientListen(self): if not self.comm.empty(): args = self.comm.get() cmd = args[0] args = args[1:] self._dispatch(cmd,args) return(cmd) commandTable = ( ( "INIT", init ), ( "END", end ), ( "SI" , showImage ), ( "CLS", cls), ( "FILL", fill), ( "CSET", clockSet), ( "CCOLOR", clockColor), ( "CRUN", clockRun), ( "CSTOP", clockStop), ( "CTEAM", cteam), )
def __init__(self,name,bigScreen): Screen.__init__(self,name) self.clock = HDMIClock(self.screen,BLACK) self.state = 0 self.bigScreen = bigScreen self.bigStopped = False