Merge remote-tracking branch 'ofw/dev' into mntm-dev

This commit is contained in:
Willy-JL
2024-09-07 16:19:32 +02:00
29 changed files with 423 additions and 84 deletions

View File

@@ -48,6 +48,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);
@@ -230,7 +250,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 =
@@ -248,6 +270,15 @@ static bool dolphin_process_event(FuriEventLoopObject* object, void* context) {
dolphin_state_load(dolphin->state);
dolphin_reset_butthurt_timer(dolphin);
} 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

@@ -6,16 +6,16 @@
#include "dolphin_deed.h"
#ifdef __cplusplus
extern "C" {
#endif
extern const uint32_t DOLPHIN_LEVELS[];
extern const size_t DOLPHIN_LEVEL_COUNT;
#define BUTTHURT_MAX 14
#define BUTTHURT_MIN 0
typedef enum {
DolphinFlagHappyMode = 1,
} DolphinFlags;
typedef struct DolphinState DolphinState;
typedef struct {
uint8_t icounter_daily_limit[DolphinAppMAX];
@@ -57,7 +57,3 @@ bool dolphin_state_is_levelup(uint32_t icounter);
void dolphin_state_increase_level(DolphinState* dolphin_state);
uint8_t dolphin_get_level(uint32_t icounter);
#ifdef __cplusplus
}
#endif