コード例 #1
0
ファイル: phone_module.py プロジェクト: TheQYD/cobblr-phone
def Process():
    button = str(SystemState.pressed_button)
    pygame = SystemState.pygame
    screen = SystemState.screen
    serial_port = SystemState.PhoneState.serial_port

    if button == 'delete':
        SystemState.pressed_buttons = SystemState.pressed_buttons[:-1]
        TextWriter.Write(state=SystemState,
                         text=SystemState.pressed_buttons,
                         text_type="top")
    elif button == 'go_back':
        Menu.Back(change_application=True)
    elif button == 'call':
        if SystemState.screen_mode == 1:
            Menu.JumpTo(application='phone',
                        screen_mode=2,
                        store_history=False,
                        change_application=True)
            serial_message = "ATD " + SystemState.pressed_buttons + ';'
            WriteToSerial(serial_port, serial_message)
            TextWriter.Write(text="Calling", text_type='message')
            TextWriter.Write(text=SystemState.pressed_buttons,
                             text_type='subtext')
        else:
            Menu.JumpTo(application='phone',
                        screen_mode=2,
                        store_history=False,
                        change_application=True)
            WriteToSerial(serial_port, "ATA")
            TextWriter.Write(text=SystemState.pressed_buttons,
                             text_type='subtext')
    elif button == 'hangup':
        Menu.Back(change_application=True)
        WriteToSerial(serial_port, "ATH")
        TextWriter.Write(text=SystemState.pressed_buttons, text_type='top')
    elif button == 'hash':
        SystemState.pressed_buttons = SystemState.pressed_buttons + '#'
        TextWriter.Write(text=SystemState.pressed_buttons, text_type='top')
    elif button == 'star':
        SystemState.pressed_buttons = SystemState.pressed_buttons + '*'
        TextWriter.Write(text=SystemState.pressed_buttons, text_type='top')
    else:
        SystemState.pressed_buttons = SystemState.pressed_buttons + str(button)
        TextWriter.Write(text=SystemState.pressed_buttons, text_type='top')
コード例 #2
0
def Process():
  if SystemState.pressed_button == 'power':
    Menu.JumpTo('desktop', 2)
    TextWriter.Write(
      text="Shutdown Cobblr?",
      text_type='prompt',
      size=25,
      centered=True,
      permatext=True
      )
  elif SystemState.pressed_button == 'decline':
    Menu.Back()
  elif SystemState.pressed_button == 'accept':
    os.system('sudo init 0')
    SystemState.pygame.exit()
    sys.exit(0)
  else:
    Menu.JumpTo(SystemState.pressed_button, 1)
コード例 #3
0
def Process():
    button = str(SystemState.pressed_button)
    pygame = SystemState.pygame
    screen = SystemState.screen
    screen_mode = SystemState.screen_mode

    if button == 'record':
        if SystemState.AudioState.recording_audio == True:
            SystemState.AudioState.recording_audio = False
            StopRecordingAudio()
        else:
            TextWriter.Write(text='Rec',
                             position=(10, 10),
                             color=(255, 0, 0),
                             state=SystemState,
                             size=20)
            SystemState.AudioState.recording_audio = True
            CallRecordAudio()
    elif button == 'play':
        Menu.JumpTo(screen_mode=3, toggle=True)
        Play()
    elif button == 'pause':
        Menu.JumpTo(screen_mode=2, toggle=True)
        Pause()
    elif button == 'library':
        SystemState.AudioState.recording_audio = False
        Menu.JumpTo(screen_mode=2)
        StopRecordingAudio()
        OpenLibrary()
        Pause()
    elif button == 'go_back':
        SystemState.AudioState.recording_audio = False
        Menu.Back()
    elif button == 'rewind':
        Rewind()
    elif button == 'fast_forward':
        FastForward()
    elif button == 'next':
        if SystemState.AudioState.audio_count > 0:
            NextRecording()
    elif button == 'previous':
        if SystemState.AudioState.audio_count > 0:
            PreviousRecording()
    elif button == 'delete':
        if SystemState.AudioState.audio_count > 0:
            Menu.JumpTo(screen_mode=2)
            TextWriter.Write(state=SystemState,
                             text='Delete?',
                             position=(125, 75),
                             size=20)
    elif button == 'accept':
        DeleteAudio()
        OpenLibrary()
        Menu.Back()
    elif button == 'decline':
        OpenLibrary()
        Menu.Back()
