Пример #1
0
def Main():
  """Runs once the user has entered the application."""

  pygame = SystemState.pygame
  while SystemState.application == 'camera':
    Events.CheckEvents()
    if SystemState.screen_mode in (1, 2, 5, 6):
      SystemState.CameraState.camera_stream = True
    else:
      SystemState.CameraState.camera_stream = False

    if SystemState.CameraState.camera_stream == True:
      # Button on RPi.GPIO 8
      if not RPi.GPIO.input(8):
        CallTakePhoto()

      SystemState.CameraState.stream = io.BytesIO() # Capture into in-memory stream
      SystemState.camera.capture(SystemState.CameraState.stream, use_video_port=True, splitter_port=0, format='rgb')
      SystemState.CameraState.stream.seek(0)
      SystemState.CameraState.stream.readinto(SystemState.rgb)  # stream -> YUV buffer
      SystemState.CameraState.stream.close()
      SystemState.img = SystemState.pygame.image.frombuffer(SystemState.rgb[0: (320 * 240 * 3)], (320, 240), 'RGB' )
      xa = (320 - SystemState.img.get_width() ) / 2
      ya = (240 - SystemState.img.get_height()) / 2
      Screen.RefreshScreen(image=SystemState.img, wx=xa, wy=ya)
Пример #2
0
def Main():
  """Main loop for the camera application."""
  pygame = SystemState.pygame
  SystemState.camera.resolution = (320, 240)
  
  while SystemState.application == 'video':
    # Check for button presses, messages, and which mode we're in.
    Events.CheckEvents()
    if SystemState.screen_mode in (1, 2, 3):
      SystemState.VideoState.video_stream = True
    else:
      SystemState.VideoState.video_stream = False
    try:
      video_message_queue = SystemState.VideoState.video_message_queue.get(None)
    except Queue.Empty:
      video_message_queue = None
    
    # Checking video message queue for record messages.
    if video_message_queue != None:
      recording_state = video_message_queue.get('recording')
      if recording_state == True:
        timestamp = str(int(time.time()))
        __CallRecordAudio(timestamp)
        __CallRecordVideo(timestamp)
        SystemState.VideoState.video_recording = True
      elif recording_state == False:
        SystemState.VideoState.video_recording = False
        TextWriter.ClearPermatext()
    
    # Checking the gpio button that starts recording.
    if SystemState.VideoState.video_recording == False:
      if not RPi.GPIO.input(8) and SystemState.screen_mode == 1:
        SystemState.VideoState.video_message_queue.put({'recording': True})
        Menu.JumpTo(screen_mode=6)
        TextWriter.Write(
          text='Rec', 
          position=(10, 10), 
          color=(255,0,0), 
          permatext=True,
          state=SystemState, 
          size=20
        ) 
    
    # Check if we are in a streaming mode. If so, throw frames at the screen.
    if SystemState.VideoState.video_stream == True:
      SystemState.VideoState.stream = io.BytesIO() # Capture into in-memory stream
      SystemState.camera.capture(SystemState.VideoState.stream, use_video_port=True, splitter_port=0, format='rgb')
      SystemState.VideoState.stream.seek(0)
      SystemState.VideoState.stream.readinto(SystemState.rgb)  
      SystemState.VideoState.stream.close()
      SystemState.VideoState.img = SystemState.pygame.image.frombuffer(SystemState.rgb[0: (320 * 240 * 3)], (320, 240), 'RGB' )
      xa = (320 - SystemState.VideoState.img.get_width() ) / 2
      ya = (240 - SystemState.VideoState.img.get_height()) / 2
      Screen.RefreshScreen(image=SystemState.VideoState.img, wx=xa, wy=ya)