Exemplo n.º 1
0
    def build(self):
        self.root = Accordion(min_space=30)

        self.overviewItem = AccordionItem(title=unichr(252) + 'bersicht')
        self.overview = Overview()
        self.overviewItem.add_widget(self.overview)
        #self.closeButton = Button(text = 'Beenden', size=(100, 50), size_hint=(None, None), background_color=[1,0,0,1])
        #self.closeButton.bind(on_press=self.closeApp)
        #self.overviewItem.add_widget(self.closeButton)
        self.root.add_widget(self.overviewItem)

        self.scheduleItem = AccordionItem(title='Stundenplan')
        self.schedule = Schedule()
        self.scheduleItem.add_widget(self.schedule)
        self.root.add_widget(self.scheduleItem)

        self.appointmentsItem = AccordionItem(title='Termine')
        self.appointments = Appointments()
        self.appointmentsItem.add_widget(self.appointments)
        self.root.add_widget(self.appointmentsItem)

        self.todoListItem = AccordionItem(title='Haushalts-Abenteuer')
        self.todoList = TodoList()
        self.todoListItem.add_widget(self.todoList)
        self.root.add_widget(self.todoListItem)

        self.newsItem = AccordionItem(title='Nachrichten')
        self.news = Feeds()
        self.newsItem.add_widget(self.news)
        self.root.add_widget(self.newsItem)

        self.pictureItem = AccordionItem(title='Bilder')
        self.pictureFrame = PictureFrame()
        self.pictureItem.add_widget(self.pictureFrame)
        self.root.add_widget(self.pictureItem)

        self.scheduleItem.collapse = False

        self.ledClock = LedMatrix()

        # initial weather data
        self.overview.updateWeather()
        # continuous updates
        EACH_SECOND = 1
        ONE_MINUTE = 60
        FOUR_HOURS = 14400
        Clock.schedule_interval(self.__updateLedClock, EACH_SECOND)
        Clock.schedule_interval(self.__updateItems, ONE_MINUTE)
        Clock.schedule_interval(self.__updateWeather, FOUR_HOURS)

        return self.root
Exemplo n.º 2
0
def main():
    print("starting in some seconds")
    time.sleep(1)
    print("starting led badge")

    TextScroller(LedMatrix()).scroll_text("It's demo time... :) ...   ")
    # test_text_scroller()
    run_rotating_plasma()
Exemplo n.º 3
0
def main():
    lm = LedMatrix()

    pygame.init()
    pygame.joystick.init()
    joy = Joystick(0)

    gameMain = LifeGameMain(lm, joy)
    try:
        gameMain.start()
    except KeyboardInterrupt:
        pass
    except:
        print(traceback.format_exc())

    if lm != None:
        lm.term()