コード例 #4
0
ファイル: video_module.py プロジェクト: TheQYD/cobblr-video
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)
コード例 #5
0
def RefreshDesktop():
  """Places the time and battery power on the screen.

  Args:
    None

  Return:
    None
  
  RefreshDesktop refreshes the clock, battery indicator, etc every 60 seconds.
  It does this by setting a permanent timeout that runs every 60 seconds. When
  it runs, RefreshScreen is called. When RefreshScreen is called, the desktop
  application's Main() function is called, which prints the new information
  on the screen.

  This is only called when the system is sitting on the desktop.
  """
  if SystemState.application == 'desktop':
    SystemState.screen.fill(SystemState.background_color)
    Menu.JumpTo('desktop', toggle=True, change_application=True)
コード例 #6
0
def Process():
    button = str(SystemState.pressed_button)
    pygame = SystemState.pygame
    screen = SystemState.screen
    screen_mode = SystemState.screen_mode
    back_pressed = 0

    try:
        if button == 'delete':
            SystemState.pressed_buttons = SystemState.pressed_buttons[:-1]
        elif button == 'plus':
            SystemState.pressed_buttons = SystemState.pressed_buttons + '+'
        elif button == 'minus':
            SystemState.pressed_buttons = SystemState.pressed_buttons + '-'
        elif button == 'multiply':
            SystemState.pressed_buttons = SystemState.pressed_buttons + '*'
        elif button == 'divide':
            SystemState.pressed_buttons = SystemState.pressed_buttons + '/'
        elif button == 'equals' and len(SystemState.pressed_buttons) > 0:
            SystemState.pressed_buttons = str(eval(
                SystemState.pressed_buttons))
        elif button == 'point':
            SystemState.pressed_buttons = SystemState.pressed_buttons + '.'
        elif button == 'right_parentheses':
            SystemState.pressed_buttons = SystemState.pressed_buttons + '('
        elif button == 'left_parentheses':
            SystemState.pressed_buttons = SystemState.pressed_buttons + ')'
        elif button == 'alt':
            print 'alt'
        elif button == 'go_back':
            back_pressed = 1
            Menu.Back()
        else:
            SystemState.pressed_buttons = SystemState.pressed_buttons + str(
                button)

        if back_pressed == 0:
            UpdateText(0)
    except:
        if back_pressed == 0:
            UpdateText(1)
