def __init_display(self, sf, fps): if is_pi() and config.blank_console: call_and_log("setterm -blank force", shell=True) bgcolor = (0.0, 0.0, 0.0, 0.0) # fix dispmanx alpha layer https://github.com/tipam/pi3d/issues/197 monkey_patch() self.width = 1920 if sf == 0: #adapt to screen size self.DISPLAY = pi3d.Display.create(background=bgcolor, layer=1) sf = self.width / self.DISPLAY.width self.height = self.DISPLAY.height * sf else: logger.debug("Forcing size") self.height = 1080 self.DISPLAY = pi3d.Display.create(x=0, y=0, w=int(self.width / sf), h=int(self.height / sf), background=bgcolor, layer=1) self.DISPLAY.frames_per_second = fps logger.info("Display %dx%d@%d", self.DISPLAY.width, self.DISPLAY.height, self.DISPLAY.frames_per_second) self.CAMERA = pi3d.Camera(is_3d=False, scale=1 / sf) opengles.glBlendFuncSeparate(pi3d.constants.GL_SRC_ALPHA, pi3d.constants.GL_ONE_MINUS_SRC_ALPHA, 1, pi3d.constants.GL_ONE_MINUS_SRC_ALPHA) self.sf = sf
def __init_display(self, sf, fps): if is_pi() and config.blank_console: call_and_log("video/blank_console.sh blank", shell=True) bgcolor = (0.0, 0.0, 0.0, 0.0) self.width = 1920 if sf == 0: #adapt to screen size self.DISPLAY = pi3d.Display.create(background=bgcolor, layer=1, use_pygame=True) sf = self.width / self.DISPLAY.width self.height = self.DISPLAY.height * sf else: logger.debug("Forcing size") self.height = 1080 self.DISPLAY = pi3d.Display.create(x=0, y=0, w=int(self.width / sf), h=int(self.height / sf), background=bgcolor, layer=1, use_pygame=True) self.DISPLAY.frames_per_second = fps logger.info("Display %dx%d@%d", self.DISPLAY.width, self.DISPLAY.height, self.DISPLAY.frames_per_second) self.CAMERA = pi3d.Camera(is_3d=False, scale=1 / sf) opengles.glBlendFuncSeparate(pi3d.constants.GL_SRC_ALPHA, pi3d.constants.GL_ONE_MINUS_SRC_ALPHA, 1, pi3d.constants.GL_ONE_MINUS_SRC_ALPHA) self.sf = sf
def process_event(self, ev): if ev.name == 'score_changed': self.current_score = ev.data['yellow'], ev.data['black'] elif ev.name == 'replay_start': self.replay_data = ev.data if ev.name != 'upload_request': return self.bus.notify('upload_start') text = 'Replay' if self.replay_data.get('type') == 'goal': text = '{} goal'.format( self.replay_data.get('team', '?').capitalize()) title = "{}: {}-{}".format(text, self.current_score[0], self.current_score[1]) logger.info("Uploading video: %s", title) try: in_file = os.path.join(config.replay_path, 'replay_long.h264') out_file = os.path.join(config.replay_path, 'replay_long.mp4') call_and_log(["video/convert.sh", in_file, out_file]) video_id = initialize_upload(title, out_file) url = 'http://www.youtube.com/watch?v={}'.format(video_id) self.bus.notify('upload_ok', url) return except HttpError as e: logger.error("An HTTP error %d occurred:\n%s", e.resp.status, e.content) except Exception as e: logger.error("An error occurred: %s", e) self.bus.notify('upload_error')
def process_event(self, ev): if ev.name == "score_changed": self.current_score = ev.data["yellow"], ev.data["black"] elif ev.name == "replay_start": self.replay_data = ev.data if ev.name != "upload_request": return self.bus.notify("upload_start") text = "Replay" if self.replay_data.get("type") == "goal": text = "{} goal".format(self.replay_data.get("team", "?").capitalize()) title = "{}: {}-{}".format(text, self.current_score[0], self.current_score[1]) logger.info("Uploading video: %s", title) try: in_file = os.path.join(config.replay_path, "replay_long.h264") out_file = os.path.join(config.replay_path, "replay_long.mp4") call_and_log(["video/convert.sh", in_file, out_file]) video_id = initialize_upload(title, out_file) url = "http://www.youtube.com/watch?v={}".format(video_id) self.bus.notify("upload_ok", url) return except HttpError as e: logger.error("An HTTP error %d occurred:\n%s", e.resp.status, e.content) except Exception as e: logger.error("An error occurred: %s", e) self.bus.notify("upload_error")
def __init__(self): # https://sites.google.com/site/semilleroadt/raspberry-pi-tutorials/gpio: # "According to it, configure GPIO18 (WiringPi Pin 1)..." # Raspberry base PWM frequency: 19,200,000 Hz # Resulted frequency: base freq / 101 / 5 = 38.019 kHz # Signal duty cycle = 3/5 = ~60% process.call_and_log("gpio mode 1 pwm && gpio pwm-ms && gpio pwmr 5 && gpio pwmc 101 && gpio pwm 1 2", shell=True)
def replay(self, replay_type, trigger, extra={}): extra['type'] = trigger call_and_log(["video/generate-replay.sh", config.replay_path, str(config.ignore_recent_chunks), str(config.long_chunks), str(config.short_chunks)]) self.bus.notify('replay_start', extra) if is_pi(): call_and_log(["video/replay.sh", os.path.join(config.replay_path, "replay_{}.h264".format(replay_type)), str(config.replay_fps)]) else: time.sleep(3) self.bus.notify('replay_end')
def replay(self, replay_type, trigger, extra={}): extra['type'] = trigger call_and_log(["video/generate-replay.sh", config.replay_path, str(config.ignore_recent_chunks), str(config.long_chunks), str(config.short_chunks)]) # If we want to keep replays, make a copy of the files with a timestamp. if config.save_replays == True: copyfile(os.path.join(config.replay_save_path, "replay_short.h264"), os.path.join(config.replay_save_path, "{}_replay_short.h264".format(int(time.time())))) copyfile(os.path.join(config.replay_save_path, "replay_long.h264"), os.path.join(config.replay_save_path, "{}_replay_long.h264".format(int(time.time())))) self.bus.notify('replay_start', extra) if is_pi(): call_and_log(["video/replay.sh", os.path.join(config.replay_path, "replay_{}.h264".format(replay_type)), str(config.replay_fps)]) else: time.sleep(3) self.bus.notify('replay_end')
def replay(self, replay_type, trigger, extra={}): extra['type'] = trigger call_and_log([ "video/generate-replay.sh", config.replay_path, str(config.ignore_recent_chunks), str(config.long_chunks), str(config.short_chunks) ]) self.bus.notify('replay_start', extra) if is_pi(): call_and_log([ "video/replay.sh", os.path.join(config.replay_path, "replay_{}.h264".format(replay_type)), str(config.replay_fps) ]) else: time.sleep(3) self.bus.notify('replay_end')
def run(self): try: while self.DISPLAY.loop_running(): self.checkSchedules() if not self.overlay_mode: if self.bg_img: self.bg_img.draw() self.bg.draw() self.instructions.draw() self.goal_time.quick_change( self.__get_time_since_last_goal()) self.goal_time.draw() self.feedback.draw() self.logo.draw() self.people.draw() self.yCounter.draw() self.bCounter.draw() if not self.overlay_mode: self.winner.draw() self.game_mode_ui.quick_change(self.__get_mode_string()) self.game_mode_ui.draw() self.yPlayers.draw() self.bPlayers.draw() if self.draw_menu: self.menu.draw() if self.show_leds: self.__draw_leds() except: traceback.print_exc() if is_pi() and config.blank_console: call_and_log("setterm -blank poke", shell=True)
def run(self): try: while self.DISPLAY.loop_running(): self.checkSchedules() if not self.overlay_mode: if self.bg_img: self.bg_img.draw() self.bg.draw() self.instructions.draw() self.goal_time.quick_change(self.__get_time_since_last_goal()) self.goal_time.draw() self.feedback.draw() self.logo.draw() self.people.draw() self.yCounter.draw() self.bCounter.draw() if not self.overlay_mode: self.winner.draw() self.game_mode_ui.quick_change(self.__get_mode_string()) self.game_mode_ui.draw() self.yPlayers.draw() self.bPlayers.draw() if self.draw_menu: self.menu.draw() if self.show_leds: self.__draw_leds() except: traceback.print_exc() if is_pi() and config.blank_console: call_and_log("setterm -blank poke", shell=True)
def __del__(self): process.call_and_log("gpio pwm 1 0", shell=True)