rockbox/apps/alarm_menu.c
William Wilgus 3237ae4a4f LCD core move buf ptr and address look up function viewport struct
I'm currently running up against the limitations of the lcd_draw functions
I want these functions to be able to be used on any size buffer not
just buffers with a stride matching the underlying device

[DONE] allow the framebuffer to be decoupled from the device framebuffer
[DONE need examples] allow for some simple blit like transformations
[DONE] remove the device framebuffer from the plugin api
[DONE}ditto remote framebuffer
[DONE] remove _viewport_get_framebuffer you can call struct *vp = lcd_set_viewport(NULL) and vp->buffer->fb_ptr

while remote lcds may compile (and work in the sim) its not been tested on targets

[FIXED] backdrops need work to be screen agnostic

[FIXED] screen statusbar is not being combined into the main viewport correctly yet

[FIXED] screen elements are displayed incorrectly  after switch to void*

[FIXED] core didn't restore proper viewport on splash etc.

[NEEDS TESTING] remote lcd garbled data

[FIXED] osd lib garbled screen on bmp_part

[FIXED] grey_set_vp needs to return old viewport like lcd_set_viewport

[FIXED] Viewport update now handles viewports with differing buffers/strides by copying to the main buffer

[FIXED] splash on top of WPS leaves old framebuffer data (doesn't redraw)
[UPDATE] refined this a bit more to have clear_viewport set the clean bit and have skin_render do its own screen clear
scrolling viewports no longer trigger wps refresh
also fixed a bug where guisyncyesno was displaying and then disappearing

[ADDED!] New LCD macros that allow you to create properly size frame buffers in you desired size without wasting bytes
(LCD_ and LCD_REMOTE_)
LCD_STRIDE(w, h) same as STRIDE_MAIN
LCD_FBSTRIDE(w, h) returns target specific stride for a buffer W x H
LCD_NBELEMS(w, h) returns the number of fb_data sized elemenst needed for a buffer W x H
LCD_NATIVE_STRIDE(s) conversion between rockbox native vertical and lcd native stride (2bitH)
test_viewports.c has an example of usage

[FIXED!!] 2bit targets don't respect non-native strides
[FIXED] Few define snags

Change-Id: I0d04c3834e464eca84a5a715743a297a0cefd0af
2020-10-26 12:28:48 -04:00

198 lines
5.5 KiB
C

/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2003 Uwe Freese
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include "config.h"
#include <stdbool.h>
#include "lcd.h"
#include "action.h"
#include "kernel.h"
#include <string.h>
#include "settings.h"
#include "power.h"
#include "icons.h"
#include "rtc.h"
#include "misc.h"
#include "screens.h"
#include "talk.h"
#include "lang.h"
#include "alarm_menu.h"
#include "splash.h"
#include "viewport.h"
static void speak_time(int hours, int minutes, bool speak_hours, bool enqueue)
{
if (global_settings.talk_menu){
if(speak_hours) {
talk_value(hours, UNIT_HOUR, enqueue);
talk_value(minutes, UNIT_MIN, true);
} else {
talk_value(minutes, UNIT_MIN, enqueue);
}
}
}
int alarm_screen(void)
{
int h, m;
bool done = false;
struct tm *tm;
int togo;
int button;
bool update = true;
bool hour_wrapped = false;
struct viewport vp[NB_SCREENS];
struct viewport * last_vp;
rtc_get_alarm(&h, &m);
/* After a battery change the RTC values are out of range */
if (m > 60 || h > 24) {
m = 0;
h = 12;
} else {
m = m / 5 * 5; /* 5 min accuracy should be enough */
}
FOR_NB_SCREENS(i)
{
viewport_set_defaults(&vp[i], i);
}
while(!done) {
if(update)
{
FOR_NB_SCREENS(i)
{
screens[i].set_viewport(&vp[i]);
screens[i].clear_viewport();
screens[i].puts(0, 4, str(LANG_ALARM_MOD_KEYS));
}
/* Talk when entering the wakeup screen */
speak_time(h, m, true, true);
update = false;
}
FOR_NB_SCREENS(i)
{
last_vp = screens[i].set_viewport(&vp[i]);
screens[i].putsf(0, 1, str(LANG_ALARM_MOD_TIME));
screens[i].putsf(0, 2, "%02d:%02d", h, m);
screens[i].update_viewport();
screens[i].set_viewport(last_vp);
}
button = get_action(CONTEXT_SETTINGS,HZ);
switch(button) {
case ACTION_STD_OK:
/* prevent that an alarm occurs in the shutdown procedure */
/* accept alarms only if they are in 2 minutes or more */
tm = get_time();
togo = (m + h * 60 - tm->tm_min - tm->tm_hour * 60 + 1440) % 1440;
if (togo > 1) {
rtc_init();
rtc_set_alarm(h,m);
rtc_enable_alarm(true);
if (global_settings.talk_menu)
{
talk_id(LANG_ALARM_MOD_TIME_TO_GO, true);
talk_value(togo / 60, UNIT_HOUR, true);
talk_value(togo % 60, UNIT_MIN, true);
talk_force_enqueue_next();
}
splashf(HZ*2, str(LANG_ALARM_MOD_TIME_TO_GO),
togo / 60, togo % 60);
done = true;
} else {
splash(HZ, ID2P(LANG_ALARM_MOD_ERROR));
update = true;
}
break;
/* inc(m) */
case ACTION_SETTINGS_INC:
case ACTION_SETTINGS_INCREPEAT:
m += 5;
if (m == 60) {
h += 1;
m = 0;
hour_wrapped = true;
}
if (h == 24)
h = 0;
speak_time(h, m, hour_wrapped, false);
break;
/* dec(m) */
case ACTION_SETTINGS_DEC:
case ACTION_SETTINGS_DECREPEAT:
m -= 5;
if (m == -5) {
h -= 1;
m = 55;
hour_wrapped = true;
}
if (h == -1)
h = 23;
speak_time(h, m, hour_wrapped, false);
break;
/* inc(h) */
case ACTION_STD_NEXT:
case ACTION_STD_NEXTREPEAT:
h = (h+1) % 24;
if (global_settings.talk_menu)
talk_value(h, UNIT_HOUR, false);
break;
/* dec(h) */
case ACTION_STD_PREV:
case ACTION_STD_PREVREPEAT:
h = (h+23) % 24;
if (global_settings.talk_menu)
talk_value(h, UNIT_HOUR, false);
break;
case ACTION_STD_CANCEL:
rtc_enable_alarm(false);
splash(HZ*2, ID2P(LANG_ALARM_MOD_DISABLE));
done = true;
break;
case ACTION_NONE:
hour_wrapped = false;
break;
default:
if(default_event_handler(button) == SYS_USB_CONNECTED)
{
rtc_enable_alarm(false);
return 1;
}
break;
}
}
return 0;
}