mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-11-23 13:03:13 +00:00
add simple version of clock
for now, and update is planned
This commit is contained in:
parent
08c1a55756
commit
8f80999589
2 changed files with 23 additions and 286 deletions
|
@ -55,7 +55,7 @@ See changelog in releases for latest updates!
|
|||
- ESP32: WiFi Marauder companion plugin [(By 0xchocolate)](https://github.com/0xchocolate/flipperzero-firmware-with-wifi-marauder-companion)
|
||||
- NRF24: Sniffer & MouseJacker (with changes) [(By mothball187)](https://github.com/mothball187/flipperzero-nrf24/tree/main/mousejacker)
|
||||
- HID Analyzer [(By Ownasaurus)](https://github.com/Ownasaurus/flipperzero-firmware/tree/hid-analyzer/applications/hid_analyzer)
|
||||
- Clock/Stopwatch (with small fixes) [(By CompaqDisc, Stopwatch & Sound Alert By RogueMaster)](https://github.com/RogueMaster/flipperzero-firmware-wPlugins/blob/unleashed/applications/clock_app/clock_app.c)
|
||||
- Simple Clock (fixed) !! New version WIP, wait for updates !! [(Original by CompaqDisc)](https://gist.github.com/CompaqDisc/4e329c501bd03c1e801849b81f48ea61)
|
||||
- UniversalRF Remix (with changes)(only RAW subghz files) [(By ESurge)(Original UniversalRF By jimilinuxguy)](https://github.com/ESurge/flipperzero-firmware-unirfremix)
|
||||
- Tetris (with fixes) [(By jeffplang)](https://github.com/jeffplang/flipperzero-firmware/tree/tetris_game/applications/tetris_game)
|
||||
- Spectrum Analyzer (with changes) [(By jolcese)](https://github.com/jolcese/flipperzero-firmware/tree/spectrum/applications/spectrum_analyzer) - [Ultra Narrow mode & scan channels non-consecutively](https://github.com/theY4Kman/flipperzero-firmware/commits?author=theY4Kman)
|
||||
|
|
|
@ -1,16 +1,14 @@
|
|||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
|
||||
#include <gui/elements.h>
|
||||
|
||||
#include <gui/gui.h>
|
||||
#include <input/input.h>
|
||||
#include <notification/notification.h>
|
||||
#include <notification/notification_messages.h>
|
||||
|
||||
#define TAG "Clock"
|
||||
|
||||
bool timerStarted = false;
|
||||
int timerSecs = 0;
|
||||
int songSelect = 2;
|
||||
#define CLOCK_DATE_FORMAT "%.4d-%.2d-%.2d"
|
||||
#define CLOCK_TIME_FORMAT "%.2d:%.2d:%.2d"
|
||||
|
||||
typedef enum {
|
||||
EventTypeTick,
|
||||
|
@ -28,6 +26,7 @@ typedef struct {
|
|||
|
||||
static void clock_input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) {
|
||||
furi_assert(event_queue);
|
||||
|
||||
PluginEvent event = {.type = EventTypeKey, .input = *input_event};
|
||||
furi_message_queue_put(event_queue, &event, FuriWaitForever);
|
||||
}
|
||||
|
@ -35,292 +34,50 @@ 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 = (ClockState*)acquire_mutex((ValueMutex*)ctx, 25);
|
||||
char strings[3][20];
|
||||
int curMin = (timerSecs / 60);
|
||||
int curSec = timerSecs - (curMin * 60);
|
||||
|
||||
char strings[2][20];
|
||||
|
||||
snprintf(
|
||||
strings[0],
|
||||
sizeof(strings[0]),
|
||||
"%.4d-%.2d-%.2d",
|
||||
CLOCK_DATE_FORMAT,
|
||||
state->datetime.year,
|
||||
state->datetime.month,
|
||||
state->datetime.day);
|
||||
snprintf(
|
||||
strings[1],
|
||||
sizeof(strings[1]),
|
||||
"%.2d:%.2d:%.2d",
|
||||
CLOCK_TIME_FORMAT,
|
||||
state->datetime.hour,
|
||||
state->datetime.minute,
|
||||
state->datetime.second);
|
||||
snprintf(strings[2], sizeof(strings[2]), "%.2d:%.2d", curMin, curSec);
|
||||
|
||||
release_mutex((ValueMutex*)ctx, state);
|
||||
canvas_set_font(canvas, FontBigNumbers);
|
||||
canvas_draw_str_aligned(canvas, 64, 8, AlignCenter, AlignCenter, strings[1]);
|
||||
canvas_draw_str_aligned(canvas, 64, 42 - 16, AlignCenter, AlignCenter, strings[1]);
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
canvas_draw_str_aligned(canvas, 64, 20, AlignCenter, AlignTop, strings[0]);
|
||||
// elements_button_left(canvas, "Alarms");
|
||||
// elements_button_right(canvas, "Settings");
|
||||
// elements_button_center(canvas, "Reset");
|
||||
canvas_set_font(canvas, FontBigNumbers);
|
||||
canvas_draw_str_aligned(canvas, 64, 32, AlignCenter, AlignTop, strings[2]);
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
if(timerStarted) {
|
||||
elements_button_center(canvas, "Stop");
|
||||
} else {
|
||||
elements_button_center(canvas, "Start");
|
||||
}
|
||||
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");
|
||||
}
|
||||
canvas_draw_str_aligned(canvas, 64, 52 - 8, AlignCenter, AlignTop, strings[0]);
|
||||
}
|
||||
|
||||
static void clock_state_init(ClockState* const state) {
|
||||
furi_hal_rtc_get_datetime(&state->datetime);
|
||||
}
|
||||
|
||||
const NotificationSequence clock_alert_silent = {
|
||||
&message_force_vibro_setting_on,
|
||||
&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_force_speaker_volume_setting_1f,
|
||||
&message_force_vibro_setting_on,
|
||||
&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_force_speaker_volume_setting_1f,
|
||||
&message_force_vibro_setting_on,
|
||||
&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_force_speaker_volume_setting_1f,
|
||||
&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_force_speaker_volume_setting_1f,
|
||||
&message_force_vibro_setting_on,
|
||||
&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_force_speaker_volume_setting_1f,
|
||||
&message_force_vibro_setting_on,
|
||||
&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_force_speaker_volume_setting_1f,
|
||||
&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_force_speaker_volume_setting_1f,
|
||||
&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_force_speaker_volume_setting_1f,
|
||||
&message_note_d6,
|
||||
&message_delay_100,
|
||||
&message_delay_10,
|
||||
&message_delay_10,
|
||||
&message_sound_off,
|
||||
NULL,
|
||||
};
|
||||
|
||||
// Runs every 1000ms by default
|
||||
static void clock_tick(void* ctx) {
|
||||
furi_assert(ctx);
|
||||
FuriMessageQueue* event_queue = ctx;
|
||||
PluginEvent event = {.type = EventTypeTick};
|
||||
if(timerStarted) {
|
||||
timerSecs = timerSecs + 1;
|
||||
if(timerSecs % 60 == 0 && songSelect != 0) {
|
||||
NotificationApp* notification = furi_record_open("notification");
|
||||
notification_message(notification, &clock_alert_perMin);
|
||||
furi_record_close("notification");
|
||||
}
|
||||
if(songSelect == 1) {
|
||||
if(timerSecs == 80) {
|
||||
NotificationApp* notification = furi_record_open("notification");
|
||||
notification_message(notification, &clock_alert_pr1);
|
||||
furi_record_close("notification");
|
||||
}
|
||||
if(timerSecs == 81) {
|
||||
NotificationApp* notification = furi_record_open("notification");
|
||||
notification_message(notification, &clock_alert_pr2);
|
||||
furi_record_close("notification");
|
||||
}
|
||||
if(timerSecs == 82) {
|
||||
NotificationApp* notification = furi_record_open("notification");
|
||||
notification_message(notification, &clock_alert_pr3);
|
||||
furi_record_close("notification");
|
||||
}
|
||||
} else if(songSelect == 2) {
|
||||
if(timerSecs == 80) {
|
||||
NotificationApp* notification = furi_record_open("notification");
|
||||
notification_message(notification, &clock_alert_mario1);
|
||||
furi_record_close("notification");
|
||||
}
|
||||
if(timerSecs == 81) {
|
||||
NotificationApp* notification = furi_record_open("notification");
|
||||
notification_message(notification, &clock_alert_mario2);
|
||||
furi_record_close("notification");
|
||||
}
|
||||
if(timerSecs == 82) {
|
||||
NotificationApp* notification = furi_record_open("notification");
|
||||
notification_message(notification, &clock_alert_mario3);
|
||||
furi_record_close("notification");
|
||||
}
|
||||
} else {
|
||||
if(timerSecs == 80) {
|
||||
NotificationApp* notification = furi_record_open("notification");
|
||||
notification_message(notification, &clock_alert_silent);
|
||||
furi_record_close("notification");
|
||||
}
|
||||
}
|
||||
}
|
||||
// It's OK to loose this event if system overloaded
|
||||
furi_message_queue_put(event_queue, &event, 0);
|
||||
}
|
||||
|
||||
int32_t clock_app(void* p) {
|
||||
UNUSED(p);
|
||||
timerStarted = false;
|
||||
timerSecs = 0;
|
||||
songSelect = 2;
|
||||
FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(PluginEvent));
|
||||
|
||||
ClockState* plugin_state = malloc(sizeof(ClockState));
|
||||
clock_state_init(plugin_state);
|
||||
ValueMutex state_mutex;
|
||||
|
@ -329,56 +86,34 @@ int32_t clock_app(void* p) {
|
|||
free(plugin_state);
|
||||
return 255;
|
||||
}
|
||||
|
||||
// Set system callbacks
|
||||
ViewPort* view_port = view_port_alloc();
|
||||
view_port_draw_callback_set(view_port, clock_render_callback, &state_mutex);
|
||||
view_port_input_callback_set(view_port, clock_input_callback, event_queue);
|
||||
FuriTimer* timer = furi_timer_alloc(clock_tick, FuriTimerTypePeriodic, event_queue);
|
||||
furi_timer_start(timer, furi_kernel_get_tick_frequency());
|
||||
|
||||
// Open GUI and register view_port
|
||||
Gui* gui = furi_record_open("gui");
|
||||
gui_add_view_port(gui, view_port, GuiLayerFullscreen);
|
||||
|
||||
// Main loop
|
||||
PluginEvent event;
|
||||
for(bool processing = true; processing;) {
|
||||
FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100);
|
||||
ClockState* plugin_state = (ClockState*)acquire_mutex_block(&state_mutex);
|
||||
|
||||
if(event_status == FuriStatusOk) {
|
||||
// press events
|
||||
if(event.type == EventTypeKey) {
|
||||
if(event.input.type == InputTypeShort || event.input.type == InputTypeRepeat) {
|
||||
switch(event.input.key) {
|
||||
case InputKeyUp:
|
||||
if(timerStarted) timerSecs = timerSecs + 5;
|
||||
break;
|
||||
case InputKeyDown:
|
||||
if(timerStarted) timerSecs = timerSecs - 5;
|
||||
break;
|
||||
case InputKeyRight:
|
||||
if(songSelect == 0) {
|
||||
songSelect = 1;
|
||||
} else if(songSelect == 1) {
|
||||
songSelect = 2;
|
||||
} else if(songSelect == 2) {
|
||||
songSelect = 3;
|
||||
} else {
|
||||
songSelect = 0;
|
||||
}
|
||||
break;
|
||||
case InputKeyLeft:
|
||||
break;
|
||||
case InputKeyOk:
|
||||
if(songSelect == 1 || songSelect == 2 || songSelect == 3) {
|
||||
NotificationApp* notification = furi_record_open("notification");
|
||||
notification_message(notification, &clock_alert_startStop);
|
||||
furi_record_close("notification");
|
||||
}
|
||||
if(timerStarted) {
|
||||
timerStarted = false;
|
||||
timerSecs = 0;
|
||||
} else {
|
||||
timerStarted = true;
|
||||
}
|
||||
break;
|
||||
case InputKeyBack:
|
||||
// Exit the plugin
|
||||
|
@ -390,12 +125,14 @@ int32_t clock_app(void* p) {
|
|||
furi_hal_rtc_get_datetime(&plugin_state->datetime);
|
||||
}
|
||||
} else {
|
||||
FURI_LOG_D(TAG, "osMessageQueue: event timeout");
|
||||
FURI_LOG_D(TAG, "furi_message_queue: event timeout");
|
||||
// event timeout
|
||||
}
|
||||
|
||||
view_port_update(view_port);
|
||||
release_mutex(&state_mutex, plugin_state);
|
||||
}
|
||||
|
||||
furi_timer_free(timer);
|
||||
view_port_enabled_set(view_port, false);
|
||||
gui_remove_view_port(gui, view_port);
|
||||
|
|
Loading…
Reference in a new issue