def setup(self, all_sprites): self.image = None self.zoomPoint = None self.preview = False self.timer = 0 # detect focus self.focus = ProcessFocus() self.focus.start() # stack images self.stack = ProcessStacking() self.stack.start() self.showStack = False # tracking images self.telescope = Telescope(self.config['telescope_dev']) self.tracker = ProcessTracking(self.telescope) self.tracker.start() self.tracking = False self.focusText = LcarsText((255,0,0), (17,303), "Focus: ") self.trackingText = LcarsText((255,0,0), (17,380), "Track: ") all_sprites.add(LcarsBackgroundImage("assets/jarvis.png")) all_sprites.add(self.focusText) all_sprites.add(self.trackingText)
def setup(self, all_sprites): all_sprites.add(LcarsBackgroundImage("assets/lcars_splash.png"), layer=0) all_sprites.add(LcarsText(colours.ORANGE, (270, -1), "LCARS SYSTEM MONITOR", 1.8), layer=1) all_sprites.add(LcarsText( colours.BLUE, (330, -1), "ONLY AUTHORIZED PERSONNEL MAY ACCESS THIS TERMINAL", 1.5), layer=1) all_sprites.add(LcarsText(colours.BLUE, (360, -1), "TOUCH SCREEN TO PROCEED", 1.5), layer=1) all_sprites.add(LcarsGifImage("assets/animated/st_logo.gif", (103, 369), 50), layer=1) # sounds Sound("assets/audio/panel/215.wav").play() self.sound_beep1 = Sound("assets/audio/panel/206.wav") self.sound_denied = Sound("assets/audio/access_denied.wav") self.sound_deny1 = Sound("assets/audio/deny_1.wav") self.sound_deny2 = Sound("assets/audio/deny_2.wav") self.granted = False
def loadfile(self, all_sprites, target, layer): # Load data from file returnpayload = read_txt("/opt/local/var/lib/lcars/" + target) # Router heading all_sprites.add(LcarsText(colours.ORANGE, (140, 175), returnpayload[0].split(',')[0], 2), layer = layer) all_sprites.add(LcarsText(colours.ORANGE, (140, 400), returnpayload[0].split(',')[1].lstrip(), 2), layer = layer) # Loop through results index = 1 ypos = 200 while index < len(returnpayload): all_sprites.add(LcarsText(colours.BLUE, (ypos, 175), returnpayload[index].split(',')[0], 2), layer = layer) # Change color based on status if returnpayload[index].lstrip().split(',')[1].lstrip() == "ONLINE": all_sprites.add(LcarsText(colours.GREEN, (ypos, 400), "ONLINE", 2), layer = layer) else: all_sprites.add(LcarsText(colours.RED, (ypos, 400), "OFFLINE", 2), layer = layer) # Bump index and vertical pos index += 1 ypos += 50 # Add a little flair all_sprites.add(LcarsGifImage("assets/animated/fwscan.gif", (320, 556), 100), layer = layer) # Save layer, this is a hack if target == "routers": self.routers = all_sprites.get_sprites_from_layer(layer) elif target == "sensors": self.sensors = all_sprites.get_sprites_from_layer(layer) elif target == "sites": self.sites = all_sprites.get_sprites_from_layer(layer) elif target == "printers": self.printers = all_sprites.get_sprites_from_layer(layer)
def setup(self, all_sprites): script_dir = dirname(__file__) ipath = join(script_dir, '../assets/lcars_screen_2.png') all_sprites.add(LcarsBackgroundImage(ipath), layer=0) all_sprites.add(LcarsText(colours.ORANGE, (170, -1), "AUTHORIZATION REQUIRED", 2), layer=1) all_sprites.add(LcarsText( colours.BLUE, (230, -1), "ONLY AUTHORIZED PERSONNEL MAY ACCESS THIS TERMINAL", 1.5), layer=1) all_sprites.add(LcarsText(colours.BLUE, (260, -1), "TOUCH TERMINAL TO PROCEED", 1.5), layer=1) all_sprites.add(LcarsText(colours.BLUE, (290, -1), "FAILED ATTEMPTS WILL BE REPORTED", 1.5), layer=1) # all_sprites.add(LcarsGifImage("assets/gadgets/stlogorotating.gif", (103, 369), 50), layer=1) # sounds # Sound("assets/audio/panel/215.wav").play() # Sound("assets/audio/enter_authorization_code.wav").play() # self.sound_granted = Sound("assets/audio/accessing.wav") # self.sound_beep1 = Sound("assets/audio/panel/206.wav") # self.sound_denied = Sound("assets/audio/access_denied.wav") # self.sound_deny1 = Sound("assets/audio/deny_1.wav") # self.sound_deny2 = Sound("assets/audio/deny_2.wav") self.attempts = 0 self.granted = False
def setup(self, all_sprites): # Load BG image all_sprites.add(LcarsBackgroundImage("assets/lcars_bg.png"), layer=0) # Time/Date display self.stardate = LcarsText(colours.BLUE, (12, 380), "", 1.5) self.lastClockUpdate = 0 all_sprites.add(self.stardate, layer=1) # Static text all_sprites.add(LcarsText(colours.BLACK, (8, 40), "LCARS 1123"), layer=1) all_sprites.add(LcarsText(colours.ORANGE, (0, 135), "NETWORK STATUS", 2), layer=1) # Interfaces all_sprites.add(LcarsButton(colours.RED_BROWN, "btn", (6, 660), "MAIN", self.logoutHandler), layer=2) all_sprites.add(LcarsButton(randomcolor(), "nav", (145, 15), "LAN", self.display_lan), layer=2) all_sprites.add(LcarsButton(randomcolor(), "nav", (200, 15), "INTERNET", self.display_internet), layer=2) all_sprites.add(LcarsButton(randomcolor(), "nav", (255, 15), "SERVER", self.nullfunction), layer=2) all_sprites.add(LcarsButton(randomcolor(), "nav", (310, 15), "", self.nullfunction), layer=2) all_sprites.add(LcarsButton(randomcolor(), "nav", (365, 15), "", self.nullfunction), layer=2) all_sprites.add(LcarsButton(randomcolor(), "btn", (140, 660), "ROUTERS", self.display_lan), layer=3) all_sprites.add(LcarsButton(randomcolor(), "btn", (200, 660), "PRINTERS", self.display_printers), layer=3) all_sprites.add(LcarsButton(randomcolor(), "btn", (260, 660), "SENSORS", self.display_sensors), layer=3) self.lan_buttons = all_sprites.get_sprites_from_layer(3) # Pull in information self.loadfile(all_sprites, "routers", 4) self.loadfile(all_sprites, "sites", 5) self.toggle_sprites(self.sites, False) self.loadfile(all_sprites, "sensors", 6) self.toggle_sprites(self.sensors, False) self.loadfile(all_sprites, "printers", 7) self.toggle_sprites(self.printers, False) # SFX self.beep1 = Sound("assets/audio/panel/201.wav") Sound("assets/audio/hail_2.wav").play()
def setup(self, all_sprites): all_sprites.add(LcarsBackgroundImage("assets/lcars_splash.png"), layer=0) all_sprites.add(LcarsText(colours.ORANGE, (270, -1), "AUTHORIZATION REQUIRED", 2), layer=1) all_sprites.add(LcarsGifImage("assets/animated/st_logo.gif", (103, 369), 50), layer=1) all_sprites.add(LcarsButton(colours.GREY_BLUE, "btn", (320, 130), "1", self.num_1), layer=2) all_sprites.add(LcarsButton(colours.GREY_BLUE, "btn", (370, 130), "2", self.num_2), layer=2) all_sprites.add(LcarsButton(colours.GREY_BLUE, "btn", (320, 270), "3", self.num_3), layer=2) all_sprites.add(LcarsButton(colours.GREY_BLUE, "btn", (370, 270), "4", self.num_4), layer=2) all_sprites.add(LcarsButton(colours.GREY_BLUE, "btn", (320, 410), "5", self.num_5), layer=2) all_sprites.add(LcarsButton(colours.GREY_BLUE, "btn", (370, 410), "6", self.num_6), layer=2) all_sprites.add(LcarsButton(colours.GREY_BLUE, "btn", (320, 550), "7", self.num_7), layer=2) all_sprites.add(LcarsButton(colours.GREY_BLUE, "btn", (370, 550), "8", self.num_8), layer=2) # sounds Sound("assets/audio/panel/215.wav").play() Sound("assets/audio/enter_authorization_code.wav").play() self.sound_granted = Sound("assets/audio/accessing.wav") self.sound_beep1 = Sound("assets/audio/panel/206.wav") self.sound_denied = Sound("assets/audio/access_denied.wav") self.sound_deny2 = Sound("assets/audio/deny_2.wav") ############ # SET PIN CODE WITH THIS VARIABLE ############ self.pin = 1234 ############ # Variables for PIN code verification self.correct = 0 self.pin_i = 0 self.granted = False
def setup(self, all_sprites): # Load BG image all_sprites.add(LcarsBackgroundImage("assets/lcars_bg.png"), layer=0) # Time/Date display self.stardate = LcarsText(colours.BLUE, (12, 380), "", 1.5) self.lastClockUpdate = 0 all_sprites.add(self.stardate, layer=1) # Static text all_sprites.add(LcarsText(colours.BLACK, (8, 40), "LCARS 1123"), layer=1) all_sprites.add(LcarsText(colours.ORANGE, (0, 135), "OPERATIONS", 2), layer=1) # Interfaces all_sprites.add(LcarsButton(colours.RED_BROWN, "btn", (6, 660), "MAIN", self.logoutHandler), layer=2) all_sprites.add(LcarsButton(randomcolor(), "nav", (145, 15), "TERMINAL", self.display_hw), layer=2) all_sprites.add(LcarsButton(randomcolor(), "nav", (200, 15), "LCARS UI", self.display_lcars), layer=2) all_sprites.add(LcarsButton(randomcolor(), "nav", (255, 15), "BUTTON 3", self.nullfunction), layer=2) all_sprites.add(LcarsButton(randomcolor(), "nav", (310, 15), "BUTTON 4", self.nullfunction), layer=2) all_sprites.add(LcarsButton(randomcolor(), "nav", (365, 15), "", self.nullfunction), layer=2) # Local hardware all_sprites.add(LcarsText(colours.ORANGE, (140, 175), "UPTIME", 2), layer=3) all_sprites.add(LcarsText(colours.BLUE, (200, 175), get_uptime(), 2), layer=3) all_sprites.add(LcarsText(colours.ORANGE, (260, 175), "SYSTEM LOAD AVG", 2), layer=3) all_sprites.add(LcarsText(colours.BLUE, (320, 175), get_load(), 2), layer=3) all_sprites.add(LcarsButton(colours.ORANGE, "btn", (380, 175), "REBOOT", self.reboot), layer=3) all_sprites.add(LcarsButton(colours.RED, "btn", (380, 350), "SHUTDOWN", self.shutdown), layer=3) self.hw = all_sprites.get_sprites_from_layer(3) # LCARS UI # Check for update if update_available() == False: all_sprites.add(LcarsText(colours.ORANGE, (140, 175), "LATEST VERSION INSTALLED", 2), layer=4) elif update_available() == True: all_sprites.add(LcarsText(colours.ORANGE, (140, 175), "UPDATE AVAILABLE", 2), layer=4) all_sprites.add(LcarsButton(colours.BLUE, "btn", (200, 175), "UPDATE LCARS", self.git_pull), layer=4) all_sprites.add(LcarsButton(colours.ORANGE, "btn", (260, 175), "RESTART LCARS", self.exit), layer=4) self.lcars = all_sprites.get_sprites_from_layer(4) self.toggle_sprites(self.lcars, False) # SFX self.beep1 = Sound("assets/audio/panel/201.wav") Sound("assets/audio/hail_2.wav").play()
def setup(self, all_sprites): all_sprites.add(LcarsBackgroundImage("assets/lcars_screen_2.png"), layer=0) all_sprites.add(LcarsGifImage("assets/gadgets/stlogorotating.gif", (103, 369), 50), layer=0) all_sprites.add(LcarsText(colours.ORANGE, (270, -1), "AUTHORIZATION REQUIRED", 2), layer=0) all_sprites.add(LcarsText(colours.BLUE, (330, -1), "ONLY AUTHORIZED PERSONNEL MAY ACCESS THIS TERMINAL", 1.5), layer=1) all_sprites.add(LcarsText(colours.BLUE, (360, -1), "TOUCH TERMINAL TO PROCEED", 1.5), layer=1) #all_sprites.add(LcarsText(colours.BLUE, (390, -1), "FAILED ATTEMPTS WILL BE REPORTED", 1.5),layer=1) all_sprites.add(LcarsButton(colours.GREY_BLUE, (320, 130), "1", self.num_1), layer=2) all_sprites.add(LcarsButton(colours.GREY_BLUE, (370, 130), "2", self.num_2), layer=2) all_sprites.add(LcarsButton(colours.GREY_BLUE, (320, 270), "3", self.num_3), layer=2) all_sprites.add(LcarsButton(colours.GREY_BLUE, (370, 270), "4", self.num_4), layer=2) all_sprites.add(LcarsButton(colours.GREY_BLUE, (320, 410), "5", self.num_5), layer=2) all_sprites.add(LcarsButton(colours.GREY_BLUE, (370, 410), "6", self.num_6), layer=2) all_sprites.add(LcarsButton(colours.GREY_BLUE, (320, 550), "7", self.num_7), layer=2) all_sprites.add(LcarsButton(colours.GREY_BLUE, (370, 550), "8", self.num_8), layer=2) self.layer1 = all_sprites.get_sprites_from_layer(1) self.layer2 = all_sprites.get_sprites_from_layer(2) # sounds Sound("assets/audio/panel/215.wav").play() self.sound_granted = Sound("assets/audio/accessing.wav") self.sound_beep1 = Sound("assets/audio/panel/201.wav") self.sound_denied = Sound("assets/audio/access_denied.wav") self.sound_deny1 = Sound("assets/audio/deny_1.wav") self.sound_deny2 = Sound("assets/audio/deny_2.wav") ############ # SET PIN CODE WITH THIS VARIABLE ############ self.pin = 7212 ############ self.reset()
def setup(self, all_sprites): # Load BG image all_sprites.add(LcarsBackgroundImage("assets/lcars_bg.png"), layer=0) # Time/Date display self.stardate = LcarsText(colours.BLUE, (12, 380), "", 1.5) self.lastClockUpdate = 0 all_sprites.add(self.stardate, layer=1) # Static text all_sprites.add(LcarsText(colours.BLACK, (8, 40), "LCARS 1123"), layer=1) all_sprites.add(LcarsText(colours.ORANGE, (0, 135), "SECTION NAME", 2), layer=1) # Interfaces all_sprites.add(LcarsButton(colours.RED_BROWN, "btn", (6, 660), "MAIN", self.logoutHandler), layer=2) all_sprites.add(LcarsButton(randomcolor(), "nav", (145, 15), "BUTTON 1", self.nullfunction), layer=2) all_sprites.add(LcarsButton(randomcolor(), "nav", (200, 15), "BUTTON 2", self.nullfunction), layer=2) all_sprites.add(LcarsButton(randomcolor(), "nav", (255, 15), "BUTTON 3", self.nullfunction), layer=2) all_sprites.add(LcarsButton(randomcolor(), "nav", (310, 15), "BUTTON 4", self.nullfunction), layer=2) all_sprites.add(LcarsButton(randomcolor(), "nav", (365, 15), "", self.nullfunction), layer=2) # Info text all_sprites.add(LcarsText(colours.BLUE, (244, 174), "TEXT GOES HERE", 1.5), layer=3) self.info_text = all_sprites.get_sprites_from_layer(3) # SFX self.beep1 = Sound("assets/audio/panel/201.wav") Sound("assets/audio/hail_2.wav").play()
def setup(self, all_sprites): # Load standard LCARS BG image all_sprites.add(LcarsBackgroundImage("assets/lcars_bg.png"), layer=0) # Setup time/date display self.stardate = LcarsText(colours.BLUE, (12, 380), "", 1.5) self.lastClockUpdate = 0 all_sprites.add(self.stardate, layer=1) # Static text all_sprites.add(LcarsText(colours.BLACK, (8, 40), "LCARS 1123"), layer=1) all_sprites.add(LcarsText(colours.ORANGE, (0, 135), "MAIN MENU", 2), layer=1) # Buttons all_sprites.add(LcarsButton(colours.RED_BROWN, "btn", (6, 660), "LOGOUT", self.load_idle), layer=4) all_sprites.add(LcarsButton(randomcolor(), "nav", (145, 15), "ENVIRO", self.load_enviro), layer=4) all_sprites.add(LcarsButton(randomcolor(), "nav", (200, 15), "NETWORK", self.load_network), layer=4) all_sprites.add(LcarsButton(randomcolor(), "nav", (255, 15), "POWER", self.load_power), layer=4) all_sprites.add(LcarsButton(randomcolor(), "nav", (310, 15), "OPERATIONS", self.load_auth), layer=4) all_sprites.add(LcarsButton(randomcolor(), "nav", (365, 15), "", self.load_template), layer=4) # Load data from file #returnpayload = read_txt("/opt/local/var/lib/lcars/alert") # First line in file is always going to be heading #all_sprites.add(LcarsText(colours.ORANGE, (137, 133), returnpayload[0], 1.8), layer=3) # Loop through results starting at second element #index = 1 #ypos = 190 #while index < len(returnpayload): # all_sprites.add(LcarsText(colours.BLUE, (ypos, 150), returnpayload[index], 1.5), layer=3) # Bump index and vertical pos # index += 1 # ypos += 50 # Rotating Deep Space 9 #yieldall_sprites.add(LcarsGifImage("assets/animated/ds9_3d.gif", (148, 475), 100), layer=1) weather = get_weather() #"%s\nTemperature: %s\nPrecipitations %s" % (current.summary, current.temperature, current.precipProbability) all_sprites.add(LcarsText(colours.BLUE, (150, 300), weather.summary , 1.5), layer=3) all_sprites.add(LcarsText(colours.BLUE, (200, 300), "Temperature: %s C / Feels like: %s" % (weather.temperature, weather.apparentTemperature) , 1.5), layer=3) all_sprites.add(LcarsText(colours.BLUE, (250, 300), "Wind: %s KPH %s" % (weather.windSpeed, degrees_to_cardinal(weather.windBearing)) , 1.5), layer=3) all_sprites.add(LcarsText(colours.BLUE, (300, 300), "Precipitations: %s" % (weather.precipProbability) , 1.5), layer=3) #all_sprites.add(LcarsText(colours.BLUE, (350, 300), "Type: %s / Qty: %s cm" % (weather.precipType, weather.precipAccumulation) , 1.5), layer=3) #all_sprites.add(LcarsText(colours.BLUE, (350, 300), "Sunset: %s / Sunrise: %s cm" % (weather.precipType, weather.precipAccumulation) , 1.5), layer=3) all_sprites.add(LcarsGifImage("assets/weather/%s.gif" % (weather.icon), (100, 144), 50), layer=1) self.beep1 = Sound("assets/audio/panel/201.wav") Sound("assets/audio/panel/220.wav").play()
def setup(self, all_sprites): all_sprites.add(LcarsBackgroundImage("assets/lcars_screen_1.png"), layer=0) # panel text all_sprites.add(LcarsText(colours.BLACK, (11, 75), "MOSF"), layer=1) all_sprites.add(LcarsText(colours.ORANGE, (0, 135), "LONG RANGE PROBE", 2.5), layer=1) all_sprites.add(LcarsText(colours.BLACK, (54, 667), "192 168 0 3"), layer=1) # date display self.stardate = LcarsText(colours.BLACK, (444, 506), "", 1) self.lastClockUpdate = 0 all_sprites.add(self.stardate, layer=1) # permanent buttons all_sprites.add(LcarsButton(colours.RED_BROWN, (6, 662), "LOGOUT", self.logoutHandler), layer=1) all_sprites.add(LcarsBlockSmall(colours.ORANGE, (211, 16), "ABOUT", self.aboutHandler), layer=1) all_sprites.add(LcarsBlockLarge(colours.BLUE, (145, 16), "DEMO", self.demoHandler), layer=1) all_sprites.add(LcarsBlockHuge(colours.PEACH, (249, 16), "EXPLORE", self.exploreHandler), layer=1) all_sprites.add(LcarsElbow(colours.BEIGE, (400, 16), "MAIN"), layer=1) # Sounds self.beep1 = Sound("assets/audio/panel/201.wav") #Sound("assets/audio/panel/220.wav").play() #-----Screens-----# # Main Screen all_sprites.add(LcarsText(colours.WHITE, (265, 458), "WELCOME", 1.5), layer=3) all_sprites.add(LcarsText(colours.BLUE, (244, 174), "TO THE Museum of Science Fiction", 1.5), layer=3) all_sprites.add(LcarsText(colours.BLUE, (286, 174), "LONG RANGE PROBE EXHIBIT", 1.5), layer=3) all_sprites.add(LcarsText(colours.BLUE, (330, 174), "LOOK AROUND", 1.5), layer=3) self.info_text = all_sprites.get_sprites_from_layer(3)
class ScreenTemplate(LcarsScreen): def setup(self, all_sprites): # Load BG image all_sprites.add(LcarsBackgroundImage("assets/lcars_bg.png"), layer=0) # Time/Date display self.stardate = LcarsText(colours.BLUE, (12, 380), "", 1.5) self.lastClockUpdate = 0 all_sprites.add(self.stardate, layer=1) # Static text all_sprites.add(LcarsText(colours.BLACK, (8, 40), "LCARS 1123"), layer=1) all_sprites.add(LcarsText(colours.ORANGE, (0, 135), "SECTION NAME", 2), layer=1) # Interfaces all_sprites.add(LcarsButton(colours.RED_BROWN, "btn", (6, 660), "MAIN", self.logoutHandler), layer=2) all_sprites.add(LcarsButton(randomcolor(), "nav", (145, 15), "BUTTON 1", self.nullfunction), layer=2) all_sprites.add(LcarsButton(randomcolor(), "nav", (200, 15), "BUTTON 2", self.nullfunction), layer=2) all_sprites.add(LcarsButton(randomcolor(), "nav", (255, 15), "BUTTON 3", self.nullfunction), layer=2) all_sprites.add(LcarsButton(randomcolor(), "nav", (310, 15), "BUTTON 4", self.nullfunction), layer=2) all_sprites.add(LcarsButton(randomcolor(), "nav", (365, 15), "", self.nullfunction), layer=2) # Info text all_sprites.add(LcarsText(colours.BLUE, (244, 174), "TEXT GOES HERE", 1.5), layer=3) self.info_text = all_sprites.get_sprites_from_layer(3) # SFX self.beep1 = Sound("assets/audio/panel/201.wav") Sound("assets/audio/hail_2.wav").play() def update(self, screenSurface, fpsClock): if pygame.time.get_ticks() - self.lastClockUpdate > 1000: self.stardate.setText("{}".format( datetime.now().strftime("%a %b %d, %Y - %X"))) self.lastClockUpdate = pygame.time.get_ticks() LcarsScreen.update(self, screenSurface, fpsClock) def handleEvents(self, event, fpsClock): LcarsScreen.handleEvents(self, event, fpsClock) if event.type == pygame.MOUSEBUTTONDOWN: self.beep1.play() if event.type == pygame.MOUSEBUTTONUP: return False def hideInfoText(self): if self.info_text[0].visible: for sprite in self.info_text: sprite.visible = False def nullfunction(self, item, event, clock): print("I am a fish.") def logoutHandler(self, item, event, clock): from screens.main import ScreenMain self.loadScreen(ScreenMain())
def setup(self, all_sprites): # Weather parameters self.temperature = -9999 self.tStr = None self.pressure = -9999 self.pStr = None self.humidity = -9999 self.hStr = None self.battery = -9999 self.load = -9999 self.pwrStr = None self.timestamp = -9999 self.tsStr = None self.displayedValue = "Temp" self.paramStr = self.tStr self.timestampDT = dt.datetime.now() self.beatWarningTime = 10. * 60. self.runningCam = False self.cmdCamGo = [ 'sudo', '-H', '-u', 'pi', 'adafruit-io', 'camera', 'start', '-f', 'camera_feed', '-m', 'false', '-r', '5', '-v', 'false' ] self.cmdCamStop = [ 'sudo', '-H', '-u', 'pi', 'adafruit-io', 'camera', 'stop' ] # Background image/overall layout script_dir = dirname(__file__) ipath = join(script_dir, '../assets/mainscreen.png') all_sprites.add(LcarsBackgroundImage(ipath), layer=0) # Screen brightness we start from self.sbrightness = 0.5 # Need this to not crash the auto brightness # button, so choose a default that's easily elimated # from any logging activity just in case self.lux = 86.75309 # Screen control buttons buttonBri = LcarsButton((255, 204, 153), (5, 270), "BRIGHTER", self.screenBrighterHandler) buttonDim = LcarsButton((255, 153, 102), (5, 375), "DIMMER", self.screenDimmerHandler) buttonOff = LcarsButton((204, 102, 102), (50, 270), "OFF", self.logoutHandler) # Add this one to self to make it easily changed elsewhere self.buttonAuto = LcarsButton(colours.BLUE, (50, 375), "AUTO", self.autoBrightHandler) all_sprites.add(buttonBri, layer=4) all_sprites.add(buttonDim, layer=4) all_sprites.add(buttonOff, layer=4) all_sprites.add(self.buttonAuto, layer=4) # Header text all_sprites.add(LcarsText((255, 204, 153), (-5, 55), "WEATHER", size=3), layer=1) # date display sDateFmt = "%d%m.%y %H:%M:%S" sDate = "{}".format(datetime.now().strftime(sDateFmt)) self.stardate = LcarsText(colours.BLUE, (55, 55), sDate, size=2.0) self.lastClockUpdate = 0 self.whenLastRead = dt.datetime.now() all_sprites.add(self.stardate, layer=1) # Section/Parameter ID Text self.sensorTimestampText = LcarsText((0, 0, 0), (95, 275), "LAST UPDATE: ", 1.0) # self.sectionText = LcarsText((255, 204, 153), (120, 55), # "TEMPERATURE:", 3.) all_sprites.add(self.sensorTimestampText, layer=4) # all_sprites.add(self.sectionText, layer=4) # Section Value Text. If the temperature isn't nuts, it's probably # a good enough value to display so start with that. self.paramValueText = LcarsText((255, 204, 153), (170, -1), "XX.X C|XX.X F", 4.5) all_sprites.add(self.paramValueText, layer=3) self.info_text = all_sprites.get_sprites_from_layer(3) # buttons # (Bottom) #buttrowpos = (270, 65) # (Top) buttrowpos = (125, 55) self.butt1 = LcarsButton(colours.PURPLE, buttrowpos, "Temperature", self.cTempHandler) self.butt2 = LcarsButton( colours.PURPLE, (buttrowpos[0], buttrowpos[1] + self.butt1.size[0]), "Pressure", self.cPressHandler) self.butt3 = LcarsButton(colours.PURPLE, (buttrowpos[0], buttrowpos[1] + self.butt1.size[0] + self.butt2.size[0]), "Humidity", self.cHumiHandler) self.butt4 = LcarsButton( colours.PURPLE, (buttrowpos[0], buttrowpos[1] + self.butt1.size[0] + self.butt2.size[0] + self.butt3.size[0]), "Power", self.cPowerHandler) all_sprites.add(self.butt1, layer=5) all_sprites.add(self.butt2, layer=5) all_sprites.add(self.butt3, layer=5) all_sprites.add(self.butt4, layer=5) campos = (270, 320) self.buttcam = LcarsButton((204, 102, 102), campos, "KITTY CAM", self.camHandler) all_sprites.add(self.buttcam, layer=4) # Local (intranet) MQTT server setup; Hopefully we can can start # with the current values already there if all is well with MQTT self.client = mqtt.Client() self.client.on_connect = self.on_connect self.client.on_message = self.on_message self.client.username_pw_set("WeatherduinoUser", "rainyday") self.client.connect("localhost", 1883, 60) # Non-blocking call that processes network traffic, dispatches # callbacks and handles reconnecting. Must call client.loop_stop() # when you're done with stuff. self.client.loop_start() if self.temperature != -9999: self.paramStr = self.tStr # Note: We need to explicitly update the strings since they're # caught in the time loop and may lag self.updateDisplayedSensorStrings() # Highlight the default choice so we know where we are and trigger self.butt1.changeColor(colours.WHITE) self.butt2.changeColor(self.butt2.inactiveColor) self.butt3.changeColor(self.butt3.inactiveColor) self.butt4.changeColor(self.butt4.inactiveColor) # Automatically control screen brightness at start? self.autosbrightness = True self.buttonAuto.changeColor(colours.WHITE)
class ScreenOps(LcarsScreen): def setup(self, all_sprites): # Load BG image all_sprites.add(LcarsBackgroundImage("assets/lcars_bg.png"), layer=0) # Time/Date display self.stardate = LcarsText(colours.BLUE, (12, 380), "", 1.5) self.lastClockUpdate = 0 all_sprites.add(self.stardate, layer=1) # Static text all_sprites.add(LcarsText(colours.BLACK, (8, 40), "LCARS 1123"), layer=1) all_sprites.add(LcarsText(colours.ORANGE, (0, 135), "OPERATIONS", 2), layer=1) # Interfaces all_sprites.add(LcarsButton(colours.RED_BROWN, "btn", (6, 660), "MAIN", self.logoutHandler), layer=2) all_sprites.add(LcarsButton(randomcolor(), "nav", (145, 15), "TERMINAL", self.display_hw), layer=2) all_sprites.add(LcarsButton(randomcolor(), "nav", (200, 15), "LCARS UI", self.display_lcars), layer=2) all_sprites.add(LcarsButton(randomcolor(), "nav", (255, 15), "BUTTON 3", self.nullfunction), layer=2) all_sprites.add(LcarsButton(randomcolor(), "nav", (310, 15), "BUTTON 4", self.nullfunction), layer=2) all_sprites.add(LcarsButton(randomcolor(), "nav", (365, 15), "", self.nullfunction), layer=2) # Local hardware all_sprites.add(LcarsText(colours.ORANGE, (140, 175), "UPTIME", 2), layer=3) all_sprites.add(LcarsText(colours.BLUE, (200, 175), get_uptime(), 2), layer=3) all_sprites.add(LcarsText(colours.ORANGE, (260, 175), "SYSTEM LOAD AVG", 2), layer=3) all_sprites.add(LcarsText(colours.BLUE, (320, 175), get_load(), 2), layer=3) all_sprites.add(LcarsButton(colours.ORANGE, "btn", (380, 175), "REBOOT", self.reboot), layer=3) all_sprites.add(LcarsButton(colours.RED, "btn", (380, 350), "SHUTDOWN", self.shutdown), layer=3) self.hw = all_sprites.get_sprites_from_layer(3) # LCARS UI # Check for update if update_available() == False: all_sprites.add(LcarsText(colours.ORANGE, (140, 175), "LATEST VERSION INSTALLED", 2), layer=4) elif update_available() == True: all_sprites.add(LcarsText(colours.ORANGE, (140, 175), "UPDATE AVAILABLE", 2), layer=4) all_sprites.add(LcarsButton(colours.BLUE, "btn", (200, 175), "UPDATE LCARS", self.git_pull), layer=4) all_sprites.add(LcarsButton(colours.ORANGE, "btn", (260, 175), "RESTART LCARS", self.exit), layer=4) self.lcars = all_sprites.get_sprites_from_layer(4) self.toggle_sprites(self.lcars, False) # SFX self.beep1 = Sound("assets/audio/panel/201.wav") Sound("assets/audio/hail_2.wav").play() def update(self, screenSurface, fpsClock): if pygame.time.get_ticks() - self.lastClockUpdate > 1000: self.stardate.setText("{}".format(datetime.now().strftime("%a %b %d, %Y - %X"))) self.lastClockUpdate = pygame.time.get_ticks() LcarsScreen.update(self, screenSurface, fpsClock) def handleEvents(self, event, fpsClock): LcarsScreen.handleEvents(self, event, fpsClock) if event.type == pygame.MOUSEBUTTONDOWN: self.beep1.play() if event.type == pygame.MOUSEBUTTONUP: return False # Button functions def display_hw(self, item, event, clock): self.toggle_sprites(self.hw, True) self.toggle_sprites(self.lcars, False) def display_lcars(self, item, event, clock): self.toggle_sprites(self.hw, False) self.toggle_sprites(self.lcars, True) def toggle_sprites(self, object, status): for sprite in object: sprite.visible = status def nullfunction(self, item, event, clock): print("I am a fish.") def logoutHandler(self, item, event, clock): from screens.main import ScreenMain self.loadScreen(ScreenMain()) def reboot(self, item, event, clock): subprocess.call(["reboot"]) def shutdown(self, item, event, clock): subprocess.call(["shutdown"]) def git_pull(self, item, event, clock): subprocess.call(["git", "pull"]) # Force LCARS restart sys.exit() def exit(self, item, event, clock): sys.exit()
class ScreenMain(LcarsScreen): def setup(self, all_sprites): all_sprites.add(LcarsBackgroundImage("assets/lcars_screen_1b.png"), layer=0) # panel text all_sprites.add(LcarsText(colours.BLACK, (11, 52), "LCARS 105"), layer=1) all_sprites.add(LcarsText(colours.ORANGE, (0, 135), "HOME AUTOMATION", 2), layer=1) all_sprites.add(LcarsText(colours.BLACK, (444, 612), "192 168 0 3"), layer=1) # info text all_sprites.add(LcarsText(colours.WHITE, (192, 174), "EVENT LOG:", 1.5), layer=3) all_sprites.add(LcarsText(colours.BLUE, (244, 174), "2 ALARM ZONES TRIGGERED", 1.5), layer=3) all_sprites.add(LcarsText(colours.BLUE, (286, 174), "14.3 kWh USED YESTERDAY", 1.5), layer=3) all_sprites.add(LcarsText(colours.BLUE, (330, 174), "1.3 Tb DATA USED THIS MONTH", 1.5), layer=3) self.info_text = all_sprites.get_sprites_from_layer(3) # date display self.stardate = LcarsText(colours.BLUE, (12, 380), "STAR DATE 2711.05 17:54:32", 1.5) self.lastClockUpdate = 0 all_sprites.add(self.stardate, layer=1) # buttons all_sprites.add(LcarsButton(colours.RED_BROWN, "rounded", (6, 662), "LOGOUT", self.logoutHandler), layer=4) all_sprites.add(LcarsButton(colours.BEIGE, "rect", (145, 15), "SENSORS", self.sensorsHandler), layer=4) all_sprites.add(LcarsButton(colours.PURPLE, "rect", (200, 15), "GAUGES", self.gaugesHandler), layer=4) all_sprites.add(LcarsButton(colours.PEACH, "rect", (255, 15), "WEATHER", self.weatherHandler), layer=4) # gadgets all_sprites.add(LcarsGifImage("assets/gadgets/fwscan.gif", (277, 556), 100), layer=1) self.sensor_gadget = LcarsGifImage("assets/gadgets/lcars_anim2.gif", (235, 150), 100) self.sensor_gadget.visible = False all_sprites.add(self.sensor_gadget, layer=2) self.dashboard = LcarsImage("assets/gadgets/dashboard.png", (187, 232)) self.dashboard.visible = False all_sprites.add(self.dashboard, layer=2) self.weather = LcarsImage("assets/weather.jpg", (188, 122)) self.weather.visible = False all_sprites.add(self.weather, layer=2) #all_sprites.add(LcarsMoveToMouse(colours.WHITE), layer=1) self.beep1 = Sound("assets/audio/panel/201.wav") Sound("assets/audio/panel/220.wav").play() def update(self, screenSurface, fpsClock): if pygame.time.get_ticks() - self.lastClockUpdate > 1000: self.stardate.setText("STAR DATE {}".format( datetime.now().strftime("%d%m.%y %H:%M:%S"))) self.lastClockUpdate = pygame.time.get_ticks() LcarsScreen.update(self, screenSurface, fpsClock) def handleEvents(self, event, fpsClock): LcarsScreen.handleEvents(self, event, fpsClock) if event.type == pygame.MOUSEBUTTONDOWN: self.beep1.play() if event.type == pygame.MOUSEBUTTONUP: return False def hideInfoText(self): if self.info_text[0].visible: for sprite in self.info_text: sprite.visible = False def gaugesHandler(self, item, event, clock): self.hideInfoText() self.sensor_gadget.visible = False self.dashboard.visible = True self.weather.visible = False def sensorsHandler(self, item, event, clock): self.hideInfoText() self.sensor_gadget.visible = True self.dashboard.visible = False self.weather.visible = False def weatherHandler(self, item, event, clock): self.hideInfoText() self.sensor_gadget.visible = False self.dashboard.visible = False self.weather.visible = True def logoutHandler(self, item, event, clock): from screens.authorize import ScreenAuthorize self.loadScreen(ScreenAuthorize())
def setup(self, all_sprites): # Load standard LCARS BG image all_sprites.add(LcarsBackgroundImage("assets/lcars_bg.png"), layer=0) # Setup time/date display self.stardate = LcarsText(colours.BLUE, (12, 380), "", 1.5) self.lastClockUpdate = 0 all_sprites.add(self.stardate, layer=1) # Static text all_sprites.add(LcarsText(colours.BLACK, (8, 40), "LCARS 1123"), layer=1) all_sprites.add(LcarsText(colours.ORANGE, (0, 135), "MAIN MENU", 2), layer=1) # Buttons all_sprites.add(LcarsButton(colours.RED_BROWN, "btn", (6, 660), "LOGOUT", self.load_idle), layer=4) all_sprites.add(LcarsButton(randomcolor(), "nav", (145, 15), "ENVIRO", self.load_enviro), layer=4) all_sprites.add(LcarsButton(randomcolor(), "nav", (200, 15), "NETWORK", self.load_network), layer=4) all_sprites.add(LcarsButton(randomcolor(), "nav", (255, 15), "POWER", self.load_power), layer=4) all_sprites.add(LcarsButton(randomcolor(), "nav", (310, 15), "OPERATIONS", self.load_auth), layer=4) all_sprites.add(LcarsButton(randomcolor(), "nav", (365, 15), "", self.load_template), layer=4) # Load data from file returnpayload = read_txt("/var/lib/lcars/alert") # First line in file is always going to be heading all_sprites.add(LcarsText(colours.ORANGE, (137, 133), returnpayload[0], 1.8), layer=3) # Loop through results starting at second element index = 1 ypos = 190 while index < len(returnpayload): all_sprites.add(LcarsText(colours.BLUE, (ypos, 150), returnpayload[index], 1.5), layer=3) # Bump index and vertical pos index += 1 ypos += 50 # Rotating Deep Space 9 all_sprites.add(LcarsGifImage("assets/animated/ds9_3d.gif", (148, 475), 100), layer=1) self.beep1 = Sound("assets/audio/panel/201.wav") Sound("assets/audio/panel/220.wav").play()
def setup(self, all_sprites): all_sprites.add(LcarsBackgroundImage("assets/lcars_screen_1b.png"), layer=0) # panel text all_sprites.add(LcarsText(colours.BLACK, (11, 52), "LCARS 105"), layer=1) all_sprites.add(LcarsText(colours.ORANGE, (0, 135), "HOME AUTOMATION", 2), layer=1) all_sprites.add(LcarsText(colours.BLACK, (444, 612), "192 168 0 3"), layer=1) # info text all_sprites.add(LcarsText(colours.WHITE, (192, 174), "EVENT LOG:", 1.5), layer=3) all_sprites.add(LcarsText(colours.BLUE, (244, 174), "2 ALARM ZONES TRIGGERED", 1.5), layer=3) all_sprites.add(LcarsText(colours.BLUE, (286, 174), "14.3 kWh USED YESTERDAY", 1.5), layer=3) all_sprites.add(LcarsText(colours.BLUE, (330, 174), "1.3 Tb DATA USED THIS MONTH", 1.5), layer=3) self.info_text = all_sprites.get_sprites_from_layer(3) # date display self.stardate = LcarsText(colours.BLUE, (12, 380), "STAR DATE 2711.05 17:54:32", 1.5) self.lastClockUpdate = 0 all_sprites.add(self.stardate, layer=1) # buttons all_sprites.add(LcarsButton(colours.RED_BROWN, "rounded", (6, 662), "LOGOUT", self.logoutHandler), layer=4) all_sprites.add(LcarsButton(colours.BEIGE, "rect", (145, 15), "SENSORS", self.sensorsHandler), layer=4) all_sprites.add(LcarsButton(colours.PURPLE, "rect", (200, 15), "GAUGES", self.gaugesHandler), layer=4) all_sprites.add(LcarsButton(colours.PEACH, "rect", (255, 15), "WEATHER", self.weatherHandler), layer=4) # gadgets all_sprites.add(LcarsGifImage("assets/gadgets/fwscan.gif", (277, 556), 100), layer=1) self.sensor_gadget = LcarsGifImage("assets/gadgets/lcars_anim2.gif", (235, 150), 100) self.sensor_gadget.visible = False all_sprites.add(self.sensor_gadget, layer=2) self.dashboard = LcarsImage("assets/gadgets/dashboard.png", (187, 232)) self.dashboard.visible = False all_sprites.add(self.dashboard, layer=2) self.weather = LcarsImage("assets/weather.jpg", (188, 122)) self.weather.visible = False all_sprites.add(self.weather, layer=2) #all_sprites.add(LcarsMoveToMouse(colours.WHITE), layer=1) self.beep1 = Sound("assets/audio/panel/201.wav") Sound("assets/audio/panel/220.wav").play()
class ScreenExplore(LcarsScreen): def setup(self, all_sprites): all_sprites.add(LcarsBackgroundImage("assets/lcars_screen_1.png"), layer=0) # panel text all_sprites.add(LcarsText(colours.BLACK, (11, 75), "MOSF"), layer=1) all_sprites.add(LcarsText(colours.ORANGE, (0, 135), "LONG RANGE PROBE", 2.5), layer=1) all_sprites.add(LcarsText(colours.BLACK, (54, 667), "192 168 0 3"), layer=1) # date display self.stardate = LcarsText(colours.BLACK, (444, 506), "", 1) self.lastClockUpdate = 0 all_sprites.add(self.stardate, layer=1) # permanent buttons all_sprites.add(LcarsButton(colours.RED_BROWN, (6, 662), "LOGOUT", self.logoutHandler), layer=1) all_sprites.add(LcarsBlockSmall(colours.ORANGE, (211, 16), "ABOUT", self.aboutHandler), layer=1) all_sprites.add(LcarsBlockLarge(colours.BLUE, (145, 16), "DEMO", self.demoHandler), layer=1) all_sprites.add(LcarsBlockHuge(colours.PEACH, (249, 16), "EXPLORE", self.exploreHandler), layer=1) all_sprites.add(LcarsElbow(colours.BEIGE, (400, 16), "MAIN", self.mainHandler), layer=1) # Sounds self.beep1 = Sound("assets/audio/panel/201.wav") #Sound("assets/audio/panel/220.wav").play() ###################################################################### ##### Explore Screen ##### # Explore Screen --------------------------------------------------------------------------------- all_sprites.add(LcarsText(colours.RED_BROWN, (142, 140), "Select a section for more information", 1.25), layer=70) self.explore_screen_text = all_sprites.get_sprites_from_layer(70) # self.hideText(self.explore_screen_text) self.probe_forward_image = LcarsImage("assets/probe_front.png", (172, 500), self.forwardHandler) all_sprites.add(self.probe_forward_image, layer =70) self.probe_aft_image = LcarsImage("assets/probe_rear.png", (172, 150), self.aftHandler) all_sprites.add(self.probe_aft_image, layer=70) ##### Forward Section ##### self.forward_text = LcarsText(colours.RED_BROWN, (142, 140), "Select a component for more information", 1.25) self.forward_text.visible = False all_sprites.add(self.forward_text, layer=71) # self.forward_text.visible = False self.forward_plate = LcarsImage("assets/forward/front_section.png", (172, 150)) self.forward_plate.visible = False all_sprites.add(self.forward_plate, layer =71) ## Back Forward Button ## self.forward_button = LcarsTabBlock(colours.RED_BROWN, (372, 650), "BACK", self.forwardHandler) self.forward_button.visible = False all_sprites.add(self.forward_button, layer=60) ## Back Aft Button ## self.aft_button = LcarsTabBlock(colours.RED_BROWN, (372, 650), "BACK", self.exploreHandler) self.aft_button.visible = False all_sprites.add(self.aft_button, layer=60) # BTO ARRAY # all_sprites.add(LcarsText(colours.WHITE, (112, 140), "B.T.O. ARRAY", 1.75), layer=61) all_sprites.add(LcarsText(colours.ORANGE, (162, 140), "The B.T.O. Array is the primary method of communication for the probe.", 1.25), layer=61) all_sprites.add(LcarsText(colours.ORANGE, (192, 140), "The array is entirely composed of the S.B.S. High-Gain Parabolic Antenna,", 1.25), layer = 61) all_sprites.add(LcarsText(colours.ORANGE, (222, 140), "which is capable of simultaneous dual transmission in the S and X bands", 1.25), layer=61) all_sprites.add(LcarsText(colours.ORANGE, (252, 140), "and receipt of control commands in the Ka and Ku bands. The array is", 1.25), layer=61) all_sprites.add(LcarsText(colours.ORANGE, (282, 140), "paired with the Yokel Sensor Suite to determine physical properties of ", 1.25), layer=61) all_sprites.add(LcarsText(colours.ORANGE, (312, 140), "local bodies using microwave radiation.", 1.25), layer=61) self.communication_text = all_sprites.get_sprites_from_layer(61) self.hideText(self.communication_text) # YOKEL SENSOR SUITE # all_sprites.add(LcarsText(colours.WHITE, (112, 140), "YOKEL SENSOR SUITE", 1.75), layer=62) all_sprites.add(LcarsText(colours.ORANGE, (162, 140), "The Yokel Sensor Suite houses the scientific payload and guidance", 1.25), layer=62) all_sprites.add(LcarsText(colours.ORANGE, (192, 140), "system on the probe. The instruments contained within are:", 1.25), layer=62) all_sprites.add(LcarsText(colours.WHITE, (222, 150), "Autonomous Telemetry Guidance Unit", 1.25), layer=62) all_sprites.add(LcarsText(colours.WHITE, (242, 150), "Energetic Particle Detector", 1.25), layer=62) all_sprites.add(LcarsText(colours.WHITE, (262, 150), "Gravitational Mapping Unit", 1.25), layer=62) all_sprites.add(LcarsText(colours.WHITE, (282, 150), "High Energy Multi-Spectral Analyzer", 1.25), layer=62) all_sprites.add(LcarsText(colours.WHITE, (302, 150), "Magnetometry Suite", 1.25), layer=62) all_sprites.add(LcarsText(colours.WHITE, (322, 150), "Radar Detection & Tracking System", 1.25), layer=62) all_sprites.add(LcarsText(colours.WHITE, (342, 150), "Radio Science Array", 1.25), layer=62) all_sprites.add(LcarsText(colours.WHITE, (362, 150), "Space Radiation Measurement System", 1.25), layer=62) all_sprites.add(LcarsText(colours.ORANGE, (392, 140), "Collected data is stored in the Optical Data Chips for later processing.", 1.25), layer=62) self.sensor_text = all_sprites.get_sprites_from_layer(62) self.hideText(self.sensor_text) # Probe Computers # all_sprites.add(LcarsText(colours.WHITE, (112, 140), "PROBE COMPUTERS", 1.75), layer=63) all_sprites.add(LcarsText(colours.ORANGE, (162, 140), "This probe features two onboard computers, the Guidance Computer and", 1.25), layer=63) all_sprites.add(LcarsText(colours.WHITE, (162, 473), "Guidance Computer", 1.25), layer=63) all_sprites.add(LcarsText(colours.ORANGE, (192, 140), "the Data Processing Unit , which handle all data and control processes.", 1.25), layer=63) all_sprites.add(LcarsText(colours.WHITE, (192, 165), "Data Processing Unit", 1.25), layer=63) all_sprites.add(LcarsText(colours.ORANGE, (222, 140), "The Guidance Computer receives control commands through the BTO ", 1.25), layer=63) all_sprites.add(LcarsText(colours.ORANGE, (252, 140), "Array, and local object data from the Yokel Sensor Suite, to ensure safe", 1.25), layer=63) all_sprites.add(LcarsText(colours.ORANGE, (282, 140), "travel. The Data Processing Unit receives all raw data from the Optical", 1.25), layer=63) all_sprites.add(LcarsText(colours.ORANGE, (312, 140), "and processes the data for transmission. For redundancy, both", 1.25), layer=63) all_sprites.add(LcarsText(colours.ORANGE, (342, 140), "computers are independently capable of assuming the others' duties.", 1.25), layer=63) self.computer_text = all_sprites.get_sprites_from_layer(63) self.hideText(self.computer_text) # Optical Data Chips # all_sprites.add(LcarsText(colours.WHITE, (112, 140), "OPTICAL DATA CHIPS", 1.75), layer=64) all_sprites.add(LcarsText(colours.ORANGE, (162, 140), "This probe is equipped with 24 optical data chips for the storage of sensor", 1.25), layer=64) all_sprites.add(LcarsText(colours.ORANGE, (192, 140), "and control data. Each chip, which can store up to 830 TB of data, is", 1.25), layer=64) all_sprites.add(LcarsText(colours.ORANGE, (222, 140), "constructed of a nano-structured quartz composite. Data is read/written", 1.25), layer=64) all_sprites.add(LcarsText(colours.ORANGE, (252, 140), "to the chips using a Smith-Taylor laser system.", 1.25), layer=64) self.chip_text = all_sprites.get_sprites_from_layer(64) self.hideText(self.chip_text) # Lofton Microfusion Core # all_sprites.add(LcarsText(colours.WHITE, (112, 140), "LOFTON MICROFUSION CORE", 1.75), layer=65) all_sprites.add(LcarsText(colours.ORANGE, (162, 140), "All of the required power for the probe is provided by the Lofton", 1.25), layer=65) all_sprites.add(LcarsText(colours.ORANGE, (192, 140), "Microfusion Core. Encased within a shielded tungsten-titanium shell,", 1.25), layer=65) all_sprites.add(LcarsText(colours.ORANGE, (222, 140), "11.3 KW of power are produced from a micro-aneutronic fusion reaction ", 1.25), layer=65) all_sprites.add(LcarsText(colours.ORANGE, (252, 140), "which is converted to electricity via electrostatic direct conversion.", 1.25), layer=65) all_sprites.add(LcarsText(colours.ORANGE, (282, 140), "Of the 11.3 KW produced, 8 KW are used by the ion propulsion system,", 1.25), layer=65) all_sprites.add(LcarsText(colours.ORANGE, (312, 140), "1.4 KW by the sensor suite, 1 KW by the computers, and 0.9 KW by the", 1.25), layer=65) all_sprites.add(LcarsText(colours.ORANGE, (342, 140), "communication array during normal operation. Helium is used for the", 1.25), layer=65) all_sprites.add(LcarsText(colours.ORANGE, (372, 140), "fusion reaction which is provided by the monopropellant tank.", 1.25), layer=65) self.fusion_text = all_sprites.get_sprites_from_layer(65) self.hideText(self.fusion_text) ###### AFT SECTION ###### all_sprites.add(LcarsText(colours.WHITE, (112, 140), "PROPULSION SYSTEM", 1.75), layer=66) all_sprites.add(LcarsText(colours.ORANGE, (162, 140), "After launch, the probe is driven by the Kehrer Hybrid Ion Drive, is", 1.25), layer=66) all_sprites.add(LcarsText(colours.ORANGE, (192, 140), "capable of both ion and chemical propulsion, and is comprised of the ", 1.25), layer=66) all_sprites.add(LcarsText(colours.ORANGE, (222, 140), "engine, thrusters, and fuel tanks. Ion propulsion creates thrust by drawing", 1.25), layer=66) all_sprites.add(LcarsText(colours.ORANGE, (252, 140), "power from the fusion core to accelerate and expel Xenon ions from the", 1.25), layer=66) all_sprites.add(LcarsText(colours.ORANGE, (282, 140), "two, 420 kg storage tanks, and is the main method of propulsion. For quick", 1.25), layer=66) all_sprites.add(LcarsText(colours.ORANGE, (312, 140), "changes in velocity, the chemical propulsion system is activated. This", 1.25), layer=66) all_sprites.add(LcarsText(colours.ORANGE, (342, 140), "system uses the monopropellant hydrazine, which is stored in the 300 kg ", 1.25), layer=66) all_sprites.add(LcarsText(colours.ORANGE, (372, 140), "storage tank. The combination of two different propulsion methods allows", 1.25), layer=66) all_sprites.add(LcarsText(colours.ORANGE, (402, 140), "the probe a versatile mix of range and maneuverability.", 1.25), layer=66) self.propulsion_text = all_sprites.get_sprites_from_layer(66) self.hideText(self.propulsion_text) #TEST self.test = LcarsButton(colours.RED_BROWN, (6, 662), "LOGOUT", self.logoutHandler) self.test.visible = False all_sprites.add(self.test, layer = 4) def hideText(self, name): if name[0].visible: for sprite in name: sprite.visible = False def showText(self, name): for sprite in name: sprite.visible = True def update(self, screenSurface, fpsClock): if pygame.time.get_ticks() - self.lastClockUpdate > 1000: self.stardate.setText("EARTH DATE {}".format(datetime.now().strftime("%m.%d.%y %H:%M:%S"))) self.lastClockUpdate = pygame.time.get_ticks() LcarsScreen.update(self, screenSurface, fpsClock) def handleEvents(self, event, fpsClock): LcarsScreen.handleEvents(self, event, fpsClock) if event.type == pygame.MOUSEBUTTONDOWN: self.beep1.play() if event.type == pygame.MOUSEBUTTONUP: return False def logoutHandler(self, item, event, clock): # demo() from screens.authorize import ScreenAuthorize self.loadScreen(ScreenAuthorize()) def aboutHandler(self, item, event, clock): # demo() from screens.aboutScreen import ScreenAbout self.loadScreen(ScreenAbout()) def demoHandler(self, item, event, clock): demo(a) # from screens.demoScreen import ScreenDemo # self.loadScreen(ScreenDemo()) def exploreHandler(self, item, event, clock): # demo() # Turn off all content here self.test.visible = False self.loadScreen(ScreenExplore()) def mainHandler(self, item, event, clock): # demo() from screens.main import ScreenMain self.loadScreen(ScreenMain()) ## ****** Explore Screen Handlers ****** # Forward Section forwardHandler # - Open front hatches & activate red interior lighting # Communications Array communicationsHandler # - Illuminate # Sensors Array sensorsHandler # - Change spin speed & light up and down? sonar beep? # Data Acquisition & Processing Node computerHandler # - Illuminate (fiber optic lighting) # Optical Data Storage Modules chipsHandler # - Pulse # Power System powerHandler # - Pulse # Aft Section aftHandler # - Open rear hatches # Ion Thrusters thrustersHandler # - Pulse (have 2 LED colors, Red & Blue) # Ion Drive driveHandler # - Pulse (have 2 LED colors, Red & Blue) # Fuel Tanks tanksHandler # - illumate section by section # Impulse Chemical Reaction Tank impulseHandler # - Illuminate # ** Main ** def forwardHandler(self, item, event, clock): self.hideText(self.explore_screen_text) self.probe_forward_image.visible = False self.probe_aft_image.visible = False self.hideText(self.propulsion_text) self.forward_button.visible = False self.hideText(self.communication_text) self.hideText(self.sensor_text) self.hideText(self.computer_text) self.hideText(self.chip_text) self.hideText(self.fusion_text) # self.showText(self.forward_text) self.forward_text.visible = True # self.aft_button.visible = True #Put others here self.forward_plate.visible = True def aftHandler(self, item, event, clock): self.hideText(self.explore_screen_text) self.probe_forward_image.visible = False self.probe_aft_image.visible = False self.showText(self.propulsion_text) self.aft_button.visible = False door_br(a, 1) door_bl(a, 1) for i in range(60, 0, -15): blue_thruster(a, 1) time.sleep(float(i)/100) red_thruster(a, 1) time.sleep(float(i)/200) blue_thruster(a, 0) time.sleep(float(i)/100) red_thruster(a, 0) blue_thruster(a, 1) red_thruster(a, 1) time.sleep(2) areset(a) # ** Forward ** def communicationsHandler(self, item, event, clock): self.showText(self.communication_text) self.aft_button.visible = False self.forward_button.visible = True def sensorsHandler(self, item, event, clock): self.showText(self.sensor_text) self.aft_button.visible = False self.forward_button.visible = True def computerHandler(self, item, event, clock): self.showText(self.computer_text) self.aft_button.visible = False self.forward_button.visible = True def chipsHandler(self, item, event, clock): self.showText(self.chip_text) self.aft_button.visible = False self.forward_button.visible = True def powerHandler(self, item, event, clock): self.showText(self.fusion_text) self.aft_button.visible = False self.forward_button.visible = True # ** Aft ** def thrustersHandler(self, item, event, clock): self.test.visible = False def driveHandler(self, item, event, clock): self.test.visible = False def tanksHandler(self, item, event, clock): self.test.visible = False def impulseHandler(self, item, event, clock): self.test.visible = False def backForwardHandler(self, item, event, clock): self.test.visible = False def moreSensorHandler(self, item, event, clock): self.test.visible = False
class ScreenMain(LcarsScreen): def setup(self, all_sprites): all_sprites.add(LcarsBackgroundImage("assets/lcars_screen_1.png"), layer=0) # panel text all_sprites.add(LcarsText(colours.BLACK, (11, 75), "MOSF"), layer=1) all_sprites.add(LcarsText(colours.ORANGE, (0, 135), "LONG RANGE PROBE", 2.5), layer=1) all_sprites.add(LcarsText(colours.BLACK, (54, 667), "192 168 0 3"), layer=1) # date display self.stardate = LcarsText(colours.BLACK, (444, 506), "", 1) self.lastClockUpdate = 0 all_sprites.add(self.stardate, layer=1) # permanent buttons all_sprites.add(LcarsButton(colours.RED_BROWN, (6, 662), "LOGOUT", self.logoutHandler), layer=1) all_sprites.add(LcarsBlockSmall(colours.ORANGE, (211, 16), "ABOUT", self.aboutHandler), layer=1) all_sprites.add(LcarsBlockLarge(colours.BLUE, (145, 16), "DEMO", self.demoHandler), layer=1) all_sprites.add(LcarsBlockHuge(colours.PEACH, (249, 16), "EXPLORE", self.exploreHandler), layer=1) all_sprites.add(LcarsElbow(colours.BEIGE, (400, 16), "MAIN"), layer=1) # Sounds self.beep1 = Sound("assets/audio/panel/201.wav") #Sound("assets/audio/panel/220.wav").play() #-----Screens-----# # Main Screen all_sprites.add(LcarsText(colours.WHITE, (265, 458), "WELCOME", 1.5), layer=3) all_sprites.add(LcarsText(colours.BLUE, (244, 174), "TO THE Museum of Science Fiction", 1.5), layer=3) all_sprites.add(LcarsText(colours.BLUE, (286, 174), "LONG RANGE PROBE EXHIBIT", 1.5), layer=3) all_sprites.add(LcarsText(colours.BLUE, (330, 174), "LOOK AROUND", 1.5), layer=3) self.info_text = all_sprites.get_sprites_from_layer(3) # Demo Screen #116-800: 684 : 342 #90-440 : 350 : 175 # About Screen # Explore Screen # # gadgets #all_sprites.add(LcarsGifImage("assets/gadgets/fwscan.gif", (277, 556), 100), layer=1) #self.sensor_gadget = LcarsGifImage("assets/gadgets/lcars_anim2.gif", (235, 150), 100) #self.sensor_gadget.visible = False #all_sprites.add(self.sensor_gadget, layer=2) #self.dashboard = LcarsImage("assets/gadgets/dashboard.png", (187, 232)) #self.dashboard.visible = False #all_sprites.add(self.dashboard, layer=2) #self.weather = LcarsImage("assets/weather.jpg", (188, 122)) #self.weather.visible = False #all_sprites.add(self.weather, layer=2) #self.earth = LcarsGifImage("assets/gadgets/earth.gif", (187, 122), 100) #self.earth.visible = False #all_sprites.add(self.earth, layer=2) # Uniform def update(self, screenSurface, fpsClock): if pygame.time.get_ticks() - self.lastClockUpdate > 1000: self.stardate.setText("EARTH DATE {}".format(datetime.now().strftime("%m.%d.%y %H:%M:%S"))) self.lastClockUpdate = pygame.time.get_ticks() LcarsScreen.update(self, screenSurface, fpsClock) def handleEvents(self, event, fpsClock): LcarsScreen.handleEvents(self, event, fpsClock) if event.type == pygame.MOUSEBUTTONDOWN: self.beep1.play() if event.type == pygame.MOUSEBUTTONUP: return False # Screen Handlers def logoutHandler(self, item, event, clock): from screens.authorize import ScreenAuthorize self.loadScreen(ScreenAuthorize()) def aboutHandler(self, item, event, clock): from screens.aboutScreen import ScreenAbout self.loadScreen(ScreenAbout()) def demoHandler(self, item, event, clock): from screens.demoScreen import ScreenDemo self.loadScreen(ScreenDemo()) def exploreHandler(self, item, event, clock): from screens.exploreScreen import ScreenExplore self.loadScreen(ScreenExplore())
class ScreenMain(LcarsScreen): def setup(self, all_sprites): all_sprites.add(LcarsBackgroundImage("assets/lcars_screen_1b.png"), layer=0) # panel text all_sprites.add(LcarsText(colours.BLACK, (11, 52), "LCARS 105"), layer=1) all_sprites.add(LcarsText(colours.ORANGE, (0, 135), "HOME AUTOMATION", 2), layer=1) all_sprites.add(LcarsText(colours.BLACK, (183, 74), "LIGHTS"), layer=1) all_sprites.add(LcarsText(colours.BLACK, (222, 57), "CAMERAS"), layer=1) all_sprites.add(LcarsText(colours.BLACK, (372, 70), "ENERGY"), layer=1) all_sprites.add(LcarsText(colours.BLACK, (444, 612), "192 168 0 3"), layer=1) # info text all_sprites.add(LcarsText(colours.WHITE, (192, 174), "EVENT LOG:", 1.5), layer=3) all_sprites.add(LcarsText(colours.BLUE, (244, 174), "2 ALARM ZONES TRIGGERED", 1.5), layer=3) all_sprites.add(LcarsText(colours.BLUE, (286, 174), "14.3 kWh USED YESTERDAY", 1.5), layer=3) all_sprites.add(LcarsText(colours.BLUE, (330, 174), "1.3 Tb DATA USED THIS MONTH", 1.5), layer=3) self.info_text = all_sprites.get_sprites_from_layer(3) # date display self.stardate = LcarsText(colours.BLUE, (12, 380), "STAR DATE 2711.05 17:54:32", 1.5) self.lastClockUpdate = 0 all_sprites.add(self.stardate, layer=1) # buttons all_sprites.add(LcarsButton(colours.RED_BROWN, (6, 662), "LOGOUT", self.logoutHandler), layer=4) all_sprites.add(LcarsButton(colours.BEIGE, (107, 127), "SENSORS", self.sensorsHandler), layer=4) all_sprites.add(LcarsButton(colours.PURPLE, (107, 262), "GAUGES", self.gaugesHandler), layer=4) all_sprites.add(LcarsButton(colours.PEACH, (107, 398), "WEATHER", self.weatherHandler), layer=4) # gadgets all_sprites.add(LcarsGifImage("assets/gadgets/fwscan.gif", (277, 556), 100), layer=1) self.sensor_gadget = LcarsGifImage("assets/gadgets/lcars_anim2.gif", (235, 150), 100) self.sensor_gadget.visible = False all_sprites.add(self.sensor_gadget, layer=2) self.dashboard = LcarsImage("assets/gadgets/dashboard.png", (187, 232)) self.dashboard.visible = False all_sprites.add(self.dashboard, layer=2) self.weather = LcarsImage("assets/weather.jpg", (188, 122)) self.weather.visible = False all_sprites.add(self.weather, layer=2) #all_sprites.add(LcarsMoveToMouse(colours.WHITE), layer=1) self.beep1 = Sound("assets/audio/panel/201.wav") Sound("assets/audio/panel/220.wav").play() def update(self, screenSurface, fpsClock): if pygame.time.get_ticks() - self.lastClockUpdate > 1000: self.stardate.setText("STAR DATE {}".format(datetime.now().strftime("%d%m.%y %H:%M:%S"))) self.lastClockUpdate = pygame.time.get_ticks() LcarsScreen.update(self, screenSurface, fpsClock) def handleEvents(self, event, fpsClock): LcarsScreen.handleEvents(self, event, fpsClock) if event.type == pygame.MOUSEBUTTONDOWN: self.beep1.play() if event.type == pygame.MOUSEBUTTONUP: return False def hideInfoText(self): if self.info_text[0].visible: for sprite in self.info_text: sprite.visible = False def gaugesHandler(self, item, event, clock): self.hideInfoText() self.sensor_gadget.visible = False self.dashboard.visible = True self.weather.visible = False def sensorsHandler(self, item, event, clock): self.hideInfoText() self.sensor_gadget.visible = True self.dashboard.visible = False self.weather.visible = False def weatherHandler(self, item, event, clock): self.hideInfoText() self.sensor_gadget.visible = False self.dashboard.visible = False self.weather.visible = True def logoutHandler(self, item, event, clock): from screens.authorize import ScreenAuthorize self.loadScreen(ScreenAuthorize())
def setup(self, all_sprites): all_sprites.add(LcarsBackgroundImage("assets/lcars_screen_1b.png"), layer=0) # panel text all_sprites.add(LcarsText(colours.BLACK, (11, 52), "LCARS 105"), layer=1) all_sprites.add(LcarsText(colours.ORANGE, (0, 135), "HOME AUTOMATION", 2), layer=1) all_sprites.add(LcarsText(colours.BLACK, (183, 74), "LIGHTS"), layer=1) all_sprites.add(LcarsText(colours.BLACK, (222, 57), "CAMERAS"), layer=1) all_sprites.add(LcarsText(colours.BLACK, (372, 70), "ENERGY"), layer=1) all_sprites.add(LcarsText(colours.BLACK, (444, 612), "192 168 0 3"), layer=1) # info text all_sprites.add(LcarsText(colours.WHITE, (192, 174), "EVENT LOG:", 1.5), layer=3) all_sprites.add(LcarsText(colours.BLUE, (244, 174), "2 ALARM ZONES TRIGGERED", 1.5), layer=3) all_sprites.add(LcarsText(colours.BLUE, (286, 174), "14.3 kWh USED YESTERDAY", 1.5), layer=3) all_sprites.add(LcarsText(colours.BLUE, (330, 174), "1.3 Tb DATA USED THIS MONTH", 1.5), layer=3) self.info_text = all_sprites.get_sprites_from_layer(3) # date display self.stardate = LcarsText(colours.BLUE, (12, 380), "STAR DATE 2711.05 17:54:32", 1.5) self.lastClockUpdate = 0 all_sprites.add(self.stardate, layer=1) # buttons all_sprites.add(LcarsButton(colours.RED_BROWN, (6, 662), "LOGOUT", self.logoutHandler), layer=4) all_sprites.add(LcarsButton(colours.BEIGE, (107, 127), "SENSORS", self.sensorsHandler), layer=4) all_sprites.add(LcarsButton(colours.PURPLE, (107, 262), "GAUGES", self.gaugesHandler), layer=4) all_sprites.add(LcarsButton(colours.PEACH, (107, 398), "WEATHER", self.weatherHandler), layer=4) # gadgets all_sprites.add(LcarsGifImage("assets/gadgets/fwscan.gif", (277, 556), 100), layer=1) self.sensor_gadget = LcarsGifImage("assets/gadgets/lcars_anim2.gif", (235, 150), 100) self.sensor_gadget.visible = False all_sprites.add(self.sensor_gadget, layer=2) self.dashboard = LcarsImage("assets/gadgets/dashboard.png", (187, 232)) self.dashboard.visible = False all_sprites.add(self.dashboard, layer=2) self.weather = LcarsImage("assets/weather.jpg", (188, 122)) self.weather.visible = False all_sprites.add(self.weather, layer=2) #all_sprites.add(LcarsMoveToMouse(colours.WHITE), layer=1) self.beep1 = Sound("assets/audio/panel/201.wav") Sound("assets/audio/panel/220.wav").play()
def setup(self, all_sprites): all_sprites.add(LcarsBackgroundImage("assets/lcars_screen_3.png"), layer=0) all_sprites.add(LcarsGifImage("assets/gadgets/stlogorotating2.gif", (232, 895), 50), layer=0) all_sprites.add(LcarsText(colours.ORANGE, (608, -1), "AUTHORIZATION REQUIRED", 2), layer=0) all_sprites.add(LcarsText( colours.BLUE, (743, -1), "ONLY AUTHORIZED PERSONNEL MAY ACCESS THIS TERMINAL", 1.5), layer=1) all_sprites.add(LcarsText(colours.BLUE, (810, -1), "TOUCH TERMINAL TO PROCEED", 1.5), layer=1) #all_sprites.add(LcarsText(colours.BLUE, (878, -1), "FAILED ATTEMPTS WILL BE REPORTED", 1.5), layer=1) all_sprites.add(LcarsButton(colours.GREY_BLUE, (740, 312), "1", self.num_1), layer=2) all_sprites.add(LcarsButton(colours.GREY_BLUE, (843, 312), "2", self.num_2), layer=2) all_sprites.add(LcarsButton(colours.GREY_BLUE, (740, 648), "3", self.num_3), layer=2) all_sprites.add(LcarsButton(colours.GREY_BLUE, (843, 648), "4", self.num_4), layer=2) all_sprites.add(LcarsButton(colours.GREY_BLUE, (740, 984), "5", self.num_5), layer=2) all_sprites.add(LcarsButton(colours.GREY_BLUE, (843, 984), "6", self.num_6), layer=2) all_sprites.add(LcarsButton(colours.GREY_BLUE, (740, 1320), "7", self.num_7), layer=2) all_sprites.add(LcarsButton(colours.GREY_BLUE, (843, 1320), "8", self.num_8), layer=2) if config.DEV_MODE: all_sprites.add(LcarsButton(colours.GREY_BLUE, (0, 1848), "X", self.exitHandler, (68, 72)), layer=2) self.layer1 = all_sprites.get_sprites_from_layer(1) self.layer2 = all_sprites.get_sprites_from_layer(2) # sounds Sound("assets/audio/panel/215.wav").play() self.sound_granted = Sound("assets/audio/accessing.wav") self.sound_beep1 = Sound("assets/audio/panel/201.wav") self.sound_denied = Sound("assets/audio/access_denied.wav") self.sound_deny1 = Sound("assets/audio/deny_1.wav") self.sound_deny2 = Sound("assets/audio/deny_2.wav") ############ # SET PIN CODE WITH THIS VARIABLE ############ self.pin = 1234 ############ self.reset()
class ScreenEnviro(LcarsScreen): def setup(self, all_sprites): # Load BG image all_sprites.add(LcarsBackgroundImage("assets/lcars_bg.png"), layer=0) # Time/Date display self.stardate = LcarsText(colours.BLUE, (12, 380), "", 1.5) self.lastClockUpdate = 0 all_sprites.add(self.stardate, layer=1) # Static text all_sprites.add(LcarsText(colours.BLACK, (8, 40), "LCARS 1123"), layer=1) all_sprites.add(LcarsText(colours.ORANGE, (0, 135), "ENVIRONMENT", 2), layer=1) # Interfaces all_sprites.add(LcarsButton(colours.RED_BROWN, "btn", (6, 660), "MAIN", self.logoutHandler), layer=2) all_sprites.add(LcarsButton(randomcolor(), "nav", (145, 15), "CURRENT", self.nullfunction), layer=2) all_sprites.add(LcarsButton(randomcolor(), "nav", (200, 15), "TODAY", self.nullfunction), layer=2) all_sprites.add(LcarsButton(randomcolor(), "nav", (255, 15), "TOMORROW", self.nullfunction), layer=2) all_sprites.add(LcarsButton(randomcolor(), "nav", (310, 15), "WEEK", self.nullfunction), layer=2) all_sprites.add(LcarsButton(randomcolor(), "nav", (365, 15), "", self.nullfunction), layer=2) # Info text weather = get_weather() #"%s\nTemperature: %s\nPrecipitations %s" % (current.summary, current.temperature, current.precipProbability) all_sprites.add(LcarsText(colours.BLUE, (150, 300), weather.summary, 1.5), layer=3) all_sprites.add(LcarsText( colours.BLUE, (200, 300), "Temperature: %s C / Feels like: %s" % (weather.temperature, weather.apparentTemperature), 1.5), layer=3) all_sprites.add(LcarsText( colours.BLUE, (250, 300), "Wind: %s KPH %s" % (weather.windSpeed, degrees_to_cardinal(weather.windBearing)), 1.5), layer=3) all_sprites.add(LcarsText( colours.BLUE, (300, 300), "Precipitations: %s" % (weather.precipProbability), 1.5), layer=3) #all_sprites.add(LcarsText(colours.BLUE, (350, 300), "Type: %s / Qty: %s cm" % (weather.precipType, weather.precipAccumulation) , 1.5), layer=3) #all_sprites.add(LcarsText(colours.BLUE, (350, 300), "Sunset: %s / Sunrise: %s cm" % (weather.precipType, weather.precipAccumulation) , 1.5), layer=3) all_sprites.add(LcarsGifImage("assets/weather/%s.gif" % (weather.icon), (100, 144), 50), layer=1) self.info_text = all_sprites.get_sprites_from_layer(3) # SFX self.beep1 = Sound("assets/audio/panel/201.wav") Sound("assets/audio/hail_2.wav").play() def update(self, screenSurface, fpsClock): if pygame.time.get_ticks() - self.lastClockUpdate > 1000: self.stardate.setText("{}".format( datetime.now().strftime("%a %b %d, %Y - %X"))) self.lastClockUpdate = pygame.time.get_ticks() LcarsScreen.update(self, screenSurface, fpsClock) def handleEvents(self, event, fpsClock): LcarsScreen.handleEvents(self, event, fpsClock) if event.type == pygame.MOUSEBUTTONDOWN: self.beep1.play() if event.type == pygame.MOUSEBUTTONUP: return False def hideInfoText(self): if self.info_text[0].visible: for sprite in self.info_text: sprite.visible = False def nullfunction(self, item, event, clock): print("I am a fish.") def logoutHandler(self, item, event, clock): from screens.main import ScreenMain self.loadScreen(ScreenMain())
class ScreenMain(LcarsScreen): def setup(self, all_sprites): # Load standard LCARS BG image all_sprites.add(LcarsBackgroundImage("assets/lcars_bg.png"), layer=0) # Setup time/date display self.stardate = LcarsText(colours.BLUE, (12, 380), "", 1.5) self.lastClockUpdate = 0 all_sprites.add(self.stardate, layer=1) # Static text all_sprites.add(LcarsText(colours.BLACK, (8, 40), "LCARS 1123"), layer=1) all_sprites.add(LcarsText(colours.ORANGE, (0, 135), "MAIN MENU", 2), layer=1) # Buttons all_sprites.add(LcarsButton(colours.RED_BROWN, "btn", (6, 660), "LOGOUT", self.load_idle), layer=4) all_sprites.add(LcarsButton(randomcolor(), "nav", (145, 15), "ENVIRO", self.load_enviro), layer=4) all_sprites.add(LcarsButton(randomcolor(), "nav", (200, 15), "NETWORK", self.load_network), layer=4) all_sprites.add(LcarsButton(randomcolor(), "nav", (255, 15), "POWER", self.load_power), layer=4) all_sprites.add(LcarsButton(randomcolor(), "nav", (310, 15), "OPERATIONS", self.load_auth), layer=4) all_sprites.add(LcarsButton(randomcolor(), "nav", (365, 15), "", self.load_template), layer=4) # Load data from file returnpayload = read_txt("/var/lib/lcars/alert") # First line in file is always going to be heading all_sprites.add(LcarsText(colours.ORANGE, (137, 133), returnpayload[0], 1.8), layer=3) # Loop through results starting at second element index = 1 ypos = 190 while index < len(returnpayload): all_sprites.add(LcarsText(colours.BLUE, (ypos, 150), returnpayload[index], 1.5), layer=3) # Bump index and vertical pos index += 1 ypos += 50 # Rotating Deep Space 9 all_sprites.add(LcarsGifImage("assets/animated/ds9_3d.gif", (148, 475), 100), layer=1) self.beep1 = Sound("assets/audio/panel/201.wav") Sound("assets/audio/panel/220.wav").play() def update(self, screenSurface, fpsClock): if pygame.time.get_ticks() - self.lastClockUpdate > 1000: self.stardate.setText("{}".format( datetime.now().strftime("%a %b %d, %Y - %X"))) self.lastClockUpdate = pygame.time.get_ticks() LcarsScreen.update(self, screenSurface, fpsClock) def handleEvents(self, event, fpsClock): LcarsScreen.handleEvents(self, event, fpsClock) if event.type == pygame.MOUSEBUTTONDOWN: self.beep1.play() if event.type == pygame.MOUSEBUTTONUP: return False def nullfunction(self, item, event, clock): print("I am a fish.") def load_template(self, item, event, clock): from screens.template import ScreenTemplate self.loadScreen(ScreenTemplate()) # def load_auth(self, item, event, clock): # from screens.authorize import ScreenAuthorize # self.loadScreen(ScreenAuthorize()) def load_auth(self, item, event, clock): from screens.ops import ScreenOps self.loadScreen(ScreenOps()) def load_power(self, item, event, clock): from screens.power import ScreenPower self.loadScreen(ScreenPower()) def load_idle(self, item, event, clock): from screens.idle import ScreenIdle self.loadScreen(ScreenIdle()) def load_network(self, item, event, clock): from screens.network import ScreenNetwork self.loadScreen(ScreenNetwork()) def load_enviro(self, item, event, clock): from screens.enviro import ScreenEnviro self.loadScreen(ScreenEnviro())
class ScreenMain(LcarsScreen): def setup(self, all_sprites): all_sprites.add(LcarsBackgroundImage("assets/lcars_screen_1b.png"), layer=0) # panel text all_sprites.add(LcarsText(colours.BLACK, (11, 52), "LCARS 105"), layer=1) all_sprites.add(LcarsText(colours.ORANGE, (0, 135), "DATA INTERFACE", 2), layer=1) all_sprites.add(LcarsText(colours.BLACK, (183, 74), "LIGHTS"), layer=1) all_sprites.add(LcarsText(colours.BLACK, (222, 57), "CAMERAS"), layer=1) all_sprites.add(LcarsText(colours.BLACK, (372, 70), "ENERGY"), layer=1) all_sprites.add(LcarsText( colours.BLACK, (444, 612), socket.gethostbyname(socket.gethostname()).replace(".", " ")), layer=1) # info text all_sprites.add(LcarsText(colours.WHITE, (192, 130), "EVENT LOG:", 1.5), layer=3) all_sprites.add(LcarsText(colours.BLUE, (244, 130), "acpi", 1), layer=3) all_sprites.add(LcarsText(colours.BLUE, (286, 130), "uptime", 1), layer=3) all_sprites.add(LcarsText(colours.BLUE, (330, 130), "fqdn", 1), layer=3) self.info_text = all_sprites.get_sprites_from_layer(3) # date display self.stardate = LcarsText(colours.BLUE, (12, 380), "STAR DATE 2711.05 17:54:32", 1.5) self.lastClockUpdate = 0 all_sprites.add(self.stardate, layer=1) # buttons all_sprites.add(LcarsButton(colours.RED_BROWN, (6, 662), "LOGOUT", self.logoutHandler), layer=4) all_sprites.add(LcarsButton(colours.BEIGE, (107, 127), "SENSORS", self.sensorsHandler), layer=4) all_sprites.add(LcarsButton(colours.PURPLE, (107, 262), "GAUGES", self.gaugesHandler), layer=4) all_sprites.add(LcarsButton(colours.PEACH, (107, 398), "WEATHER", self.weatherHandler), layer=4) # gadgets all_sprites.add(LcarsGifImage("assets/gadgets/fwscan.gif", (277, 556), 100), layer=1) self.sensor_gadget = LcarsGifImage("assets/gadgets/lcars_anim2.gif", (235, 150), 100) self.sensor_gadget.visible = False all_sprites.add(self.sensor_gadget, layer=2) self.dashboard = LcarsImage("assets/gadgets/dashboard.png", (187, 232)) self.dashboard.visible = False all_sprites.add(self.dashboard, layer=2) self.weather = LcarsImage("assets/weather.jpg", (188, 122)) self.weather.visible = False all_sprites.add(self.weather, layer=2) #all_sprites.add(LcarsMoveToMouse(colours.WHITE), layer=1) self.beep1 = Sound("assets/audio/panel/201.wav") Sound("assets/audio/panel/220.wav").play() def update(self, screenSurface, fpsClock): if pygame.time.get_ticks() - self.lastClockUpdate > 1000: self.stardate.setText("STAR DATE {}".format( datetime.now().strftime("%d%m.%y %H:%M:%S"))) self.lastClockUpdate = pygame.time.get_ticks() self.info_text[1].setText( subprocess.check_output("acpi").upper()[:-1]) self.info_text[2].setText( subprocess.check_output("uptime").upper()[1:-1]) self.info_text[3].setText( subprocess.check_output("fqdn").upper()[:-1]) LcarsScreen.update(self, screenSurface, fpsClock) def handleEvents(self, event, fpsClock): LcarsScreen.handleEvents(self, event, fpsClock) if event.type == pygame.MOUSEBUTTONDOWN: self.beep1.play() if event.type == pygame.MOUSEBUTTONUP: return False def hideInfoText(self): if self.info_text[0].visible: for sprite in self.info_text: sprite.visible = False def showInfoText(self): self.sensor_gadget.visible = False self.dashboard.visible = False self.weather.visible = False for sprite in self.info_text: sprite.visible = True def gaugesHandler(self, item, event, clock): if self.dashboard.visible: self.showInfoText() return self.hideInfoText() self.sensor_gadget.visible = False self.dashboard.visible = True self.weather.visible = False def sensorsHandler(self, item, event, clock): if self.sensor_gadget.visible: self.showInfoText() return self.hideInfoText() self.sensor_gadget.visible = True self.dashboard.visible = False self.weather.visible = False def weatherHandler(self, item, event, clock): if self.weather.visible: self.showInfoText() return self.hideInfoText() self.sensor_gadget.visible = False self.dashboard.visible = False self.weather.visible = True def logoutHandler(self, item, event, clock): from screens.authorize import ScreenAuthorize self.loadScreen(ScreenAuthorize())
class MainScreen(LcarsScreen): def __init__(self, config, camera): self.config = config self.cam = camera LcarsScreen.__init__(self) def setup(self, all_sprites): self.image = None self.zoomPoint = None self.preview = False self.timer = 0 # detect focus self.focus = ProcessFocus() self.focus.start() # stack images self.stack = ProcessStacking() self.stack.start() self.showStack = False # tracking images self.telescope = Telescope(self.config['telescope_dev']) self.tracker = ProcessTracking(self.telescope) self.tracker.start() self.tracking = False self.focusText = LcarsText((255,0,0), (17,303), "Focus: ") self.trackingText = LcarsText((255,0,0), (17,380), "Track: ") all_sprites.add(LcarsBackgroundImage("assets/jarvis.png")) all_sprites.add(self.focusText) all_sprites.add(self.trackingText) #all_sprites.add(LcarsGifImage("assets/jarvis_gadgets.gif", (83, 258))) # all_sprites.add(LcarsMoveToMouse(colours.BEIGE)) def setImage(self, image): # do background processing self.focus.addFrame(image) if self.tracking: self.tracker.addFrame(image) if self.showStack: self.stack.addFrame(image) if self.showStack and self.stack.outputFrame is not None: image = self.stack.getFrame() if self.tracking: image = self.tracker.getFrame() if (image == None): return self.image = pygame.image.frombuffer(image, (len(image[0]), len(image)), 'RGB').convert() def update(self, screenSurface, fpsClock): if pygame.time.get_ticks() - self.timer > 100: self.focusText.setText("Focus: %d" % self.focus.focus) self.timer = pygame.time.get_ticks() self.trackingText.setText("Track: %s" % self.tracker.getStatus()) if (self.image != None): screenSurface.blit(self.image, # placement of preview window (100, 100), # area of image to display Rect(100, 100, self.image.get_width(), self.image.get_height())) def handleEvents(self, event, fpsClock): if (event.type == KEYUP and event.key == K_p): if (self.preview): self.cam.stopPreview() self.preview = False else: self.cam.startPreview() self.preview = True if (event.type == KEYUP and event.key == K_t): self.tracking = not self.tracking if not self.tracking: self.tracker.reset() if (event.type == KEYUP and event.key == K_s): #self.showStack = not self.showStack #self.stack.clear() self.telescope.down() if (event.type == KEYUP and event.key == K_w): self.telescope.up() if (event.type == KEYUP and event.key == K_a): self.telescope.left() if (event.type == KEYUP and event.key == K_d): self.telescope.right() if (event.type == KEYUP and event.key == K_1): self.telescope.setSteps("3") if (event.type == KEYUP and event.key == K_2): self.telescope.setSteps("4") if (event.type == KEYUP and event.key == K_3): self.telescope.setSteps("5") if (event.type == KEYUP and event.key == K_z): self.telescope.stop() if (event.type == KEYUP and event.key == K_x): self.telescope.start() return LcarsScreen.handleEvents(self, event, fpsClock) def timeStamped(self, fname, fmt='%Y-%m-%d-%H-%M-%S_{fname}'): return datetime.now().strftime(fmt).format(fname=fname)
class ScreenMain(LcarsScreen): def setup(self, all_sprites): # Load standard LCARS BG image all_sprites.add(LcarsBackgroundImage("assets/lcars_bg.png"), layer=0) # Setup time/date display self.stardate = LcarsText(colours.BLUE, (12, 380), "", 1.5) self.lastClockUpdate = 0 all_sprites.add(self.stardate, layer=1) # Static text all_sprites.add(LcarsText(colours.BLACK, (8, 40), "LCARS 1123"), layer=1) all_sprites.add(LcarsText(colours.ORANGE, (0, 135), "MAIN MENU", 2), layer=1) # Buttons all_sprites.add(LcarsButton(colours.RED_BROWN, "btn", (6, 660), "LOGOUT", self.load_idle), layer=4) all_sprites.add(LcarsButton(randomcolor(), "nav", (145, 15), "ENVIRO", self.load_enviro), layer=4) all_sprites.add(LcarsButton(randomcolor(), "nav", (200, 15), "NETWORK", self.load_network), layer=4) all_sprites.add(LcarsButton(randomcolor(), "nav", (255, 15), "POWER", self.load_power), layer=4) all_sprites.add(LcarsButton(randomcolor(), "nav", (310, 15), "OPERATIONS", self.load_auth), layer=4) all_sprites.add(LcarsButton(randomcolor(), "nav", (365, 15), "", self.load_template), layer=4) # Load data from file #returnpayload = read_txt("/opt/local/var/lib/lcars/alert") # First line in file is always going to be heading #all_sprites.add(LcarsText(colours.ORANGE, (137, 133), returnpayload[0], 1.8), layer=3) # Loop through results starting at second element #index = 1 #ypos = 190 #while index < len(returnpayload): # all_sprites.add(LcarsText(colours.BLUE, (ypos, 150), returnpayload[index], 1.5), layer=3) # Bump index and vertical pos # index += 1 # ypos += 50 # Rotating Deep Space 9 #yieldall_sprites.add(LcarsGifImage("assets/animated/ds9_3d.gif", (148, 475), 100), layer=1) weather = get_weather() #"%s\nTemperature: %s\nPrecipitations %s" % (current.summary, current.temperature, current.precipProbability) all_sprites.add(LcarsText(colours.BLUE, (150, 300), weather.summary , 1.5), layer=3) all_sprites.add(LcarsText(colours.BLUE, (200, 300), "Temperature: %s C / Feels like: %s" % (weather.temperature, weather.apparentTemperature) , 1.5), layer=3) all_sprites.add(LcarsText(colours.BLUE, (250, 300), "Wind: %s KPH %s" % (weather.windSpeed, degrees_to_cardinal(weather.windBearing)) , 1.5), layer=3) all_sprites.add(LcarsText(colours.BLUE, (300, 300), "Precipitations: %s" % (weather.precipProbability) , 1.5), layer=3) #all_sprites.add(LcarsText(colours.BLUE, (350, 300), "Type: %s / Qty: %s cm" % (weather.precipType, weather.precipAccumulation) , 1.5), layer=3) #all_sprites.add(LcarsText(colours.BLUE, (350, 300), "Sunset: %s / Sunrise: %s cm" % (weather.precipType, weather.precipAccumulation) , 1.5), layer=3) all_sprites.add(LcarsGifImage("assets/weather/%s.gif" % (weather.icon), (100, 144), 50), layer=1) self.beep1 = Sound("assets/audio/panel/201.wav") Sound("assets/audio/panel/220.wav").play() def update(self, screenSurface, fpsClock): if pygame.time.get_ticks() - self.lastClockUpdate > 1000: self.stardate.setText("{}".format(datetime.now().strftime("%a %b %d, %Y - %X"))) self.lastClockUpdate = pygame.time.get_ticks() LcarsScreen.update(self, screenSurface, fpsClock) def handleEvents(self, event, fpsClock): LcarsScreen.handleEvents(self, event, fpsClock) if event.type == pygame.MOUSEBUTTONDOWN: self.beep1.play() if event.type == pygame.MOUSEBUTTONUP: return False def nullfunction(self, item, event, clock): print("I am a fish.") def load_template(self, item, event, clock): from screens.template import ScreenTemplate self.loadScreen(ScreenTemplate()) # def load_auth(self, item, event, clock): # from screens.authorize import ScreenAuthorize # self.loadScreen(ScreenAuthorize()) def load_auth(self, item, event, clock): from screens.ops import ScreenOps self.loadScreen(ScreenOps()) def load_power(self, item, event, clock): from screens.power import ScreenPower self.loadScreen(ScreenPower()) def load_idle(self, item, event, clock): from screens.idle import ScreenIdle self.loadScreen(ScreenIdle()) def load_network(self, item, event, clock): from screens.network import ScreenNetwork self.loadScreen(ScreenNetwork()) def load_enviro(self, item, event, clock): from screens.enviro import ScreenEnviro self.loadScreen(ScreenEnviro())
class ScreenNetwork(LcarsScreen): def setup(self, all_sprites): # Load BG image all_sprites.add(LcarsBackgroundImage("assets/lcars_bg.png"), layer=0) # Time/Date display self.stardate = LcarsText(colours.BLUE, (12, 380), "", 1.5) self.lastClockUpdate = 0 all_sprites.add(self.stardate, layer=1) # Static text all_sprites.add(LcarsText(colours.BLACK, (8, 40), "LCARS 1123"), layer=1) all_sprites.add(LcarsText(colours.ORANGE, (0, 135), "NETWORK STATUS", 2), layer=1) # Interfaces all_sprites.add(LcarsButton(colours.RED_BROWN, "btn", (6, 660), "MAIN", self.logoutHandler), layer=2) all_sprites.add(LcarsButton(randomcolor(), "nav", (145, 15), "LAN", self.display_lan), layer=2) all_sprites.add(LcarsButton(randomcolor(), "nav", (200, 15), "INTERNET", self.display_internet), layer=2) all_sprites.add(LcarsButton(randomcolor(), "nav", (255, 15), "SERVER", self.nullfunction), layer=2) all_sprites.add(LcarsButton(randomcolor(), "nav", (310, 15), "", self.nullfunction), layer=2) all_sprites.add(LcarsButton(randomcolor(), "nav", (365, 15), "", self.nullfunction), layer=2) all_sprites.add(LcarsButton(randomcolor(), "btn", (140, 660), "ROUTERS", self.display_lan), layer=3) all_sprites.add(LcarsButton(randomcolor(), "btn", (200, 660), "PRINTERS", self.display_printers), layer=3) all_sprites.add(LcarsButton(randomcolor(), "btn", (260, 660), "SENSORS", self.display_sensors), layer=3) self.lan_buttons = all_sprites.get_sprites_from_layer(3) # Pull in information self.loadfile(all_sprites, "routers", 4) self.loadfile(all_sprites, "sites", 5) self.toggle_sprites(self.sites, False) self.loadfile(all_sprites, "sensors", 6) self.toggle_sprites(self.sensors, False) self.loadfile(all_sprites, "printers", 7) self.toggle_sprites(self.printers, False) # SFX self.beep1 = Sound("assets/audio/panel/201.wav") Sound("assets/audio/hail_2.wav").play() def update(self, screenSurface, fpsClock): if pygame.time.get_ticks() - self.lastClockUpdate > 1000: self.stardate.setText("{}".format(datetime.now().strftime("%a %b %d, %Y - %X"))) self.lastClockUpdate = pygame.time.get_ticks() LcarsScreen.update(self, screenSurface, fpsClock) def handleEvents(self, event, fpsClock): LcarsScreen.handleEvents(self, event, fpsClock) if event.type == pygame.MOUSEBUTTONDOWN: self.beep1.play() if event.type == pygame.MOUSEBUTTONUP: return False def loadfile(self, all_sprites, target, layer): # Load data from file returnpayload = read_txt("/opt/local/var/lib/lcars/" + target) # Router heading all_sprites.add(LcarsText(colours.ORANGE, (140, 175), returnpayload[0].split(',')[0], 2), layer = layer) all_sprites.add(LcarsText(colours.ORANGE, (140, 400), returnpayload[0].split(',')[1].lstrip(), 2), layer = layer) # Loop through results index = 1 ypos = 200 while index < len(returnpayload): all_sprites.add(LcarsText(colours.BLUE, (ypos, 175), returnpayload[index].split(',')[0], 2), layer = layer) # Change color based on status if returnpayload[index].lstrip().split(',')[1].lstrip() == "ONLINE": all_sprites.add(LcarsText(colours.GREEN, (ypos, 400), "ONLINE", 2), layer = layer) else: all_sprites.add(LcarsText(colours.RED, (ypos, 400), "OFFLINE", 2), layer = layer) # Bump index and vertical pos index += 1 ypos += 50 # Add a little flair all_sprites.add(LcarsGifImage("assets/animated/fwscan.gif", (320, 556), 100), layer = layer) # Save layer, this is a hack if target == "routers": self.routers = all_sprites.get_sprites_from_layer(layer) elif target == "sensors": self.sensors = all_sprites.get_sprites_from_layer(layer) elif target == "sites": self.sites = all_sprites.get_sprites_from_layer(layer) elif target == "printers": self.printers = all_sprites.get_sprites_from_layer(layer) # Button functions def display_lan(self, item, event, clock): self.toggle_sprites(self.routers, True) self.toggle_sprites(self.lan_buttons, True) self.toggle_sprites(self.sites, False) self.toggle_sprites(self.sensors, False) self.toggle_sprites(self.printers, False) def display_sensors(self, item, event, clock): self.toggle_sprites(self.routers, False) self.toggle_sprites(self.sites, False) self.toggle_sprites(self.sensors, True) self.toggle_sprites(self.printers, False) self.toggle_sprites(self.lan_buttons, True) def display_printers(self, item, event, clock): self.toggle_sprites(self.routers, False) self.toggle_sprites(self.sites, False) self.toggle_sprites(self.sensors, False) self.toggle_sprites(self.printers, True) self.toggle_sprites(self.lan_buttons, True) def display_internet(self, item, event, clock): self.toggle_sprites(self.routers, False) self.toggle_sprites(self.sites, True) self.toggle_sprites(self.sensors, False) self.toggle_sprites(self.printers, False) self.toggle_sprites(self.lan_buttons, False) def toggle_sprites(self, object, status): for sprite in object: sprite.visible = status def nullfunction(self, item, event, clock): print("I am a fish.") def logoutHandler(self, item, event, clock): from screens.main import ScreenMain self.loadScreen(ScreenMain())
class ScreenMain(LcarsScreen): def setup(self, all_sprites): # Weather parameters self.temperature = -9999 self.tStr = None self.pressure = -9999 self.pStr = None self.humidity = -9999 self.hStr = None self.battery = -9999 self.load = -9999 self.pwrStr = None self.timestamp = -9999 self.tsStr = None self.displayedValue = "Temp" self.paramStr = self.tStr self.timestampDT = dt.datetime.now() self.beatWarningTime = 10. * 60. self.runningCam = False self.cmdCamGo = [ 'sudo', '-H', '-u', 'pi', 'adafruit-io', 'camera', 'start', '-f', 'camera_feed', '-m', 'false', '-r', '5', '-v', 'false' ] self.cmdCamStop = [ 'sudo', '-H', '-u', 'pi', 'adafruit-io', 'camera', 'stop' ] # Background image/overall layout script_dir = dirname(__file__) ipath = join(script_dir, '../assets/mainscreen.png') all_sprites.add(LcarsBackgroundImage(ipath), layer=0) # Screen brightness we start from self.sbrightness = 0.5 # Need this to not crash the auto brightness # button, so choose a default that's easily elimated # from any logging activity just in case self.lux = 86.75309 # Screen control buttons buttonBri = LcarsButton((255, 204, 153), (5, 270), "BRIGHTER", self.screenBrighterHandler) buttonDim = LcarsButton((255, 153, 102), (5, 375), "DIMMER", self.screenDimmerHandler) buttonOff = LcarsButton((204, 102, 102), (50, 270), "OFF", self.logoutHandler) # Add this one to self to make it easily changed elsewhere self.buttonAuto = LcarsButton(colours.BLUE, (50, 375), "AUTO", self.autoBrightHandler) all_sprites.add(buttonBri, layer=4) all_sprites.add(buttonDim, layer=4) all_sprites.add(buttonOff, layer=4) all_sprites.add(self.buttonAuto, layer=4) # Header text all_sprites.add(LcarsText((255, 204, 153), (-5, 55), "WEATHER", size=3), layer=1) # date display sDateFmt = "%d%m.%y %H:%M:%S" sDate = "{}".format(datetime.now().strftime(sDateFmt)) self.stardate = LcarsText(colours.BLUE, (55, 55), sDate, size=2.0) self.lastClockUpdate = 0 self.whenLastRead = dt.datetime.now() all_sprites.add(self.stardate, layer=1) # Section/Parameter ID Text self.sensorTimestampText = LcarsText((0, 0, 0), (95, 275), "LAST UPDATE: ", 1.0) # self.sectionText = LcarsText((255, 204, 153), (120, 55), # "TEMPERATURE:", 3.) all_sprites.add(self.sensorTimestampText, layer=4) # all_sprites.add(self.sectionText, layer=4) # Section Value Text. If the temperature isn't nuts, it's probably # a good enough value to display so start with that. self.paramValueText = LcarsText((255, 204, 153), (170, -1), "XX.X C|XX.X F", 4.5) all_sprites.add(self.paramValueText, layer=3) self.info_text = all_sprites.get_sprites_from_layer(3) # buttons # (Bottom) #buttrowpos = (270, 65) # (Top) buttrowpos = (125, 55) self.butt1 = LcarsButton(colours.PURPLE, buttrowpos, "Temperature", self.cTempHandler) self.butt2 = LcarsButton( colours.PURPLE, (buttrowpos[0], buttrowpos[1] + self.butt1.size[0]), "Pressure", self.cPressHandler) self.butt3 = LcarsButton(colours.PURPLE, (buttrowpos[0], buttrowpos[1] + self.butt1.size[0] + self.butt2.size[0]), "Humidity", self.cHumiHandler) self.butt4 = LcarsButton( colours.PURPLE, (buttrowpos[0], buttrowpos[1] + self.butt1.size[0] + self.butt2.size[0] + self.butt3.size[0]), "Power", self.cPowerHandler) all_sprites.add(self.butt1, layer=5) all_sprites.add(self.butt2, layer=5) all_sprites.add(self.butt3, layer=5) all_sprites.add(self.butt4, layer=5) campos = (270, 320) self.buttcam = LcarsButton((204, 102, 102), campos, "KITTY CAM", self.camHandler) all_sprites.add(self.buttcam, layer=4) # Local (intranet) MQTT server setup; Hopefully we can can start # with the current values already there if all is well with MQTT self.client = mqtt.Client() self.client.on_connect = self.on_connect self.client.on_message = self.on_message self.client.username_pw_set("WeatherduinoUser", "rainyday") self.client.connect("localhost", 1883, 60) # Non-blocking call that processes network traffic, dispatches # callbacks and handles reconnecting. Must call client.loop_stop() # when you're done with stuff. self.client.loop_start() if self.temperature != -9999: self.paramStr = self.tStr # Note: We need to explicitly update the strings since they're # caught in the time loop and may lag self.updateDisplayedSensorStrings() # Highlight the default choice so we know where we are and trigger self.butt1.changeColor(colours.WHITE) self.butt2.changeColor(self.butt2.inactiveColor) self.butt3.changeColor(self.butt3.inactiveColor) self.butt4.changeColor(self.butt4.inactiveColor) # Automatically control screen brightness at start? self.autosbrightness = True self.buttonAuto.changeColor(colours.WHITE) def update(self, screenSurface, fpsClock): if pygame.time.get_ticks() - self.lastClockUpdate > 1000: sDateFmt = "%d%m.%y %H:%M:%S" sDate = "{}".format(datetime.now().strftime(sDateFmt)) self.stardate.setText(sDate) self.lastClockUpdate = pygame.time.get_ticks() LcarsScreen.update(self, screenSurface, fpsClock) # Update the heartbeat indicator(s) self.beatCounterDT = (dt.datetime.now() - self.timestampDT) self.beatCounter = self.beatCounterDT.total_seconds() # Heartbeat bar for whether we read the timestamp remotely correctly if self.beatCounter > self.beatWarningTime: self.beatColor = (255, 0, 0) else: self.beatColor = (0, 255, 0) # Changing text color depending on time of last good (outdoor) read if ((dt.datetime.now() - self.whenLastRead).total_seconds()) > self.beatWarningTime * 2.: # Warning text color self.paramValueText.changeColour((204, 102, 102)) else: # Normal text color self.paramValueText.changeColour((255, 204, 153)) self.curHeartbeat(screenSurface) def handleEvents(self, event, fpsClock): LcarsScreen.handleEvents(self, event, fpsClock) if event.type == pygame.MOUSEBUTTONDOWN: # self.beep1.play() pass if event.type == pygame.MOUSEBUTTONUP: return False def autoBrightHandler(self, item, event, clock): if self.autosbrightness is True: self.autosbrightness = False self.buttonAuto.changeColor(colours.BLUE) else: self.autosbrightness = True self.buttonAuto.changeColor(colours.WHITE) try: # First read/scale the last value from the sensor self.theLuxRanger() print "setting to %f" % (self.sbrightness) self.screenBrightAbsolute() except: # If we're here, something went wrong # but I don't know what to say yet print "Whoops" pass def camHandler(self, item, event, clock): try: if self.runningCam is False: self.runningCam = True sub.call(self.cmdCamGo) else: self.runningCam = False sub.call(self.cmdCamStop) except OSError: pass def screenBrightAbsolute(self): try: screenPWM.screenPWM(self.sbrightness, pin=18) except OSError: print "Failure to set screen brightness to %f" % \ (self.sbrightness) self.autosbrightness = False def screenBrighterHandler(self, item, event, clock): try: self.sbrightness += 0.1 if self.sbrightness < 0.1: self.sbrightness = 0.1 if self.sbrightness > 1.0: self.sbrightness = 1.0 screenPWM.screenPWM(self.sbrightness, pin=18) except OSError: pass def screenDimmerHandler(self, item, event, clock): try: self.sbrightness -= 0.1 if self.sbrightness < 0.1: self.sbrightness = 0.1 if self.sbrightness > 1.0: self.sbrightness = 1.0 screenPWM.screenPWM(self.sbrightness, pin=18) except OSError: pass def cTempHandler(self, item, event, clock): self.displayedValue = "Temp" self.paramStr = self.tStr self.updateDisplayedSensorStrings() self.butt1.changeColor(colours.WHITE) self.butt2.changeColor(self.butt2.inactiveColor) self.butt3.changeColor(self.butt3.inactiveColor) self.butt4.changeColor(self.butt4.inactiveColor) def cPressHandler(self, item, event, clock): self.displayedValue = "Pre" self.paramStr = self.pStr self.updateDisplayedSensorStrings() self.butt1.changeColor(self.butt1.inactiveColor) self.butt2.changeColor(colours.WHITE) self.butt3.changeColor(self.butt3.inactiveColor) self.butt4.changeColor(self.butt4.inactiveColor) def cHumiHandler(self, item, event, clock): self.displayedValue = "Humi" self.paramStr = self.hStr self.updateDisplayedSensorStrings() self.butt1.changeColor(self.butt1.inactiveColor) self.butt2.changeColor(self.butt2.inactiveColor) self.butt3.changeColor(colours.WHITE) self.butt4.changeColor(self.butt4.inactiveColor) def cPowerHandler(self, item, event, clock): self.displayedValue = "Powr" self.paramStr = self.pwrStr self.updateDisplayedSensorStrings() self.butt1.changeColor(self.butt1.inactiveColor) self.butt2.changeColor(self.butt2.inactiveColor) self.butt3.changeColor(self.butt3.inactiveColor) self.butt4.changeColor(colours.WHITE) def logoutHandler(self, item, event, clock): from screens.blanker import ScreenBlanker self.client.loop_stop() self.client.unsubscribe("Ostation/#") self.client.unsubscribe("Istation/#") self.client.disconnect() self.loadScreen(ScreenBlanker()) def updateDisplayedSensorStrings(self): """ Update the sensor value and associated timestamp when demanded """ self.paramValueText.setText(self.paramStr) self.sensorTimestampText.setText(self.tsStr) def curHeartbeat(self, screenSurface): pygame.draw.rect(screenSurface, self.beatColor, (211, 98.5, 235, 14.5), 0) def on_connect(self, client, userdata, flags, rc): """ Callback for when the client receives a CONNACK response from server. """ print("Connected with result code " + str(rc)) # Subscribing in on_connect() means that if we lose the connection and # reconnect then subscriptions will be renewed. # The character '#' is a wildcard meaning all. client.subscribe("Ostation/#") client.subscribe("Istation/lux") def on_message(self, client, userdata, msg): """ Callback for when a PUBLISH message is received from the server. """ if msg.topic.find("Ostation") > -1: if msg.topic.find("temperature") > -1: self.temperature = np.float(msg.payload) self.tStr = "%02.1f C | %02.1f F" % (self.temperature, CtoF(self.temperature)) print "Update", self.tStr self.whenLastRead = dt.datetime.now() elif msg.topic.find("pressure") > -1: self.pressure = np.float(msg.payload) self.pStr = "%04.2f mB" % (self.pressure) print "Update", self.pStr self.whenLastRead = dt.datetime.now() elif msg.topic.find("humidity") > -1: self.humidity = np.float(msg.payload) self.hStr = "%03.0f %%" % (self.humidity) print "Update", self.hStr self.whenLastRead = dt.datetime.now() elif msg.topic.find("battery") > -1: self.battery = np.float(msg.payload) self.pwrStr = "%01.2f / %01.2f V" % (self.battery, self.load) print "Update", self.pwrStr self.whenLastRead = dt.datetime.now() elif msg.topic.find("load") > -1: self.load = np.float(msg.payload) self.pwrStr = "%01.2f / %01.2f V" % (self.battery, self.load) print "Update", self.pwrStr self.whenLastRead = dt.datetime.now() elif msg.topic.find("timestamp") > -1: sDateFmt = "%d%m.%y %H:%M:%S" self.timestamp = np.int(msg.payload) self.timestampDT = datetime.fromtimestamp(self.timestamp) sDate = "{}".format(self.timestampDT.strftime(sDateFmt)) self.tsStr = "Last Update: %s" % (sDate) print "Update", self.tsStr # Display string updates if self.displayedValue == "Temp": self.paramStr = self.tStr if self.displayedValue == "Pres": self.paramStr = self.pStr if self.displayedValue == "Humi": self.paramStr = self.hStr if self.displayedValue == "Powr": self.paramStr = self.pwrStr elif msg.topic.find("Istation") > -1: if msg.topic.find("lux") > -1: self.lux = np.float(msg.payload) if self.autosbrightness is True: self.theLuxRanger() self.screenBrightAbsolute() self.updateDisplayedSensorStrings() def theLuxRanger(self): # Turn the lux into a brightness value # > xr == full brightness # < mr == min brightness # Screen range - 1.0 to 0.2 inclusive mr = 3. xr = 100. if self.lux >= xr: self.sbrightness = 1.0 elif self.lux < xr and self.lux >= mr: self.sbrightness = ((self.lux - mr) * (1.0 - 0.2) / (xr - mr)) + 0.2 self.sbrightness = np.round(self.sbrightness, 3) else: self.sbrightness = 0.05 print "Lux: ", self.lux, self.sbrightness
def setup(self, all_sprites): all_sprites.add(LcarsBackgroundImage("assets/lcars_screen_1.png"), layer=0) # panel text all_sprites.add(LcarsText(colours.BLACK, (11, 75), "MOSF"), layer=1) all_sprites.add(LcarsText(colours.ORANGE, (0, 135), "LONG RANGE PROBE", 2.5), layer=1) all_sprites.add(LcarsText(colours.BLACK, (54, 667), "192 168 0 3"), layer=1) # date display self.stardate = LcarsText(colours.BLACK, (444, 506), "", 1) self.lastClockUpdate = 0 all_sprites.add(self.stardate, layer=1) # permanent buttons all_sprites.add(LcarsButton(colours.RED_BROWN, (6, 662), "LOGOUT", self.logoutHandler), layer=1) all_sprites.add(LcarsBlockSmall(colours.ORANGE, (211, 16), "ABOUT", self.aboutHandler), layer=1) all_sprites.add(LcarsBlockLarge(colours.BLUE, (145, 16), "DEMO", self.demoHandler), layer=1) all_sprites.add(LcarsBlockHuge(colours.PEACH, (249, 16), "EXPLORE", self.exploreHandler), layer=1) all_sprites.add(LcarsElbow(colours.BEIGE, (400, 16), "MAIN", self.mainHandler), layer=1) # Sounds self.beep1 = Sound("assets/audio/panel/201.wav") #Sound("assets/audio/panel/220.wav").play() ###################################################################### ##### Explore Screen ##### # Explore Screen --------------------------------------------------------------------------------- all_sprites.add(LcarsText(colours.RED_BROWN, (142, 140), "Select a section for more information", 1.25), layer=70) self.explore_screen_text = all_sprites.get_sprites_from_layer(70) # self.hideText(self.explore_screen_text) self.probe_forward_image = LcarsImage("assets/probe_front.png", (172, 500), self.forwardHandler) all_sprites.add(self.probe_forward_image, layer =70) self.probe_aft_image = LcarsImage("assets/probe_rear.png", (172, 150), self.aftHandler) all_sprites.add(self.probe_aft_image, layer=70) ##### Forward Section ##### self.forward_text = LcarsText(colours.RED_BROWN, (142, 140), "Select a component for more information", 1.25) self.forward_text.visible = False all_sprites.add(self.forward_text, layer=71) # self.forward_text.visible = False self.forward_plate = LcarsImage("assets/forward/front_section.png", (172, 150)) self.forward_plate.visible = False all_sprites.add(self.forward_plate, layer =71) ## Back Forward Button ## self.forward_button = LcarsTabBlock(colours.RED_BROWN, (372, 650), "BACK", self.forwardHandler) self.forward_button.visible = False all_sprites.add(self.forward_button, layer=60) ## Back Aft Button ## self.aft_button = LcarsTabBlock(colours.RED_BROWN, (372, 650), "BACK", self.exploreHandler) self.aft_button.visible = False all_sprites.add(self.aft_button, layer=60) # BTO ARRAY # all_sprites.add(LcarsText(colours.WHITE, (112, 140), "B.T.O. ARRAY", 1.75), layer=61) all_sprites.add(LcarsText(colours.ORANGE, (162, 140), "The B.T.O. Array is the primary method of communication for the probe.", 1.25), layer=61) all_sprites.add(LcarsText(colours.ORANGE, (192, 140), "The array is entirely composed of the S.B.S. High-Gain Parabolic Antenna,", 1.25), layer = 61) all_sprites.add(LcarsText(colours.ORANGE, (222, 140), "which is capable of simultaneous dual transmission in the S and X bands", 1.25), layer=61) all_sprites.add(LcarsText(colours.ORANGE, (252, 140), "and receipt of control commands in the Ka and Ku bands. The array is", 1.25), layer=61) all_sprites.add(LcarsText(colours.ORANGE, (282, 140), "paired with the Yokel Sensor Suite to determine physical properties of ", 1.25), layer=61) all_sprites.add(LcarsText(colours.ORANGE, (312, 140), "local bodies using microwave radiation.", 1.25), layer=61) self.communication_text = all_sprites.get_sprites_from_layer(61) self.hideText(self.communication_text) # YOKEL SENSOR SUITE # all_sprites.add(LcarsText(colours.WHITE, (112, 140), "YOKEL SENSOR SUITE", 1.75), layer=62) all_sprites.add(LcarsText(colours.ORANGE, (162, 140), "The Yokel Sensor Suite houses the scientific payload and guidance", 1.25), layer=62) all_sprites.add(LcarsText(colours.ORANGE, (192, 140), "system on the probe. The instruments contained within are:", 1.25), layer=62) all_sprites.add(LcarsText(colours.WHITE, (222, 150), "Autonomous Telemetry Guidance Unit", 1.25), layer=62) all_sprites.add(LcarsText(colours.WHITE, (242, 150), "Energetic Particle Detector", 1.25), layer=62) all_sprites.add(LcarsText(colours.WHITE, (262, 150), "Gravitational Mapping Unit", 1.25), layer=62) all_sprites.add(LcarsText(colours.WHITE, (282, 150), "High Energy Multi-Spectral Analyzer", 1.25), layer=62) all_sprites.add(LcarsText(colours.WHITE, (302, 150), "Magnetometry Suite", 1.25), layer=62) all_sprites.add(LcarsText(colours.WHITE, (322, 150), "Radar Detection & Tracking System", 1.25), layer=62) all_sprites.add(LcarsText(colours.WHITE, (342, 150), "Radio Science Array", 1.25), layer=62) all_sprites.add(LcarsText(colours.WHITE, (362, 150), "Space Radiation Measurement System", 1.25), layer=62) all_sprites.add(LcarsText(colours.ORANGE, (392, 140), "Collected data is stored in the Optical Data Chips for later processing.", 1.25), layer=62) self.sensor_text = all_sprites.get_sprites_from_layer(62) self.hideText(self.sensor_text) # Probe Computers # all_sprites.add(LcarsText(colours.WHITE, (112, 140), "PROBE COMPUTERS", 1.75), layer=63) all_sprites.add(LcarsText(colours.ORANGE, (162, 140), "This probe features two onboard computers, the Guidance Computer and", 1.25), layer=63) all_sprites.add(LcarsText(colours.WHITE, (162, 473), "Guidance Computer", 1.25), layer=63) all_sprites.add(LcarsText(colours.ORANGE, (192, 140), "the Data Processing Unit , which handle all data and control processes.", 1.25), layer=63) all_sprites.add(LcarsText(colours.WHITE, (192, 165), "Data Processing Unit", 1.25), layer=63) all_sprites.add(LcarsText(colours.ORANGE, (222, 140), "The Guidance Computer receives control commands through the BTO ", 1.25), layer=63) all_sprites.add(LcarsText(colours.ORANGE, (252, 140), "Array, and local object data from the Yokel Sensor Suite, to ensure safe", 1.25), layer=63) all_sprites.add(LcarsText(colours.ORANGE, (282, 140), "travel. The Data Processing Unit receives all raw data from the Optical", 1.25), layer=63) all_sprites.add(LcarsText(colours.ORANGE, (312, 140), "and processes the data for transmission. For redundancy, both", 1.25), layer=63) all_sprites.add(LcarsText(colours.ORANGE, (342, 140), "computers are independently capable of assuming the others' duties.", 1.25), layer=63) self.computer_text = all_sprites.get_sprites_from_layer(63) self.hideText(self.computer_text) # Optical Data Chips # all_sprites.add(LcarsText(colours.WHITE, (112, 140), "OPTICAL DATA CHIPS", 1.75), layer=64) all_sprites.add(LcarsText(colours.ORANGE, (162, 140), "This probe is equipped with 24 optical data chips for the storage of sensor", 1.25), layer=64) all_sprites.add(LcarsText(colours.ORANGE, (192, 140), "and control data. Each chip, which can store up to 830 TB of data, is", 1.25), layer=64) all_sprites.add(LcarsText(colours.ORANGE, (222, 140), "constructed of a nano-structured quartz composite. Data is read/written", 1.25), layer=64) all_sprites.add(LcarsText(colours.ORANGE, (252, 140), "to the chips using a Smith-Taylor laser system.", 1.25), layer=64) self.chip_text = all_sprites.get_sprites_from_layer(64) self.hideText(self.chip_text) # Lofton Microfusion Core # all_sprites.add(LcarsText(colours.WHITE, (112, 140), "LOFTON MICROFUSION CORE", 1.75), layer=65) all_sprites.add(LcarsText(colours.ORANGE, (162, 140), "All of the required power for the probe is provided by the Lofton", 1.25), layer=65) all_sprites.add(LcarsText(colours.ORANGE, (192, 140), "Microfusion Core. Encased within a shielded tungsten-titanium shell,", 1.25), layer=65) all_sprites.add(LcarsText(colours.ORANGE, (222, 140), "11.3 KW of power are produced from a micro-aneutronic fusion reaction ", 1.25), layer=65) all_sprites.add(LcarsText(colours.ORANGE, (252, 140), "which is converted to electricity via electrostatic direct conversion.", 1.25), layer=65) all_sprites.add(LcarsText(colours.ORANGE, (282, 140), "Of the 11.3 KW produced, 8 KW are used by the ion propulsion system,", 1.25), layer=65) all_sprites.add(LcarsText(colours.ORANGE, (312, 140), "1.4 KW by the sensor suite, 1 KW by the computers, and 0.9 KW by the", 1.25), layer=65) all_sprites.add(LcarsText(colours.ORANGE, (342, 140), "communication array during normal operation. Helium is used for the", 1.25), layer=65) all_sprites.add(LcarsText(colours.ORANGE, (372, 140), "fusion reaction which is provided by the monopropellant tank.", 1.25), layer=65) self.fusion_text = all_sprites.get_sprites_from_layer(65) self.hideText(self.fusion_text) ###### AFT SECTION ###### all_sprites.add(LcarsText(colours.WHITE, (112, 140), "PROPULSION SYSTEM", 1.75), layer=66) all_sprites.add(LcarsText(colours.ORANGE, (162, 140), "After launch, the probe is driven by the Kehrer Hybrid Ion Drive, is", 1.25), layer=66) all_sprites.add(LcarsText(colours.ORANGE, (192, 140), "capable of both ion and chemical propulsion, and is comprised of the ", 1.25), layer=66) all_sprites.add(LcarsText(colours.ORANGE, (222, 140), "engine, thrusters, and fuel tanks. Ion propulsion creates thrust by drawing", 1.25), layer=66) all_sprites.add(LcarsText(colours.ORANGE, (252, 140), "power from the fusion core to accelerate and expel Xenon ions from the", 1.25), layer=66) all_sprites.add(LcarsText(colours.ORANGE, (282, 140), "two, 420 kg storage tanks, and is the main method of propulsion. For quick", 1.25), layer=66) all_sprites.add(LcarsText(colours.ORANGE, (312, 140), "changes in velocity, the chemical propulsion system is activated. This", 1.25), layer=66) all_sprites.add(LcarsText(colours.ORANGE, (342, 140), "system uses the monopropellant hydrazine, which is stored in the 300 kg ", 1.25), layer=66) all_sprites.add(LcarsText(colours.ORANGE, (372, 140), "storage tank. The combination of two different propulsion methods allows", 1.25), layer=66) all_sprites.add(LcarsText(colours.ORANGE, (402, 140), "the probe a versatile mix of range and maneuverability.", 1.25), layer=66) self.propulsion_text = all_sprites.get_sprites_from_layer(66) self.hideText(self.propulsion_text) #TEST self.test = LcarsButton(colours.RED_BROWN, (6, 662), "LOGOUT", self.logoutHandler) self.test.visible = False all_sprites.add(self.test, layer = 4)
def setup(self, all_sprites): areset(a) all_sprites.add(LcarsBackgroundImage("assets/lcars_screen_1.png"), layer=0) # panel text all_sprites.add(LcarsText(colours.BLACK, (11, 75), "MOSF"), layer=1) all_sprites.add(LcarsText(colours.ORANGE, (0, 135), "LONG RANGE PROBE", 2.5), layer=1) all_sprites.add(LcarsText(colours.BLACK, (54, 667), "192 168 0 3"), layer=1) # date display self.stardate = LcarsText(colours.BLACK, (444, 506), "", 1) self.lastClockUpdate = 0 all_sprites.add(self.stardate, layer=1) # permanent buttons all_sprites.add(LcarsButton(colours.RED_BROWN, (6, 662), "LOGOUT", self.logoutHandler), layer=1) all_sprites.add(LcarsBlockSmall(colours.ORANGE, (211, 16), "ABOUT", self.aboutHandler), layer=1) all_sprites.add(LcarsBlockLarge(colours.BLUE, (145, 16), "DEMO", self.demoHandler), layer=1) all_sprites.add(LcarsBlockHuge(colours.PEACH, (249, 16), "EXPLORE", self.exploreHandler), layer=1) all_sprites.add(LcarsElbow(colours.BEIGE, (400, 16), "MAIN"), layer=1) # Sounds self.beep_1 = Sound("assets/audio/panel/201.wav") self.fwoosh = Sound("assets/audio/panel/250.m4a") self.fwoosh.set_volume(1.0) self.fwoosh.play() time.sleep(6) # Sound("assets/audio/panel/220.wav").play() #-----Screens-----# # Main Screen ------------------------------------------------------------------------------------ #116-800: 684 : 342 #90-440 : 350 : 175 all_sprites.add(LcarsText(colours.WHITE, (192, 174), "WELCOME", 1.5), layer=3) all_sprites.add(LcarsText(colours.BLUE, (244, 174), "TO THE Museum of Science Fiction", 1.5), layer=3) all_sprites.add(LcarsText(colours.BLUE, (286, 174), "LONG RANGE PROBE EXHIBIT", 1.5), layer=3) all_sprites.add(LcarsText(colours.BLUE, (330, 174), "LOOK AROUND", 1.5), layer=3) self.main_text = all_sprites.get_sprites_from_layer(3) # Logout Screen ---------------------------------------------------------------------------------- self.logout_image = LcarsImage("assets/intro_screen.png", (0,0), self.mainHandler) self.logout_image.visible = False all_sprites.add(self.logout_image, layer=49) #Previously layer2 self.logout_gif = LcarsGifImage("assets/gadgets/MOSF.gif", (90, 330), 35) self.logout_gif.visible = False all_sprites.add(self.logout_gif, layer=49) #Previously 2 all_sprites.add(LcarsText(colours.ORANGE, (270, -1), "LONG RANGE PROBE", 3), layer=50) all_sprites.add(LcarsText(colours.ORANGE, (390, -1), "TOUCH TERMINAL TO PROCEED", 1.5), layer=50) self.logout_text = all_sprites.get_sprites_from_layer(50) self.hideText(self.logout_text) # Demo Screen ------------------------------------------------------------------------------------ # About Screen ----------------------------------------------------------------------------------- self.purpose = LcarsButton(colours.GREY_BLUE, (107, 127), "PURPOSE", self.purposeHandler) self.purpose.visible = False all_sprites.add(self.purpose, layer=4) self.details = LcarsButton(colours.ORANGE, (107, 262), "DETAILS", self.detailsHandler) self.details.visible = False all_sprites.add(self.details, layer=4) self.personnel = LcarsButton(colours.GREY_BLUE, (107, 398), "PERSONNEL", self.personnelHandler) self.personnel.visible = False all_sprites.add(self.personnel, layer=4) self.sources = LcarsButton(colours.ORANGE, (107, 533), "SOURCES", self.sourcesHandler) self.sources.visible = False all_sprites.add(self.sources, layer=4) # Purpose all_sprites.add(LcarsText(colours.WHITE, (192, 140), "To inspire", 1.25), layer=5) #all_sprites.add(LcarsText(colours.BLUE, (244, 174), "TO THE Museum of Science Fiction", 1), # layer=3) #all_sprites.add(LcarsText(colours.BLUE, (286, 174), "LONG RANGE PROBE EXHIBIT", 1), # layer=3) #all_sprites.add(LcarsText(colours.BLUE, (330, 174), "LOOK AROUND", 1), # layer=3) self.purpose_text = all_sprites.get_sprites_from_layer(5) self.hideText(self.purpose_text) # Details all_sprites.add(LcarsText(colours.ORANGE, (192, 140), "LENGTH: ", 1.25), layer=6) all_sprites.add(LcarsText(colours.WHITE, (192, 220), "1.5 m (4 ft 6 in)", 1.25), layer=6) all_sprites.add(LcarsText(colours.ORANGE, (212, 140), "WIDTH: ", 1.25), layer=6) all_sprites.add(LcarsText(colours.WHITE, (212, 220), "0.45 m (blah)", 1.25), layer=6) all_sprites.add(LcarsText(colours.ORANGE, (232, 140), "HEIGHT: ", 1.25), layer=6) all_sprites.add(LcarsText(colours.WHITE, (232, 220), "0.25 m (blah)", 1.25), layer=6) all_sprites.add(LcarsText(colours.ORANGE, (252, 140), "MASS: ", 1.25), layer=6) all_sprites.add(LcarsText(colours.WHITE, (252, 220), "20 kg (30 slugs)", 1.25), layer=6) all_sprites.add(LcarsText(colours.ORANGE, (292, 140), "MATERIALS: ", 1.25), layer=6) all_sprites.add(LcarsText(colours.WHITE, (292, 220), "Carbon fiber reinforced fiberglass shell, internal components 3-D printed PLA plastic", 1.25), layer=6) all_sprites.add(LcarsText(colours.ORANGE, (332, 140), "CONTROL: ", 1.25), layer=6) all_sprites.add(LcarsText(colours.WHITE, (332, 220), "7 in touchscreen via Rasberry Pi, lights & movement via Arduino Mega", 1.25), layer=6) all_sprites.add(LcarsText(colours.ORANGE, (372, 140), "COST: ", 1.25), layer=6) all_sprites.add(LcarsText(colours.WHITE, (372, 220), "$$$", 1.25), layer=6) self.details_text = all_sprites.get_sprites_from_layer(6) self.hideText(self.details_text) # Personnel all_sprites.add(LcarsText(colours.RED_BROWN, (192, 140), "Designed and built by a team of four mechanical & aerospace", 1.25), layer=7) all_sprites.add(LcarsText(colours.RED_BROWN, (212, 140), "engineering students at North Carolina State University", 1.25), layer=7) self.personnel_text= all_sprites.get_sprites_from_layer(7) self.hideText(self.personnel_text) self.personnel_image1 = LcarsImage("assets/ncsu.png", (192, 560)) self.personnel_image1.visible = False all_sprites.add(self.personnel_image1, layer=7) # Sources all_sprites.add(LcarsText(colours.GREY_BLUE, (192, 140), "SPECIAL THANKS TO:", 1.25), layer=8) all_sprites.add(LcarsText(colours.WHITE, (212, 180), "Toby Kurien", 1.25), layer=8) all_sprites.add(LcarsText(colours.WHITE,(232, 180), "NC State EI Garage", 1.25), layer=8) self.sources_text = all_sprites.get_sprites_from_layer(8) self.hideText(self.sources_text) # Explore Screen --------------------------------------------------------------------------------- all_sprites.add(LcarsText(colours.RED_BROWN, (142, 140), "Select a section for more information", 1.25), layer=70) self.explore_screen_text = all_sprites.get_sprites_from_layer(70) self.hideText(self.explore_screen_text) self.probe_forward_image = LcarsImage("assets/probe_front.png", (172, 500), self.forwardHandler) self.probe_forward_image.visible = False all_sprites.add(self.probe_forward_image, layer =70) self.probe_aft_image = LcarsImage("assets/probe_rear.png", (172, 150), self.aftHandler) self.probe_aft_image.visible = False all_sprites.add(self.probe_aft_image, layer=70) ##### Forward Section ##### all_sprites.add(LcarsText(colours.RED_BROWN, (142, 140), "Select a component for more information", 1.25), layer=71) self.forward_text = all_sprites.get_sprites_from_layer(71) # self.forward_text.visible = False self.forward_plate = LcarsImage("assets/forward/front_section.png", (172, 533)) self.forward_plate.visible = False all_sprites.add(self.probe_forward_image, layer =71) ## Back Forward Button ## self.forward_button = LcarsTabBlock(colours.RED_BROWN, (372, 650), "BACK", self.forwardHandler) self.forward_button.visible = False all_sprites.add(self.forward_button, layer=60) ## Back Aft Button ## self.aft_button = LcarsTabBlock(colours.RED_BROWN, (372, 650), "BACK", self.exploreHandler) self.aft_button.visible = False all_sprites.add(self.aft_button, layer=60) # BTO ARRAY # all_sprites.add(LcarsText(colours.WHITE, (112, 140), "B.T.O. ARRAY", 1.75), layer=61) all_sprites.add(LcarsText(colours.ORANGE, (162, 140), "The B.T.O. Array is the primary method of communication for the probe.", 1.25), layer=61) all_sprites.add(LcarsText(colours.ORANGE, (192, 140), "The array is entirely composed of the S.B.S. High-Gain Parabolic Antenna,", 1.25), layer = 61) all_sprites.add(LcarsText(colours.ORANGE, (222, 140), "which is capable of simultaneous dual transmission in the S and X bands", 1.25), layer=61) all_sprites.add(LcarsText(colours.ORANGE, (252, 140), "and receipt of control commands in the Ka and Ku bands. The array is", 1.25), layer=61) all_sprites.add(LcarsText(colours.ORANGE, (282, 140), "paired with the Yokel Sensor Suite to determine physical properties of ", 1.25), layer=61) all_sprites.add(LcarsText(colours.ORANGE, (312, 140), "local bodies using microwave radiation.", 1.25), layer=61) self.communication_text = all_sprites.get_sprites_from_layer(61) self.hideText(self.communication_text) # YOKEL SENSOR SUITE # all_sprites.add(LcarsText(colours.WHITE, (112, 140), "YOKEL SENSOR SUITE", 1.75), layer=62) all_sprites.add(LcarsText(colours.ORANGE, (162, 140), "The Yokel Sensor Suite houses the scientific payload and guidance", 1.25), layer=62) all_sprites.add(LcarsText(colours.ORANGE, (192, 140), "system on the probe. The instruments contained within are:", 1.25), layer=62) all_sprites.add(LcarsText(colours.WHITE, (222, 150), "Autonomous Telemetry Guidance Unit", 1.25), layer=62) all_sprites.add(LcarsText(colours.WHITE, (242, 150), "Energetic Particle Detector", 1.25), layer=62) all_sprites.add(LcarsText(colours.WHITE, (262, 150), "Gravitational Mapping Unit", 1.25), layer=62) all_sprites.add(LcarsText(colours.WHITE, (282, 150), "High Energy Multi-Spectral Analyzer", 1.25), layer=62) all_sprites.add(LcarsText(colours.WHITE, (302, 150), "Magnetometry Suite", 1.25), layer=62) all_sprites.add(LcarsText(colours.WHITE, (322, 150), "Radar Detection & Tracking System", 1.25), layer=62) all_sprites.add(LcarsText(colours.WHITE, (342, 150), "Radio Science Array", 1.25), layer=62) all_sprites.add(LcarsText(colours.WHITE, (362, 150), "Space Radiation Measurement System", 1.25), layer=62) all_sprites.add(LcarsText(colours.ORANGE, (392, 140), "Collected data is stored in the Optical Data Chips for later processing.", 1.25), layer=62) self.sensor_text = all_sprites.get_sprites_from_layer(62) self.hideText(self.sensor_text) # Probe Computers # all_sprites.add(LcarsText(colours.WHITE, (112, 140), "PROBE COMPUTERS", 1.75), layer=63) all_sprites.add(LcarsText(colours.ORANGE, (162, 140), "This probe features two onboard computers, the Guidance Computer and", 1.25), layer=63) all_sprites.add(LcarsText(colours.WHITE, (162, 473), "Guidance Computer", 1.25), layer=63) all_sprites.add(LcarsText(colours.ORANGE, (192, 140), "the Data Processing Unit , which handle all data and control processes.", 1.25), layer=63) all_sprites.add(LcarsText(colours.WHITE, (192, 165), "Data Processing Unit", 1.25), layer=63) all_sprites.add(LcarsText(colours.ORANGE, (222, 140), "The Guidance Computer receives control commands through the BTO ", 1.25), layer=63) all_sprites.add(LcarsText(colours.ORANGE, (252, 140), "Array, and local object data from the Yokel Sensor Suite, to ensure safe", 1.25), layer=63) all_sprites.add(LcarsText(colours.ORANGE, (282, 140), "travel. The Data Processing Unit receives all raw data from the Optical", 1.25), layer=63) all_sprites.add(LcarsText(colours.ORANGE, (312, 140), "and processes the data for transmission. For redundancy, both", 1.25), layer=63) all_sprites.add(LcarsText(colours.ORANGE, (342, 140), "computers are independently capable of assuming the others' duties.", 1.25), layer=63) self.computer_text = all_sprites.get_sprites_from_layer(63) self.hideText(self.computer_text) # Optical Data Chips # all_sprites.add(LcarsText(colours.WHITE, (112, 140), "OPTICAL DATA CHIPS", 1.75), layer=64) all_sprites.add(LcarsText(colours.ORANGE, (162, 140), "This probe is equipped with 24 optical data chips for the storage of sensor", 1.25), layer=64) all_sprites.add(LcarsText(colours.ORANGE, (192, 140), "and control data. Each chip, which can store up to 830 TB of data, is", 1.25), layer=64) all_sprites.add(LcarsText(colours.ORANGE, (222, 140), "constructed of a nano-structured quartz composite. Data is read/written", 1.25), layer=64) all_sprites.add(LcarsText(colours.ORANGE, (252, 140), "to the chips using a Smith-Taylor laser system.", 1.25), layer=64) self.chip_text = all_sprites.get_sprites_from_layer(64) self.hideText(self.chip_text) # Lofton Microfusion Core # all_sprites.add(LcarsText(colours.WHITE, (112, 140), "LOFTON MICROFUSION CORE", 1.75), layer=65) all_sprites.add(LcarsText(colours.ORANGE, (162, 140), "All of the required power for the probe is provided by the Lofton", 1.25), layer=65) all_sprites.add(LcarsText(colours.ORANGE, (192, 140), "Microfusion Core. Encased within a shielded tungsten-titanium shell,", 1.25), layer=65) all_sprites.add(LcarsText(colours.ORANGE, (222, 140), "11.3 KW of power are produced from a micro-aneutronic fusion reaction ", 1.25), layer=65) all_sprites.add(LcarsText(colours.ORANGE, (252, 140), "which is converted to electricity via electrostatic direct conversion.", 1.25), layer=65) all_sprites.add(LcarsText(colours.ORANGE, (282, 140), "Of the 11.3 KW produced, 8 KW are used by the ion propulsion system,", 1.25), layer=65) all_sprites.add(LcarsText(colours.ORANGE, (312, 140), "1.4 KW by the sensor suite, 1 KW by the computers, and 0.9 KW by the", 1.25), layer=65) all_sprites.add(LcarsText(colours.ORANGE, (342, 140), "communication array during normal operation. Helium is used for the", 1.25), layer=65) all_sprites.add(LcarsText(colours.ORANGE, (372, 140), "fusion reaction which is provided by the monopropellant tank.", 1.25), layer=65) self.fusion_text = all_sprites.get_sprites_from_layer(65) self.hideText(self.fusion_text) ###### AFT SECTION ###### all_sprites.add(LcarsText(colours.WHITE, (112, 140), "PROPULSION SYSTEM", 1.75), layer=66) all_sprites.add(LcarsText(colours.ORANGE, (162, 140), "After launch, the probe is driven by the Kehrer Hybrid Ion Drive, is", 1.25), layer=66) all_sprites.add(LcarsText(colours.ORANGE, (192, 140), "capable of both ion and chemical propulsion, and is comprised of the ", 1.25), layer=66) all_sprites.add(LcarsText(colours.ORANGE, (222, 140), "engine, thrusters, and fuel tanks. Ion propulsion creates thrust by drawing", 1.25), layer=66) all_sprites.add(LcarsText(colours.ORANGE, (252, 140), "power from the fusion core to accelerate and expel Xenon ions from the", 1.25), layer=66) all_sprites.add(LcarsText(colours.ORANGE, (282, 140), "two, 420 kg storage tanks, and is the main method of propulsion. For quick", 1.25), layer=66) all_sprites.add(LcarsText(colours.ORANGE, (312, 140), "changes in velocity, the chemical propulsion system is activated. This", 1.25), layer=66) all_sprites.add(LcarsText(colours.ORANGE, (342, 140), "system uses the monopropellant hydrazine, which is stored in the 300 kg ", 1.25), layer=66) all_sprites.add(LcarsText(colours.ORANGE, (372, 140), "storage tank. The combination of two different propulsion methods allows", 1.25), layer=66) all_sprites.add(LcarsText(colours.ORANGE, (402, 140), "the probe a versatile mix of range and maneuverability.", 1.25), layer=66) self.propulsion_text = all_sprites.get_sprites_from_layer(66) self.hideText(self.propulsion_text)
class ScreenMain(LcarsScreen): def setup(self, all_sprites): # Weather parameters self.temperature = -9999 self.tStr = None self.pressure = -9999 self.pStr = None self.humidity = -9999 self.hStr = None self.battery = -9999 self.load = -9999 self.pwrStr = None self.timestamp = -9999 self.tsStr = None self.displayedValue = "Temp" self.paramStr = self.tStr self.timestampDT = dt.datetime.now() self.beatWarningTime = 10.*60. self.runningCam = False self.cmdCamGo = ['sudo', '-H', '-u', 'pi', 'adafruit-io', 'camera', 'start', '-f', 'camera_feed', '-m', 'false', '-r', '5', '-v', 'false'] self.cmdCamStop = ['sudo', '-H', '-u', 'pi', 'adafruit-io', 'camera', 'stop'] # Background image/overall layout script_dir = dirname(__file__) ipath = join(script_dir, '../assets/mainscreen.png') all_sprites.add(LcarsBackgroundImage(ipath), layer=0) # Screen brightness we start from self.sbrightness = 0.5 # Need this to not crash the auto brightness # button, so choose a default that's easily elimated # from any logging activity just in case self.lux = 86.75309 # Screen control buttons buttonBri = LcarsButton((255, 204, 153), (5, 270), "BRIGHTER", self.screenBrighterHandler) buttonDim = LcarsButton((255, 153, 102), (5, 375), "DIMMER", self.screenDimmerHandler) buttonOff = LcarsButton((204, 102, 102), (50, 270), "OFF", self.logoutHandler) # Add this one to self to make it easily changed elsewhere self.buttonAuto = LcarsButton(colours.BLUE, (50, 375), "AUTO", self.autoBrightHandler) all_sprites.add(buttonBri, layer=4) all_sprites.add(buttonDim, layer=4) all_sprites.add(buttonOff, layer=4) all_sprites.add(self.buttonAuto, layer=4) # Header text all_sprites.add(LcarsText((255, 204, 153), (-5, 55), "WEATHER", size=3), layer=1) # date display sDateFmt = "%d%m.%y %H:%M:%S" sDate = "{}".format(datetime.now().strftime(sDateFmt)) self.stardate = LcarsText(colours.BLUE, (55, 55), sDate, size=2.0) self.lastClockUpdate = 0 self.whenLastRead = dt.datetime.now() all_sprites.add(self.stardate, layer=1) # Section/Parameter ID Text self.sensorTimestampText = LcarsText((0, 0, 0), (95, 275), "LAST UPDATE: ", 1.0) # self.sectionText = LcarsText((255, 204, 153), (120, 55), # "TEMPERATURE:", 3.) all_sprites.add(self.sensorTimestampText, layer=4) # all_sprites.add(self.sectionText, layer=4) # Section Value Text. If the temperature isn't nuts, it's probably # a good enough value to display so start with that. self.paramValueText = LcarsText((255, 204, 153), (170, -1), "XX.X C|XX.X F", 4.5) all_sprites.add(self.paramValueText, layer=3) self.info_text = all_sprites.get_sprites_from_layer(3) # buttons # (Bottom) #buttrowpos = (270, 65) # (Top) buttrowpos = (125, 55) self.butt1 = LcarsButton(colours.PURPLE, buttrowpos, "Temperature", self.cTempHandler) self.butt2 = LcarsButton(colours.PURPLE, (buttrowpos[0], buttrowpos[1] + self.butt1.size[0]), "Pressure", self.cPressHandler) self.butt3 = LcarsButton(colours.PURPLE, (buttrowpos[0], buttrowpos[1] + self.butt1.size[0] + self.butt2.size[0]), "Humidity", self.cHumiHandler) self.butt4 = LcarsButton(colours.PURPLE, (buttrowpos[0], buttrowpos[1] + self.butt1.size[0] + self.butt2.size[0] + self.butt3.size[0]), "Power", self.cPowerHandler) all_sprites.add(self.butt1, layer=5) all_sprites.add(self.butt2, layer=5) all_sprites.add(self.butt3, layer=5) all_sprites.add(self.butt4, layer=5) campos = (270, 320) self.buttcam = LcarsButton((204, 102, 102), campos, "KITTY CAM", self.camHandler) all_sprites.add(self.buttcam, layer=4) # Local (intranet) MQTT server setup; Hopefully we can can start # with the current values already there if all is well with MQTT self.client = mqtt.Client() self.client.on_connect = self.on_connect self.client.on_message = self.on_message self.client.username_pw_set("WeatherduinoUser", "rainyday") self.client.connect("localhost", 1883, 60) # Non-blocking call that processes network traffic, dispatches # callbacks and handles reconnecting. Must call client.loop_stop() # when you're done with stuff. self.client.loop_start() if self.temperature != -9999: self.paramStr = self.tStr # Note: We need to explicitly update the strings since they're # caught in the time loop and may lag self.updateDisplayedSensorStrings() # Highlight the default choice so we know where we are and trigger self.butt1.changeColor(colours.WHITE) self.butt2.changeColor(self.butt2.inactiveColor) self.butt3.changeColor(self.butt3.inactiveColor) self.butt4.changeColor(self.butt4.inactiveColor) # Automatically control screen brightness at start? self.autosbrightness = True self.buttonAuto.changeColor(colours.WHITE) def update(self, screenSurface, fpsClock): if pygame.time.get_ticks() - self.lastClockUpdate > 1000: sDateFmt = "%d%m.%y %H:%M:%S" sDate = "{}".format(datetime.now().strftime(sDateFmt)) self.stardate.setText(sDate) self.lastClockUpdate = pygame.time.get_ticks() LcarsScreen.update(self, screenSurface, fpsClock) # Update the heartbeat indicator(s) self.beatCounterDT = (dt.datetime.now() - self.timestampDT) self.beatCounter = self.beatCounterDT.total_seconds() # Heartbeat bar for whether we read the timestamp remotely correctly if self.beatCounter > self.beatWarningTime: self.beatColor = (255, 0, 0) else: self.beatColor = (0, 255, 0) # Changing text color depending on time of last good (outdoor) read if ((dt.datetime.now() - self.whenLastRead).total_seconds()) > self.beatWarningTime*2.: # Warning text color self.paramValueText.changeColour((204, 102, 102)) else: # Normal text color self.paramValueText.changeColour((255, 204, 153)) self.curHeartbeat(screenSurface) def handleEvents(self, event, fpsClock): LcarsScreen.handleEvents(self, event, fpsClock) if event.type == pygame.MOUSEBUTTONDOWN: # self.beep1.play() pass if event.type == pygame.MOUSEBUTTONUP: return False def autoBrightHandler(self, item, event, clock): if self.autosbrightness is True: self.autosbrightness = False self.buttonAuto.changeColor(colours.BLUE) else: self.autosbrightness = True self.buttonAuto.changeColor(colours.WHITE) try: # First read/scale the last value from the sensor self.theLuxRanger() print "setting to %f" % (self.sbrightness) self.screenBrightAbsolute() except: # If we're here, something went wrong # but I don't know what to say yet print "Whoops" pass def camHandler(self, item, event, clock): try: if self.runningCam is False: self.runningCam = True sub.call(self.cmdCamGo) else: self.runningCam = False sub.call(self.cmdCamStop) except OSError: pass def screenBrightAbsolute(self): try: screenPWM.screenPWM(self.sbrightness, pin=18) except OSError: print "Failure to set screen brightness to %f" % \ (self.sbrightness) self.autosbrightness = False def screenBrighterHandler(self, item, event, clock): try: self.sbrightness += 0.1 if self.sbrightness < 0.1: self.sbrightness = 0.1 if self.sbrightness > 1.0: self.sbrightness = 1.0 screenPWM.screenPWM(self.sbrightness, pin=18) except OSError: pass def screenDimmerHandler(self, item, event, clock): try: self.sbrightness -= 0.1 if self.sbrightness < 0.1: self.sbrightness = 0.1 if self.sbrightness > 1.0: self.sbrightness = 1.0 screenPWM.screenPWM(self.sbrightness, pin=18) except OSError: pass def cTempHandler(self, item, event, clock): self.displayedValue = "Temp" self.paramStr = self.tStr self.updateDisplayedSensorStrings() self.butt1.changeColor(colours.WHITE) self.butt2.changeColor(self.butt2.inactiveColor) self.butt3.changeColor(self.butt3.inactiveColor) self.butt4.changeColor(self.butt4.inactiveColor) def cPressHandler(self, item, event, clock): self.displayedValue = "Pre" self.paramStr = self.pStr self.updateDisplayedSensorStrings() self.butt1.changeColor(self.butt1.inactiveColor) self.butt2.changeColor(colours.WHITE) self.butt3.changeColor(self.butt3.inactiveColor) self.butt4.changeColor(self.butt4.inactiveColor) def cHumiHandler(self, item, event, clock): self.displayedValue = "Humi" self.paramStr = self.hStr self.updateDisplayedSensorStrings() self.butt1.changeColor(self.butt1.inactiveColor) self.butt2.changeColor(self.butt2.inactiveColor) self.butt3.changeColor(colours.WHITE) self.butt4.changeColor(self.butt4.inactiveColor) def cPowerHandler(self, item, event, clock): self.displayedValue = "Powr" self.paramStr = self.pwrStr self.updateDisplayedSensorStrings() self.butt1.changeColor(self.butt1.inactiveColor) self.butt2.changeColor(self.butt2.inactiveColor) self.butt3.changeColor(self.butt3.inactiveColor) self.butt4.changeColor(colours.WHITE) def logoutHandler(self, item, event, clock): from screens.blanker import ScreenBlanker self.client.loop_stop() self.client.unsubscribe("Ostation/#") self.client.unsubscribe("Istation/#") self.client.disconnect() self.loadScreen(ScreenBlanker()) def updateDisplayedSensorStrings(self): """ Update the sensor value and associated timestamp when demanded """ self.paramValueText.setText(self.paramStr) self.sensorTimestampText.setText(self.tsStr) def curHeartbeat(self, screenSurface): pygame.draw.rect(screenSurface, self.beatColor, (211, 98.5, 235, 14.5), 0) def on_connect(self, client, userdata, flags, rc): """ Callback for when the client receives a CONNACK response from server. """ print("Connected with result code "+str(rc)) # Subscribing in on_connect() means that if we lose the connection and # reconnect then subscriptions will be renewed. # The character '#' is a wildcard meaning all. client.subscribe("Ostation/#") client.subscribe("Istation/lux") def on_message(self, client, userdata, msg): """ Callback for when a PUBLISH message is received from the server. """ if msg.topic.find("Ostation") > -1: if msg.topic.find("temperature") > -1: self.temperature = np.float(msg.payload) self.tStr = "%02.1f C | %02.1f F" % (self.temperature, CtoF(self.temperature)) print "Update", self.tStr self.whenLastRead = dt.datetime.now() elif msg.topic.find("pressure") > -1: self.pressure = np.float(msg.payload) self.pStr = "%04.2f mB" % (self.pressure) print "Update", self.pStr self.whenLastRead = dt.datetime.now() elif msg.topic.find("humidity") > -1: self.humidity = np.float(msg.payload) self.hStr = "%03.0f %%" % (self.humidity) print "Update", self.hStr self.whenLastRead = dt.datetime.now() elif msg.topic.find("battery") > -1: self.battery = np.float(msg.payload) self.pwrStr = "%01.2f / %01.2f V" % (self.battery, self.load) print "Update", self.pwrStr self.whenLastRead = dt.datetime.now() elif msg.topic.find("load") > -1: self.load = np.float(msg.payload) self.pwrStr = "%01.2f / %01.2f V" % (self.battery, self.load) print "Update", self.pwrStr self.whenLastRead = dt.datetime.now() elif msg.topic.find("timestamp") > -1: sDateFmt = "%d%m.%y %H:%M:%S" self.timestamp = np.int(msg.payload) self.timestampDT = datetime.fromtimestamp(self.timestamp) sDate = "{}".format(self.timestampDT.strftime(sDateFmt)) self.tsStr = "Last Update: %s" % (sDate) print "Update", self.tsStr # Display string updates if self.displayedValue == "Temp": self.paramStr = self.tStr if self.displayedValue == "Pres": self.paramStr = self.pStr if self.displayedValue == "Humi": self.paramStr = self.hStr if self.displayedValue == "Powr": self.paramStr = self.pwrStr elif msg.topic.find("Istation") > -1: if msg.topic.find("lux") > -1: self.lux = np.float(msg.payload) if self.autosbrightness is True: self.theLuxRanger() self.screenBrightAbsolute() self.updateDisplayedSensorStrings() def theLuxRanger(self): # Turn the lux into a brightness value # > xr == full brightness # < mr == min brightness # Screen range - 1.0 to 0.2 inclusive mr = 3. xr = 100. if self.lux >= xr: self.sbrightness = 1.0 elif self.lux < xr and self.lux >= mr: self.sbrightness = ((self.lux - mr)*(1.0 - 0.2)/(xr - mr)) + 0.2 self.sbrightness = np.round(self.sbrightness, 3) else: self.sbrightness = 0.05 print "Lux: ", self.lux, self.sbrightness
def setup(self, all_sprites): # Weather parameters self.temperature = -9999 self.tStr = None self.pressure = -9999 self.pStr = None self.humidity = -9999 self.hStr = None self.battery = -9999 self.load = -9999 self.pwrStr = None self.timestamp = -9999 self.tsStr = None self.displayedValue = "Temp" self.paramStr = self.tStr self.timestampDT = dt.datetime.now() self.beatWarningTime = 10.*60. self.runningCam = False self.cmdCamGo = ['sudo', '-H', '-u', 'pi', 'adafruit-io', 'camera', 'start', '-f', 'camera_feed', '-m', 'false', '-r', '5', '-v', 'false'] self.cmdCamStop = ['sudo', '-H', '-u', 'pi', 'adafruit-io', 'camera', 'stop'] # Background image/overall layout script_dir = dirname(__file__) ipath = join(script_dir, '../assets/mainscreen.png') all_sprites.add(LcarsBackgroundImage(ipath), layer=0) # Screen brightness we start from self.sbrightness = 0.5 # Need this to not crash the auto brightness # button, so choose a default that's easily elimated # from any logging activity just in case self.lux = 86.75309 # Screen control buttons buttonBri = LcarsButton((255, 204, 153), (5, 270), "BRIGHTER", self.screenBrighterHandler) buttonDim = LcarsButton((255, 153, 102), (5, 375), "DIMMER", self.screenDimmerHandler) buttonOff = LcarsButton((204, 102, 102), (50, 270), "OFF", self.logoutHandler) # Add this one to self to make it easily changed elsewhere self.buttonAuto = LcarsButton(colours.BLUE, (50, 375), "AUTO", self.autoBrightHandler) all_sprites.add(buttonBri, layer=4) all_sprites.add(buttonDim, layer=4) all_sprites.add(buttonOff, layer=4) all_sprites.add(self.buttonAuto, layer=4) # Header text all_sprites.add(LcarsText((255, 204, 153), (-5, 55), "WEATHER", size=3), layer=1) # date display sDateFmt = "%d%m.%y %H:%M:%S" sDate = "{}".format(datetime.now().strftime(sDateFmt)) self.stardate = LcarsText(colours.BLUE, (55, 55), sDate, size=2.0) self.lastClockUpdate = 0 self.whenLastRead = dt.datetime.now() all_sprites.add(self.stardate, layer=1) # Section/Parameter ID Text self.sensorTimestampText = LcarsText((0, 0, 0), (95, 275), "LAST UPDATE: ", 1.0) # self.sectionText = LcarsText((255, 204, 153), (120, 55), # "TEMPERATURE:", 3.) all_sprites.add(self.sensorTimestampText, layer=4) # all_sprites.add(self.sectionText, layer=4) # Section Value Text. If the temperature isn't nuts, it's probably # a good enough value to display so start with that. self.paramValueText = LcarsText((255, 204, 153), (170, -1), "XX.X C|XX.X F", 4.5) all_sprites.add(self.paramValueText, layer=3) self.info_text = all_sprites.get_sprites_from_layer(3) # buttons # (Bottom) #buttrowpos = (270, 65) # (Top) buttrowpos = (125, 55) self.butt1 = LcarsButton(colours.PURPLE, buttrowpos, "Temperature", self.cTempHandler) self.butt2 = LcarsButton(colours.PURPLE, (buttrowpos[0], buttrowpos[1] + self.butt1.size[0]), "Pressure", self.cPressHandler) self.butt3 = LcarsButton(colours.PURPLE, (buttrowpos[0], buttrowpos[1] + self.butt1.size[0] + self.butt2.size[0]), "Humidity", self.cHumiHandler) self.butt4 = LcarsButton(colours.PURPLE, (buttrowpos[0], buttrowpos[1] + self.butt1.size[0] + self.butt2.size[0] + self.butt3.size[0]), "Power", self.cPowerHandler) all_sprites.add(self.butt1, layer=5) all_sprites.add(self.butt2, layer=5) all_sprites.add(self.butt3, layer=5) all_sprites.add(self.butt4, layer=5) campos = (270, 320) self.buttcam = LcarsButton((204, 102, 102), campos, "KITTY CAM", self.camHandler) all_sprites.add(self.buttcam, layer=4) # Local (intranet) MQTT server setup; Hopefully we can can start # with the current values already there if all is well with MQTT self.client = mqtt.Client() self.client.on_connect = self.on_connect self.client.on_message = self.on_message self.client.username_pw_set("WeatherduinoUser", "rainyday") self.client.connect("localhost", 1883, 60) # Non-blocking call that processes network traffic, dispatches # callbacks and handles reconnecting. Must call client.loop_stop() # when you're done with stuff. self.client.loop_start() if self.temperature != -9999: self.paramStr = self.tStr # Note: We need to explicitly update the strings since they're # caught in the time loop and may lag self.updateDisplayedSensorStrings() # Highlight the default choice so we know where we are and trigger self.butt1.changeColor(colours.WHITE) self.butt2.changeColor(self.butt2.inactiveColor) self.butt3.changeColor(self.butt3.inactiveColor) self.butt4.changeColor(self.butt4.inactiveColor) # Automatically control screen brightness at start? self.autosbrightness = True self.buttonAuto.changeColor(colours.WHITE)
def setup(self, all_sprites): # Load BG image all_sprites.add(LcarsBackgroundImage("assets/lcars_bg.png"), layer=0) # Time/Date display self.stardate = LcarsText(colours.BLUE, (12, 380), "", 1.5) self.lastClockUpdate = 0 all_sprites.add(self.stardate, layer=1) # Static text all_sprites.add(LcarsText(colours.BLACK, (8, 40), "LCARS 1123"), layer=1) all_sprites.add(LcarsText(colours.ORANGE, (0, 135), "ENVIRONMENT", 2), layer=1) # Interfaces all_sprites.add(LcarsButton(colours.RED_BROWN, "btn", (6, 660), "MAIN", self.logoutHandler), layer=2) all_sprites.add(LcarsButton(randomcolor(), "nav", (145, 15), "CURRENT", self.nullfunction), layer=2) all_sprites.add(LcarsButton(randomcolor(), "nav", (200, 15), "TODAY", self.nullfunction), layer=2) all_sprites.add(LcarsButton(randomcolor(), "nav", (255, 15), "TOMORROW", self.nullfunction), layer=2) all_sprites.add(LcarsButton(randomcolor(), "nav", (310, 15), "WEEK", self.nullfunction), layer=2) all_sprites.add(LcarsButton(randomcolor(), "nav", (365, 15), "", self.nullfunction), layer=2) # Info text weather = get_weather() #"%s\nTemperature: %s\nPrecipitations %s" % (current.summary, current.temperature, current.precipProbability) all_sprites.add(LcarsText(colours.BLUE, (150, 300), weather.summary, 1.5), layer=3) all_sprites.add(LcarsText( colours.BLUE, (200, 300), "Temperature: %s C / Feels like: %s" % (weather.temperature, weather.apparentTemperature), 1.5), layer=3) all_sprites.add(LcarsText( colours.BLUE, (250, 300), "Wind: %s KPH %s" % (weather.windSpeed, degrees_to_cardinal(weather.windBearing)), 1.5), layer=3) all_sprites.add(LcarsText( colours.BLUE, (300, 300), "Precipitations: %s" % (weather.precipProbability), 1.5), layer=3) #all_sprites.add(LcarsText(colours.BLUE, (350, 300), "Type: %s / Qty: %s cm" % (weather.precipType, weather.precipAccumulation) , 1.5), layer=3) #all_sprites.add(LcarsText(colours.BLUE, (350, 300), "Sunset: %s / Sunrise: %s cm" % (weather.precipType, weather.precipAccumulation) , 1.5), layer=3) all_sprites.add(LcarsGifImage("assets/weather/%s.gif" % (weather.icon), (100, 144), 50), layer=1) self.info_text = all_sprites.get_sprites_from_layer(3) # SFX self.beep1 = Sound("assets/audio/panel/201.wav") Sound("assets/audio/hail_2.wav").play()
def setup(self, all_sprites): all_sprites.add(LcarsBackgroundImage("assets/lcars_screen_1.png"), layer=0) # panel text all_sprites.add(LcarsText(colours.BLACK, (11, 75), "MOSF"), layer=1) all_sprites.add(LcarsText(colours.ORANGE, (0, 135), "LONG RANGE PROBE", 2.5), layer=1) all_sprites.add(LcarsText(colours.BLACK, (54, 667), "192 168 0 3"), layer=1) # info text #all_sprites.add(LcarsText(colours.WHITE, (192, 174), "WELCOME", 1.5), # layer=3) #all_sprites.add(LcarsText(colours.BLUE, (244, 174), "TO THE Museum of Science Fiction", 1.5), # layer=3) #all_sprites.add(LcarsText(colours.BLUE, (286, 174), "LONG RANGE PROBE EXHIBIT", 1.5), # layer=3) #all_sprites.add(LcarsText(colours.BLUE, (330, 174), "LOOK AROUND", 1.5), # layer=3) #self.info_text = all_sprites.get_sprites_from_layer(3) # date display self.stardate = LcarsText(colours.BLACK, (444, 506), "", 1) self.lastClockUpdate = 0 all_sprites.add(self.stardate, layer=1) # permanent buttons all_sprites.add(LcarsButton(colours.RED_BROWN, (6, 662), "LOGOUT", self.logoutHandler), layer=1) all_sprites.add(LcarsBlockSmall(colours.ORANGE, (211, 16), "ABOUT", self.aboutHandler), layer=1) all_sprites.add(LcarsBlockLarge(colours.BLUE, (145, 16), "DEMO", self.demoHandler), layer=1) all_sprites.add(LcarsBlockHuge(colours.PEACH, (249, 16), "EXPLORE", self.exploreHandler), layer=1) all_sprites.add(LcarsElbow(colours.BEIGE, (400, 16), "MAIN", self.mainHandler), layer=1) # Sounds self.beep1 = Sound("assets/audio/panel/201.wav") #Sound("assets/audio/panel/220.wav").play() # specific buttons self.purpose = LcarsButton(colours.GREY_BLUE, (107, 127), "PURPOSE", self.purposeHandler) self.purpose.visible = True all_sprites.add(self.purpose, layer=4) self.details = LcarsButton(colours.ORANGE, (107, 262), "DETAILS", self.detailsHandler) self.details.visible = True all_sprites.add(self.details, layer=4) self.personnel = LcarsButton(colours.GREY_BLUE, (107, 398), "PERSONNEL", self.personnelHandler) self.personnel.visible = True all_sprites.add(self.personnel, layer=4) self.sources = LcarsButton(colours.ORANGE, (107, 533), "SOURCES", self.sourcesHandler) self.sources.visible = True all_sprites.add(self.sources, layer=4) # Purpose all_sprites.add(LcarsText(colours.WHITE, (172, 140), "To inspire the next generation of STEAM", 2.7), layer=3) all_sprites.add(LcarsText(colours.WHITE, (217, 140), "(science, technology, engineering, art,", 2.7), layer=3) all_sprites.add(LcarsText(colours.WHITE, (262, 140), "mathematics) students to innovate with", 2.7), layer=3) all_sprites.add(LcarsText(colours.WHITE, (307, 140), "unique projects and boldly go where no", 2.7), layer=3) all_sprites.add(LcarsText(colours.WHITE, (352, 140), "one has gone before.", 2.7), layer=3) #all_sprites.add(LcarsText(colours.BLUE, (244, 174), "TO THE Museum of Science Fiction", 1), # layer=3) #all_sprites.add(LcarsText(colours.BLUE, (286, 174), "LONG RANGE PROBE EXHIBIT", 1), # layer=3) #all_sprites.add(LcarsText(colours.BLUE, (330, 174), "LOOK AROUND", 1), # layer=3) self.purpose_text = all_sprites.get_sprites_from_layer(3) self.hideText(self.purpose_text) # Details all_sprites.add(LcarsText(colours.ORANGE, (192, 140), "LENGTH: ", 1.25), layer=6) all_sprites.add(LcarsText(colours.WHITE, (192, 220), "1.5 m (4 ft 6 in)", 1.25), layer=6) all_sprites.add(LcarsText(colours.ORANGE, (212, 140), "WIDTH: ", 1.25), layer=6) all_sprites.add(LcarsText(colours.WHITE, (212, 220), "0.45 m (1 ft 6 in)", 1.25), layer=6) all_sprites.add(LcarsText(colours.ORANGE, (232, 140), "HEIGHT: ", 1.25), layer=6) all_sprites.add(LcarsText(colours.WHITE, (232, 220), "0.25 m (10 in)", 1.25), layer=6) all_sprites.add(LcarsText(colours.ORANGE, (252, 140), "MASS: ", 1.25), layer=6) all_sprites.add(LcarsText(colours.WHITE, (252, 220), "20 kg (30 slugs)", 1.25), layer=6) all_sprites.add(LcarsText(colours.ORANGE, (292, 140), "MATERIALS: ", 1.25), layer=6) all_sprites.add(LcarsText(colours.WHITE, (292, 220), "Carbon fiber reinforced fiberglass shell, internal components 3D-printed PLA plastic", 1.25), layer=6) all_sprites.add(LcarsText(colours.ORANGE, (332, 140), "CONTROL: ", 1.25), layer=6) all_sprites.add(LcarsText(colours.WHITE, (332, 220), "7-inch touchscreen via Rasberry Pi, lights & movement via Arduino Mega", 1.25), layer=6) all_sprites.add(LcarsText(colours.ORANGE, (372, 140), "COST: ", 1.25), layer=6) all_sprites.add(LcarsText(colours.WHITE, (372, 220), "$1,000, 800 man-hours", 1.25), layer=6) self.details_text = all_sprites.get_sprites_from_layer(6) self.hideText(self.details_text) # Personnel all_sprites.add(LcarsText(colours.RED_BROWN, (192, 140), "Designed and built by a team of four mechanical & aerospace", 1.25), layer=7) all_sprites.add(LcarsText(colours.RED_BROWN, (212, 140), "engineering students at North Carolina State University", 1.25), layer=7) self.personnel_text= all_sprites.get_sprites_from_layer(7) self.hideText(self.personnel_text) self.personnel_image1 = LcarsImage("assets/ncsu.png", (192, 560)) self.personnel_image1.visible = False all_sprites.add(self.personnel_image1, layer=7) # Sources all_sprites.add(LcarsText(colours.GREY_BLUE, (192, 140), "SPECIAL THANKS TO:", 1.25), layer=8) all_sprites.add(LcarsText(colours.WHITE, (212, 180), "Toby Kurien (creator of LCARS Python Graphical Interface)", 1.25), layer=8) all_sprites.add(LcarsText(colours.WHITE, (232, 180), "NC State Mechanical Engineering Department", 1.25), layer=8) all_sprites.add(LcarsText(colours.WHITE,(252, 180), "NC State Entrepreneurship Initiative Garage", 1.25), layer=8) self.sources_text = all_sprites.get_sprites_from_layer(8) self.hideText(self.sources_text) #TEST self.test = LcarsButton(colours.RED_BROWN, (6, 662), "LOGOUT", self.logoutHandler) self.test.visible = False all_sprites.add(self.test, layer = 4)
def setup(self, all_sprites): all_sprites.add(LcarsBackgroundImage("assets/lcars_screen_1b.png"), layer=0) # panel text all_sprites.add(LcarsText(colours.BLACK, (11, 52), "LCARS 105"), layer=1) all_sprites.add(LcarsText(colours.ORANGE, (0, 135), "DATA INTERFACE", 2), layer=1) all_sprites.add(LcarsText(colours.BLACK, (183, 74), "LIGHTS"), layer=1) all_sprites.add(LcarsText(colours.BLACK, (222, 57), "CAMERAS"), layer=1) all_sprites.add(LcarsText(colours.BLACK, (372, 70), "ENERGY"), layer=1) all_sprites.add(LcarsText( colours.BLACK, (444, 612), socket.gethostbyname(socket.gethostname()).replace(".", " ")), layer=1) # info text all_sprites.add(LcarsText(colours.WHITE, (192, 130), "EVENT LOG:", 1.5), layer=3) all_sprites.add(LcarsText(colours.BLUE, (244, 130), "acpi", 1), layer=3) all_sprites.add(LcarsText(colours.BLUE, (286, 130), "uptime", 1), layer=3) all_sprites.add(LcarsText(colours.BLUE, (330, 130), "fqdn", 1), layer=3) self.info_text = all_sprites.get_sprites_from_layer(3) # date display self.stardate = LcarsText(colours.BLUE, (12, 380), "STAR DATE 2711.05 17:54:32", 1.5) self.lastClockUpdate = 0 all_sprites.add(self.stardate, layer=1) # buttons all_sprites.add(LcarsButton(colours.RED_BROWN, (6, 662), "LOGOUT", self.logoutHandler), layer=4) all_sprites.add(LcarsButton(colours.BEIGE, (107, 127), "SENSORS", self.sensorsHandler), layer=4) all_sprites.add(LcarsButton(colours.PURPLE, (107, 262), "GAUGES", self.gaugesHandler), layer=4) all_sprites.add(LcarsButton(colours.PEACH, (107, 398), "WEATHER", self.weatherHandler), layer=4) # gadgets all_sprites.add(LcarsGifImage("assets/gadgets/fwscan.gif", (277, 556), 100), layer=1) self.sensor_gadget = LcarsGifImage("assets/gadgets/lcars_anim2.gif", (235, 150), 100) self.sensor_gadget.visible = False all_sprites.add(self.sensor_gadget, layer=2) self.dashboard = LcarsImage("assets/gadgets/dashboard.png", (187, 232)) self.dashboard.visible = False all_sprites.add(self.dashboard, layer=2) self.weather = LcarsImage("assets/weather.jpg", (188, 122)) self.weather.visible = False all_sprites.add(self.weather, layer=2) #all_sprites.add(LcarsMoveToMouse(colours.WHITE), layer=1) self.beep1 = Sound("assets/audio/panel/201.wav") Sound("assets/audio/panel/220.wav").play()
def setup(self, all_sprites): #self.mainscreen=mainscr all_sprites.add( LcarsBackgroundImage("assets/lcars_screen_2_modern.png"), layer=0) all_sprites.add(LcarsGifImage("assets/gadgets/stlogorotating.gif", (103, 369), 50), layer=0) all_sprites.add(LcarsText(colours.BLUEMID, (270, -1), "AUTHORIZATION REQUIRED", 2), layer=1) all_sprites.add(LcarsText( colours.BLUEMID, (330, -1), "ONLY AUTHORIZED PERSONNEL MAY ACCESS THIS TERMINAL", 1.5), layer=1) all_sprites.add(LcarsText(colours.BLUEMID, (360, -1), "TOUCH TERMINAL TO PROCEED", 1.5), layer=1) #all_sprites.add(LcarsText(colours.BLUE, (390, -1), "FAILED ATTEMPTS WILL BE REPORTED", 1.5),layer=1) button_row_1 = 230 button_row_2 = 270 button_row_3 = 310 button_row_4 = 350 button_col_1 = 210 button_col_2 = 340 button_col_3 = 470 button_image = pygame.image.load("assets/buttonpad.png") button_image_down = pygame.image.load("assets/buttonpaddown.png") all_sprites.add(UltimateButton( (button_row_1, button_col_1), text="1", handler=self.num_1, image_set=[button_image, button_image, button_image_down]), layer=2) all_sprites.add(UltimateButton( (button_row_1, button_col_2), text="2", handler=self.num_2, image_set=[button_image, button_image, button_image_down]), layer=2) all_sprites.add(UltimateButton( (button_row_1, button_col_3), text="3", handler=self.num_3, image_set=[button_image, button_image, button_image_down]), layer=2) all_sprites.add(UltimateButton( (button_row_2, button_col_1), text="4", handler=self.num_4, image_set=[button_image, button_image, button_image_down]), layer=2) all_sprites.add(UltimateButton( (button_row_2, button_col_2), text="5", handler=self.num_5, image_set=[button_image, button_image, button_image_down]), layer=2) all_sprites.add(UltimateButton( (button_row_2, button_col_3), text="6", handler=self.num_6, image_set=[button_image, button_image, button_image_down]), layer=2) all_sprites.add(UltimateButton( (button_row_3, button_col_1), text="7", handler=self.num_7, image_set=[button_image, button_image, button_image_down]), layer=2) all_sprites.add(UltimateButton( (button_row_3, button_col_2), text="8", handler=self.num_8, image_set=[button_image, button_image, button_image_down]), layer=2) all_sprites.add(UltimateButton( (button_row_3, button_col_3), text="9", handler=self.num_3, image_set=[button_image, button_image, button_image_down]), layer=2) all_sprites.add(UltimateButton( (button_row_4, button_col_2), text="0", handler=self.num_7, image_set=[button_image, button_image, button_image_down]), layer=2) if config.DEV_MODE: all_sprites.add(LcarsButton(colours.GREY_BLUE, (0, 770), "X", self.exitHandler, (30, 30)), layer=2) self.layer1 = all_sprites.get_sprites_from_layer(1) self.layer2 = all_sprites.get_sprites_from_layer(2) # sounds Sound("assets/audio/panel/215.wav").play() self.sound_granted = Sound("assets/audio/accessing.wav") self.sound_beep1 = Sound("assets/audio/panel/201.wav") self.sound_denied = Sound("assets/audio/access_denied.wav") self.sound_deny1 = Sound("assets/audio/deny_1.wav") self.sound_deny2 = Sound("assets/audio/deny_2.wav") ############ # SET PIN CODE WITH THIS VARIABLE ############ self.pin = 1337 ############ self.reset()