mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2025-12-12 04:34:43 +04:00
Merge remote-tracking branch 'OFW/astra/3934-alarm-improvements' into dev
This commit is contained in:
@@ -249,7 +249,7 @@ static void gui_redraw(Gui* gui) {
|
||||
|
||||
canvas_reset(gui->canvas);
|
||||
|
||||
if(gui->lockdown) {
|
||||
if(gui_is_lockdown(gui)) {
|
||||
gui_redraw_desktop(gui);
|
||||
bool need_attention =
|
||||
(gui_view_port_find_enabled(gui->layers[GuiLayerWindow]) != 0 ||
|
||||
@@ -299,7 +299,7 @@ static void gui_input(Gui* gui, InputEvent* input_event) {
|
||||
|
||||
ViewPort* view_port = NULL;
|
||||
|
||||
if(gui->lockdown) {
|
||||
if(gui_is_lockdown(gui)) {
|
||||
view_port = gui_view_port_find_enabled(gui->layers[GuiLayerDesktop]);
|
||||
} else {
|
||||
view_port = gui_view_port_find_enabled(gui->layers[GuiLayerFullscreen]);
|
||||
@@ -495,6 +495,23 @@ void gui_set_lockdown(Gui* gui, bool lockdown) {
|
||||
gui_update(gui);
|
||||
}
|
||||
|
||||
void gui_set_lockdown_inhibit(Gui* gui, bool inhibit) {
|
||||
furi_check(gui);
|
||||
|
||||
gui_lock(gui);
|
||||
gui->lockdown_inhibit = inhibit;
|
||||
gui_unlock(gui);
|
||||
|
||||
// Request redraw
|
||||
gui_update(gui);
|
||||
}
|
||||
|
||||
bool gui_is_lockdown(const Gui* gui) {
|
||||
furi_check(gui);
|
||||
|
||||
return gui->lockdown && !gui->lockdown_inhibit;
|
||||
}
|
||||
|
||||
Canvas* gui_direct_draw_acquire(Gui* gui) {
|
||||
furi_check(gui);
|
||||
|
||||
|
||||
@@ -110,6 +110,23 @@ size_t gui_get_framebuffer_size(const Gui* gui);
|
||||
*/
|
||||
void gui_set_lockdown(Gui* gui, bool lockdown);
|
||||
|
||||
/** Inhibit lockdown mode
|
||||
*
|
||||
* Lockdown mode can be inhibited by calling this function with inhibit set to true.
|
||||
* This is used to show information even when flipper is locked.
|
||||
*
|
||||
* @param gui Gui instance
|
||||
* @param inhibit true to inhibit lockdown mode
|
||||
*/
|
||||
void gui_set_lockdown_inhibit(Gui* gui, bool inhibit);
|
||||
|
||||
/** Check if Gui is in lockdown mode
|
||||
*
|
||||
* @param gui Gui instance
|
||||
* @return bool true if Gui is in lockdown mode
|
||||
*/
|
||||
bool gui_is_lockdown(const Gui* gui);
|
||||
|
||||
/** Acquire Direct Draw lock and get Canvas instance
|
||||
*
|
||||
* This method return Canvas instance for use in monopoly mode. Direct draw lock
|
||||
|
||||
@@ -51,6 +51,7 @@ struct Gui {
|
||||
|
||||
// Layers and Canvas
|
||||
bool lockdown;
|
||||
bool lockdown_inhibit;
|
||||
bool direct_draw;
|
||||
ViewPortArray_t layers[GuiLayerMAX];
|
||||
Canvas* canvas;
|
||||
|
||||
@@ -11,9 +11,16 @@
|
||||
|
||||
#define TAG "ClockSettingsAlarm"
|
||||
|
||||
#define SNOOZE_MINUTES 9
|
||||
#define TIMEOUT_MINUTES 10
|
||||
|
||||
typedef struct {
|
||||
DateTime now;
|
||||
DateTime snooze_until;
|
||||
DateTime alarm_start;
|
||||
IconAnimation* icon;
|
||||
|
||||
bool is_snooze;
|
||||
} ClockSettingsAlramModel;
|
||||
|
||||
const NotificationSequence sequence_alarm = {
|
||||
@@ -47,12 +54,15 @@ static void clock_settings_alarm_draw_callback(Canvas* canvas, void* ctx) {
|
||||
ClockSettingsAlramModel* model = ctx;
|
||||
char buffer[64] = {};
|
||||
|
||||
// Clock icon
|
||||
canvas_draw_icon_animation(canvas, 5, 6, model->icon);
|
||||
|
||||
// Time
|
||||
canvas_set_font(canvas, FontBigNumbers);
|
||||
snprintf(buffer, sizeof(buffer), "%02u:%02u", model->now.hour, model->now.minute);
|
||||
canvas_draw_str(canvas, 58, 32, buffer);
|
||||
|
||||
// Date
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
snprintf(
|
||||
buffer,
|
||||
@@ -62,6 +72,11 @@ static void clock_settings_alarm_draw_callback(Canvas* canvas, void* ctx) {
|
||||
model->now.month,
|
||||
model->now.year);
|
||||
canvas_draw_str(canvas, 60, 44, buffer);
|
||||
|
||||
// Press Back to snooze
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
canvas_draw_icon_ex(canvas, 5, 50, &I_back_btn_10x8, 0);
|
||||
canvas_draw_str_aligned(canvas, 20, 50, AlignLeft, AlignTop, "Snooze");
|
||||
}
|
||||
|
||||
static void clock_settings_alarm_input_callback(InputEvent* input_event, void* ctx) {
|
||||
@@ -81,8 +96,10 @@ int32_t clock_settings_alarm(void* p) {
|
||||
|
||||
// View Model
|
||||
ClockSettingsAlramModel model;
|
||||
model.is_snooze = false;
|
||||
|
||||
furi_hal_rtc_get_datetime(&model.now);
|
||||
furi_hal_rtc_get_alarm(&model.alarm_start);
|
||||
model.icon = icon_animation_alloc(&A_Alarm_47x39);
|
||||
|
||||
// Alloc message queue
|
||||
@@ -95,6 +112,7 @@ int32_t clock_settings_alarm(void* p) {
|
||||
|
||||
// Register view port in GUI
|
||||
Gui* gui = furi_record_open(RECORD_GUI);
|
||||
gui_set_lockdown_inhibit(gui, true);
|
||||
gui_add_view_port(gui, view_port, GuiLayerFullscreen);
|
||||
|
||||
NotificationApp* notification = furi_record_open(RECORD_NOTIFICATION);
|
||||
@@ -110,12 +128,43 @@ int32_t clock_settings_alarm(void* p) {
|
||||
while(running) {
|
||||
if(furi_message_queue_get(event_queue, &event, 2000) == FuriStatusOk) {
|
||||
if(event.type == InputTypePress) {
|
||||
running = false;
|
||||
// Snooze
|
||||
if(event.key == InputKeyBack) {
|
||||
furi_hal_rtc_get_datetime(&model.snooze_until);
|
||||
model.snooze_until.minute += SNOOZE_MINUTES;
|
||||
model.snooze_until.hour += model.snooze_until.minute / 60;
|
||||
model.snooze_until.minute %= 60;
|
||||
model.snooze_until.hour %= 24;
|
||||
|
||||
model.is_snooze = true;
|
||||
model.alarm_start = model.snooze_until; // For correct timeout behavior
|
||||
view_port_enabled_set(view_port, false);
|
||||
gui_set_lockdown_inhibit(gui, false);
|
||||
} else {
|
||||
running = false;
|
||||
}
|
||||
}
|
||||
} else if(model.is_snooze) {
|
||||
furi_hal_rtc_get_datetime(&model.now);
|
||||
if(datetime_datetime_to_timestamp(&model.now) >=
|
||||
datetime_datetime_to_timestamp(&model.snooze_until)) {
|
||||
view_port_enabled_set(view_port, true);
|
||||
gui_set_lockdown_inhibit(gui, true);
|
||||
|
||||
model.is_snooze = false;
|
||||
}
|
||||
} else {
|
||||
notification_message(notification, &sequence_alarm);
|
||||
furi_hal_rtc_get_datetime(&model.now);
|
||||
view_port_update(view_port);
|
||||
|
||||
// Stop the alarm if it has been ringing for more than TIMEOUT_MINUTES
|
||||
if((model.now.hour == model.alarm_start.hour &&
|
||||
model.now.minute >= model.alarm_start.minute + TIMEOUT_MINUTES) ||
|
||||
(model.now.hour == (model.alarm_start.hour + 1) % 24 &&
|
||||
model.now.minute < (model.alarm_start.minute + TIMEOUT_MINUTES) % 60)) {
|
||||
running = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,6 +174,7 @@ int32_t clock_settings_alarm(void* p) {
|
||||
furi_record_close(RECORD_NOTIFICATION);
|
||||
|
||||
view_port_enabled_set(view_port, false);
|
||||
gui_set_lockdown_inhibit(gui, false);
|
||||
gui_remove_view_port(gui, view_port);
|
||||
view_port_free(view_port);
|
||||
furi_message_queue_free(event_queue);
|
||||
|
||||
@@ -1741,9 +1741,11 @@ Function,+,gui_add_view_port,void,"Gui*, ViewPort*, GuiLayer"
|
||||
Function,+,gui_direct_draw_acquire,Canvas*,Gui*
|
||||
Function,+,gui_direct_draw_release,void,Gui*
|
||||
Function,+,gui_get_framebuffer_size,size_t,const Gui*
|
||||
Function,+,gui_is_lockdown,_Bool,const Gui*
|
||||
Function,+,gui_remove_framebuffer_callback,void,"Gui*, GuiCanvasCommitCallback, void*"
|
||||
Function,+,gui_remove_view_port,void,"Gui*, ViewPort*"
|
||||
Function,+,gui_set_lockdown,void,"Gui*, _Bool"
|
||||
Function,+,gui_set_lockdown_inhibit,void,"Gui*, _Bool"
|
||||
Function,-,gui_view_port_send_to_back,void,"Gui*, ViewPort*"
|
||||
Function,+,gui_view_port_send_to_front,void,"Gui*, ViewPort*"
|
||||
Function,-,hci_send_req,int,"hci_request*, uint8_t"
|
||||
|
||||
|
@@ -2007,9 +2007,11 @@ Function,+,gui_add_view_port,void,"Gui*, ViewPort*, GuiLayer"
|
||||
Function,+,gui_direct_draw_acquire,Canvas*,Gui*
|
||||
Function,+,gui_direct_draw_release,void,Gui*
|
||||
Function,+,gui_get_framebuffer_size,size_t,const Gui*
|
||||
Function,+,gui_is_lockdown,_Bool,const Gui*
|
||||
Function,+,gui_remove_framebuffer_callback,void,"Gui*, GuiCanvasCommitCallback, void*"
|
||||
Function,+,gui_remove_view_port,void,"Gui*, ViewPort*"
|
||||
Function,+,gui_set_lockdown,void,"Gui*, _Bool"
|
||||
Function,+,gui_set_lockdown_inhibit,void,"Gui*, _Bool"
|
||||
Function,-,gui_view_port_send_to_back,void,"Gui*, ViewPort*"
|
||||
Function,+,gui_view_port_send_to_front,void,"Gui*, ViewPort*"
|
||||
Function,-,hci_send_req,int,"hci_request*, uint8_t"
|
||||
|
||||
|
Reference in New Issue
Block a user