1
mirror of https://github.com/DarkFlippers/unleashed-firmware.git synced 2025-12-12 04:34:43 +04:00

[FL-3897] Happy mode (#3863)

* feat: happy mode
* feat: remove sad dolphin when powering off in happy mode
* style: address review comments
* Dolphin: add missing furi_checks
* Komi: add missing region initialization on startup

Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
porta
2024-09-07 14:54:23 +03:00
committed by GitHub
parent 3c75356b49
commit 266d4b3234
23 changed files with 231 additions and 72 deletions

View File

@@ -47,6 +47,26 @@ void dolphin_deed(DolphinDeed deed) {
furi_record_close(RECORD_DOLPHIN);
}
void dolphin_get_settings(Dolphin* dolphin, DolphinSettings* settings) {
furi_check(dolphin);
furi_check(settings);
DolphinEvent event;
event.type = DolphinEventTypeSettingsGet;
event.settings = settings;
dolphin_event_send_wait(dolphin, &event);
}
void dolphin_set_settings(Dolphin* dolphin, DolphinSettings* settings) {
furi_check(dolphin);
furi_check(settings);
DolphinEvent event;
event.type = DolphinEventTypeSettingsSet;
event.settings = settings;
dolphin_event_send_wait(dolphin, &event);
}
DolphinStats dolphin_stats(Dolphin* dolphin) {
furi_check(dolphin);
@@ -211,7 +231,9 @@ static bool dolphin_process_event(FuriEventLoopObject* object, void* context) {
} else if(event.type == DolphinEventTypeStats) {
event.stats->icounter = dolphin->state->data.icounter;
event.stats->butthurt = dolphin->state->data.butthurt;
event.stats->butthurt = (dolphin->state->data.flags & DolphinFlagHappyMode) ?
0 :
dolphin->state->data.butthurt;
event.stats->timestamp = dolphin->state->data.timestamp;
event.stats->level = dolphin_get_level(dolphin->state->data.icounter);
event.stats->level_up_is_pending =
@@ -228,6 +250,15 @@ static bool dolphin_process_event(FuriEventLoopObject* object, void* context) {
dolphin_state_load(dolphin->state);
furi_event_loop_timer_start(dolphin->butthurt_timer, BUTTHURT_INCREASE_PERIOD_TICKS);
} else if(event.type == DolphinEventTypeSettingsGet) {
event.settings->happy_mode = dolphin->state->data.flags & DolphinFlagHappyMode;
} else if(event.type == DolphinEventTypeSettingsSet) {
dolphin->state->data.flags &= ~DolphinFlagHappyMode;
if(event.settings->happy_mode) dolphin->state->data.flags |= DolphinFlagHappyMode;
dolphin->state->dirty = true;
dolphin_state_save(dolphin->state);
} else {
furi_crash();
}

View File

@@ -21,6 +21,10 @@ typedef struct {
bool level_up_is_pending;
} DolphinStats;
typedef struct {
bool happy_mode;
} DolphinSettings;
typedef enum {
DolphinPubsubEventUpdate,
} DolphinPubsubEvent;
@@ -31,6 +35,10 @@ typedef enum {
*/
void dolphin_deed(DolphinDeed deed);
void dolphin_get_settings(Dolphin* dolphin, DolphinSettings* settings);
void dolphin_set_settings(Dolphin* dolphin, DolphinSettings* settings);
/** Retrieve dolphin stats
* Thread safe, blocking
*/

View File

@@ -13,6 +13,8 @@ typedef enum {
DolphinEventTypeFlush,
DolphinEventTypeLevel,
DolphinEventTypeReloadState,
DolphinEventTypeSettingsGet,
DolphinEventTypeSettingsSet,
} DolphinEventType;
typedef struct {
@@ -21,6 +23,7 @@ typedef struct {
union {
DolphinDeed deed;
DolphinStats* stats;
DolphinSettings* settings;
};
} DolphinEvent;

View File

@@ -5,6 +5,10 @@
#include "dolphin_deed.h"
typedef enum {
DolphinFlagHappyMode = 1,
} DolphinFlags;
typedef struct DolphinState DolphinState;
typedef struct {
uint8_t icounter_daily_limit[DolphinAppMAX];