This commit is contained in:
RogueMaster
2022-09-16 15:37:27 -04:00
parent 48c3679e97
commit 853f274a7e
6 changed files with 486 additions and 338 deletions
+1 -15
View File
@@ -5,21 +5,7 @@ App(
entry_point="clock_app",
cdefines=["APP_CLOCK"],
requires=["gui"],
provides=["clock_settings"],
icon="A_Clock_14",
stack_size=2 * 1024,
order=9,
)
App(
appid="clock_settings",
name="Clock",
apptype=FlipperAppType.SETTINGS,
entry_point="clock_settings_app",
requires=["gui","clock"],
stack_size=1 * 1024,
order=20,
)
)
+485 -143
View File
@@ -1,10 +1,209 @@
#include <furi.h>
#include <furi_hal.h>
#include <gui/gui.h>
#include <gui/elements.h>
#include <gui/gui.h>
#include <input/input.h>
#include <dolphin/dolphin.h>
#include <notification/notification.h>
#include <notification/notification_messages.h>
#include <desktop_settings/desktop_settings_app.h>
#include "clock_app.h"
#define TAG "Clock"
typedef enum {
EventTypeTick,
EventTypeKey,
} EventType;
typedef struct {
EventType type;
InputEvent input;
} PluginEvent;
typedef struct {
FuriMutex* mutex;
FuriMessageQueue* event_queue;
DesktopSettings* desktop_settings;
uint32_t timer_start_timestamp;
uint32_t lastexp_timestamp;
uint32_t timer_stopped_seconds;
uint32_t songSelect;
uint32_t codeSequence;
uint32_t timerSecs;
uint32_t alert_time;
bool timer_running;
bool militaryTime; // 24 hour
bool w_test;
} ClockState;
const NotificationSequence clock_alert_silent = {
&message_vibro_on,
&message_red_255,
&message_green_255,
&message_blue_255,
&message_display_backlight_on,
&message_vibro_off,
&message_display_backlight_off,
&message_delay_50,
&message_display_backlight_on,
NULL,
};
const NotificationSequence clock_alert_pr1 = {
&message_vibro_on,
&message_red_255,
&message_green_255,
&message_blue_255,
&message_display_backlight_on,
&message_note_g5,
&message_delay_100,
&message_delay_100,
&message_delay_50,
&message_sound_off,
&message_vibro_off,
&message_display_backlight_off,
&message_delay_50,
&message_display_backlight_on,
&message_note_g5,
&message_delay_100,
&message_delay_100,
&message_delay_50,
&message_sound_off,
NULL,
};
const NotificationSequence clock_alert_pr2 = {
&message_vibro_on,
&message_note_fs5,
&message_delay_100,
&message_delay_100,
&message_sound_off,
&message_display_backlight_off,
&message_vibro_off,
&message_delay_50,
&message_note_g5,
&message_delay_100,
&message_delay_100,
&message_sound_off,
&message_display_backlight_on,
&message_delay_50,
&message_note_a5,
&message_delay_100,
&message_delay_100,
&message_sound_off,
NULL,
};
const NotificationSequence clock_alert_pr3 = {
&message_display_backlight_off,
&message_note_g5,
&message_delay_100,
&message_delay_100,
&message_sound_off,
&message_delay_50,
&message_red_255,
&message_green_255,
&message_blue_255,
&message_display_backlight_on,
&message_delay_100,
NULL,
};
const NotificationSequence clock_alert_mario1 = {
&message_vibro_on,
&message_red_255,
&message_green_255,
&message_blue_255,
&message_display_backlight_on,
&message_note_e5,
&message_delay_100,
&message_delay_100,
&message_delay_50,
&message_sound_off,
&message_note_e5,
&message_delay_100,
&message_delay_100,
&message_delay_50,
&message_sound_off,
&message_vibro_off,
&message_display_backlight_off,
&message_delay_100,
&message_display_backlight_on,
&message_delay_100,
&message_note_e5,
&message_delay_100,
&message_delay_100,
&message_delay_50,
&message_sound_off,
NULL,
};
const NotificationSequence clock_alert_mario2 = {
&message_vibro_on,
&message_display_backlight_off,
&message_delay_100,
&message_display_backlight_on,
&message_delay_100,
&message_note_c5,
&message_delay_100,
&message_delay_100,
&message_sound_off,
&message_display_backlight_off,
&message_vibro_off,
&message_delay_50,
&message_note_e5,
&message_delay_100,
&message_delay_100,
&message_sound_off,
&message_display_backlight_on,
NULL,
};
const NotificationSequence clock_alert_mario3 = {
&message_display_backlight_off,
&message_note_g5,
&message_delay_100,
&message_delay_100,
&message_delay_100,
&message_delay_100,
&message_sound_off,
&message_delay_50,
&message_red_255,
&message_green_255,
&message_blue_255,
&message_display_backlight_on,
&message_delay_100,
&message_note_g4,
&message_delay_100,
&message_delay_100,
&message_delay_100,
&message_delay_100,
&message_sound_off,
NULL,
};
const NotificationSequence clock_alert_perMin = {
&message_note_g5,
&message_delay_100,
&message_delay_50,
&message_sound_off,
&message_delay_10,
&message_note_g4,
&message_delay_50,
&message_delay_10,
&message_delay_10,
&message_sound_off,
NULL,
};
const NotificationSequence clock_alert_startStop = {
&message_red_255,
&message_green_255,
&message_blue_255,
&message_note_d6,
&message_delay_100,
&message_delay_10,
&message_delay_10,
&message_sound_off,
NULL,
};
static void desktop_view_main_dumbmode_changed(DesktopSettings* settings) {
settings->is_dumbmode = !settings->is_dumbmode;
SAVE_DESKTOP_SETTINGS(settings);
}
static void clock_input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) {
furi_assert(event_queue);
@@ -13,98 +212,102 @@ static void clock_input_callback(InputEvent* input_event, FuriMessageQueue* even
}
static void clock_render_callback(Canvas* const canvas, void* ctx) {
//canvas_clear(canvas);
//canvas_set_color(canvas, ColorBlack);
ClockState* state = ctx;
if(furi_mutex_acquire(state->mutex, 200) != FuriStatusOk) {
//FURI_LOG_D(TAG, "Can't obtain mutex, requeue render");
// Can't obtain mutex, requeue render
PluginEvent event = {.type = EventTypeTick};
furi_message_queue_put(state->event_queue, &event, 0);
return;
}
FuriHalRtcDateTime curr_dt;
furi_hal_rtc_get_datetime(&curr_dt);
uint32_t curr_ts = furi_hal_rtc_datetime_to_timestamp(&curr_dt);
char time_string[TIME_LEN];
char date_string[DATE_LEN];
char meridian_string[MERIDIAN_LEN];
char timer_string[20];
if(state->settings.time_format == H24) {
snprintf(
time_string, TIME_LEN, CLOCK_TIME_FORMAT, curr_dt.hour, curr_dt.minute, curr_dt.second);
} else {
bool pm = curr_dt.hour > 12;
snprintf(
time_string,
TIME_LEN,
CLOCK_TIME_FORMAT,
pm ? curr_dt.hour - 12 : curr_dt.hour,
curr_dt.minute,
curr_dt.second);
snprintf(
meridian_string,
MERIDIAN_LEN,
MERIDIAN_FORMAT,
pm ? MERIDIAN_STRING_PM : MERIDIAN_STRING_AM);
char strings[3][20];
snprintf(strings[0], 20, "%.4d-%.2d-%.2d", curr_dt.year, curr_dt.month, curr_dt.day);
uint8_t hour = curr_dt.hour;
char strAMPM[3];
snprintf(strAMPM, sizeof(strAMPM), "%s", "AM");
if(!state->militaryTime && hour > 12) {
hour -= 12;
snprintf(strAMPM, sizeof(strAMPM), "%s", "PM");
}
if(state->settings.date_format == Iso) {
snprintf(
date_string, DATE_LEN, CLOCK_ISO_DATE_FORMAT, curr_dt.year, curr_dt.month, curr_dt.day);
} else {
snprintf(
date_string, DATE_LEN, CLOCK_RFC_DATE_FORMAT, curr_dt.day, curr_dt.month, curr_dt.year);
}
snprintf(strings[1], 20, "%.2d:%.2d:%.2d", hour, curr_dt.minute, curr_dt.second);
bool timer_running = state->timer_running;
uint32_t songSelect = state->songSelect;
int alert_time = (int)state->alert_time;
uint32_t timer_start_timestamp = state->timer_start_timestamp;
uint32_t timer_stopped_seconds = state->timer_stopped_seconds;
char alertTime[4];
snprintf(alertTime, sizeof(alertTime), "%d", alert_time);
furi_mutex_release(state->mutex);
canvas_set_font(canvas, FontBigNumbers);
if(timer_start_timestamp != 0) {
if(timer_start_timestamp != 0 && !state->w_test) {
int32_t elapsed_secs = timer_running ? (curr_ts - timer_start_timestamp) :
timer_stopped_seconds;
snprintf(timer_string, 20, "%.2ld:%.2ld", elapsed_secs / 60, elapsed_secs % 60);
canvas_draw_str_aligned(canvas, 64, 8, AlignCenter, AlignCenter, time_string); // DRAW TIME
canvas_draw_str_aligned(canvas, 64, 32, AlignCenter, AlignTop, timer_string); // DRAW TIMER
snprintf(strings[2], 20, "%.2ld:%.2ld", elapsed_secs / 60, elapsed_secs % 60);
canvas_draw_str_aligned(canvas, 64, 8, AlignCenter, AlignCenter, strings[1]); // DRAW TIME
canvas_draw_str_aligned(canvas, 64, 32, AlignCenter, AlignTop, strings[2]); // DRAW TIMER
canvas_set_font(canvas, FontBatteryPercent);
if(!state->militaryTime)
canvas_draw_str_aligned(canvas, 117, 4, AlignCenter, AlignCenter, strAMPM);
canvas_draw_str_aligned(canvas, 117, 11, AlignCenter, AlignCenter, alertTime);
canvas_draw_str_aligned(canvas, 64, 20, AlignCenter, AlignTop, strings[0]); // DRAW DATE
canvas_set_font(canvas, FontSecondary);
canvas_draw_str_aligned(canvas, 64, 20, AlignCenter, AlignTop, date_string); // DRAW DATE
elements_button_left(canvas, "Reset");
} else {
canvas_draw_str_aligned(canvas, 64, 28, AlignCenter, AlignCenter, time_string);
if(state->w_test) canvas_set_font(canvas, FontBatteryPercent);
if(state->w_test && timer_start_timestamp != 0) {
int32_t elapsed_secs = timer_running ? (curr_ts - timer_start_timestamp) :
timer_stopped_seconds;
snprintf(strings[2], 20, "%.2ld:%.2ld", elapsed_secs / 60, elapsed_secs % 60);
canvas_draw_str_aligned(
canvas, 64, 40, AlignCenter, AlignTop, strings[2]); // DRAW TIMER
}
canvas_draw_str_aligned(canvas, 64, 26, AlignCenter, AlignCenter, strings[1]); // DRAW TIME
canvas_set_font(canvas, FontBatteryPercent);
if(!state->militaryTime) {
canvas_draw_str_aligned(canvas, 69, 15, AlignCenter, AlignCenter, strAMPM);
}
if(!state->w_test)
canvas_draw_str_aligned(
canvas, 64, 38, AlignCenter, AlignTop, strings[0]); // DRAW DATE
canvas_set_font(canvas, FontSecondary);
canvas_draw_str_aligned(canvas, 64, 42, AlignCenter, AlignTop, date_string);
if(state->settings.time_format == H12)
canvas_draw_str_aligned(canvas, 65, 12, AlignCenter, AlignCenter, meridian_string);
if(!state->desktop_settings->is_dumbmode && !state->w_test)
elements_button_left(canvas, state->militaryTime ? "12h" : "24h");
}
if(timer_running) {
elements_button_center(canvas, "Stop");
} else if(timer_start_timestamp != 0 && !timer_running) {
elements_button_center(canvas, "Start");
if(!state->desktop_settings->is_dumbmode && !state->w_test) {
if(timer_running) {
elements_button_center(canvas, "Stop");
} else {
elements_button_center(canvas, "Start");
}
}
if(timer_running && !state->w_test) {
if(songSelect == 0) {
elements_button_right(canvas, "S:OFF");
} else if(songSelect == 1) {
elements_button_right(canvas, "S:PoRa");
} else if(songSelect == 2) {
elements_button_right(canvas, "S:Mario");
} else if(songSelect == 3) {
elements_button_right(canvas, "S:ByMin");
}
}
}
static void clock_state_init(ClockState* const state) {
LOAD_CLOCK_SETTINGS(&state->settings);
if(state->settings.time_format != H12 && state->settings.time_format != H24) {
state->settings.time_format = H12;
}
if(state->settings.date_format != Iso && state->settings.date_format != Rfc) {
state->settings.date_format = Iso;
}
FURI_LOG_D(TAG, "Time format: %s", state->settings.time_format == H12 ? "12h" : "24h");
FURI_LOG_D(
TAG, "Date format: %s", state->settings.date_format == Iso ? "ISO 8601" : "RFC 5322");
//furi_hal_rtc_get_datetime(&state->datetime);
memset(state, 0, sizeof(ClockState));
state->militaryTime = false;
state->songSelect = 2;
state->codeSequence = 0;
state->lastexp_timestamp = 0;
state->timer_start_timestamp = 0;
state->timer_stopped_seconds = 0;
state->timerSecs = 0;
state->alert_time = 80;
state->desktop_settings = malloc(sizeof(DesktopSettings));
state->w_test = false;
}
// Runs every 1000ms by default
@@ -112,127 +315,266 @@ static void clock_tick(void* ctx) {
furi_assert(ctx);
FuriMessageQueue* event_queue = ctx;
PluginEvent event = {.type = EventTypeTick};
// It's OK to loose this event if system overloaded
// It's OK to lose this event if system overloaded
furi_message_queue_put(event_queue, &event, 0);
}
int32_t clock_app(void* p) {
UNUSED(p);
ClockState* plugin_state = malloc(sizeof(ClockState));
clock_state_init(plugin_state);
plugin_state->event_queue = furi_message_queue_alloc(8, sizeof(PluginEvent));
if(plugin_state->event_queue == NULL) {
FURI_LOG_E(TAG, "Cannot create event queue");
FURI_LOG_E(TAG, "cannot create event queue\n");
free(plugin_state);
return 255;
}
//FURI_LOG_D(TAG, "Event queue created");
plugin_state->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
if(plugin_state->mutex == NULL) {
FURI_LOG_E(TAG, "Cannot create mutex");
FURI_LOG_E(TAG, "cannot create mutex\n");
furi_message_queue_free(plugin_state->event_queue);
free(plugin_state);
return 255;
}
//FURI_LOG_D(TAG, "Mutex created");
clock_state_init(plugin_state);
// Set system callbacks
ViewPort* view_port = view_port_alloc();
view_port_draw_callback_set(view_port, clock_render_callback, plugin_state);
view_port_input_callback_set(view_port, clock_input_callback, plugin_state->event_queue);
FuriTimer* timer =
furi_timer_alloc(clock_tick, FuriTimerTypePeriodic, plugin_state->event_queue);
if(timer == NULL) {
FURI_LOG_E(TAG, "Cannot create timer");
FURI_LOG_E(TAG, "cannot create timer\n");
furi_mutex_free(plugin_state->mutex);
furi_message_queue_free(plugin_state->event_queue);
free(plugin_state);
return 255;
}
//FURI_LOG_D(TAG, "Timer created");
LOAD_DESKTOP_SETTINGS(plugin_state->desktop_settings);
// Set system callbacks
ViewPort* view_port = view_port_alloc();
view_port_draw_callback_set(view_port, clock_render_callback, plugin_state);
view_port_input_callback_set(view_port, clock_input_callback, plugin_state->event_queue);
NotificationApp* notification = furi_record_open(RECORD_NOTIFICATION);
// Open GUI and register view_port
Gui* gui = furi_record_open(RECORD_GUI);
gui_add_view_port(gui, view_port, GuiLayerFullscreen);
furi_timer_start(timer, furi_kernel_get_tick_frequency());
//FURI_LOG_D(TAG, "Timer started");
// Main loop
PluginEvent event;
for(bool processing = true; processing;) {
FuriStatus event_status = furi_message_queue_get(plugin_state->event_queue, &event, 100);
if(event_status != FuriStatusOk) continue;
if(furi_mutex_acquire(plugin_state->mutex, FuriWaitForever) != FuriStatusOk) continue;
// press events
if(event.type == EventTypeKey) {
if(event.input.type == InputTypeShort || event.input.type == InputTypeRepeat) {
switch(event.input.key) {
case InputKeyUp:
case InputKeyDown:
case InputKeyRight:
break;
case InputKeyLeft:
if(plugin_state->timer_start_timestamp != 0) {
// Reset seconds
plugin_state->timer_running = false;
plugin_state->timer_start_timestamp = 0;
plugin_state->timer_stopped_seconds = 0;
}
break;
case InputKeyOk:;
// START/STOP TIMER
FuriHalRtcDateTime curr_dt;
furi_hal_rtc_get_datetime(&curr_dt);
uint32_t curr_ts = furi_hal_rtc_datetime_to_timestamp(&curr_dt);
if(plugin_state->timer_running) {
// Update stopped seconds
plugin_state->timer_stopped_seconds =
curr_ts - plugin_state->timer_start_timestamp;
} else {
if(plugin_state->timer_start_timestamp == 0) {
// Set starting timestamp if this is first time
plugin_state->timer_start_timestamp = curr_ts;
if(event_status == FuriStatusOk) {
if(furi_mutex_acquire(plugin_state->mutex, FuriWaitForever) != FuriStatusOk) continue;
// press events
if(event.type == EventTypeKey) {
if(event.input.type == InputTypeShort || event.input.type == InputTypeRepeat) {
switch(event.input.key) {
case InputKeyUp:
if(plugin_state->codeSequence == 0 || plugin_state->codeSequence == 1) {
plugin_state->codeSequence++;
if(plugin_state->timer_running)
plugin_state->alert_time = plugin_state->alert_time + 5;
} else {
// Timer was already running, need to slightly readjust so we don't
// count the intervening time
plugin_state->timer_start_timestamp =
curr_ts - plugin_state->timer_stopped_seconds;
plugin_state->codeSequence = 0;
if(plugin_state->timer_running)
plugin_state->alert_time = plugin_state->alert_time + 5;
}
break;
case InputKeyDown:
if(plugin_state->codeSequence == 2 || plugin_state->codeSequence == 3) {
plugin_state->codeSequence++;
if(plugin_state->timer_running)
plugin_state->alert_time = plugin_state->alert_time - 5;
} else {
plugin_state->codeSequence = 0;
if(plugin_state->timer_running)
plugin_state->alert_time = plugin_state->alert_time - 5;
}
break;
case InputKeyRight:
if(plugin_state->codeSequence == 5 || plugin_state->codeSequence == 7) {
plugin_state->codeSequence++;
if(plugin_state->codeSequence == 8) {
desktop_view_main_dumbmode_changed(plugin_state->desktop_settings);
}
} else {
plugin_state->codeSequence = 0;
if(plugin_state->songSelect == 0) {
plugin_state->songSelect = 1;
} else if(plugin_state->songSelect == 1) {
plugin_state->songSelect = 2;
} else if(plugin_state->songSelect == 2) {
plugin_state->songSelect = 3;
} else {
plugin_state->songSelect = 0;
}
}
break;
case InputKeyLeft:
if(plugin_state->codeSequence == 4 || plugin_state->codeSequence == 6) {
plugin_state->codeSequence++;
} else {
plugin_state->codeSequence = 0;
if(plugin_state->timer_start_timestamp != 0) {
// START? TIMER
FuriHalRtcDateTime curr_dt;
furi_hal_rtc_get_datetime(&curr_dt);
uint32_t curr_ts = furi_hal_rtc_datetime_to_timestamp(&curr_dt);
// Reset seconds
plugin_state->timer_start_timestamp = curr_ts;
plugin_state->timer_stopped_seconds = 0;
plugin_state->timerSecs = 0;
} else {
// Toggle 12/24 hours
if(!plugin_state->desktop_settings->is_dumbmode)
plugin_state->militaryTime = !plugin_state->militaryTime;
}
}
break;
case InputKeyOk:
if(plugin_state->codeSequence == 9) {
plugin_state->codeSequence++;
} else {
plugin_state->codeSequence = 0;
if(!plugin_state->desktop_settings->is_dumbmode) {
if(plugin_state->songSelect == 1 ||
plugin_state->songSelect == 2 ||
plugin_state->songSelect == 3) {
notification_message(notification, &clock_alert_startStop);
}
// START/STOP TIMER
FuriHalRtcDateTime curr_dt;
furi_hal_rtc_get_datetime(&curr_dt);
uint32_t curr_ts = furi_hal_rtc_datetime_to_timestamp(&curr_dt);
if(plugin_state->timer_running) {
// Update stopped seconds
plugin_state->timer_stopped_seconds =
curr_ts - plugin_state->timer_start_timestamp;
} else {
if(plugin_state->timer_start_timestamp == 0) {
// Set starting timestamp if this is first time
plugin_state->timer_start_timestamp = curr_ts;
} else {
// Timer was already running, need to slightly readjust so we don't
// count the intervening time
plugin_state->timer_start_timestamp =
curr_ts - plugin_state->timer_stopped_seconds;
}
}
plugin_state->timer_running = !plugin_state->timer_running;
}
}
break;
case InputKeyBack:
if(plugin_state->codeSequence == 8) {
plugin_state->codeSequence++;
} else {
plugin_state->w_test = false;
// Don't Exit the plugin
plugin_state->codeSequence--;
if(plugin_state->codeSequence < -1) processing = false;
}
break;
}
if(plugin_state->codeSequence == 10) {
plugin_state->codeSequence = 0;
plugin_state->desktop_settings->is_dumbmode =
true; // MAKE SURE IT'S ON SO IT GETS TURNED OFF
desktop_view_main_dumbmode_changed(plugin_state->desktop_settings);
if(plugin_state->songSelect == 1 || plugin_state->songSelect == 2 ||
plugin_state->songSelect == 3) {
notification_message(notification, &sequence_success);
}
plugin_state->militaryTime = true; // 24 HR TIME FOR THIS
plugin_state->w_test = true; // OH HEY NOW LETS GAIN EXP & MORE FUN
DOLPHIN_DEED(getRandomDeed());
}
} else if(event.input.type == InputTypeLong) {
if(event.input.key == InputKeyLeft) {
plugin_state->codeSequence = 0;
if(plugin_state->timer_start_timestamp != 0) {
// Reset seconds
plugin_state->timer_running = false;
plugin_state->timer_start_timestamp = 0;
plugin_state->timer_stopped_seconds = 0;
plugin_state->timerSecs = 0;
}
} else if(event.input.key == InputKeyBack) {
// Exit the plugin
processing = false;
}
}
} else if(event.type == EventTypeTick) {
// Do nothing, just need to update viewport
if(plugin_state->timer_running) {
plugin_state->timerSecs = plugin_state->timerSecs + 1;
if(plugin_state->timerSecs % 60 == 0 && plugin_state->timerSecs != 0) {
notification_message(notification, &clock_alert_perMin);
}
if(plugin_state->songSelect == 1) {
if(plugin_state->timerSecs == plugin_state->alert_time) {
FuriHalRtcDateTime curr_dt;
furi_hal_rtc_get_datetime(&curr_dt);
uint32_t curr_ts = furi_hal_rtc_datetime_to_timestamp(&curr_dt);
if(plugin_state->lastexp_timestamp + 10 <= curr_ts &&
plugin_state->w_test) {
plugin_state->lastexp_timestamp = curr_ts;
DOLPHIN_DEED(getRandomDeed());
}
notification_message(notification, &clock_alert_pr1);
}
if(plugin_state->timerSecs == plugin_state->alert_time + 1) {
notification_message(notification, &clock_alert_pr2);
}
if(plugin_state->timerSecs == plugin_state->alert_time + 2) {
notification_message(notification, &clock_alert_pr3);
}
} else if(plugin_state->songSelect == 2) {
if(plugin_state->timerSecs == plugin_state->alert_time) {
FuriHalRtcDateTime curr_dt;
furi_hal_rtc_get_datetime(&curr_dt);
uint32_t curr_ts = furi_hal_rtc_datetime_to_timestamp(&curr_dt);
if(plugin_state->lastexp_timestamp + 10 <= curr_ts &&
plugin_state->w_test) {
plugin_state->lastexp_timestamp = curr_ts;
DOLPHIN_DEED(getRandomDeed());
}
notification_message(notification, &clock_alert_mario1);
}
if(plugin_state->timerSecs == plugin_state->alert_time + 1) {
notification_message(notification, &clock_alert_mario2);
}
if(plugin_state->timerSecs == plugin_state->alert_time + 2) {
notification_message(notification, &clock_alert_mario3);
}
} else {
if(plugin_state->timerSecs == plugin_state->alert_time) {
FuriHalRtcDateTime curr_dt;
furi_hal_rtc_get_datetime(&curr_dt);
uint32_t curr_ts = furi_hal_rtc_datetime_to_timestamp(&curr_dt);
if(plugin_state->lastexp_timestamp + 10 <= curr_ts &&
plugin_state->w_test) {
plugin_state->lastexp_timestamp = curr_ts;
DOLPHIN_DEED(getRandomDeed());
}
notification_message(notification, &clock_alert_silent);
}
}
plugin_state->timer_running = !plugin_state->timer_running;
break;
case InputKeyBack:
// Exit the plugin
processing = false;
break;
}
}
} /*else if(event.type == EventTypeTick) {
furi_hal_rtc_get_datetime(&plugin_state->datetime);
}*/
view_port_update(view_port);
furi_mutex_release(plugin_state->mutex);
view_port_update(view_port);
furi_mutex_release(plugin_state->mutex);
} else {
// event timeout
// FURI_LOG_D(TAG, "osMessageQueue: event timeout");
}
}
// Cleanup
furi_timer_free(timer);
view_port_enabled_set(view_port, false);
gui_remove_view_port(gui, view_port);
furi_record_close(RECORD_NOTIFICATION);
furi_record_close(RECORD_GUI);
view_port_free(view_port);
furi_message_queue_free(plugin_state->event_queue);
furi_mutex_free(plugin_state->mutex);
free(plugin_state->desktop_settings);
free(plugin_state);
return 0;
}
-38
View File
@@ -1,38 +0,0 @@
#pragma once
#include <input/input.h>
#include "clock_settings.h"
#define TAG "Clock"
#define CLOCK_ISO_DATE_FORMAT "%.4d-%.2d-%.2d"
#define CLOCK_RFC_DATE_FORMAT "%.2d-%.2d-%.4d"
#define CLOCK_TIME_FORMAT "%.2d:%.2d:%.2d"
#define MERIDIAN_FORMAT "%s"
#define MERIDIAN_STRING_AM "AM"
#define MERIDIAN_STRING_PM "PM"
#define TIME_LEN 12
#define DATE_LEN 14
#define MERIDIAN_LEN 3
typedef enum {
EventTypeTick,
EventTypeKey,
} EventType;
typedef struct {
EventType type;
InputEvent input;
} PluginEvent;
typedef struct {
ClockSettings settings;
FuriHalRtcDateTime datetime;
FuriMutex* mutex;
FuriMessageQueue* event_queue;
uint32_t timer_start_timestamp;
uint32_t timer_stopped_seconds;
bool timer_running;
} ClockState;
@@ -1,37 +0,0 @@
#pragma once
#include "clock_settings_filename.h"
#include <furi_hal.h>
#include <stdint.h>
#include <stdbool.h>
#include <toolbox/saved_struct.h>
#include <storage/storage.h>
#define CLOCK_SETTINGS_VER (1)
#define CLOCK_SETTINGS_PATH EXT_PATH(CLOCK_SETTINGS_FILE_NAME)
#define CLOCK_SETTINGS_MAGIC (0xC1)
#define SAVE_CLOCK_SETTINGS(x) \
saved_struct_save( \
CLOCK_SETTINGS_PATH, (x), sizeof(ClockSettings), CLOCK_SETTINGS_MAGIC, CLOCK_SETTINGS_VER)
#define LOAD_CLOCK_SETTINGS(x) \
saved_struct_load( \
CLOCK_SETTINGS_PATH, (x), sizeof(ClockSettings), CLOCK_SETTINGS_MAGIC, CLOCK_SETTINGS_VER)
typedef enum {
H12 = 1,
H24 = 2,
} TimeFormat;
typedef enum {
Iso = 1, // ISO 8601: yyyy-mm-dd
Rfc = 2, // RFC 5322: dd-mm-yyyy
} DateFormat;
typedef struct {
TimeFormat time_format;
DateFormat date_format;
uint8_t increment_precision;
} ClockSettings;
@@ -1,102 +0,0 @@
#include <furi.h>
#include <gui/modules/variable_item_list.h>
#include <gui/view_dispatcher.h>
#include <lib/toolbox/value_index.h>
#include "clock_settings.h"
#define TAG "Clock"
typedef struct {
ClockSettings clock_settings;
Gui* gui;
ViewDispatcher* view_dispatcher;
VariableItemList* variable_item_list;
} ClockAppSettings;
static uint32_t clock_app_settings_exit(void* context) {
UNUSED(context);
return VIEW_NONE;
}
#define TIME_FORMAT_COUNT 2
const char* const time_format_text[TIME_FORMAT_COUNT] = {
"12h",
"24h",
};
const uint32_t time_format_value[TIME_FORMAT_COUNT] = {H12, H24};
#define DATE_FORMAT_COUNT 2
const char* const date_format_text[DATE_FORMAT_COUNT] = {
"mm-dd", // ISO 8601
"dd-mm", // RFC 5322
};
const uint32_t date_format_value[DATE_FORMAT_COUNT] = {Iso, Rfc};
static void time_format_changed(VariableItem* item) {
ClockAppSettings* app = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, time_format_text[index]);
app->clock_settings.time_format = time_format_value[index];
}
static void date_format_changed(VariableItem* item) {
ClockAppSettings* app = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, date_format_text[index]);
app->clock_settings.date_format = date_format_value[index];
}
static ClockAppSettings* alloc_settings() {
ClockAppSettings* app = malloc(sizeof(ClockAppSettings));
LOAD_CLOCK_SETTINGS(&app->clock_settings);
app->gui = furi_record_open(RECORD_GUI);
app->variable_item_list = variable_item_list_alloc();
View* view = variable_item_list_get_view(app->variable_item_list);
view_set_previous_callback(view, clock_app_settings_exit);
VariableItem* item;
uint8_t value_index;
item = variable_item_list_add(
app->variable_item_list, "Clock format", TIME_FORMAT_COUNT, time_format_changed, app);
value_index = value_index_uint32(
(uint32_t)(app->clock_settings.time_format), time_format_value, TIME_FORMAT_COUNT);
//FURI_LOG_T(TAG, "Time format index: %u", value_index);
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, time_format_text[value_index]);
item = variable_item_list_add(
app->variable_item_list, "Date format", DATE_FORMAT_COUNT, date_format_changed, app);
value_index = value_index_uint32(
(uint32_t)(app->clock_settings.date_format), date_format_value, DATE_FORMAT_COUNT);
//FURI_LOG_T(TAG, "Date format index: %u", value_index);
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, date_format_text[value_index]);
app->view_dispatcher = view_dispatcher_alloc();
view_dispatcher_enable_queue(app->view_dispatcher);
view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
view_dispatcher_add_view(app->view_dispatcher, 0, view);
view_dispatcher_switch_to_view(app->view_dispatcher, 0);
return app;
}
static void free_settings(ClockAppSettings* app) {
view_dispatcher_remove_view(app->view_dispatcher, 0);
variable_item_list_free(app->variable_item_list);
view_dispatcher_free(app->view_dispatcher);
furi_record_close(RECORD_GUI);
SAVE_CLOCK_SETTINGS(&app->clock_settings);
free(app);
}
extern int32_t clock_settings_app(void* p) {
UNUSED(p);
ClockAppSettings* app = alloc_settings();
view_dispatcher_run(app->view_dispatcher);
free_settings(app);
return 0;
}
@@ -1,3 +0,0 @@
#pragma once
#define CLOCK_SETTINGS_FILE_NAME ".clock.settings"