A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 160 lines 5.1 kB view raw
1/*************************************************************************** 2 * __________ __ ___. 3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 * \/ \/ \/ \/ \/ 8 * $Id$ 9 * 10 * Copyright (C) 2005 Jonas Häggqvist 11 * 12 * This program is free software; you can redistribute it and/or 13 * modify it under the terms of the GNU General Public License 14 * as published by the Free Software Foundation; either version 2 15 * of the License, or (at your option) any later version. 16 * 17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 18 * KIND, either express or implied. 19 * 20 **************************************************************************/ 21#include "plugin.h" 22#include "lib/pluginlib_actions.h" 23 24/* this set the context to use with PLA */ 25static const struct button_mapping *plugin_contexts[] 26 = { pla_main_ctx, 27#ifdef HAVE_REMOTE_LCD 28 pla_remote_ctx, 29#endif 30 }; 31 32#define DISPLAY_WIDTH LCD_WIDTH 33#define DISPLAY_HEIGHT LCD_HEIGHT 34#define RAND_SCALE 5 35 36#ifdef HAVE_REMOTE_LCD 37#define REMOTE_WIDTH LCD_REMOTE_WIDTH 38#define REMOTE_HEIGHT LCD_REMOTE_HEIGHT 39#include "pluginbitmaps/remote_rockboxlogo.h" 40#define REMOTE_LOGO_WIDTH BMPWIDTH_remote_rockboxlogo 41#define REMOTE_LOGO_HEIGHT BMPHEIGHT_remote_rockboxlogo 42#define REMOTE_LOGO remote_rockboxlogo 43#endif /* HAVE_REMOTE_LCD */ 44 45#define LOGO rockboxlogo 46#include "pluginbitmaps/rockboxlogo.h" 47#define LOGO_WIDTH BMPWIDTH_rockboxlogo 48#define LOGO_HEIGHT BMPHEIGHT_rockboxlogo 49 50/* We use PLA */ 51#define LP_QUIT PLA_EXIT 52#define LP_DEC_X PLA_LEFT 53#define LP_DEC_X_REPEAT PLA_LEFT_REPEAT 54#define LP_INC_X PLA_RIGHT 55#define LP_INC_X_REPEAT PLA_RIGHT_REPEAT 56 57#if (CONFIG_KEYPAD == IPOD_1G2G_PAD) \ 58 || (CONFIG_KEYPAD == IPOD_3G_PAD) \ 59 || (CONFIG_KEYPAD == IPOD_4G_PAD) 60#define LP_QUIT2 PLA_UP 61#define LP_DEC_Y PLA_SCROLL_BACK 62#define LP_DEC_Y_REPEAT PLA_SCROLL_BACK_REPEAT 63#define LP_INC_Y PLA_SCROLL_FWD 64#define LP_INC_Y_REPEAT PLA_SCROLL_FWD_REPEAT 65#else 66#define LP_QUIT2 PLA_CANCEL 67#define LP_DEC_Y PLA_DOWN 68#define LP_DEC_Y_REPEAT PLA_DOWN_REPEAT 69#define LP_INC_Y PLA_UP 70#define LP_INC_Y_REPEAT PLA_UP_REPEAT 71#endif 72 73 74enum plugin_status plugin_start(const void* parameter) { 75 int button; 76 int timer = 10; 77 int x = (DISPLAY_WIDTH / 2) - (LOGO_WIDTH / 2); 78 int y = (DISPLAY_HEIGHT / 2) - (LOGO_HEIGHT / 2); 79 int dx; 80 int dy; 81 82 (void)parameter; 83 84 rb->srand(*rb->current_tick); 85 dx = rb->rand()%(2*RAND_SCALE+1) - RAND_SCALE; 86 dy = rb->rand()%(2*RAND_SCALE+1) - RAND_SCALE; 87 88 while (1) { 89 rb->lcd_clear_display(); 90 rb->lcd_bitmap((const fb_data*)LOGO, x, y, LOGO_WIDTH, LOGO_HEIGHT); 91#ifdef REMOTE_LOGO 92 rb->lcd_remote_clear_display(); 93 rb->lcd_remote_bitmap((const fb_remote_data*)REMOTE_LOGO, 94 (x * (REMOTE_WIDTH - REMOTE_LOGO_WIDTH)) / (DISPLAY_WIDTH - LOGO_WIDTH), 95 (y * (REMOTE_HEIGHT - REMOTE_LOGO_HEIGHT)) / (DISPLAY_HEIGHT - LOGO_HEIGHT), 96 REMOTE_LOGO_WIDTH, REMOTE_LOGO_HEIGHT); 97#endif 98 x += dx; 99 if (x < 0) { 100 dx = -dx; 101 x = 0; 102 } 103 if (x > DISPLAY_WIDTH - LOGO_WIDTH) { 104 dx = -dx; 105 x = DISPLAY_WIDTH - LOGO_WIDTH; 106 } 107 108 y += dy; 109 if (y < 0) { 110 dy = -dy; 111 y = 0; 112 } 113 if (y > DISPLAY_HEIGHT - LOGO_HEIGHT) { 114 dy = -dy; 115 y = DISPLAY_HEIGHT - LOGO_HEIGHT; 116 } 117 118 rb->lcd_update(); 119#ifdef REMOTE_LOGO 120 rb->lcd_remote_update(); 121#endif 122 rb->sleep(HZ/timer); 123 124 125 126 /*We get button from PLA this way */ 127 button = pluginlib_getaction(TIMEOUT_NOBLOCK, plugin_contexts, 128 ARRAYLEN(plugin_contexts)); 129 130 switch (button) { 131 case LP_QUIT: 132 case LP_QUIT2: 133 return PLUGIN_OK; 134 case LP_DEC_X: 135 case LP_DEC_X_REPEAT: 136 if (dx) 137 dx += (dx < 0) ? 1 : -1; 138 break; 139 case LP_INC_X: 140 case LP_INC_X_REPEAT: 141 dx += (dx < 0) ? -1 : 1; 142 break; 143 case LP_DEC_Y: 144 case LP_DEC_Y_REPEAT: 145 if (dy) 146 dy += (dy < 0) ? 1 : -1; 147 break; 148 case LP_INC_Y: 149 case LP_INC_Y_REPEAT: 150 dy += (dy < 0) ? -1 : 1; 151 break; 152 153 default: 154 if (rb->default_event_handler(button) == SYS_USB_CONNECTED) { 155 return PLUGIN_USB_CONNECTED; 156 } 157 break; 158 } 159 } 160}