A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 209 lines 6.7 kB view raw
1/*************************************************************************** 2 * __________ __ ___. 3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 * \/ \/ \/ \/ \/ 8 * $Id$ 9 * 10 * Copyright (C) 2007 Kévin Ferrare, graphic design 2003 Zakk Roberts 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 "time.h" 24#include "lib/pluginlib_actions.h" 25#include "lib/pluginlib_exit.h" 26#include "lib/xlcd.h" 27 28#include "clock.h" 29#include "clock_counter.h" 30#include "clock_draw.h" 31#include "clock_menu.h" 32#include "clock_settings.h" 33 34 35 36/* Keymaps */ 37const struct button_mapping* plugin_contexts[]={ 38 pla_main_ctx, 39#ifdef HAVE_REMOTE_LCD 40 pla_remote_ctx, 41#endif 42}; 43#define PLA_ARRAY_COUNT sizeof(plugin_contexts)/sizeof(plugin_contexts[0]) 44 45#define ACTION_COUNTER_TOGGLE PLA_SELECT 46#define ACTION_COUNTER_RESET PLA_SELECT_REPEAT 47#define ACTION_MODE_NEXT PLA_RIGHT 48#define ACTION_MODE_NEXT_REPEAT PLA_RIGHT_REPEAT 49#define ACTION_MODE_PREV PLA_LEFT 50#define ACTION_MODE_PREV_REPEAT PLA_LEFT_REPEAT 51#if (CONFIG_KEYPAD == IPOD_1G2G_PAD) \ 52 || (CONFIG_KEYPAD == IPOD_3G_PAD) \ 53 || (CONFIG_KEYPAD == IPOD_4G_PAD) 54#define ACTION_MENU PLA_UP 55#else 56#define ACTION_MENU PLA_CANCEL 57#define ACTION_SKIN_NEXT PLA_UP 58#define ACTION_SKIN_NEXT_REPEAT PLA_UP_REPEAT 59#endif 60#define ACTION_SKIN_PREV PLA_DOWN 61#define ACTION_SKIN_PREV_REPEAT PLA_DOWN_REPEAT 62 63/************************** 64 * Cleanup on plugin return 65 *************************/ 66static void cleanup(void) 67{ 68 if(clock_settings.general.save_settings == 1) 69 save_settings(); 70 71 /* restore set backlight timeout */ 72 rb->backlight_set_timeout(rb->global_settings->backlight_timeout); 73} 74 75/* puts the current time into the time struct */ 76static void clock_update_time( struct time* time){ 77 struct tm* current_time = rb->get_time(); 78 time->hour = current_time->tm_hour; 79 time->minute = current_time->tm_min; 80 time->second = current_time->tm_sec; 81 82 /********************* 83 * Date info 84 *********************/ 85 time->year = current_time->tm_year + 1900; 86 time->day = current_time->tm_mday; 87 time->month = current_time->tm_mon + 1; 88 89} 90 91void format_date(char* buffer, struct time* time, enum date_format format){ 92 switch(format){ 93 case JAPANESE: 94 rb->snprintf(buffer, 20, "%04d/%02d/%02d", 95 time->year, time->month, time->day); 96 break; 97 case EUROPEAN: 98 rb->snprintf(buffer, 20, "%02d/%02d/%04d", 99 time->day, time->month, time->year); 100 break; 101 case ENGLISH: 102 rb->snprintf(buffer, 20, "%02d/%02d/%04d", 103 time->month, time->day, time->year); 104 break; 105 case NONE: 106 default: 107 break; 108 } 109} 110 111/********************************************************************** 112 * Plugin starts here 113 **********************************************************************/ 114enum plugin_status plugin_start(const void* parameter){ 115 int button; 116 int last_second = -1; 117 bool redraw=true; 118 struct time time; 119 struct counter counter; 120 bool exit_clock = false; 121 (void)parameter; 122 atexit(cleanup); 123 124#if LCD_DEPTH > 1 125 rb->lcd_set_backdrop(NULL); 126#endif 127 128 load_settings(); 129 130 /* init xlcd functions */ 131 counter_init(&counter); 132 clock_draw_set_colors(); 133 134 while(!exit_clock){ 135 clock_update_time(&time); 136 137 if(!clock_settings.general.idle_poweroff) 138 rb->reset_poweroff_timer(); 139 140 /************************* 141 * Scan for button presses 142 ************************/ 143 button = pluginlib_getaction(HZ/10, plugin_contexts, PLA_ARRAY_COUNT); 144 redraw=true;/* we'll set it to false afterwards if there was no action */ 145 switch (button){ 146 case ACTION_COUNTER_TOGGLE: /* start/stop counter */ 147 show_counter = true; 148 counter_toggle(&counter); 149 break; 150 151 case ACTION_COUNTER_RESET: /* reset counter */ 152 if(show_counter) 153 { 154 counter_reset(&counter); 155 show_counter = false; 156 } 157 break; 158 159 case ACTION_MODE_NEXT_REPEAT: 160 case ACTION_MODE_NEXT: 161 clock_settings.mode++; 162 if(clock_settings.mode >= NB_CLOCK_MODES) 163 clock_settings.mode = 0; 164 break; 165 166 case ACTION_MODE_PREV_REPEAT: 167 case ACTION_MODE_PREV: 168 clock_settings.mode--; 169 if(clock_settings.mode < 0) 170 clock_settings.mode = NB_CLOCK_MODES-1; 171 break; 172 case ACTION_SKIN_PREV_REPEAT: 173 case ACTION_SKIN_PREV: 174 clock_settings_skin_next(&clock_settings); 175 break; 176#if defined(ACTION_SKIN_NEXT) && defined(ACTION_SKIN_NEXT_REPEAT) 177 case ACTION_SKIN_NEXT_REPEAT: 178 case ACTION_SKIN_NEXT: 179 clock_settings_skin_previous(&clock_settings); 180 break; 181#endif 182 case ACTION_MENU: 183 FOR_NB_SCREENS(i) 184 rb->viewportmanager_theme_enable(i, true, NULL); 185 exit_clock=main_menu(); 186 FOR_NB_SCREENS(i) 187 rb->viewportmanager_theme_undo(i, false); 188 break; 189 default: 190 exit_on_usb(button); 191 if(time.second != last_second){ 192 last_second=time.second; 193 redraw=true; 194 }else 195 redraw=false; 196 break; 197 } 198 199 if (redraw && !exit_clock) 200 { 201 clock_draw_set_colors(); 202 FOR_NB_SCREENS(i) 203 clock_draw(rb->screens[i], &time, &counter); 204 redraw=false; 205 } 206 } 207 208 return PLUGIN_OK; 209}