Exemplo n.º 4
0
def get_readings(sensor):
    # The sense HAT does not include any way to obtain an air quality score via gas measurement,
    # so we can create one using the temperature and humidity reading based on distance from ideal values
    max_iaq = 500
    min_iaq = 25

    temperature_ideal = 25
    temperature_worst_variance = 40

    humidity_ideal = 40
    humidity_worst_variance = 40
    humidity_weighting = 0.25 # this means % of the AQ figure will be humidity, the rest will be temperature

    # Get the current temperature and humidity readings
    current_temperature = sensor.get_temperature()
    current_humidity = sensor.get_humidity()

    # Find out how far from the ideal the current values are
    current_temperature_variance = abs(current_temperature - temperature_ideal)/temperature_worst_variance
    # if the variance is greater than 1 (100%), set it to as a maximum
    # note also that 100% here is the worst possible value
    if current_temperature_variance > 1:
        current_temperature_variance = 1

    # Do the same thing for the humidity reading
    current_humidity_variance = abs(current_humidity - humidity_ideal)/humidity_worst_variance
    if current_humidity_variance > 1:
        current_humidity_variance = 1

    # Scale the current variance measurements in accordance with the weighting to calculate a percentage
    # this gives us a score where 1 is the worst possible value
    air_quality_score = (current_humidity_variance * humidity_weighting) + (current_temperature_variance * (1 - humidity_weighting))
    air_quality_score = air_quality_score * 500

    # As we have a sense HAT we can give an indication of the air quality on the LED matrix
    from ledmatrix import LedMatrix

    display = LedMatrix()
    display.clear()
    if air_quality_score < 100:
        # Happy face!
        face_color = [0, 255, 0]
        face_pixels = [
            0, 0, 1, 1, 1, 1, 0, 0,
            0, 1, 0, 0, 0, 0, 1, 0,
            1, 0, 1, 0, 0, 1, 0, 1,
            1, 0, 0, 0, 0, 0, 0, 1,
            1, 0, 1, 0, 0, 1, 0, 1,
            1, 0, 0, 1, 1, 0, 0, 1,
            0, 1, 0, 0, 0, 0, 1, 0,
            0, 0, 1, 1, 1, 1, 0, 0
        ]
    elif air_quality_score < 250:
        # Neutral face
        face_color = [250, 255, 0]
        face_pixels = [
            0, 0, 1, 1, 1, 1, 0, 0,
            0, 1, 0, 0, 0, 0, 1, 0,
            1, 0, 1, 0, 0, 1, 0, 1,
            1, 0, 0, 0, 0, 0, 0, 1,
            1, 0, 1, 1, 1, 1, 0, 1,
            1, 0, 0, 0, 0, 0, 0, 1,
            0, 1, 0, 0, 0, 0, 1, 0,
            0, 0, 1, 1, 1, 1, 0, 0
        ]
    else:
        # Sad face
        face_color = [255, 0, 0]
        face_pixels = [
            0, 0, 1, 1, 1, 1, 0, 0,
            0, 1, 0, 0, 0, 0, 1, 0,
            1, 0, 1, 0, 0, 1, 0, 1,
            1, 0, 0, 0, 0, 0, 0, 1,
            1, 0, 0, 1, 1, 0, 0, 1,
            1, 0, 1, 0, 0, 1, 0, 1,
            0, 1, 0, 0, 0, 0, 1, 0,
            0, 0, 1, 1, 1, 1, 0, 0
        ]

    for x in range(64):
        if face_pixels[x] == 1:
            face_pixels[x] = face_color
        elif face_pixels[x] == 0:
            face_pixels[x] = [0,0,0]

    display.set_pixels(face_pixels)

    return [
        {
            'measurement': 'balena-sense',
            'fields': {
                'temperature': float(current_temperature),
                'pressure': float(sensor.environ.pressure),
                'humidity': float(current_humidity),
                'air_quality_score': float(air_quality_score)
            }
        }
    ]
Exemplo n.º 5
0
def test_text_scroller():
    TextScroller(LedMatrix()).scroll_text("hallo welt 42!")
Exemplo n.º 6
0
def run_plasma_demo():
    PlasmaDemo(LedMatrix()).run()
Exemplo n.º 7
0
def run_game_of_life():
    mat = LedMatrix()
    gol = GameOfLife(mat)
    gol.run()
Exemplo n.º 8
0
def flicker():
    print("flickering the display as fast as possible")
    matrix = LedMatrix()
    for i in range(10):
        matrix.tm.write([0] * 8)
        matrix.tm.write([255] * 8)
Exemplo n.º 9
0
def testmatrix():
    matrix = LedMatrix()
    print("all off")
    for y in range(matrix.height):
        for x in range(matrix.width):
            matrix.px(x, y, False)
    matrix.show()
    time.sleep(0.3)

    print("all on")
    for y in range(matrix.height):
        for x in range(matrix.width):
            matrix.px(x, y, True)
            matrix.show()
            time.sleep(0.1)

    print("every other on")
    for y in range(matrix.height):
        for x in range(matrix.width):
            matrix.px(x, y, x % 2 == 0)
            matrix.show()
            time.sleep(0.1)
Exemplo n.º 10
0
def run_rotating_plasma():
    RotatingPlasmaDemo(LedMatrix()).run()
Exemplo n.º 11
0
def run_pingpong_demo():
    mat = LedMatrix()
    PingPong(mat).run()