コード例 #7
0
def InitSystem():
    """Initilizes the entire system.

  Args:
    None

  Returns:
    None

  The Init() first initilizes pygame and sets the modes. Then, it loads
  applications engine.SystemState found in the applications/ directory. After
  that, it loads each module for each application and stores it in a list. If that
  module is present, it checks if there are functions in each module to be
  called. The functions are placed in each <application_name>_module.py file.

  The functions are:

    Init():
      Init sets up the environement or starts services necessary for the module
      to run.

    Process():
      Process runs when a button on the screen is pressed. It responds to the
      button press with an Screen.

    Main():
      Main runs after switching to an application. Any computation or animation
      being done belongs in the Main function. Main can hold a while loop, but
      the conditioning would have to be rigged like this:

         " while SystemState.application == (application_name): "

    Thread():
      Similar to Main, but get's called when Cobblr is initialized. Thread is
      a part of the module that get's spawned as a thread from within
      init. If there is a set of tasks that the module must run outside of the
      main thread, it is placed in the module's Thread function.

  A module needs any of these to work correctly, depending on what it does.
  Init looks for these and either calls them, as is the case of Init and
  Thread, or uses them later based on some Screen. as is the case with Process
  and Screen.
  """
    logging.info('starting Cobblr.')
    os.chdir('/opt/cobblr')
    # Initializing pygame and screen.
    #pygame.init()
    pygame.mouse.set_visible(False)
    modes = pygame.display.list_modes(16)
    applications = SystemState.applications
    #display_info = pygame.display.Info()
    #SystemState.resolution = (display_info.current_w, display_info.current_h)
    # Assigning variables used by other modules to SystemState
    SystemState.pyaudio = pyaudio.PyAudio()
    SystemState.pygame = pygame
    SystemState.screen = pygame.display.set_mode(modes[0], pygame.FULLSCREEN,
                                                 16)
    SystemState.cobblr_config = yaml.load(open("config/cobblr.yaml"))

    SystemState.gpio_interrupts = __FetchGPIOConfig()
    # Setup for storing application configs and modules.
    application_configs = {}
    application_modules = []

    # Setup which application is the startup applicaton.
    startup_info = SystemState.cobblr_config["startup"]
    SystemState.startup_application = startup_info["application"]
    SystemState.startup_screen_mode = startup_info["screen_mode"]

    # Reading each application's config file.
    logging.info("reading application config files")

    SystemState.camera = picamera.PiCamera()

    for application in applications:
        application = str(application)
        application_dir = os.path.join("applications", application)
        application_config_dir = os.path.join(application_dir, "config")
        application_config = os.path.join(application_config_dir,
                                          application + ".yaml")

        # Initializing the config.
        logging.debug('starting %s application.', application)
        config.Init(application_config)
        config_object = config.SystemConfig.applications[application]
        application_configs[application] = config_object
        application_module = config_object["module"]
        application_modules.append(application_module)

    # Storing the application configs for use by other modules.
    SystemState.application_configs = application_configs

    # Initialize modules and pass them to the system state.
    application_modules = map(importlib.import_module, application_modules)
    SystemState.application_modules = dict(
        zip(applications, application_modules))

    # Initializing Thread and Init modules if available.
    logging.info('starting Init and Thread modules.')
    for application in SystemState.application_modules:
        current_application = config.SystemConfig.applications[application]
        init_settings = current_application["Init"]
        thread_settings = current_application["Thread"]

        if init_settings is True:
            SystemState.application = application
            logging.debug('starting Init() for %s', application)
            init = SystemState.application_modules[application]
            init.Init()

        if thread_settings is True:
            SystemState.application = application
            logging.debug('starting Thread() for %s', application)
            thread = SystemState.application_modules[application]
            module_thread = threading.Thread(target=thread.Thread)
            module_thread.start()
            SystemState.application = None

    # Refreshing the screen, setting up screen sleep, and changing to desktop.
    logging.info('loading splash')
    SystemState.BACKLIGHT.start(100)
    SystemState.backlight_on = True
    SystemState.screen.fill((255, 255, 255))
    SystemState.BACKLIGHT.start(100)
    cobblr_image = pygame.image.load(
        "config/cobblr_splash_screen.png").convert()

    if SystemState.resolution[0] < SystemState.resolution[1]:
        SystemState.orientation = 'portrait'
        SystemState.screen.blit(cobblr_image, (17, 120))
    elif SystemState.resolution[0] < SystemState.resolution[1]:
        SystemState.orientation = 'landscape'
        SystemState.screen.blit(cobblr_image, (62, 90))

    SystemState.pygame.display.update()
    time.sleep(3)

    SystemState.screen.fill(SystemState.background_color)
    # Jump to the application and screen mode specifed in cobblr.yaml.
    Menu.JumpTo(application=SystemState.startup_application,
                screen_mode=SystemState.startup_screen_mode,
                change_application=True)
