Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ClusterM/flipperzero-firmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorits your bedtime <23366927+itsyourbedtime@users.noreply.github.com>2021-09-28 12:40:39 +0300
committerGitHub <noreply@github.com>2021-09-28 12:40:39 +0300
commit1c4e6ec74dded2318c451c50a376129dbc8352e8 (patch)
tree979994be521c8f060944d89892160530fe0dcc45 /applications/dolphin
parenta8981d317a0f36e6694e8edc891103eecb5fae7a (diff)
[FL-1824] Dolphin refactoring (#701)
* refactoring p1 * refactoring p2 * cleanups * locked screen refresh rate fix * better locked view logic * seperate dolphin service and desktop app * Desktop: Favorite app acess (Left key), Settings app * Desktop settings version, submenu header * remove unused icon anomation + naming fix Co-authored-by: あく <alleteam@gmail.com>
Diffstat (limited to 'applications/dolphin')
-rw-r--r--applications/dolphin/dolphin.c443
-rw-r--r--applications/dolphin/dolphin.h21
-rw-r--r--applications/dolphin/dolphin_i.h44
-rw-r--r--applications/dolphin/dolphin_views.c197
-rw-r--r--applications/dolphin/dolphin_views.h67
-rw-r--r--applications/dolphin/helpers/dolphin_deed.c (renamed from applications/dolphin/dolphin_deed.c)0
-rw-r--r--applications/dolphin/helpers/dolphin_deed.h (renamed from applications/dolphin/dolphin_deed.h)1
-rw-r--r--applications/dolphin/helpers/dolphin_state.c (renamed from applications/dolphin/dolphin_state.c)0
-rw-r--r--applications/dolphin/helpers/dolphin_state.h (renamed from applications/dolphin/dolphin_state.h)0
9 files changed, 55 insertions, 718 deletions
diff --git a/applications/dolphin/dolphin.c b/applications/dolphin/dolphin.c
index cdcef27e..a0d24df9 100644
--- a/applications/dolphin/dolphin.c
+++ b/applications/dolphin/dolphin.c
@@ -1,361 +1,39 @@
#include "dolphin_i.h"
-#include <stdlib.h>
-#include "applications.h"
+#include <furi.h>
-const Icon* idle_scenes[] = {&A_Wink_128x64, &A_WatchingTV_128x64};
-
-static void dolphin_switch_to_app(Dolphin* dolphin, const FlipperApplication* flipper_app) {
+bool dolphin_load(Dolphin* dolphin) {
furi_assert(dolphin);
- furi_assert(flipper_app);
- furi_assert(flipper_app->app);
- furi_assert(flipper_app->name);
-
- if(furi_thread_get_state(dolphin->scene_thread) != FuriThreadStateStopped) {
- FURI_LOG_E("Dolphin", "Thread is already running");
- return;
- }
-
- furi_thread_set_name(dolphin->scene_thread, flipper_app->name);
- furi_thread_set_stack_size(dolphin->scene_thread, flipper_app->stack_size);
- furi_thread_set_callback(dolphin->scene_thread, flipper_app->app);
-
- furi_thread_start(dolphin->scene_thread);
-}
-
-// temporary main screen animation managment
-void dolphin_scene_handler_set_scene(Dolphin* dolphin, const Icon* icon_data) {
- with_view_model(
- dolphin->idle_view_main, (DolphinViewMainModel * model) {
- if(model->animation) icon_animation_free(model->animation);
- model->animation = icon_animation_alloc(icon_data);
- icon_animation_start(model->animation);
- return true;
- });
+ return dolphin_state_load(dolphin->state);
}
-void dolphin_scene_handler_switch_scene(Dolphin* dolphin) {
- with_view_model(
- dolphin->idle_view_main, (DolphinViewMainModel * model) {
- if(icon_animation_is_last_frame(model->animation)) {
- if(model->animation) icon_animation_free(model->animation);
- model->animation = icon_animation_alloc(idle_scenes[model->scene_num]);
- icon_animation_start(model->animation);
- model->scene_num = random() % COUNT_OF(idle_scenes);
- }
- return true;
- });
-}
-
-bool dolphin_view_first_start_input(InputEvent* event, void* context) {
- furi_assert(event);
- furi_assert(context);
- Dolphin* dolphin = context;
- if(event->type == InputTypeShort) {
- DolphinViewFirstStartModel* model = view_get_model(dolphin->idle_view_first_start);
- if(event->key == InputKeyLeft) {
- if(model->page > 0) model->page--;
- } else if(event->key == InputKeyRight) {
- uint32_t page = ++model->page;
- if(page > 8) {
- dolphin_save(dolphin);
- view_dispatcher_switch_to_view(dolphin->idle_view_dispatcher, DolphinViewIdleMain);
- }
- }
- view_commit_model(dolphin->idle_view_first_start, true);
- }
- // All evennts cosumed
- return true;
-}
-
-void dolphin_lock_handler(InputEvent* event, Dolphin* dolphin) {
- furi_assert(event);
+void dolphin_save(Dolphin* dolphin) {
furi_assert(dolphin);
-
- with_view_model(
- dolphin->idle_view_main, (DolphinViewMainModel * model) {
- model->hint_timeout = HINT_TIMEOUT_L;
- return true;
- });
-
- if(event->key == InputKeyBack && event->type == InputTypeShort) {
- uint32_t press_time = HAL_GetTick();
-
- // check if pressed sequentially
- if(press_time - dolphin->lock_lastpress > UNLOCK_RST_TIMEOUT) {
- dolphin->lock_lastpress = press_time;
- dolphin->lock_count = 0;
- } else if(press_time - dolphin->lock_lastpress < UNLOCK_RST_TIMEOUT) {
- dolphin->lock_lastpress = press_time;
- dolphin->lock_count++;
- }
-
- if(dolphin->lock_count == 2) {
- dolphin->locked = false;
- dolphin->lock_count = 0;
-
- with_view_model(
- dolphin->view_lockmenu, (DolphinViewLockMenuModel * model) {
- model->locked = false;
- model->door_left_x = -57; // move doors to default pos
- model->door_right_x = 115;
- return true;
- });
-
- with_view_model(
- dolphin->idle_view_main, (DolphinViewMainModel * model) {
- model->hint_timeout = HINT_TIMEOUT_L; // "unlocked" hint timeout
- model->locked = false;
- return true;
- });
-
- view_port_enabled_set(dolphin->lock_viewport, false);
- }
- }
-}
-
-bool dolphin_view_idle_main_input(InputEvent* event, void* context) {
- furi_assert(event);
- furi_assert(context);
- Dolphin* dolphin = context;
- // unlocked
- if(!dolphin->locked) {
- if(event->key == InputKeyOk && event->type == InputTypeShort) {
- with_value_mutex(
- dolphin->menu_vm, (Menu * menu) { menu_ok(menu); });
- } else if(event->key == InputKeyUp && event->type == InputTypeShort) {
- osTimerStart(dolphin->timeout_timer, 64);
- view_dispatcher_switch_to_view(dolphin->idle_view_dispatcher, DolphinViewLockMenu);
- } else if(event->key == InputKeyDown && event->type == InputTypeShort) {
- dolphin_switch_to_app(dolphin, &FLIPPER_ARCHIVE);
- } else if(event->key == InputKeyDown && event->type == InputTypeLong) {
- view_dispatcher_switch_to_view(dolphin->idle_view_dispatcher, DolphinViewStats);
- } else if(event->key == InputKeyBack && event->type == InputTypeShort) {
- view_dispatcher_switch_to_view(dolphin->idle_view_dispatcher, DolphinViewIdleMain);
- }
-
- with_view_model(
- dolphin->idle_view_main, (DolphinViewMainModel * model) {
- model->hint_timeout = 0; // clear hint timeout
- return true;
- });
-
- } else {
- // locked
-
- dolphin_lock_handler(event, dolphin);
- dolphin_scene_handler_switch_scene(dolphin);
- }
- // All events consumed
- return true;
-}
-
-void lock_menu_refresh_handler(void* p) {
- osMessageQueueId_t event_queue = p;
DolphinEvent event;
- event.type = DolphinEventTypeTick;
- // Some tick events may lost and we don't care.
- osMessageQueuePut(event_queue, &event, 0, 0);
-}
-
-static void lock_menu_callback(void* context, uint8_t index) {
- furi_assert(context);
- Dolphin* dolphin = context;
- switch(index) {
- // lock
- case 0:
- dolphin->locked = true;
-
- with_view_model(
- dolphin->view_lockmenu, (DolphinViewLockMenuModel * model) {
- model->locked = true;
- model->exit_timeout = HINT_TIMEOUT_H;
- return true;
- });
-
- with_view_model(
- dolphin->idle_view_main, (DolphinViewMainModel * model) {
- model->locked = true;
- return true;
- });
- break;
-
- default:
- // wip message
- with_view_model(
- dolphin->view_lockmenu, (DolphinViewLockMenuModel * model) {
- model->hint_timeout = HINT_TIMEOUT_H;
- return true;
- });
- break;
- }
+ event.type = DolphinEventTypeSave;
+ furi_check(osMessageQueuePut(dolphin->event_queue, &event, 0, osWaitForever) == osOK);
}
-static void lock_icon_callback(Canvas* canvas, void* context) {
- furi_assert(context);
- Dolphin* dolphin = context;
- canvas_draw_icon_animation(canvas, 0, 0, dolphin->lock_icon);
+void dolphin_deed(Dolphin* dolphin, DolphinDeed deed) {
+ furi_assert(dolphin);
+ DolphinEvent event;
+ event.type = DolphinEventTypeDeed;
+ event.deed = deed;
+ furi_check(osMessageQueuePut(dolphin->event_queue, &event, 0, osWaitForever) == osOK);
}
-bool dolphin_view_lockmenu_input(InputEvent* event, void* context) {
- furi_assert(event);
- furi_assert(context);
- Dolphin* dolphin = context;
-
- if(event->type != InputTypeShort) return false;
-
- DolphinViewLockMenuModel* model = view_get_model(dolphin->view_lockmenu);
-
- model->hint_timeout = 0; // clear hint timeout
-
- if(event->key == InputKeyUp) {
- model->idx = CLAMP(model->idx - 1, 2, 0);
- } else if(event->key == InputKeyDown) {
- model->idx = CLAMP(model->idx + 1, 2, 0);
- } else if(event->key == InputKeyOk) {
- lock_menu_callback(context, model->idx);
- } else if(event->key == InputKeyBack) {
- model->idx = 0;
- view_dispatcher_switch_to_view(dolphin->idle_view_dispatcher, DolphinViewIdleMain);
-
- if(random() % 100 > 50)
- dolphin_scene_handler_set_scene(
- dolphin, idle_scenes[random() % COUNT_OF(idle_scenes)]);
- }
-
- view_commit_model(dolphin->view_lockmenu, true);
+DolphinDeedWeight dolphin_stats(Dolphin* dolphin) {
+ DolphinDeedWeight stats;
+ stats.butthurt = dolphin_state_get_butthurt(dolphin->state);
+ stats.icounter = dolphin_state_get_icounter(dolphin->state);
- return true;
-}
-
-bool dolphin_view_idle_down_input(InputEvent* event, void* context) {
- furi_assert(event);
- furi_assert(context);
- Dolphin* dolphin = context;
- DolphinViewStatsScreens current;
-
- if(event->type != InputTypeShort) return false;
-
- DolphinViewStatsModel* model = view_get_model(dolphin->idle_view_dolphin_stats);
-
- current = model->screen;
-
- if(event->key == InputKeyDown) {
- model->screen = (model->screen + 1) % DolphinViewStatsTotalCount;
- } else if(event->key == InputKeyUp) {
- model->screen =
- ((model->screen - 1) + DolphinViewStatsTotalCount) % DolphinViewStatsTotalCount;
- }
-
- view_commit_model(dolphin->idle_view_dolphin_stats, true);
-
- if(current == DolphinViewStatsMeta) {
- if(event->key == InputKeyLeft) {
- dolphin_deed(dolphin, DolphinDeedWrong);
- } else if(event->key == InputKeyRight) {
- dolphin_deed(dolphin, DolphinDeedIButtonRead);
- } else if(event->key == InputKeyOk) {
- dolphin_save(dolphin);
- } else {
- return false;
- }
- }
-
- if(event->key == InputKeyBack) {
- view_dispatcher_switch_to_view(dolphin->idle_view_dispatcher, DolphinViewIdleMain);
- }
-
- return true;
+ return stats;
}
Dolphin* dolphin_alloc() {
Dolphin* dolphin = furi_alloc(sizeof(Dolphin));
- // Message queue
- dolphin->event_queue = osMessageQueueNew(8, sizeof(DolphinEvent), NULL);
- furi_check(dolphin->event_queue);
- // State
- dolphin->state = dolphin_state_alloc();
- // Menu
- dolphin->menu_vm = furi_record_open("menu");
- // Scene thread
- dolphin->scene_thread = furi_thread_alloc();
- // GUI
- dolphin->gui = furi_record_open("gui");
- // Dispatcher
- dolphin->idle_view_dispatcher = view_dispatcher_alloc();
-
- // First start View
- dolphin->idle_view_first_start = view_alloc();
- view_allocate_model(
- dolphin->idle_view_first_start, ViewModelTypeLockFree, sizeof(DolphinViewFirstStartModel));
- view_set_context(dolphin->idle_view_first_start, dolphin);
- view_set_draw_callback(dolphin->idle_view_first_start, dolphin_view_first_start_draw);
- view_set_input_callback(dolphin->idle_view_first_start, dolphin_view_first_start_input);
- view_dispatcher_add_view(
- dolphin->idle_view_dispatcher, DolphinViewFirstStart, dolphin->idle_view_first_start);
-
- // Main Idle View
- dolphin->idle_view_main = view_alloc();
- view_set_context(dolphin->idle_view_main, dolphin);
- view_allocate_model(
- dolphin->idle_view_main, ViewModelTypeLockFree, sizeof(DolphinViewMainModel));
-
- view_set_draw_callback(dolphin->idle_view_main, dolphin_view_idle_main_draw);
- view_set_input_callback(dolphin->idle_view_main, dolphin_view_idle_main_input);
- view_dispatcher_add_view(
- dolphin->idle_view_dispatcher, DolphinViewIdleMain, dolphin->idle_view_main);
-
- // Lock Menu View
- dolphin->view_lockmenu = view_alloc();
- view_set_context(dolphin->view_lockmenu, dolphin);
- view_allocate_model(
- dolphin->view_lockmenu, ViewModelTypeLockFree, sizeof(DolphinViewLockMenuModel));
- view_set_draw_callback(dolphin->view_lockmenu, dolphin_view_lockmenu_draw);
- view_set_input_callback(dolphin->view_lockmenu, dolphin_view_lockmenu_input);
- view_set_previous_callback(dolphin->view_lockmenu, dolphin_view_idle_back);
- view_dispatcher_add_view(
- dolphin->idle_view_dispatcher, DolphinViewLockMenu, dolphin->view_lockmenu);
- // default doors xpos
- with_view_model(
- dolphin->view_lockmenu, (DolphinViewLockMenuModel * model) {
- model->door_left_x = -57; // defaults
- model->door_right_x = 115; // defaults
- return true;
- });
-
- dolphin->timeout_timer =
- osTimerNew(lock_menu_refresh_handler, osTimerPeriodic, dolphin->event_queue, NULL);
-
- // Stats Idle View
- dolphin->idle_view_dolphin_stats = view_alloc();
- view_set_context(dolphin->idle_view_dolphin_stats, dolphin);
- view_allocate_model(
- dolphin->idle_view_dolphin_stats, ViewModelTypeLockFree, sizeof(DolphinViewStatsModel));
- view_set_draw_callback(dolphin->idle_view_dolphin_stats, dolphin_view_idle_down_draw);
- view_set_input_callback(dolphin->idle_view_dolphin_stats, dolphin_view_idle_down_input);
- view_set_previous_callback(dolphin->idle_view_dolphin_stats, dolphin_view_idle_back);
- view_dispatcher_add_view(
- dolphin->idle_view_dispatcher, DolphinViewStats, dolphin->idle_view_dolphin_stats);
- // HW Mismatch
- dolphin->view_hw_mismatch = view_alloc();
- view_set_draw_callback(dolphin->view_hw_mismatch, dolphin_view_hw_mismatch_draw);
- view_set_previous_callback(dolphin->view_hw_mismatch, dolphin_view_idle_back);
- view_dispatcher_add_view(
- dolphin->idle_view_dispatcher, DolphinViewHwMismatch, dolphin->view_hw_mismatch);
-
- // Lock icon
- dolphin->lock_icon = icon_animation_alloc(&I_Lock_8x8);
- dolphin->lock_viewport = view_port_alloc();
- view_port_set_width(dolphin->lock_viewport, icon_animation_get_width(dolphin->lock_icon));
- view_port_draw_callback_set(dolphin->lock_viewport, lock_icon_callback, dolphin);
- view_port_enabled_set(dolphin->lock_viewport, false);
-
- // Main screen animation
- dolphin_scene_handler_set_scene(dolphin, idle_scenes[random() % COUNT_OF(idle_scenes)]);
-
- view_dispatcher_attach_to_gui(
- dolphin->idle_view_dispatcher, dolphin->gui, ViewDispatcherTypeWindow);
- gui_add_view_port(dolphin->gui, dolphin->lock_viewport, GuiLayerStatusBarLeft);
+ dolphin->state = dolphin_state_alloc();
+ dolphin->event_queue = osMessageQueueNew(8, sizeof(DolphinEvent), NULL);
return dolphin;
}
@@ -363,94 +41,33 @@ Dolphin* dolphin_alloc() {
void dolphin_free(Dolphin* dolphin) {
furi_assert(dolphin);
- gui_remove_view_port(dolphin->gui, dolphin->lock_viewport);
- view_port_free(dolphin->lock_viewport);
- icon_animation_free(dolphin->lock_icon);
-
- osTimerDelete(dolphin->timeout_timer);
-
- view_dispatcher_free(dolphin->idle_view_dispatcher);
-
- furi_record_close("gui");
- dolphin->gui = NULL;
-
- furi_thread_free(dolphin->scene_thread);
-
- furi_record_close("menu");
- dolphin->menu_vm = NULL;
-
dolphin_state_free(dolphin->state);
-
osMessageQueueDelete(dolphin->event_queue);
free(dolphin);
}
-void dolphin_save(Dolphin* dolphin) {
- furi_assert(dolphin);
- DolphinEvent event;
- event.type = DolphinEventTypeSave;
- furi_check(osMessageQueuePut(dolphin->event_queue, &event, 0, osWaitForever) == osOK);
-}
-
-void dolphin_deed(Dolphin* dolphin, DolphinDeed deed) {
- furi_assert(dolphin);
- DolphinEvent event;
- event.type = DolphinEventTypeDeed;
- event.deed = deed;
- furi_check(osMessageQueuePut(dolphin->event_queue, &event, 0, osWaitForever) == osOK);
-}
-
-int32_t dolphin_srv() {
+int32_t dolphin_srv(void* p) {
Dolphin* dolphin = dolphin_alloc();
-
- if(dolphin_state_load(dolphin->state)) {
- view_dispatcher_switch_to_view(dolphin->idle_view_dispatcher, DolphinViewIdleMain);
- } else {
- view_dispatcher_switch_to_view(dolphin->idle_view_dispatcher, DolphinViewFirstStart);
- }
-
- with_view_model(
- dolphin->idle_view_dolphin_stats, (DolphinViewStatsModel * model) {
- model->icounter = dolphin_state_get_icounter(dolphin->state);
- model->butthurt = dolphin_state_get_butthurt(dolphin->state);
- return true;
- });
-
furi_record_create("dolphin", dolphin);
- if(!furi_hal_version_do_i_belong_here()) {
- view_dispatcher_switch_to_view(dolphin->idle_view_dispatcher, DolphinViewHwMismatch);
- }
-
DolphinEvent event;
while(1) {
furi_check(osMessageQueueGet(dolphin->event_queue, &event, NULL, osWaitForever) == osOK);
-
- DolphinViewLockMenuModel* lock_model = view_get_model(dolphin->view_lockmenu);
-
- if(lock_model->locked && lock_model->exit_timeout == 0 &&
- osTimerIsRunning(dolphin->timeout_timer)) {
- osTimerStop(dolphin->timeout_timer);
- osDelay(1); // smol enterprise delay
- view_dispatcher_switch_to_view(dolphin->idle_view_dispatcher, DolphinViewIdleMain);
- }
-
- if(event.type == DolphinEventTypeTick) {
- view_commit_model(dolphin->view_lockmenu, true);
-
- } else if(event.type == DolphinEventTypeDeed) {
+ switch(event.type) {
+ case DolphinEventTypeDeed:
dolphin_state_on_deed(dolphin->state, event.deed);
- with_view_model(
- dolphin->idle_view_dolphin_stats, (DolphinViewStatsModel * model) {
- model->icounter = dolphin_state_get_icounter(dolphin->state);
- model->butthurt = dolphin_state_get_butthurt(dolphin->state);
- return true;
- });
- } else if(event.type == DolphinEventTypeSave) {
+ break;
+
+ case DolphinEventTypeSave:
dolphin_state_save(dolphin->state);
+ break;
+
+ default:
+ break;
}
}
+
dolphin_free(dolphin);
return 0;
}
diff --git a/applications/dolphin/dolphin.h b/applications/dolphin/dolphin.h
index 676f5dc5..0351417b 100644
--- a/applications/dolphin/dolphin.h
+++ b/applications/dolphin/dolphin.h
@@ -1,11 +1,30 @@
#pragma once
-#include "dolphin_deed.h"
+#include "helpers/dolphin_deed.h"
typedef struct Dolphin Dolphin;
+/* Load Dolphin state
+ * Thread safe
+ */
+
+bool dolphin_load(Dolphin* dolphin);
+
/* Deed complete notification. Call it on deed completion.
* See dolphin_deed.h for available deeds. In futures it will become part of assets.
* Thread safe
*/
+
void dolphin_deed(Dolphin* dolphin, DolphinDeed deed);
+
+/* Save Dolphin state (write to permanent memory)
+ * Thread safe
+ */
+
+void dolphin_save(Dolphin* dolphin);
+
+/* Retrieve dolphin's icounter and butthurt values
+ * Thread safe
+ */
+
+DolphinDeedWeight dolphin_stats(Dolphin* dolphin); \ No newline at end of file
diff --git a/applications/dolphin/dolphin_i.h b/applications/dolphin/dolphin_i.h
index cd562492..f9393984 100644
--- a/applications/dolphin/dolphin_i.h
+++ b/applications/dolphin/dolphin_i.h
@@ -1,22 +1,10 @@
#pragma once
-#include "dolphin.h"
-#include "dolphin_state.h"
-#include "dolphin_views.h"
-
#include <furi.h>
#include <furi-hal.h>
-#include <gui/gui.h>
-#include <gui/view_dispatcher.h>
-#include <gui/canvas.h>
-#include <menu/menu.h>
-#include <assets_icons.h>
-#include <stdint.h>
-
-#define UNLOCK_RST_TIMEOUT 500 // keypress counter reset timeout (ms)
-#define HINT_TIMEOUT_L 3 // low refresh rate timeout (app ticks)
-#define HINT_TIMEOUT_H 40 // high refresh rate timeout (app ticks)
+#include "dolphin.h"
+#include "helpers/dolphin_state.h"
typedef enum {
DolphinEventTypeDeed,
@@ -32,36 +20,12 @@ typedef struct {
} DolphinEvent;
struct Dolphin {
- // Internal message queue
- osMessageQueueId_t event_queue;
// State
DolphinState* state;
- // Menu
- ValueMutex* menu_vm;
- // Scene
- FuriThread* scene_thread;
- // GUI
- Gui* gui;
- ViewDispatcher* idle_view_dispatcher;
- View* idle_view_first_start;
- View* idle_view_main;
- View* idle_view_dolphin_stats;
- View* view_hw_mismatch;
- View* view_lockmenu;
- ViewPort* lock_viewport;
- IconAnimation* lock_icon;
-
- bool locked;
- uint8_t lock_count;
- uint32_t lock_lastpress;
- osTimerId_t timeout_timer;
+ // Queue
+ osMessageQueueId_t event_queue;
};
Dolphin* dolphin_alloc();
void dolphin_free(Dolphin* dolphin);
-
-/* Save Dolphin state (write to permanent memory)
- * Thread safe
- */
-void dolphin_save(Dolphin* dolphin);
diff --git a/applications/dolphin/dolphin_views.c b/applications/dolphin/dolphin_views.c
deleted file mode 100644
index 953671e7..00000000
--- a/applications/dolphin/dolphin_views.c
+++ /dev/null
@@ -1,197 +0,0 @@
-#include "dolphin_views.h"
-#include <gui/view.h>
-#include <gui/gui.h>
-#include <gui/elements.h>
-#include <furi-hal.h>
-#include <furi-hal-version.h>
-
-static char* Lockmenu_Items[3] = {"Lock", "Set PIN", "DUMB mode"};
-
-void dolphin_view_first_start_draw(Canvas* canvas, void* model) {
- DolphinViewFirstStartModel* m = model;
- canvas_clear(canvas);
- canvas_set_color(canvas, ColorBlack);
- canvas_set_font(canvas, FontSecondary);
- uint8_t width = canvas_width(canvas);
- uint8_t height = canvas_height(canvas);
- const char* my_name = furi_hal_version_get_name_ptr();
- if(m->page == 0) {
- canvas_draw_icon(canvas, 0, height - 48, &I_DolphinFirstStart0_70x53);
- elements_multiline_text_framed(canvas, 75, 20, "Hey m8,\npress > to\ncontinue");
- } else if(m->page == 1) {
- canvas_draw_icon(canvas, 0, height - 48, &I_DolphinFirstStart1_59x53);
- elements_multiline_text_framed(canvas, 64, 20, "First Of All,\n... >");
- } else if(m->page == 2) {
- canvas_draw_icon(canvas, 0, height - 48, &I_DolphinFirstStart2_59x51);
- elements_multiline_text_framed(canvas, 64, 20, "Thank you\nfor your\nsupport! >");
- } else if(m->page == 3) {
- canvas_draw_icon(canvas, width - 57, height - 48, &I_DolphinFirstStart3_57x48);
- elements_multiline_text_framed(canvas, 0, 20, "Kickstarter\ncampaign\nwas INSANE! >");
- } else if(m->page == 4) {
- canvas_draw_icon(canvas, width - 67, height - 50, &I_DolphinFirstStart4_67x53);
- elements_multiline_text_framed(canvas, 0, 17, "Now\nallow me\nto introduce\nmyself >");
- } else if(m->page == 5) {
- char buf[64];
- snprintf(
- buf,
- 64,
- "%s %s%s",
- "I am",
- my_name ? my_name : "Unknown",
- ",\ncyberdolphin\nliving in your\npocket >");
- canvas_draw_icon(canvas, 0, height - 48, &I_DolphinFirstStart5_54x49);
- elements_multiline_text_framed(canvas, 60, 17, buf);
- } else if(m->page == 6) {
- canvas_draw_icon(canvas, 0, height - 48, &I_DolphinFirstStart6_58x54);
- elements_multiline_text_framed(
- canvas, 63, 17, "I can grow\nsmart'n'cool\nif you use me\noften >");
- } else if(m->page == 7) {
- canvas_draw_icon(canvas, width - 61, height - 48, &I_DolphinFirstStart7_61x51);
- elements_multiline_text_framed(
- canvas, 0, 17, "As long as\nyou read, write\nand emulate >");
- } else if(m->page == 8) {
- canvas_draw_icon(canvas, width - 56, height - 48, &I_DolphinFirstStart8_56x51);
- elements_multiline_text_framed(
- canvas, 0, 17, "You can check\nmy level and\nmood in the\nPassport menu");
- }
-}
-
-void dolphin_view_idle_main_draw(Canvas* canvas, void* model) {
- canvas_clear(canvas);
- DolphinViewMainModel* m = model;
- if(m->animation) {
- canvas_draw_icon_animation(canvas, 0, -3, m->animation);
- }
-
- if(m->hint_timeout) {
- m->hint_timeout--;
- if(m->locked) {
- canvas_draw_icon(canvas, 13, 5, &I_LockPopup_100x49);
- elements_multiline_text(canvas, 65, 20, "To unlock\npress:");
- } else {
- canvas_set_font(canvas, FontPrimary);
- elements_multiline_text_framed(canvas, 42, 30, "Unlocked");
- }
- }
-}
-
-void dolphin_view_lockmenu_draw(Canvas* canvas, void* model) {
- DolphinViewLockMenuModel* m = model;
- canvas_clear(canvas);
- canvas_set_color(canvas, ColorBlack);
- canvas_draw_icon(canvas, m->door_left_x, 0, &I_DoorLeft_70x55);
- canvas_draw_icon(canvas, m->door_right_x, 0, &I_DoorRight_70x55);
- canvas_set_font(canvas, FontSecondary);
-
- if(m->locked) {
- m->exit_timeout--;
-
- m->door_left_x = CLAMP(m->door_left_x + 5, 0, -57);
- m->door_right_x = CLAMP(m->door_right_x - 5, 115, 60);
-
- if(m->door_left_x > -10) {
- canvas_set_font(canvas, FontPrimary);
- elements_multiline_text_framed(canvas, 42, 30, "Locked");
- }
-
- } else {
- if(m->door_left_x == -57) {
- for(uint8_t i = 0; i < 3; ++i) {
- canvas_draw_str_aligned(
- canvas,
- 64,
- 13 + (i * 17),
- AlignCenter,
- AlignCenter,
- (m->hint_timeout && m->idx == i) ? "Not implemented" : Lockmenu_Items[i]);
- if(m->idx == i) elements_frame(canvas, 15, 5 + (i * 17), 98, 15);
- }
- }
-
- if(m->hint_timeout) {
- m->hint_timeout--;
- }
- }
-}
-
-void dolphin_view_idle_down_draw(Canvas* canvas, void* model) {
- DolphinViewStatsModel* m = model;
- const Version* ver;
- char buffer[64];
-
- static const char* headers[] = {"FW Version info:", "Boot Version info:", "Dolphin info:"};
-
- canvas_set_color(canvas, ColorBlack);
- canvas_set_font(canvas, FontPrimary);
- canvas_draw_str(canvas, 2, 13, headers[m->screen]);
- canvas_set_font(canvas, FontSecondary);
-
- if(m->screen != DolphinViewStatsMeta) {
- // Hardware version
- const char* my_name = furi_hal_version_get_name_ptr();
- snprintf(
- buffer,
- sizeof(buffer),
- "HW: %d.F%dB%dC%d %s",
- furi_hal_version_get_hw_version(),
- furi_hal_version_get_hw_target(),
- furi_hal_version_get_hw_body(),
- furi_hal_version_get_hw_connect(),
- my_name ? my_name : "Unknown");
- canvas_draw_str(canvas, 5, 23, buffer);
-
- ver = m->screen == DolphinViewStatsBoot ? furi_hal_version_get_boot_version() :
- furi_hal_version_get_firmware_version();
-
- if(!ver) {
- canvas_draw_str(canvas, 5, 33, "No info");
- return;
- }
-
- snprintf(
- buffer,
- sizeof(buffer),
- "%s [%s]",
- version_get_version(ver),
- version_get_builddate(ver));
- canvas_draw_str(canvas, 5, 33, buffer);
-
- snprintf(
- buffer,
- sizeof(buffer),
- "%s [%s]",
- version_get_githash(ver),
- version_get_gitbranchnum(ver));
- canvas_draw_str(canvas, 5, 43, buffer);
-
- snprintf(
- buffer, sizeof(buffer), "[%s] %s", version_get_target(ver), version_get_gitbranch(ver));
- canvas_draw_str(canvas, 5, 53, buffer);
-
- } else {
- char buffer[64];
- canvas_set_font(canvas, FontSecondary);
- snprintf(buffer, 64, "Icounter: %ld", m->icounter);
- canvas_draw_str(canvas, 5, 30, buffer);
- snprintf(buffer, 64, "Butthurt: %ld", m->butthurt);
- canvas_draw_str(canvas, 5, 40, buffer);
- canvas_draw_str(canvas, 0, 53, "[< >] icounter value [ok] save");
- }
-}
-
-void dolphin_view_hw_mismatch_draw(Canvas* canvas, void* model) {
- canvas_clear(canvas);
- canvas_set_color(canvas, ColorBlack);
- canvas_set_font(canvas, FontPrimary);
- canvas_draw_str(canvas, 2, 15, "!!!! HW Mismatch !!!!");
-
- char buffer[64];
- canvas_set_font(canvas, FontSecondary);
- snprintf(buffer, 64, "HW target: F%d", furi_hal_version_get_hw_target());
- canvas_draw_str(canvas, 5, 27, buffer);
- canvas_draw_str(canvas, 5, 38, "FW target: " TARGET);
-}
-
-uint32_t dolphin_view_idle_back(void* context) {
- return DolphinViewIdleMain;
-}
diff --git a/applications/dolphin/dolphin_views.h b/applications/dolphin/dolphin_views.h
deleted file mode 100644
index 2f91b69a..00000000
--- a/applications/dolphin/dolphin_views.h
+++ /dev/null
@@ -1,67 +0,0 @@
-#pragma once
-
-#include <stdint.h>
-#include <stdbool.h>
-#include <gui/canvas.h>
-#include <input/input.h>
-#include <furi.h>
-
-// Idle screen
-typedef enum {
- DolphinViewIdleMain,
- DolphinViewFirstStart,
- DolphinViewStats,
- DolphinViewHwMismatch,
- DolphinViewLockMenu,
-} DolphinViewIdle;
-
-// Debug info
-typedef enum {
- DolphinViewStatsFw,
- DolphinViewStatsBoot,
- DolphinViewStatsMeta,
- DolphinViewStatsTotalCount,
-} DolphinViewStatsScreens;
-
-typedef struct {
- uint32_t page;
-} DolphinViewFirstStartModel;
-
-void dolphin_view_first_start_draw(Canvas* canvas, void* model);
-bool dolphin_view_first_start_input(InputEvent* event, void* context);
-
-typedef struct {
- uint32_t icounter;
- uint32_t butthurt;
- DolphinViewStatsScreens screen;
-} DolphinViewStatsModel;
-
-typedef struct {
- uint8_t idx;
- int8_t door_left_x;
- int8_t door_right_x;
- uint8_t exit_timeout;
- uint8_t hint_timeout;
-
- bool locked;
-} DolphinViewLockMenuModel;
-
-typedef struct {
- IconAnimation* animation;
- uint8_t scene_num;
- uint8_t hint_timeout;
- bool locked;
-} DolphinViewMainModel;
-
-void dolphin_view_idle_main_draw(Canvas* canvas, void* model);
-bool dolphin_view_idle_main_input(InputEvent* event, void* context);
-
-void dolphin_view_idle_up_draw(Canvas* canvas, void* model);
-
-void dolphin_view_lockmenu_draw(Canvas* canvas, void* model);
-
-void dolphin_view_idle_down_draw(Canvas* canvas, void* model);
-
-void dolphin_view_hw_mismatch_draw(Canvas* canvas, void* model);
-
-uint32_t dolphin_view_idle_back(void* context);
diff --git a/applications/dolphin/dolphin_deed.c b/applications/dolphin/helpers/dolphin_deed.c
index d589ac23..d589ac23 100644
--- a/applications/dolphin/dolphin_deed.c
+++ b/applications/dolphin/helpers/dolphin_deed.c
diff --git a/applications/dolphin/dolphin_deed.h b/applications/dolphin/helpers/dolphin_deed.h
index 2af1829a..afbf94c2 100644
--- a/applications/dolphin/dolphin_deed.h
+++ b/applications/dolphin/helpers/dolphin_deed.h
@@ -16,6 +16,7 @@ typedef enum {
typedef struct {
int32_t icounter; // how many icounter get by Deed
+ int32_t butthurt; // how many icounter get by Deed
uint32_t limit_value; // how many deeds in limit interval
uint32_t limit_interval; // interval, in minutes
} DolphinDeedWeight;
diff --git a/applications/dolphin/dolphin_state.c b/applications/dolphin/helpers/dolphin_state.c
index 99b561f1..99b561f1 100644
--- a/applications/dolphin/dolphin_state.c
+++ b/applications/dolphin/helpers/dolphin_state.c
diff --git a/applications/dolphin/dolphin_state.h b/applications/dolphin/helpers/dolphin_state.h
index cbd9611a..cbd9611a 100644
--- a/applications/dolphin/dolphin_state.h
+++ b/applications/dolphin/helpers/dolphin_state.h