Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

目覚め時計 #3906

Draft
wants to merge 9 commits into
base: dev
Choose a base branch
from
4 changes: 4 additions & 0 deletions applications/services/notification/notification_messages.c
Original file line number Diff line number Diff line change
Expand Up @@ -593,3 +593,7 @@ const NotificationSequence sequence_lcd_contrast_update = {
&message_lcd_contrast_update,
NULL,
};

const NotificationSequence sequence_empty = {
NULL,
};
3 changes: 3 additions & 0 deletions applications/services/notification/notification_messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ extern const NotificationSequence sequence_audiovisual_alert;
// LCD
extern const NotificationSequence sequence_lcd_contrast_update;

// Wait for notification queue become empty
extern const NotificationSequence sequence_empty;

#ifdef __cplusplus
}
#endif
2 changes: 2 additions & 0 deletions applications/settings/application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ App(
provides=[
"passport",
"system_settings",
"clock_settings",
"clock_settings_start",
"about",
],
)
16 changes: 16 additions & 0 deletions applications/settings/clock_settings/application.fam
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
App(
appid="clock_settings",
name="Clock",
apptype=FlipperAppType.SETTINGS,
entry_point="clock_settings",
requires=["gui"],
stack_size=1 * 1024,
order=90,
)

App(
appid="clock_settings_start",
apptype=FlipperAppType.STARTUP,
entry_point="clock_settings_start",
order=1000,
)
70 changes: 70 additions & 0 deletions applications/settings/clock_settings/clock_settings.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include "clock_settings.h"

#include <furi.h>
#include <furi_hal.h>

static bool clock_settings_custom_event_callback(void* context, uint32_t event) {
furi_assert(context);
ClockSettings* app = context;
return scene_manager_handle_custom_event(app->scene_manager, event);
}

static bool clock_settings_back_event_callback(void* context) {
furi_assert(context);
ClockSettings* app = context;
return scene_manager_handle_back_event(app->scene_manager);
}

ClockSettings* clock_settings_alloc() {
ClockSettings* app = malloc(sizeof(ClockSettings));

app->gui = furi_record_open(RECORD_GUI);

app->view_dispatcher = view_dispatcher_alloc();
app->scene_manager = scene_manager_alloc(&clock_settings_scene_handlers, app);
view_dispatcher_set_event_callback_context(app->view_dispatcher, app);

view_dispatcher_set_custom_event_callback(
app->view_dispatcher, clock_settings_custom_event_callback);
view_dispatcher_set_navigation_event_callback(
app->view_dispatcher, clock_settings_back_event_callback);

view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);

app->pwm_view = clock_settings_module_alloc();
view_dispatcher_add_view(
app->view_dispatcher, ClockSettingsViewPwm, clock_settings_module_get_view(app->pwm_view));

scene_manager_next_scene(app->scene_manager, ClockSettingsSceneStart);

return app;
}

void clock_settings_free(ClockSettings* app) {
furi_assert(app);

// Views
view_dispatcher_remove_view(app->view_dispatcher, ClockSettingsViewPwm);

clock_settings_module_free(app->pwm_view);

// View dispatcher
view_dispatcher_free(app->view_dispatcher);
scene_manager_free(app->scene_manager);

// Close records
furi_record_close(RECORD_GUI);

free(app);
}

int32_t clock_settings(void* p) {
UNUSED(p);
ClockSettings* clock_settings = clock_settings_alloc();

view_dispatcher_run(clock_settings->view_dispatcher);

clock_settings_free(clock_settings);

return 0;
}
31 changes: 31 additions & 0 deletions applications/settings/clock_settings/clock_settings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once

#include "scenes/clock_settings_scene.h"

#include <furi_hal_clock.h>
#include <furi_hal_pwm.h>

#include <gui/gui.h>
#include <gui/view_dispatcher.h>
#include <gui/scene_manager.h>
#include <gui/modules/submenu.h>
#include <gui/modules/variable_item_list.h>
#include <gui/modules/submenu.h>
#include "views/clock_settings_module.h"