コード例 #8
0
def Process():
    button = str(SystemState.pressed_button)
    pygame = SystemState.pygame
    screen = SystemState.screen
    back_pressed = 0

    if button == 'play' and len(SystemState.MusicState.song_archive) > 0:
        if SystemState.MusicState.player_state == 'Cannot Play':
            ChangeSong(1)
        else:
            LoadSong()
        if SystemState.MusicState.player_state == 'Paused' and SystemState.MusicState.song_position > 1:
            pygame.mixer.music.play(0, SystemState.MusicState.song_position)
        else:
            pygame.mixer.music.play(0, 0)
        SystemState.MusicState.player_state = 'Now Playing'
        Menu.JumpTo(screen_mode=2, toggle=True)

    if button == 'pause':
        pygame.mixer.music.pause()
        SystemState.MusicState.song_position = SystemState.MusicState.song_position + pygame.mixer.music.get_pos(
        ) / 1000.0
        SystemState.MusicState.player_state = 'Paused'
        Menu.JumpTo(screen_mode=1, toggle=True)

    if button == 'stop':
        pygame.mixer.music.stop()
        SystemState.MusicState.player_state = 'Stopped'
        if SystemState.screen_mode == 2:
            Menu.JumpTo(screen_mode=1)
        elif SystemState.screen_mode == 3:
            Menu.JumpTo(screen_mode=3, toggle=True)

    if button == 'backward':
        ChangeSong(-1)
        if SystemState.MusicState.player_state == 'Now Playing':
            pygame.mixer.music.play(0, SystemState.MusicState.song_position)

    if button == 'forward':
        ChangeSong(1)
        if SystemState.MusicState.player_state == 'Now Playing':
            pygame.mixer.music.play(0, SystemState.MusicState.song_position)

    if button == 'alt':
        if SystemState.screen_mode == 1 or SystemState.screen_mode == 2:
            Menu.JumpTo(screen_mode=3, toggle=True)
        elif SystemState.screen_mode == 3:
            if SystemState.MusicState.player_state == 'Now Playing':
                Menu.JumpTo(screen_mode=2, toggle=True)
            else:
                Menu.JumpTo(screen_mode=1, toggle=True)

    if button == 'volume_up':
        pygame.mixer.music.set_volume(pygame.mixer.music.get_volume() + 0.1)

    if button == 'repeat':
        pass

    if button == 'volume_down':
        pygame.mixer.music.set_volume(pygame.mixer.music.get_volume() - 0.1)

    if button == 'go_back':
        back_pressed = 1
        Menu.Back()

    if back_pressed == 0:
        UpdateMusicText()
コード例 #9
0
def Process():
  """Determines what buttons were pressed with each screen touch."""
  button = str(SystemState.pressed_button)
  pygame = SystemState.pygame
  screen = SystemState.screen
  screen_mode = SystemState.screen_mode

  if button == 'flash_on':
    Menu.JumpTo(screen_mode=2, toggle=True)
    SystemState.CameraState.flash_enabled = False
  elif button == 'flash_off':
    Menu.JumpTo(screen_mode=1, toggle=True)
    SystemState.CameraState.flash_enabled = True
  elif button == 'go_back':
    Menu.Back()
    SystemState.CameraState.setting = 'none'
    SystemState.CameraState.album = False
  elif button == 'gallery':
    Menu.JumpTo(screen_mode=3)
    OpenAlbum()
  elif button == 'right_arrow':
    __ProcessRightArrow()
  elif button == 'left_arrow':
    __ProcessLeftArrow()
  elif button == 'capture':
    CallTakePhoto()
  elif button == 'delete' and SystemState.CameraState.photo_count > 0:
    Menu.JumpTo(screen_mode=4)
    BlitImage(SystemState.CameraState.current_photo, SystemState.pygame, SystemState.screen)
    TextWriter.Write(state=SystemState, text='Delete?', position=(125, 75), size=20)
  elif button == 'iso':
    Menu.JumpTo(screen_mode=6)
    SystemState.CameraState.setting = 'iso'
  elif button == 'image_effect':
    Menu.JumpTo(screen_mode=6)
    SystemState.CameraState.setting = 'image_effect'
  elif button == 'rotation':
    Menu.JumpTo(screen_mode=6)
    SystemState.CameraState.setting = 'rotation'
  elif button == 'brightness':
    Menu.JumpTo(screen_mode=6)
    SystemState.CameraState.setting = 'brightness'
  elif button == 'saturation':
    Menu.JumpTo(screen_mode=6)
    SystemState.CameraState.setting = 'saturation'
  elif button == 'contrast':
    Menu.JumpTo(screen_mode=6)
    SystemState.CameraState.setting = 'contrast'
  elif button == 'sharpness':
    Menu.JumpTo(screen_mode=6)
    SystemState.CameraState.setting = 'sharpness'
  elif button == 'zoom':
    Menu.JumpTo(screen_mode=6)
    SystemState.CameraState.setting = 'zoom'
  elif button == 'meter_mode':
    Menu.JumpTo(screen_mode=6)
    SystemState.CameraState.setting = 'meter_mode'
  elif button == 'awb':
    Menu.JumpTo(screen_mode=6)
    SystemState.CameraState.setting = 'awb_mode'
  elif button == 'shutter_speed':
    Menu.JumpTo(screen_mode=6)
    SystemState.CameraState.setting = 'shutter_speed'
  elif button == 'exposure_mode':
    Menu.JumpTo(screen_mode=6)
    SystemState.CameraState.setting = 'exposure_mode'
  elif button == 'settings':
    Menu.JumpTo(screen_mode=5)
  elif button == 'accept':
    DeletePhoto()
    Menu.Back()
    OpenAlbum()
  elif button == 'decline':
    Menu.Back()
    OpenAlbum()

  if SystemState.screen_mode == 5 and SystemState.next_screen_mode == 6:
    setting = SystemState.CameraState.setting
    setting_values = setting + '_values'
    __CurrentSetting(setting_values, setting)

  SystemState.CameraState.camera_stream = False
