A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 94 lines 3.1 kB view raw
1/*************************************************************************** 2 * __________ __ ___. 3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 * \/ \/ \/ \/ \/ 8 * $Id$ 9 * 10 * Copyright (C) 2003 Uwe Freese 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 "config.h" 22 23#include <stdbool.h> 24 25#include "lcd.h" 26#include "action.h" 27#include "kernel.h" 28#include <string.h> 29#include "settings.h" 30#include "power.h" 31#include "icons.h" 32#include "rtc.h" 33#include "misc.h" 34#include "screens.h" 35#include "talk.h" 36#include "lang.h" 37#include "alarm_menu.h" 38#include "splash.h" 39#include "viewport.h" 40 41int alarm_screen(void) 42{ 43 bool usb, update; 44 struct tm *now = get_time(); 45 struct tm atm; 46 memcpy(&atm, now, sizeof(struct tm)); 47 rtc_get_alarm(&atm.tm_hour, &atm.tm_min); 48 49 /* After a battery change the RTC values are out of range */ 50 if (!valid_time(&atm)) 51 memcpy(&atm, now, sizeof(struct tm)); 52 atm.tm_sec = 0; 53 54 usb = set_time_screen(str(LANG_ALARM_MOD_TIME), &atm, false); 55 update = valid_time(&atm); /* set_time returns invalid time if canceled */ 56 57 if (!usb && update) 58 { 59 60 now = get_time(); 61 int nmins = now->tm_min + (now->tm_hour * 60); 62 int amins = atm.tm_min + (atm.tm_hour * 60); 63 int mins_togo = (amins - nmins + 1440) % 1440; 64 /* prevent that an alarm occurs in the shutdown procedure */ 65 /* accept alarms only if they are in 2 minutes or more */ 66 if (mins_togo > 1) { 67 rtc_init(); 68 rtc_set_alarm(atm.tm_hour,atm.tm_min); 69 rtc_enable_alarm(true); 70 if (global_settings.talk_menu) 71 { 72 talk_id(LANG_ALARM_MOD_TIME_TO_GO, true); 73 talk_value(mins_togo / 60, UNIT_HOUR, true); 74 talk_value(mins_togo % 60, UNIT_MIN, true); 75 talk_force_enqueue_next(); 76 } 77 /* (voiced above) */ 78 splashf(HZ*2, str(LANG_ALARM_MOD_TIME_TO_GO), 79 mins_togo / 60, mins_togo % 60); 80 } else { 81 splash(HZ, ID2P(LANG_ALARM_MOD_ERROR)); 82 update = false; 83 } 84 } 85 86 if (usb || !update) 87 { 88 if (!usb) 89 splash(HZ*2, ID2P(LANG_ALARM_MOD_DISABLE)); 90 rtc_enable_alarm(false); 91 return 1; 92 } 93 return 0; 94}