Exemplo n.º 12
0
            '/dev/tty.usbserial-DQ008J7R',  # Pycom device on macOS
            '/dev/ttyUSB0',  # Linux
            '/dev/ttyACM0',  # Linux
        ]
        for port in ports:
            if os.path.exists(port):
                config['port'] = port
                break
        # Disable automatic rendering of time
        driver.set_auto_time(False)
        # Trap Ctrl-C and service termination
        signal.signal(signal.SIGINT, sigint_handler)
        signal.signal(signal.SIGTERM, sigint_handler)

    # Initialize led matrix framebuffer on top of HAL
    display = LedMatrix(driver, config['LedMatrix'])
    driver.clear_display()

    if pycom_board:
        # We're running under MCU here
        from bootscene import BootScene
        scene = BootScene(display, config['Boot'])
        wlan = WLAN(mode=WLAN.STA)
        if not wlan.isconnected():
            print('WLAN: Scanning for networks')
            scene.render(0, 0, 0)
            default_ssid, default_auth = wlan.ssid(), wlan.auth()
            candidates = wlan.scan()
            for conf in config['networks']:
                nets = [
                    candidate for candidate in candidates
Exemplo n.º 13
0
class DashboardApp(App):
    def build(self):
        self.root = Accordion(min_space=30)

        self.overviewItem = AccordionItem(title=unichr(252) + 'bersicht')
        self.overview = Overview()
        self.overviewItem.add_widget(self.overview)
        #self.closeButton = Button(text = 'Beenden', size=(100, 50), size_hint=(None, None), background_color=[1,0,0,1])
        #self.closeButton.bind(on_press=self.closeApp)
        #self.overviewItem.add_widget(self.closeButton)
        self.root.add_widget(self.overviewItem)

        self.scheduleItem = AccordionItem(title='Stundenplan')
        self.schedule = Schedule()
        self.scheduleItem.add_widget(self.schedule)
        self.root.add_widget(self.scheduleItem)

        self.appointmentsItem = AccordionItem(title='Termine')
        self.appointments = Appointments()
        self.appointmentsItem.add_widget(self.appointments)
        self.root.add_widget(self.appointmentsItem)

        self.todoListItem = AccordionItem(title='Haushalts-Abenteuer')
        self.todoList = TodoList()
        self.todoListItem.add_widget(self.todoList)
        self.root.add_widget(self.todoListItem)

        self.newsItem = AccordionItem(title='Nachrichten')
        self.news = Feeds()
        self.newsItem.add_widget(self.news)
        self.root.add_widget(self.newsItem)

        self.pictureItem = AccordionItem(title='Bilder')
        self.pictureFrame = PictureFrame()
        self.pictureItem.add_widget(self.pictureFrame)
        self.root.add_widget(self.pictureItem)

        self.scheduleItem.collapse = False

        self.ledClock = LedMatrix()

        # initial weather data
        self.overview.updateWeather()
        # continuous updates
        EACH_SECOND = 1
        ONE_MINUTE = 60
        FOUR_HOURS = 14400
        Clock.schedule_interval(self.__updateLedClock, EACH_SECOND)
        Clock.schedule_interval(self.__updateItems, ONE_MINUTE)
        Clock.schedule_interval(self.__updateWeather, FOUR_HOURS)

        return self.root

    def __updateWeather(self, dt):
        self.overview.updateWeather()

    def __updateLedClock(self, dt):
        self.ledClock.updateLedDisplay(time.strftime("%H:%M:%S"))

    def __updateItems(self, dt):
        self.overview.updateDateTime()
        self.news.refreshFeeds()
        self.pictureFrame.updateRandomPicture()
        self.schedule.handleScheduleDisplay()
        dueAppointments = self.appointments.due()
        if not dueAppointments:
            self.appointmentsItem.title = 'Termine'
        else:
            self.appointmentsItem.title = 'Termin(e) >>heute<<'
            self.overview.updateAppointmentTile(dueAppointments)

        dueReminders = self.appointments.remind()
        if dueReminders:
            self.overview.updateReminderTile(dueReminders)

    def closeApp(self, instance):
        self.stop()