Example #1
0
    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()
Example #2
0
    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
Example #3
0
    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()
Example #4
0
    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()
Example #5
0
    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()
Example #6
0
    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()
Example #7
0
    def setup(self, all_sprites):

        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)

        self.all_sprites = all_sprites

        # Uncomment for fullscreen
        #DISPLAYSURF = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)

        # For some reason, coordinates are passed in as y,x

        pad = 5
        hpad = 10

        leftStackWidth = 0.1345
        screenWidth = pygame.display.get_surface().get_width()
        screenHeight = pygame.display.get_surface().get_height()

        # Elbow
        topLeftElbow = LcarsElbow(colours.PEACH, 0, (-40, hpad - 1),
                                  self.convertFloatToPoints(x=0.3,
                                                            y=0.15))  #0.225
        all_sprites.add(topLeftElbow, layer=1)

        # Second elbow
        secondElbow = LcarsElbow(colours.PEACH, 1,
                                 (topLeftElbow.nextObjCoordY(pad), hpad - 1),
                                 self.convertFloatToPoints(x=0.3,
                                                           y=0.15))  #0.225
        all_sprites.add(secondElbow, layer=1)

        # First Horizontal Bar
        h1 = LcarsHStrip(
            colours.PEACH,
            (self.yPercToPoints(0.0595), topLeftElbow.nextObjCoordX(pad)), 60,
            self.yPercToPoints(0.035), "")
        all_sprites.add(h1, layer=1)

        h2 = LcarsHStrip(colours.ORANGE,
                         (self.yPercToPoints(0.0595), h1.nextObjCoordX(pad)),
                         120, self.yPercToPoints(0.035), "")
        all_sprites.add(h2, layer=1)

        h3 = LcarsHStrip(colours.PEACH,
                         (self.yPercToPoints(0.0595), h2.nextObjCoordX(pad)),
                         20, self.yPercToPoints(0.035), "")
        all_sprites.add(h3, layer=1)

        h4 = LcarsHStrip(colours.ORANGE,
                         (self.yPercToPoints(0.0595), h3.nextObjCoordX(pad)),
                         50, self.yPercToPoints(0.035), "")
        all_sprites.add(h4, layer=1)

        h5 = LcarsHStrip(colours.PEACH,
                         (self.yPercToPoints(0.0595), h4.nextObjCoordX(pad)),
                         140, self.yPercToPoints(0.035), "")
        all_sprites.add(h5, layer=1)

        h6 = LcarsHStrip(colours.ORANGE,
                         (self.yPercToPoints(0.0595), h5.nextObjCoordX(pad)),
                         20, self.yPercToPoints(0.035), "")
        all_sprites.add(h6, layer=1)

        remainingWidth = screenWidth - h6.rect.left - h6.rect.width - (hpad *
                                                                       2)
        hlast = LcarsHStrip(
            colours.PEACH, (self.yPercToPoints(0.0595), h6.nextObjCoordX(pad)),
            remainingWidth - pad, self.yPercToPoints(0.035), "")
        all_sprites.add(hlast, layer=1)

        # Second Horizontal Bar
        h7 = LcarsHStrip(
            colours.PEACH,
            (secondElbow.rect.top + 1, secondElbow.nextObjCoordX(0)), 40,
            self.yPercToPoints(0.035), "")
        all_sprites.add(h7, layer=1)

        h8 = LcarsHStrip(colours.ORANGE, (h7.rect.top, h7.nextObjCoordX(pad)),
                         240, self.yPercToPoints(0.035), "")
        all_sprites.add(h8, layer=1)

        h9 = LcarsHStrip(colours.PEACH, (h7.rect.top, h8.nextObjCoordX(pad)),
                         30, self.yPercToPoints(0.035), "")
        all_sprites.add(h9, layer=1)

        h10 = LcarsHStrip(colours.ORANGE, (h7.rect.top, h9.nextObjCoordX(pad)),
                          90, self.yPercToPoints(0.035), "")
        all_sprites.add(h10, layer=1)

        h11 = LcarsHStrip(colours.PEACH, (h7.rect.top, h10.nextObjCoordX(pad)),
                          100, self.yPercToPoints(0.035), "")
        all_sprites.add(h11, layer=1)

        h12 = LcarsHStrip(colours.ORANGE,
                          (h7.rect.top, h11.nextObjCoordX(pad)), 75,
                          self.yPercToPoints(0.035), "")
        all_sprites.add(h12, layer=1)

        secondRemainingWidth = screenWidth - h12.rect.left - h12.rect.width - (
            hpad * 2)
        secondHLast = LcarsHStrip(colours.PEACH,
                                  (h7.rect.top, h12.nextObjCoordX(pad)),
                                  secondRemainingWidth - pad,
                                  self.yPercToPoints(0.035), "")
        all_sprites.add(secondHLast, layer=1)

        # Left Menu Stack
        l1 = LcarsBlockSmall(
            colours.ORANGE, (secondElbow.nextObjCoordY(pad), hpad), "MEDIA",
            self.convertFloatToPoints(x=leftStackWidth, y=0.10))
        l1.handler = self.musicHandler
        all_sprites.add(l1, layer=1)

        l2 = LcarsBlockSmall(
            colours.RED_BROWN, (l1.nextObjCoordY(pad), hpad), "COMMUNICATION",
            self.convertFloatToPoints(x=leftStackWidth, y=0.10))
        all_sprites.add(l2, layer=1)

        l3 = LcarsBlockSmall(
            colours.DARK_BLUE, (l2.nextObjCoordY(pad), hpad), "NAVIGATION",
            self.convertFloatToPoints(x=leftStackWidth, y=0.10))
        all_sprites.add(l3, layer=1)

        l4 = LcarsBlockSmall(
            colours.RED, (l3.nextObjCoordY(pad), hpad), "PERFORMANCE",
            self.convertFloatToPoints(x=leftStackWidth, y=0.075))
        all_sprites.add(l4, layer=1)

        l5 = LcarsBlockSmall(
            colours.BLUE, (l4.nextObjCoordY(pad), hpad), "ENGINEERING",
            self.convertFloatToPoints(x=leftStackWidth, y=0.075))
        all_sprites.add(l5, layer=1)

        # Variable height spacer
        bottomElbowHeight = 0.15
        remainingHeight = screenHeight - l5.rect.top - l5.rect.height - self.yPercToPoints(
            bottomElbowHeight) - (hpad * 2)
        bottomLeftSpacer = LcarsBlockSmall(
            colours.WHITE, (l5.nextObjCoordY(pad), hpad), "",
            self.convertFloatToPoints(
                x=leftStackWidth,
                y=self.convertScreenHeightPointsToFloat(remainingHeight)))
        all_sprites.add(bottomLeftSpacer, layer=1)

        # Bottom Left Elbow
        bottomLeftElbow = LcarsElbow(
            colours.PEACH, 0,
            (bottomLeftSpacer.nextObjCoordY(pad), l5.rect.left),
            self.convertFloatToPoints(x=0.3, y=bottomElbowHeight))  #0.225
        all_sprites.add(bottomLeftElbow, layer=1)

        # Bottom Horizontal Bar
        h13 = LcarsHStrip(
            colours.PEACH,
            (self.yPercToPoints(0.95), bottomLeftElbow.nextObjCoordX(pad)),
            self.yPercToPoints(0.1), self.yPercToPoints(0.035), "")
        all_sprites.add(h13, layer=1)

        # Variable width spacer
        bottomRightElbowWidth = 0.3
        bottomRemainingWidth = screenWidth - h13.rect.left - h13.rect.width - self.xPercToPoints(
            bottomRightElbowWidth) - (hpad * 2)
        bottomRightSpacer = LcarsBlockSmall(
            colours.WHITE, (h13.rect.top, h13.nextObjCoordX(pad)), "",
            self.convertFloatToPoints(
                x=self.convertScreenWidthPointsToFloat(bottomRemainingWidth),
                y=0.035))
        all_sprites.add(bottomRightSpacer, layer=1)

        # Bottom Right Elbow
        bottomRightElbow = LcarsElbow(
            colours.PEACH, 3,
            (bottomRightSpacer.rect.top, bottomRightSpacer.nextObjCoordX(pad)),
            self.convertFloatToPoints(x=bottomRightElbowWidth,
                                      y=bottomElbowHeight))  #0.225
        all_sprites.add(bottomRightElbow, layer=1)

        # weather = LcarsImage("assets/weather.jpg", (l1.rect.y , l1.nextObjCoordX(10)))
        # all_sprites.add(weather, layer=2)

        # b1 = LcarsHStrip(colours.PEACH, (400, hpad), 200, "")
        # all_sprites.add(b1, layer=1)

        # bottomRightElbow = LcarsElbow(colours.PEACH, 2, (250, 250))
        # all_sprites.add(bottomRightElbow, layer=1)

        # l2 = LcarsBlockMedium(colours.GREY_BLUE, (10, 10), "MEDIUM")
        # all_sprites.add(l2, layer=1)
        # l3 = LcarsBlockLarge(colours.PURPLE, (120, 10), "LARGE")
        # all_sprites.add(l3, layer=1)

        # 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")

        self.reset()
Example #8
0
    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()
Example #9
0
    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()
Example #10
0
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
Example #11
0
    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)
Example #12
0
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
Example #13
0
    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()
Example #14
0
    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()
Example #15
0
    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)
Example #16
0
    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()
Example #17
0
    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()