A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 208 lines 6.2 kB view raw
1/*************************************************************************** 2* __________ __ ___. 3* Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7* \/ \/ \/ \/ \/ 8* $Id$ 9* 10* Copyright (C) 2006 Jens Arnold 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 22#include "plugin.h" 23#include "lib/pluginlib_actions.h" 24 25/* this set the context to use with PLA */ 26static const struct button_mapping *plugin_contexts[] = { pla_main_ctx }; 27#define SCANRATE_QUIT PLA_EXIT 28#define SCANRATE_QUIT2 PLA_CANCEL 29#define SCANRATE_FASTINC PLA_UP 30#define SCANRATE_FASTINC_REPEAT PLA_UP_REPEAT 31#define SCANRATE_FASTDEC PLA_DOWN 32#define SCANRATE_FASTDEC_REPEAT PLA_DOWN_REPEAT 33 34#ifdef HAVE_SCROLLWHEEL 35#define SCANRATE_INC PLA_SCROLL_FWD 36#define SCANRATE_INC_REPEAT PLA_SCROLL_FWD_REPEAT 37#define SCANRATE_DEC PLA_SCROLL_BACK 38#define SCANRATE_DEC_REPEAT PLA_SCROLL_BACK_REPEAT 39#else 40#define SCANRATE_INC PLA_RIGHT 41#define SCANRATE_INC_REPEAT PLA_RIGHT_REPEAT 42#define SCANRATE_DEC PLA_LEFT 43#define SCANRATE_DEC_REPEAT PLA_LEFT_REPEAT 44#endif /*HAVE_SCROLLWHEEL*/ 45 46/* Default refresh rates in 1/10 Hz */ 47#if defined IAUDIO_M3 48#define DEFAULT_SCAN_RATE 1500 49#define HORIZ_SCAN /* LCD controller updates the panel sideways */ 50#define NEED_BOOST 51#elif defined MPIO_HD200 52#define DEFAULT_SCAN_RATE 1460 53#define NEED_BOOST 54#elif defined MPIO_HD300 55#define DEFAULT_SCAN_RATE 730 56#elif defined IAUDIO_M5 57#define DEFAULT_SCAN_RATE 730 58#elif defined IPOD_1G2G 59#define DEFAULT_SCAN_RATE 960 60#elif defined IPOD_MINI2G || defined IPOD_MINI \ 61 || defined IPOD_3G || defined IPOD_4G 62#define DEFAULT_SCAN_RATE 870 63#elif defined IRIVER_H100_SERIES 64#define DEFAULT_SCAN_RATE 700 65#elif defined SANSA_CLIP 66#define DEFAULT_SCAN_RATE 780 67#elif defined SAMSUNG_YH920 68#define DEFAULT_SCAN_RATE 700 69#else 70#define DEFAULT_SCAN_RATE 700 71#warning Generic default scanrate 72#endif 73 74#ifdef HORIZ_SCAN 75#define TEXT_X 0 76#if LCD_PIXELFORMAT == HORIZONTAL_PACKING 77#define BUF_WIDTH ((LCD_WIDTH+7)/8) 78#define BUF_HEIGHT (LCD_HEIGHT/4) 79#define TEXT_Y BUF_HEIGHT 80#else 81#define BUF_WIDTH (LCD_WIDTH) 82#define BUF_HEIGHT (LCD_HEIGHT/8/4) 83#define TEXT_Y (BUF_HEIGHT*8) 84#endif 85#else /* !HORIZ_SCAN */ 86#define TEXT_Y 0 87#if LCD_PIXELFORMAT == HORIZONTAL_PACKING 88#define BUF_WIDTH ((LCD_WIDTH+7)/8/4) 89#define BUF_HEIGHT LCD_HEIGHT 90#define TEXT_X (BUF_WIDTH*8) 91#else 92#define BUF_WIDTH (LCD_WIDTH/4) 93#define BUF_HEIGHT (LCD_HEIGHT/8) 94#define TEXT_X BUF_WIDTH 95#endif 96#endif /* !HORIZ_SCAN */ 97 98#if defined(CPU_PP) && defined(HAVE_ADJUSTABLE_CPU_FREQ) 99#define NEED_BOOST 100#endif 101 102static unsigned char bitbuffer[2][BUF_HEIGHT][BUF_WIDTH]; 103static int curbuf = 0; 104static int scan_rate = DEFAULT_SCAN_RATE; 105static bool need_refresh = false; 106 107static void timer_isr(void) 108{ 109 rb->lcd_blit_mono(bitbuffer[curbuf][0], 0, 0, BUF_WIDTH, BUF_HEIGHT, BUF_WIDTH); 110 curbuf = (curbuf + 1) & 1; 111 if (need_refresh) 112 { 113 rb->lcd_update_rect(TEXT_X, TEXT_Y, LCD_WIDTH-TEXT_X, 8); 114 need_refresh = false; 115 } 116} 117 118int plugin_main(void) 119{ 120 int button; 121 bool done = false; 122 bool change = true; 123 124 rb->lcd_setfont(FONT_SYSFIXED); 125 126 rb->lcd_putsxy(TEXT_X, TEXT_Y+12, "Adjust Frequ."); 127 rb->lcd_putsxy(TEXT_X, TEXT_Y+20, "so the block"); 128 rb->lcd_putsxy(TEXT_X, TEXT_Y+28, "stops moving."); 129#if (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) \ 130 || (CONFIG_KEYPAD == IPOD_1G2G_PAD) 131 rb->lcd_putsxy(TEXT_X, TEXT_Y+40, "Scroll: Coarse"); 132#else 133 rb->lcd_putsxy(TEXT_X, TEXT_Y+40, "U/D: Coarse"); 134#endif 135 rb->lcd_putsxy(TEXT_X, TEXT_Y+48, "L/R: Fine"); 136 rb->lcd_update(); 137 138 rb->memset(bitbuffer[0], 0, sizeof(bitbuffer[0])); 139 rb->memset(bitbuffer[1], 0xff, sizeof(bitbuffer[1])); 140#ifdef NEED_BOOST 141 rb->cpu_boost(true); 142#endif 143 /* The actual frequency is twice the displayed value */ 144 rb->timer_register(1, NULL, TIMER_FREQ * 5 / scan_rate, 145 timer_isr IF_COP(, CPU)); 146 147 while (!done) 148 { 149 if (change) 150 { 151 /* The actual frequency is twice the displayed value */ 152 rb->timer_set_period(TIMER_FREQ * 5 / scan_rate); 153 rb->lcd_putsxyf(TEXT_X, TEXT_Y, "f: %d.%d Hz", scan_rate / 10, 154 scan_rate % 10); 155 need_refresh = true; 156 change = false; 157 } 158 button = pluginlib_getaction(TIMEOUT_BLOCK, plugin_contexts, 159 ARRAYLEN(plugin_contexts)); 160 switch (button) 161 { 162 case SCANRATE_FASTINC: 163 case SCANRATE_FASTINC_REPEAT: 164 scan_rate += 10; 165 change = true; 166 break; 167 168 case SCANRATE_FASTDEC: 169 case SCANRATE_FASTDEC_REPEAT: 170 scan_rate -= 10; 171 change = true; 172 break; 173 174 case SCANRATE_INC: 175 case SCANRATE_INC_REPEAT: 176 scan_rate++; 177 change = true; 178 break; 179 180 case SCANRATE_DEC: 181 case SCANRATE_DEC_REPEAT: 182 scan_rate--; 183 change = true; 184 break; 185 186 case SCANRATE_QUIT: 187 case SCANRATE_QUIT2: 188 done = true; 189 break; 190 } 191 } 192 rb->timer_unregister(); 193#ifdef NEED_BOOST 194 rb->cpu_boost(false); 195#endif 196 197 rb->lcd_setfont(FONT_UI); 198 199 return PLUGIN_OK; 200} 201 202 203/* this is the plugin entry point */ 204enum plugin_status plugin_start(const void* parameter) 205{ 206 (void)parameter; 207 return plugin_main(); 208}