Ejemplo n.º 1
0
 def device_check(self):
     """
     description:
     """
     if not self.device_timer.check():
         return False
     # Reset all data if device was unpluged.
     if not self.session.is_connected_serial() and self.was_connected:
         self.reset()
         self.device.reset()
         self.start_device()
         self.ctrl_start()
         self.start_objects()
         self.session.reset()
         self.start_session()
     if self.device.get_id() is None:
         # How many devices are connected?
         devices = self.device.detect()
         # If is just one...
         if len(devices) == 1:
             # Configure a new device.
             self.session.reset()
             self.start_device()
             self.ctrl_start()
             self.start_objects()
             self.start_session()
             return False
         # Abort if are more than one.
         if len(devices) > 1 and (len(devices) != self.connected_devices):
             self.connected_devices = len(devices)
             echo.infoln('Too many connected devices: ' + str(devices), 1)
     return False
Ejemplo n.º 2
0
 def ctrl_start(self):
     """
     description:
     """
     echo.infoln('Input...')
     self.ctrl_keyboard_start()
     self.ctrl_mouse_start()
     self.ctrl_joystick_start()
     self.ctrl_touch_start()
Ejemplo n.º 3
0
 def info(self):
     """
     description:
     """
     echo.info('Mouse: ', 1)
     if not self.__mouse:
         echo.infoln(str(self.__mouse))
         return
     echo.infoln('Found')
     echo.debugln('Enable: ' + str(self.__enable), 2)
     echo.debugln('Factor: ' + str(self.__factor), 2)
Ejemplo n.º 4
0
 def info(self):
     """
     description:
     """
     echo.info('Keyboard: ', 1)
     if not self.__keyboard:
         echo.infoln(str(self.__keyboard))
         return
     echo.infoln('Found')
     echo.debugln('Enable: ' + str(self.__enable), 2)
     echo.debugln('Delay: ' + str(self.__delay) + 'ms', 2)
     echo.debugln('Interval: ' + str(self.__interval) + 'ms', 2)
Ejemplo n.º 5
0
 def stop_session(self):
     """
     description:
     """
     if not self.session.is_connected_serial():
         return
     echo.infoln('Session...')
     while not self.session.is_ready():
         continue
     echo.infoln('Terminating...', 1)
     for command in self.device.get_endup()["command"]:
         self.session.send_wait(command)
     self.session.stop()
     self.was_connected = False
Ejemplo n.º 6
0
 def start_screen(self):
     """
     description:
     """
     # global pygame
     echo.infoln("Screen...")
     # Set screen resolution
     self.screen_resolution = [
         int(s) for s in self.screen_size.split('x') if s.isdigit()
     ]
     # Check for minimum resolution
     if (self.screen_resolution[0] < 480) or \
        (self.screen_resolution[1] < 320):
         self.screen_resolution = (480, 320)
     self.screen_resolution[0] -= 1
     self.screen_resolution[1] -= 1
     echo.infoln(
         "Size: " + str(self.screen_resolution[0] + 1) + 'x' +
         str(self.screen_resolution[1] + 1) + ' px', 1)
     echo.infoln("Refresh rate: " + str(self.screen_rate) + ' FPS', 1)
     # Positioning
     os.environ['SDL_VIDEO_CENTERED'] = '1'
     # Initialise screen
     pygame.init()  # pylint: disable=no-member
     self.screen = pygame.display.set_mode(self.screen_resolution)
     if self.screen_full:
         pygame.display.toggle_fullscreen()
     # Window caption
     pygame.display.set_caption(self.window_title)
     # Checking fonts
     echo.debugln('Checking fonts...', 1)
     for ttf_name in ['Digital Readout Thick Upright', 'Ubuntu']:
         ttf_path = pygame.font.match_font(ttf_name)
         if ttf_path is None:
             echo.erroln('TrueType font missing.')
             echo.infoln(
                 '\"' + str(ttf_name) + '\" not found (' + str(ttf_path) +
                 ')', 2)
     # Background
     self.background = pygame.Surface(self.screen.get_size())
     self.background.fill([0, 0, 0])  # Black
     # Controls area
     self.controls = pygame.Surface([120, 240])
     # Object area
     self.object_area = pygame.Surface(
         [self.screen.get_size()[0] - 65,
          self.screen.get_size()[1] - 70])
     # Status bar
     self.status_bar = pygame.Surface([self.screen.get_size()[0], 16])
     # Clockling
     echo.debugln('Clockling...', 1)
     self.clock = pygame.time.Clock()
     # Screensaver
     self.screensaver = Screensaver(self.screen)
     self.screensaver_timer = Timer(1000 * self.screensaver_time,
                                    'COUNTDOWN')
     if not self.screensaver_enable:
         self.screensaver_timer.disable()