typedef struct ClockSettings ClockSettings;

struct ClockSettings {
Gui* gui;
ViewDispatcher* view_dispatcher;
SceneManager* scene_manager;
ClockSettingsModule* pwm_view;
};

typedef enum {
ClockSettingsViewPwm,
} ClockSettingsView;

typedef enum {
ClockSettingsCustomEventNone,
} ClockSettingsCustomEvent;
132 changes: 132 additions & 0 deletions applications/settings/clock_settings/clock_settings_alarm.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
#include <furi.h>
#include <furi_hal.h>

#include <gui/gui.h>
#include <gui/view_port.h>

#include <notification/notification.h>
#include <notification/notification_messages.h>

#include <assets_icons.h>

const NotificationSequence sequence_alarm = {
&message_force_speaker_volume_setting_1f,
&message_force_vibro_setting_on,
&message_force_display_brightness_setting_1f,
&message_vibro_on,

&message_display_backlight_on,
&message_note_c7,
&message_delay_250,

&message_display_backlight_off,
&message_note_c4,
&message_delay_250,

&message_display_backlight_on,
&message_note_c7,
&message_delay_250,

&message_display_backlight_off,
&message_note_c4,
&message_delay_250,

&message_sound_off,
&message_vibro_off,
NULL,
};

static void clock_settings_alarm_stop(void* context, uint32_t arg);

static void clock_settings_alarm_draw_callback(Canvas* canvas, void* ctx) {
UNUSED(ctx);

canvas_draw_icon(canvas, 10, 10, &I_Warning_30x23);
canvas_draw_str(canvas, 40, 20, "Wakeup");
}

static void clock_settings_alarm_input_callback(InputEvent* input_event, void* ctx) {
furi_assert(ctx);
FuriMessageQueue* event_queue = ctx;
furi_message_queue_put(event_queue, input_event, FuriWaitForever);
}

int32_t clock_settings_alarm(void* p) {
UNUSED(p);

// Alloc message queue
FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(InputEvent));

// Configure view port
ViewPort* view_port = view_port_alloc();
view_port_draw_callback_set(view_port, clock_settings_alarm_draw_callback, NULL);
view_port_input_callback_set(view_port, clock_settings_alarm_input_callback, event_queue);

// Register view port in GUI
Gui* gui = furi_record_open(RECORD_GUI);
gui_add_view_port(gui, view_port, GuiLayerFullscreen);

NotificationApp* notification = furi_record_open(RECORD_NOTIFICATION);
notification_message(notification, &sequence_alarm);

// Process events
InputEvent event;
bool running = true;
while(running) {
if(furi_message_queue_get(event_queue, &event, 2000) == FuriStatusOk) {
if(event.type == InputTypePress) {
running = false;
}
} else {
notification_message(notification, &sequence_alarm);
}
}

notification_message_block(notification, &sequence_empty);
furi_record_close(RECORD_NOTIFICATION);

view_port_enabled_set(view_port, false);
gui_remove_view_port(gui, view_port);
view_port_free(view_port);
furi_message_queue_free(event_queue);
furi_record_close(RECORD_GUI);

furi_timer_pending_callback(clock_settings_alarm_stop, NULL, 0);

return 0;
}

FuriThread* clock_settings_alarm_thread = NULL;

static void clock_settings_alarm_stop(void* context, uint32_t arg) {
UNUSED(context);
UNUSED(arg);

furi_thread_join(clock_settings_alarm_thread);
furi_thread_free(clock_settings_alarm_thread);
clock_settings_alarm_thread = NULL;
}

static void clock_settings_alarm_start(void* context, uint32_t arg) {
UNUSED(context);
UNUSED(arg);

FURI_LOG_I("ClockSettingsAlarm", "time");

if(clock_settings_alarm_thread) return;

clock_settings_alarm_thread =
furi_thread_alloc_ex("ClockAlarm", 1024, clock_settings_alarm, NULL);
furi_thread_start(clock_settings_alarm_thread);
}

