Пример #1
0
    def run(self):
        try:
            self.sleeptimer.resetsleep()
            lcd.init()
            self.framebuffer = graphics.Surface(lcd.LCD_WIDTH, lcd.LCD_HEIGHT)
            lcd.set_backlight_enabled(True)

            self.broker.register_service(services.clock.ClockService)
            self.broker.register_service(services.weather.WeatherService)
            self.broker.register_service(services.podcast.PodcastService)
            self.broker.register_service(services.audio.AudioService)
            self.broker.register_service(
                services.public_transport.PublicTransportService)

            for p, args in self.panel_defs:
                self.addpanel(p, args)
            self.activate_panel(0)

            self.broker.start_bound_services()

            while True:
                services.deliver_pending_notifications()
                self.sleeptimer.update_sleep()
                self.trigger_key_events()
                self.active_panel.update()
                if self.activate_panel:
                    if self.active_panel.paint_if_needed(self.active_panel_fb):
                        # logging.debug('Updating LCD (active_panel)')
                        lcd.update(self.active_panel_fb)
                time.sleep(1.0 / UPDATE_RATE)
        finally:
            self.broker.stop_running()
Пример #2
0
def test_init_paint_update():
    cwd = os.getcwd()
    fonts.register('tempesta', os.path.join(cwd,
                                            'assets/pf_tempesta_seven.ttf'))
    fonts.register('pixarrows', os.path.join(cwd, 'assets/pixarrows.ttf'))
    fonts.register('climacons', os.path.join(cwd, 'assets/climacons.ttf'))
    fonts.register('helvetica', os.path.join(cwd, 'assets/helvetica.ttf'))

    broker = ServiceBroker()
    clock_mock = make_service_mock('ClockServiceMock')
    clock_mock.return_value.timeofday.return_value = '13:37'
    weather_mock = make_service_mock('WeatherServiceMock')
    podcast_mock = make_service_mock('PodcastServiceMock')
    audio_mock = make_service_mock('AudioServiceMock')
    audio_mock.return_value.playback_progress.return_value = 0.5
    pt_mock = make_service_mock('PublicTransportServiceMock')
    broker.register_service(clock_mock, 'ClockService')
    broker.register_service(weather_mock, 'WeatherService')
    broker.register_service(podcast_mock, 'PodcastService')
    broker.register_service(audio_mock, 'AudioService')
    broker.register_service(pt_mock, 'PublicTransportService')

    surf = graphics.Surface(128, 64)

    for cls, config in PANELS:
        pnl = broker.instantiate(cls, config)
        pnl.paint(surf)
        pnl.update()
        monkey_test(pnl)
Пример #3
0
    def __init__(self):
        super(ShootEmUpGamePanel, self).__init__()

        self.fps = 0
        self.bg_scroll_offset = 0
        self.fg_scroll_offset = 0
        self.ship_x = 5
        self.ship_y = 24
        self.shots = []

        # Load assets
        self.fps_font = fonts.get('tempesta', 8)
        self.background_img = graphics.Surface(
            filename='assets/shmup/background.png', dither=True)
        self.foreground_img = graphics.Surface(
            filename='assets/shmup/foreground.png', dither=True)
        self.ship_img = graphics.Surface(filename='assets/shmup/ship.png', )
Пример #4
0
def monkey_test(pnl):
    """Monkey-test the panels by randomly pressing buttons."""
    surf = graphics.Surface(128, 64)
    for _ in range(100):
        key_func = random.choice(
            [pnl.up_pressed, pnl.down_pressed, pnl.center_pressed])
        key_func()
        pnl.update()
        pnl.paint(surf)
Пример #5
0
 def addpanel(self, panel_class, config):
     self.framebuffer.fill(0)
     ui.render_progressbar(self.framebuffer, 2,
                           self.framebuffer.height / 2 - 8,
                           self.framebuffer.width - 2 * 2, 16,
                           len(self.panels) / float(len(self.panel_defs)))
     self.framebuffer.center_text(self.font,
                                  panel_class.__name__,
                                  rop=graphics.rop_xor)
     self.lcd_update()
     lcd.readkeys()
     logging.info('Initializing %s', panel_class.__name__)
     try:
         instance = self.broker.instantiate(panel_class, config)
         self.panels.append(instance)
         self.backing_stores[instance] = graphics.Surface(
             lcd.LCD_WIDTH, lcd.LCD_HEIGHT)
     except Exception as e:
         logging.error('Failed to initialize panel %s',
                       panel_class.__name__)
         logging.exception(e)
Пример #6
0
 def render(self, text, width=None, height=None, baseline=None):
     bmp = self.render_text(text, width, height, baseline)
     return graphics.Surface(bmp.width, bmp.height, pixels=bmp.pixels)
Пример #7
0
 def __init__(self):
     super(DitherTestPanel, self).__init__()
     self.set_needs_repaint()
     self.img = graphics.Surface(filename='assets/dithertest.png')
     self.img.dither()
Пример #8
0
import time
import bottle
import piradio.graphics as graphics

logger = logging.getLogger('weblcd')

LCD_WIDTH, LCD_HEIGHT = 128, 64

K_LEFT = 0
K_RIGHT = 1
K_UP = 2
K_DOWN = 3
K_CENTER = 4

_KEYS = [False] * 5
_SCREEN = graphics.Surface(LCD_WIDTH, LCD_HEIGHT)


@bottle.get('/')
def get_index():
    return """
        <img src="/screen" width="128" height="64">
        <a href="/keys/left">left</a>
        <a href="/keys/right">right</a>
        <a href="/keys/up">up</a>
        <a href="/keys/down">down</a>
        <a href="/keys/center">center</a>
    """


@bottle.get('/screen')