Ejemplo n.º 7
0
 def start_device(self):
     """
     description:
     """
     echo.infoln("Device...")
     if not self.device.get_id():
         detected = self.device.detect()
         if len(detected) > 1:
             echo.warnln('Too many connected devices: ' + str(detected), 1)
             return
     echo.debugln(self.device.info())
     if self.device.get_id():
         self.window_title = self.device.system_plat + ' Mark ' + \
             self.device.system_mark
         self.window_caption = self.device.system_plat + ' Mark ' + \
             self.device.system_mark + ' - ' + \
             self.device.system_desc
Ejemplo n.º 8
0
 def run(self):
     """
     description:
     """
     echo.infoln('Ready...')
     self.running = True
     while self.running:
         for event in pygame.event.get():
             if event.type == pygame.QUIT:  # pylint: disable=no-member
                 self.running = False
             self.ctrl_check(event)
         self.draw()
         self.ctrl_handle()
         self.device_check()
     echo.infoln("Exiting...")
     self.stop()
     return False
Ejemplo n.º 9
0
 def start_armv7l(self):
     """
     description:
     """
     try:
         from fan import Fan
     except ImportError as err:
         echo.erroln("Could not load module. " + str(err))
         sys.exit(True)
     self.timer = Timer(1000)
     # Temperature sensor
     status = 'Absent'
     try:
         if self.data[self.name]["resources"]["temperature_sensor"]:
             self.temperature = 0
             status = 'Present'
     except BaseException:
         pass
     echo.debugln('Temperature sensor: ' + status, 1)
     # Status LED
     status = 'Absent'
     try:
         if self.data[self.name]["resources"]["status_led"]:
             from tools.signal import SigGen
             GPIO.setup(33, GPIO.OUT)
             self.status_led = GPIO.PWM(33, 50)
             self.status_led.start(0)
             self.status_signal = SigGen()
             self.status_signal.period(1000)
             status = 'Present'
     except BaseException:
         pass
     echo.infoln('Status LED: ' + status, 1)
     # Fan
     status = 'Absent'
     try:
         if self.data[self.name]["resources"]["fan"]:
             self.fan = Fan(32, 22, max_speed=2000)
             self.fan.set_limits(40, 60)
             self.fan_speed = 0
             status = 'Present'
     except BaseException:
         pass
     echo.infoln('Fan: ' + status, 1)
Ejemplo n.º 10
0
 def info(self):
     """
     description:
     """
     echo.info('Joystick: ', 1)
     if not self.__joystick:
         echo.infoln(str(self.__joystick))
         return
     echo.infoln(str(self.__joystick.configuration()['name']))
     echo.debugln('Enable: ' + str(self.__enable), 2)
     echo.debugln('Axes: ' + str(self.__joystick.configuration()['axes']),
                  2)
     echo.debugln(
         'Buttons: ' + str(self.__joystick.configuration()['buttons']), 2)
     echo.debugln('Balls: ' + str(self.__joystick.configuration()['balls']),
                  2)
     echo.debugln('Hats: ' + str(self.__joystick.configuration()['hats']),
                  2)
     echo.debugln('Factor: ' + str(self.__factor), 2)
Ejemplo n.º 11
0
 def info(self):
     """
     description:
     """
     echo.infoln("Host...")
     echo.debugln("Profile: " + self.profile, 1)
     echo.infoln("Name: " + self.name, 1)
     echo.debugln(
         "Machine: " + self.machine + " (" + self.architecture + ")", 1)
     echo.debugln("Processor: " + self.processor, 1)
     echo.debug("Core", 1)
     if self.core > 1:
         echo.debug("s")
     echo.debugln(": " + str(self.core))
     echo.debugln(
         "Memory: " + str(self.memory) + "GB (used: " +
         str(self.memory_used) + "%)", 1)
     echo.debug("Operating system: " + self.system, 1)
     if platform.system() == 'Linux':
         echo.debugln(" (" + self.distribution + " " +
                      self.distribution_version + ")")
     echo.debugln("Python: " + self.python_version, 1)
Ejemplo n.º 12
0
 def start_objects(self):
     """
     description:
     """
     for i in self.device.get_objects():
         i["image"] = Image(
             self.object_area,
             os.path.join(self.__img_dir, i["picture"]["file"]),
             eval(i["picture"]["split"]))
         i["boolean"] = i["default"] == "on"
         # infoln('ID: ' + str(i["id"]) + ", default: " + str(i["default"]))
         i["source"] = ''
         i["factor"] = '1'
         i["button"] = Button(i["image"], eval(i["picture"]["position"]),
                              [65, 50], i["boolean"])
         try:
             i["timer"] = Timer(i["delay"])
         except BaseException:
             i["timer"] = Timer(20)
         i["state"] = i["default"]
     if self.device.get_objects():
         echo.infoln('Objects...')
         echo.infoln('Imported: ' + str(len(self.device.get_objects())), 1)