static void clock_settings_alarm_isr(void* context) {
UNUSED(context);
furi_timer_pending_callback(clock_settings_alarm_start, NULL, 0);
}

void clock_settings_start(void) {
#ifndef FURI_RAM_EXEC
furi_hal_rtc_set_alarm_callback(clock_settings_alarm_isr, NULL);
#endif
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "../clock_settings.h"

// Generate scene on_enter handlers array
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_enter,
void (*const clock_settings_scene_on_enter_handlers[])(void*) = {
#include "clock_settings_scene_config.h"
};
#undef ADD_SCENE

// Generate scene on_event handlers array
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_event,
bool (*const clock_settings_scene_on_event_handlers[])(void* context, SceneManagerEvent event) = {
#include "clock_settings_scene_config.h"
};
#undef ADD_SCENE

// Generate scene on_exit handlers array
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_exit,
void (*const clock_settings_scene_on_exit_handlers[])(void* context) = {
#include "clock_settings_scene_config.h"
};
#undef ADD_SCENE

// Initialize scene handlers configuration structure
const SceneManagerHandlers clock_settings_scene_handlers = {
.on_enter_handlers = clock_settings_scene_on_enter_handlers,
.on_event_handlers = clock_settings_scene_on_event_handlers,
.on_exit_handlers = clock_settings_scene_on_exit_handlers,
.scene_num = ClockSettingsSceneNum,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once

#include <gui/scene_manager.h>

// Generate scene id and total number
#define ADD_SCENE(prefix, name, id) ClockSettingsScene##id,
typedef enum {
#include "clock_settings_scene_config.h"
ClockSettingsSceneNum,
} ClockSettingsScene;
#undef ADD_SCENE

extern const SceneManagerHandlers clock_settings_scene_handlers;

// Generate scene on_enter handlers declaration
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_enter(void*);
#include "clock_settings_scene_config.h"
#undef ADD_SCENE

// Generate scene on_event handlers declaration
#define ADD_SCENE(prefix, name, id) \
bool prefix##_scene_##name##_on_event(void* context, SceneManagerEvent event);
#include "clock_settings_scene_config.h"
#undef ADD_SCENE

// Generate scene on_exit handlers declaration
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_exit(void* context);
#include "clock_settings_scene_config.h"
#undef ADD_SCENE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ADD_SCENE(clock_settings, start, Start)
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include "../clock_settings.h"
#include <furi_hal.h>

typedef enum {
SubmenuIndexPwm,
SubmenuIndexClockOutput,
} SubmenuIndex;

void clock_settings_scene_start_submenu_callback(void* context, uint32_t index) {
ClockSettings* app = context;

view_dispatcher_send_custom_event(app->view_dispatcher, index);
}

void clock_settings_scene_start_on_enter(void* context) {
ClockSettings* app = context;

DateTime dt;
bool enabled = furi_hal_rtc_get_alarm(&dt);
furi_hal_rtc_set_alarm(NULL);
FURI_LOG_D("ClockSettings", "OnEnter: %u:%u enabled=%u", dt.hour, dt.minute, enabled);
clock_settings_module_set(app->pwm_view, &dt, enabled);

view_dispatcher_switch_to_view(app->view_dispatcher, ClockSettingsViewPwm);
}

bool clock_settings_scene_start_on_event(void* context, SceneManagerEvent event) {
UNUSED(context);
bool consumed = false;

if(event.type == SceneManagerEventTypeCustom) {
}

return consumed;
}

void clock_settings_scene_start_on_exit(void* context) {
ClockSettings* app = context;

DateTime dt;
bool enabled = clock_settings_module_get(app->pwm_view, &dt);
FURI_LOG_D("ClockSettings", "OnExit: %u:%u enabled=%u", dt.hour, dt.minute, enabled);
furi_hal_rtc_set_alarm(enabled ? &dt : NULL);
}
Loading
Loading