def addPower(self): # Create a new default power newPower = power.Power() # Add the power to the charcter's power list self.powers.append(newPower) # Create a PowerFrame for the power newPowerFrame = PowerFrame(newPower, self) newPowerFrame.pack()
def _init_devs(self): "Initialise the attributes for accessing devices" mapping = { pysric.SRIC_CLASS_SERVO: ( "servos", servo.Servo ) } for devtype, info in mapping.iteritems(): attrname, cls = info l = [] setattr( self, attrname, l ) if devtype in self.sricman.devices: for dev in self.sricman.devices[ devtype ]: l.append( cls( dev ) ) # Power board if pysric.SRIC_CLASS_POWER not in self.sricman.devices: raise Exception( "Power board not enumerated -- aborting." ) self.power = power.Power( self.sricman.devices[pysric.SRIC_CLASS_POWER][0] ) # Motor boards self._init_motors() self._init_ruggeduinos()
def __init__(self): warnings.filterwarnings("ignore") for arg in sys.argv: if arg == '--power': self.POWER_FONA = True print 'Powering FONA on...' else: self.POWER_FONA = False if arg == '--version': print 'TYOS VERSION ' + VERSION sys.exit() self.VERSION = VERSION if self.POWER_FONA: import power power.Power().toggle() time.sleep(10) #Setup fona self.fona = serialport.SerialPort() self.fona.connect() self.set_audio() #Setup some important objects self.scope = framebuffer.pyscope() self.toolbar = toolbar.Toolbar(self.fona) self.apps = apps.App(self.fona) self.reciever = receive.Receive(self.fona) pygame.init() #Setup surface self.WINDOWWIDTH = 320 self.WINDOWHIEGHT = 480 self.surface = pygame.display.set_mode( (self.WINDOWWIDTH, self.WINDOWHIEGHT), pygame.FULLSCREEN) pygame.mouse.set_visible(False) self.clock = pygame.time.Clock() #Colors R G B self.BLUE = (0, 0, 255) self.WHITE = (255, 255, 255) self.BLACK = (0, 0, 0) self.surface.fill(self.WHITE) self.update = True #Setup logo self.logo = pygame.image.load('/home/pi/tyos/graphics/logo.png') self.logo_rect = self.logo.get_rect() self.logo_rect.y = self.surface.get_rect().centery - 50 self.logo_rect.centerx = self.surface.get_rect().centerx #Setup Battery Icon self.bat = pygame.image.load('/home/pi/tyos/graphics/bat.png') self.bat_rect = self.bat.get_rect() self.bat_rect.centery = 15 self.bat_rect.right = self.WINDOWWIDTH - 10 #Setup Low Battery Icon self.low_bat = pygame.image.load('/home/pi/tyos/graphics/low_bat.png') self.low_bat_rect = self.low_bat.get_rect() self.low_bat_rect.centery = 380 self.low_bat_rect.centerx = self.surface.get_rect().centerx #Setup App Toolbar self.app_toolbar = pygame.Rect(0, 0, 320, 30) #Rectangle Dictionary self.rectangles = {'rects': [self.app_toolbar], 'colors': [self.BLACK]} #Reception Rectangle dictionary self.reception_bars = {'rects': [], 'colors': []} #Battery Left Text self.bat_left = { 'surface': self.toolbar.bat_left, 'rects': self.toolbar.bat_left_rect } #Setup fonts self.font = pygame.font.Font('/home/pi/tyos/fonts/arial.ttf', 20) #Setup clock Text self.clock_text = self.font.render('12:00', True, self.WHITE, self.BLACK) self.clock_text_rect = self.clock_text.get_rect() self.clock_text_rect.centerx = self.surface.get_rect().centerx self.clock_text_rect.centery = 15 #Image Dictionary self.images = { 'surfaces': [self.bat], 'rects': [self.bat_rect, self.clock_text_rect] } self.blit_logo = True self.dead_bat = False
for event in pygame.event.get(): self.update = True self.apps.update_app = True self.app_bar = self.apps.check(event) if self.reciever.call_coming: self.reciever.get_events(event) phone = tyos() try: phone.home() #E.T Reference except KeyboardInterrupt: print print 'Closing TYOS ' + phone.VERSION if phone.POWER_FONA: power.Power().toggle() pygame.quit() sys.exit() except SystemExit: pass except: print '******************************************' print 'An Error Occured' print 'Writing to log /home/pi/tyos/logs/tyos.log' print '******************************************' #If error occurs, save it to file error = traceback.format_exc() error_log = open('/home/pi/tyos/logs/tyos.log', 'w') error_log.write(error)
else: print >> sys.stderr, "Unrecognized request type" sys.exit(1) if args.reqname not in req_map: print >> sys.stderr, "\"{0}\" is not a valid request for {1}".format( args.reqname, args.reqtype) sys.exit(1) req_id = req_map[args.reqname] ############################################################################### import power p = power.Power() if is_read: if req_id < 7: print >> sys.stderr, "EUNIMPLEMENTED" sys.exit(1) elif req_id == 7: res = p.read_batt_status() elif req_id == 8: res = p.read_button() print repr(res) else: b = not (args.argument == 0) if (req_id < 6): p.set_output_rail(req_id, b) elif (req_id == 6):