コード例 #10
0
ファイル: video_module.py プロジェクト: TheQYD/cobblr-video
def Process():
  """Processing button presses."""
  button = str(SystemState.pressed_button)
  pygame = SystemState.pygame
  screen = SystemState.screen
  screen_mode = SystemState.screen_mode
  
  if button == 'library':
    OpenAlbum()
    Menu.JumpTo(screen_mode=4)
  elif button == 'go_back':
    Menu.Back()
    SystemState.VideoState.setting = 'none'
  elif button == 'play':
    __PlayVideo()
  elif button == 'settings':
    Menu.JumpTo(screen_mode=2, refresh_screen=False)
  elif button == 'delete':
    if SystemState.VideoState.video_count > 0:
      Menu.JumpTo(screen_mode=5)
      TextWriter.Write(
          state=SystemState, 
          text='Delete?', 
          position=(125, 75), 
          size=20
      )
  elif button == 'right_arrow':
    __ProcessRightArrow()
  elif button == 'left_arrow':
    __ProcessLeftArrow()
  elif button == 'iso':
    Menu.JumpTo(screen_mode=3)
    SystemState.VideoState.setting = 'iso'
  elif button == 'image_effect':
    Menu.JumpTo(screen_mode=3, refresh_screen=False)
    SystemState.VideoState.setting = 'image_effect'
  elif button == 'rotation':
    Menu.JumpTo(screen_mode=3, refresh_screen=False)
    SystemState.VideoState.setting = 'rotation'
  elif button == 'brightness':
    Menu.JumpTo(screen_mode=3, refresh_screen=False)
    SystemState.VideoState.setting = 'brightness'
  elif button == 'saturation':
    Menu.JumpTo(screen_mode=3, refresh_screen=False)
    SystemState.VideoState.setting = 'saturation'
  elif button == 'contrast':
    Menu.JumpTo(screen_mode=3, refresh_screen=False)
    SystemState.VideoState.setting = 'contrast'
  elif button == 'sharpness':
    Menu.JumpTo(screen_mode=3, refresh_screen=False)
    SystemState.VideoState.setting = 'sharpness'
  elif button == 'zoom':
    Menu.JumpTo(screen_mode=3, refresh_screen=False)
    SystemState.VideoState.setting = 'zoom'
  elif button == 'meter_mode':
    Menu.JumpTo(screen_mode=3, refresh_screen=False)
    SystemState.VideoState.setting = 'meter_mode'
  elif button == 'awb':
    Menu.JumpTo(screen_mode=3, refresh_screen=False)
    SystemState.VideoState.setting = 'awb_mode'
  elif button == 'video_stabilization':
    Menu.JumpTo(screen_mode=3, refresh_screen=False)
    SystemState.VideoState.setting = 'video_stabilization'
  elif button == 'exposure_mode':
    Menu.JumpTo(screen_mode=3, refresh_screen=False)
    SystemState.VideoState.setting = 'exposure_mode'
  elif button == 'accept':
    __DeleteVideo()
    Menu.Back()
    OpenAlbum()
  elif button == 'decline':
    Menu.Back()
    OpenAlbum()
  
  # Displaying settings title and values when you first enter a menu.
  if SystemState.screen_mode == 2 and SystemState.next_screen_mode == 3:
    setting = SystemState.VideoState.setting
    setting_values = setting + '_values'
    __CurrentSetting(setting_values, setting)