2020-12-18 23:15:29 +03:00
|
|
|
#include "dolphin_i.h"
|
2024-07-02 15:09:50 +03:00
|
|
|
|
[FL-2183] [FL-2209] Dolphin Deeds, Level up, assets generation, refactoring (#965)
* Desktop: cleanup headers
* Get loader pubsub via record
* [FL-2183] Dolphin refactoring 2022.01
* Restruct animations assets structure
* Rename assets
* Cleanup headers
* Update Recording animation
* Add BadBattery animation
* Provide loader's pubsub via record
* Fix load/unload animations
* Scripts: add flipper format support, initial dolphin packager rework. Assets: internal and external dolphin.
* Sync internal meta.txt and manifest.txt
* Reorder, rename dolphin assets
* Split essential generated assets
* Add ReadMe for dolphin assets
* Separate essential blocking animations
* Scripts: full dolphin validation before packaging
* Assets, Scripts: dolphin external resources packer
* Github: update codeowners
* Scripts: proper slots handling in dolphin animation meta
* Scripts: correct frames enumeration and fix compiled assets.
* [FL-2209] Add Dolphin Deeds points and many more
* Remove excess frame_rate
* Change dolphin assets directory
* Scripts: add internal resource support to dolphin compiler
* Scripts: add internal assets generation, renaming
* Scripts: correct assert, renaming
* Code cleanup, documentation, fixes
* Update Levelup animations
* Rename essential -> blocking
* Fix Unlocked hint
* Scripts: rewrite Templite compiller, replace regexps with token parser, split block types into code and variable blocks. Update dolphin templates.
* Documentation: add key combos description and use information
* Scripts: cleanup templit, more debug info and add dev comment
Co-authored-by: あく <alleteam@gmail.com>
2022-01-29 12:20:41 +03:00
|
|
|
#include <furi_hal.h>
|
2021-03-25 20:48:58 +03:00
|
|
|
|
[FL-2183] [FL-2209] Dolphin Deeds, Level up, assets generation, refactoring (#965)
* Desktop: cleanup headers
* Get loader pubsub via record
* [FL-2183] Dolphin refactoring 2022.01
* Restruct animations assets structure
* Rename assets
* Cleanup headers
* Update Recording animation
* Add BadBattery animation
* Provide loader's pubsub via record
* Fix load/unload animations
* Scripts: add flipper format support, initial dolphin packager rework. Assets: internal and external dolphin.
* Sync internal meta.txt and manifest.txt
* Reorder, rename dolphin assets
* Split essential generated assets
* Add ReadMe for dolphin assets
* Separate essential blocking animations
* Scripts: full dolphin validation before packaging
* Assets, Scripts: dolphin external resources packer
* Github: update codeowners
* Scripts: proper slots handling in dolphin animation meta
* Scripts: correct frames enumeration and fix compiled assets.
* [FL-2209] Add Dolphin Deeds points and many more
* Remove excess frame_rate
* Change dolphin assets directory
* Scripts: add internal resource support to dolphin compiler
* Scripts: add internal assets generation, renaming
* Scripts: correct assert, renaming
* Code cleanup, documentation, fixes
* Update Levelup animations
* Rename essential -> blocking
* Fix Unlocked hint
* Scripts: rewrite Templite compiller, replace regexps with token parser, split block types into code and variable blocks. Update dolphin templates.
* Documentation: add key combos description and use information
* Scripts: cleanup templit, more debug info and add dev comment
Co-authored-by: あく <alleteam@gmail.com>
2022-01-29 12:20:41 +03:00
|
|
|
#define TAG "Dolphin"
|
|
|
|
|
2024-07-02 15:09:50 +03:00
|
|
|
#define DOLPHIN_LOCK_EVENT_FLAG (0x1)
|
2024-07-15 20:02:45 +03:00
|
|
|
#define EVENT_QUEUE_SIZE (8)
|
2024-07-02 15:09:50 +03:00
|
|
|
|
2024-07-15 20:02:45 +03:00
|
|
|
#define SECONDS_IN_TICKS(x) ((x) * 1000UL)
|
|
|
|
#define MINUTES_IN_TICKS(x) (SECONDS_IN_TICKS(x) * 60UL)
|
|
|
|
#define HOURS_IN_TICKS(x) (MINUTES_IN_TICKS(x) * 60UL)
|
2024-07-02 15:09:50 +03:00
|
|
|
#define DATE_IN_TICKS(h, m, s) (HOURS_IN_TICKS(h) + MINUTES_IN_TICKS(m) + SECONDS_IN_TICKS(s))
|
|
|
|
|
|
|
|
#define FLUSH_TIMEOUT_TICKS (SECONDS_IN_TICKS(30UL))
|
|
|
|
|
|
|
|
#ifndef DOLPHIN_DEBUG
|
2024-07-15 20:02:45 +03:00
|
|
|
#define BUTTHURT_INCREASE_PERIOD_TICKS (HOURS_IN_TICKS(48UL))
|
|
|
|
#define CLEAR_LIMITS_PERIOD_TICKS (HOURS_IN_TICKS(24UL))
|
2024-07-02 15:09:50 +03:00
|
|
|
#define CLEAR_LIMITS_UPDATE_PERIOD_TICKS (HOURS_IN_TICKS(1UL))
|
|
|
|
#else
|
2024-07-15 20:02:45 +03:00
|
|
|
#define BUTTHURT_INCREASE_PERIOD_TICKS (SECONDS_IN_TICKS(30UL))
|
|
|
|
#define CLEAR_LIMITS_PERIOD_TICKS (MINUTES_IN_TICKS(1))
|
2024-07-02 15:09:50 +03:00
|
|
|
#define CLEAR_LIMITS_UPDATE_PERIOD_TICKS (SECONDS_IN_TICKS(5UL))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define CLEAR_LIMITS_UPDATE_THRESHOLD_TICKS (MINUTES_IN_TICKS(5UL))
|
|
|
|
|
|
|
|
#define CLEAR_LIMITS_TIME_HOURS (5UL)
|
|
|
|
#define CLEAR_LIMITS_TIME_TICKS (HOURS_IN_TICKS(CLEAR_LIMITS_TIME_HOURS))
|
|
|
|
|
|
|
|
static void dolphin_event_send_async(Dolphin* dolphin, DolphinEvent* event);
|
|
|
|
static void dolphin_event_send_wait(Dolphin* dolphin, DolphinEvent* event);
|
|
|
|
|
|
|
|
// Public API
|
[FL-2183] [FL-2209] Dolphin Deeds, Level up, assets generation, refactoring (#965)
* Desktop: cleanup headers
* Get loader pubsub via record
* [FL-2183] Dolphin refactoring 2022.01
* Restruct animations assets structure
* Rename assets
* Cleanup headers
* Update Recording animation
* Add BadBattery animation
* Provide loader's pubsub via record
* Fix load/unload animations
* Scripts: add flipper format support, initial dolphin packager rework. Assets: internal and external dolphin.
* Sync internal meta.txt and manifest.txt
* Reorder, rename dolphin assets
* Split essential generated assets
* Add ReadMe for dolphin assets
* Separate essential blocking animations
* Scripts: full dolphin validation before packaging
* Assets, Scripts: dolphin external resources packer
* Github: update codeowners
* Scripts: proper slots handling in dolphin animation meta
* Scripts: correct frames enumeration and fix compiled assets.
* [FL-2209] Add Dolphin Deeds points and many more
* Remove excess frame_rate
* Change dolphin assets directory
* Scripts: add internal resource support to dolphin compiler
* Scripts: add internal assets generation, renaming
* Scripts: correct assert, renaming
* Code cleanup, documentation, fixes
* Update Levelup animations
* Rename essential -> blocking
* Fix Unlocked hint
* Scripts: rewrite Templite compiller, replace regexps with token parser, split block types into code and variable blocks. Update dolphin templates.
* Documentation: add key combos description and use information
* Scripts: cleanup templit, more debug info and add dev comment
Co-authored-by: あく <alleteam@gmail.com>
2022-01-29 12:20:41 +03:00
|
|
|
|
2023-06-09 14:02:47 +03:00
|
|
|
void dolphin_deed(DolphinDeed deed) {
|
2024-07-02 15:09:50 +03:00
|
|
|
Dolphin* dolphin = furi_record_open(RECORD_DOLPHIN);
|
|
|
|
|
2021-09-28 12:40:39 +03:00
|
|
|
DolphinEvent event;
|
|
|
|
event.type = DolphinEventTypeDeed;
|
|
|
|
event.deed = deed;
|
2024-07-02 15:09:50 +03:00
|
|
|
|
2021-09-30 22:50:58 +03:00
|
|
|
dolphin_event_send_async(dolphin, &event);
|
2024-07-02 15:09:50 +03:00
|
|
|
|
2023-06-09 14:02:47 +03:00
|
|
|
furi_record_close(RECORD_DOLPHIN);
|
2021-03-25 20:48:58 +03:00
|
|
|
}
|
|
|
|
|
2021-09-30 22:50:58 +03:00
|
|
|
DolphinStats dolphin_stats(Dolphin* dolphin) {
|
2024-03-19 17:43:52 +03:00
|
|
|
furi_check(dolphin);
|
2021-09-30 22:50:58 +03:00
|
|
|
|
|
|
|
DolphinStats stats;
|
|
|
|
DolphinEvent event;
|
|
|
|
|
|
|
|
event.type = DolphinEventTypeStats;
|
|
|
|
event.stats = &stats;
|
|
|
|
|
|
|
|
dolphin_event_send_wait(dolphin, &event);
|
2021-05-05 12:50:03 +03:00
|
|
|
|
2021-09-28 12:40:39 +03:00
|
|
|
return stats;
|
2021-04-19 19:30:25 +03:00
|
|
|
}
|
|
|
|
|
2021-09-30 22:50:58 +03:00
|
|
|
void dolphin_flush(Dolphin* dolphin) {
|
2024-03-19 17:43:52 +03:00
|
|
|
furi_check(dolphin);
|
2021-09-30 22:50:58 +03:00
|
|
|
|
|
|
|
DolphinEvent event;
|
|
|
|
event.type = DolphinEventTypeFlush;
|
|
|
|
|
|
|
|
dolphin_event_send_wait(dolphin, &event);
|
|
|
|
}
|
|
|
|
|
2024-07-02 15:09:50 +03:00
|
|
|
void dolphin_upgrade_level(Dolphin* dolphin) {
|
|
|
|
furi_check(dolphin);
|
[FL-2183] [FL-2209] Dolphin Deeds, Level up, assets generation, refactoring (#965)
* Desktop: cleanup headers
* Get loader pubsub via record
* [FL-2183] Dolphin refactoring 2022.01
* Restruct animations assets structure
* Rename assets
* Cleanup headers
* Update Recording animation
* Add BadBattery animation
* Provide loader's pubsub via record
* Fix load/unload animations
* Scripts: add flipper format support, initial dolphin packager rework. Assets: internal and external dolphin.
* Sync internal meta.txt and manifest.txt
* Reorder, rename dolphin assets
* Split essential generated assets
* Add ReadMe for dolphin assets
* Separate essential blocking animations
* Scripts: full dolphin validation before packaging
* Assets, Scripts: dolphin external resources packer
* Github: update codeowners
* Scripts: proper slots handling in dolphin animation meta
* Scripts: correct frames enumeration and fix compiled assets.
* [FL-2209] Add Dolphin Deeds points and many more
* Remove excess frame_rate
* Change dolphin assets directory
* Scripts: add internal resource support to dolphin compiler
* Scripts: add internal assets generation, renaming
* Scripts: correct assert, renaming
* Code cleanup, documentation, fixes
* Update Levelup animations
* Rename essential -> blocking
* Fix Unlocked hint
* Scripts: rewrite Templite compiller, replace regexps with token parser, split block types into code and variable blocks. Update dolphin templates.
* Documentation: add key combos description and use information
* Scripts: cleanup templit, more debug info and add dev comment
Co-authored-by: あく <alleteam@gmail.com>
2022-01-29 12:20:41 +03:00
|
|
|
|
|
|
|
DolphinEvent event;
|
2024-07-02 15:09:50 +03:00
|
|
|
event.type = DolphinEventTypeLevel;
|
|
|
|
|
[FL-2183] [FL-2209] Dolphin Deeds, Level up, assets generation, refactoring (#965)
* Desktop: cleanup headers
* Get loader pubsub via record
* [FL-2183] Dolphin refactoring 2022.01
* Restruct animations assets structure
* Rename assets
* Cleanup headers
* Update Recording animation
* Add BadBattery animation
* Provide loader's pubsub via record
* Fix load/unload animations
* Scripts: add flipper format support, initial dolphin packager rework. Assets: internal and external dolphin.
* Sync internal meta.txt and manifest.txt
* Reorder, rename dolphin assets
* Split essential generated assets
* Add ReadMe for dolphin assets
* Separate essential blocking animations
* Scripts: full dolphin validation before packaging
* Assets, Scripts: dolphin external resources packer
* Github: update codeowners
* Scripts: proper slots handling in dolphin animation meta
* Scripts: correct frames enumeration and fix compiled assets.
* [FL-2209] Add Dolphin Deeds points and many more
* Remove excess frame_rate
* Change dolphin assets directory
* Scripts: add internal resource support to dolphin compiler
* Scripts: add internal assets generation, renaming
* Scripts: correct assert, renaming
* Code cleanup, documentation, fixes
* Update Levelup animations
* Rename essential -> blocking
* Fix Unlocked hint
* Scripts: rewrite Templite compiller, replace regexps with token parser, split block types into code and variable blocks. Update dolphin templates.
* Documentation: add key combos description and use information
* Scripts: cleanup templit, more debug info and add dev comment
Co-authored-by: あく <alleteam@gmail.com>
2022-01-29 12:20:41 +03:00
|
|
|
dolphin_event_send_async(dolphin, &event);
|
|
|
|
}
|
|
|
|
|
2024-07-02 15:09:50 +03:00
|
|
|
FuriPubSub* dolphin_get_pubsub(Dolphin* dolphin) {
|
|
|
|
furi_check(dolphin);
|
|
|
|
return dolphin->pubsub;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Private functions
|
|
|
|
|
|
|
|
static void dolphin_butthurt_timer_callback(void* context) {
|
2023-11-01 10:24:11 +03:00
|
|
|
Dolphin* dolphin = context;
|
[FL-2183] [FL-2209] Dolphin Deeds, Level up, assets generation, refactoring (#965)
* Desktop: cleanup headers
* Get loader pubsub via record
* [FL-2183] Dolphin refactoring 2022.01
* Restruct animations assets structure
* Rename assets
* Cleanup headers
* Update Recording animation
* Add BadBattery animation
* Provide loader's pubsub via record
* Fix load/unload animations
* Scripts: add flipper format support, initial dolphin packager rework. Assets: internal and external dolphin.
* Sync internal meta.txt and manifest.txt
* Reorder, rename dolphin assets
* Split essential generated assets
* Add ReadMe for dolphin assets
* Separate essential blocking animations
* Scripts: full dolphin validation before packaging
* Assets, Scripts: dolphin external resources packer
* Github: update codeowners
* Scripts: proper slots handling in dolphin animation meta
* Scripts: correct frames enumeration and fix compiled assets.
* [FL-2209] Add Dolphin Deeds points and many more
* Remove excess frame_rate
* Change dolphin assets directory
* Scripts: add internal resource support to dolphin compiler
* Scripts: add internal assets generation, renaming
* Scripts: correct assert, renaming
* Code cleanup, documentation, fixes
* Update Levelup animations
* Rename essential -> blocking
* Fix Unlocked hint
* Scripts: rewrite Templite compiller, replace regexps with token parser, split block types into code and variable blocks. Update dolphin templates.
* Documentation: add key combos description and use information
* Scripts: cleanup templit, more debug info and add dev comment
Co-authored-by: あく <alleteam@gmail.com>
2022-01-29 12:20:41 +03:00
|
|
|
furi_assert(dolphin);
|
|
|
|
|
2024-07-02 15:09:50 +03:00
|
|
|
FURI_LOG_I(TAG, "Increase butthurt");
|
|
|
|
dolphin_state_butthurted(dolphin->state);
|
|
|
|
dolphin_state_save(dolphin->state);
|
[FL-2183] [FL-2209] Dolphin Deeds, Level up, assets generation, refactoring (#965)
* Desktop: cleanup headers
* Get loader pubsub via record
* [FL-2183] Dolphin refactoring 2022.01
* Restruct animations assets structure
* Rename assets
* Cleanup headers
* Update Recording animation
* Add BadBattery animation
* Provide loader's pubsub via record
* Fix load/unload animations
* Scripts: add flipper format support, initial dolphin packager rework. Assets: internal and external dolphin.
* Sync internal meta.txt and manifest.txt
* Reorder, rename dolphin assets
* Split essential generated assets
* Add ReadMe for dolphin assets
* Separate essential blocking animations
* Scripts: full dolphin validation before packaging
* Assets, Scripts: dolphin external resources packer
* Github: update codeowners
* Scripts: proper slots handling in dolphin animation meta
* Scripts: correct frames enumeration and fix compiled assets.
* [FL-2209] Add Dolphin Deeds points and many more
* Remove excess frame_rate
* Change dolphin assets directory
* Scripts: add internal resource support to dolphin compiler
* Scripts: add internal assets generation, renaming
* Scripts: correct assert, renaming
* Code cleanup, documentation, fixes
* Update Levelup animations
* Rename essential -> blocking
* Fix Unlocked hint
* Scripts: rewrite Templite compiller, replace regexps with token parser, split block types into code and variable blocks. Update dolphin templates.
* Documentation: add key combos description and use information
* Scripts: cleanup templit, more debug info and add dev comment
Co-authored-by: あく <alleteam@gmail.com>
2022-01-29 12:20:41 +03:00
|
|
|
}
|
|
|
|
|
2024-07-02 15:09:50 +03:00
|
|
|
static void dolphin_flush_timer_callback(void* context) {
|
2023-11-01 10:24:11 +03:00
|
|
|
Dolphin* dolphin = context;
|
[FL-2183] [FL-2209] Dolphin Deeds, Level up, assets generation, refactoring (#965)
* Desktop: cleanup headers
* Get loader pubsub via record
* [FL-2183] Dolphin refactoring 2022.01
* Restruct animations assets structure
* Rename assets
* Cleanup headers
* Update Recording animation
* Add BadBattery animation
* Provide loader's pubsub via record
* Fix load/unload animations
* Scripts: add flipper format support, initial dolphin packager rework. Assets: internal and external dolphin.
* Sync internal meta.txt and manifest.txt
* Reorder, rename dolphin assets
* Split essential generated assets
* Add ReadMe for dolphin assets
* Separate essential blocking animations
* Scripts: full dolphin validation before packaging
* Assets, Scripts: dolphin external resources packer
* Github: update codeowners
* Scripts: proper slots handling in dolphin animation meta
* Scripts: correct frames enumeration and fix compiled assets.
* [FL-2209] Add Dolphin Deeds points and many more
* Remove excess frame_rate
* Change dolphin assets directory
* Scripts: add internal resource support to dolphin compiler
* Scripts: add internal assets generation, renaming
* Scripts: correct assert, renaming
* Code cleanup, documentation, fixes
* Update Levelup animations
* Rename essential -> blocking
* Fix Unlocked hint
* Scripts: rewrite Templite compiller, replace regexps with token parser, split block types into code and variable blocks. Update dolphin templates.
* Documentation: add key combos description and use information
* Scripts: cleanup templit, more debug info and add dev comment
Co-authored-by: あく <alleteam@gmail.com>
2022-01-29 12:20:41 +03:00
|
|
|
furi_assert(dolphin);
|
|
|
|
|
2024-07-02 15:09:50 +03:00
|
|
|
FURI_LOG_I(TAG, "Flush stats");
|
|
|
|
dolphin_state_save(dolphin->state);
|
|
|
|
}
|
[FL-2183] [FL-2209] Dolphin Deeds, Level up, assets generation, refactoring (#965)
* Desktop: cleanup headers
* Get loader pubsub via record
* [FL-2183] Dolphin refactoring 2022.01
* Restruct animations assets structure
* Rename assets
* Cleanup headers
* Update Recording animation
* Add BadBattery animation
* Provide loader's pubsub via record
* Fix load/unload animations
* Scripts: add flipper format support, initial dolphin packager rework. Assets: internal and external dolphin.
* Sync internal meta.txt and manifest.txt
* Reorder, rename dolphin assets
* Split essential generated assets
* Add ReadMe for dolphin assets
* Separate essential blocking animations
* Scripts: full dolphin validation before packaging
* Assets, Scripts: dolphin external resources packer
* Github: update codeowners
* Scripts: proper slots handling in dolphin animation meta
* Scripts: correct frames enumeration and fix compiled assets.
* [FL-2209] Add Dolphin Deeds points and many more
* Remove excess frame_rate
* Change dolphin assets directory
* Scripts: add internal resource support to dolphin compiler
* Scripts: add internal assets generation, renaming
* Scripts: correct assert, renaming
* Code cleanup, documentation, fixes
* Update Levelup animations
* Rename essential -> blocking
* Fix Unlocked hint
* Scripts: rewrite Templite compiller, replace regexps with token parser, split block types into code and variable blocks. Update dolphin templates.
* Documentation: add key combos description and use information
* Scripts: cleanup templit, more debug info and add dev comment
Co-authored-by: あく <alleteam@gmail.com>
2022-01-29 12:20:41 +03:00
|
|
|
|
2024-07-02 15:09:50 +03:00
|
|
|
static void dolphin_clear_limits_timer_callback(void* context) {
|
|
|
|
Dolphin* dolphin = context;
|
|
|
|
furi_assert(dolphin);
|
|
|
|
|
|
|
|
FURI_LOG_I(TAG, "Clear limits");
|
|
|
|
dolphin_state_clear_limits(dolphin->state);
|
|
|
|
dolphin_state_save(dolphin->state);
|
[FL-2183] [FL-2209] Dolphin Deeds, Level up, assets generation, refactoring (#965)
* Desktop: cleanup headers
* Get loader pubsub via record
* [FL-2183] Dolphin refactoring 2022.01
* Restruct animations assets structure
* Rename assets
* Cleanup headers
* Update Recording animation
* Add BadBattery animation
* Provide loader's pubsub via record
* Fix load/unload animations
* Scripts: add flipper format support, initial dolphin packager rework. Assets: internal and external dolphin.
* Sync internal meta.txt and manifest.txt
* Reorder, rename dolphin assets
* Split essential generated assets
* Add ReadMe for dolphin assets
* Separate essential blocking animations
* Scripts: full dolphin validation before packaging
* Assets, Scripts: dolphin external resources packer
* Github: update codeowners
* Scripts: proper slots handling in dolphin animation meta
* Scripts: correct frames enumeration and fix compiled assets.
* [FL-2209] Add Dolphin Deeds points and many more
* Remove excess frame_rate
* Change dolphin assets directory
* Scripts: add internal resource support to dolphin compiler
* Scripts: add internal assets generation, renaming
* Scripts: correct assert, renaming
* Code cleanup, documentation, fixes
* Update Levelup animations
* Rename essential -> blocking
* Fix Unlocked hint
* Scripts: rewrite Templite compiller, replace regexps with token parser, split block types into code and variable blocks. Update dolphin templates.
* Documentation: add key combos description and use information
* Scripts: cleanup templit, more debug info and add dev comment
Co-authored-by: あく <alleteam@gmail.com>
2022-01-29 12:20:41 +03:00
|
|
|
}
|
|
|
|
|
2024-07-02 15:09:50 +03:00
|
|
|
static Dolphin* dolphin_alloc(void) {
|
2022-02-18 22:53:46 +03:00
|
|
|
Dolphin* dolphin = malloc(sizeof(Dolphin));
|
2021-04-13 21:06:25 +03:00
|
|
|
|
2021-09-28 12:40:39 +03:00
|
|
|
dolphin->state = dolphin_state_alloc();
|
2021-11-24 19:21:12 +03:00
|
|
|
dolphin->pubsub = furi_pubsub_alloc();
|
2024-07-02 15:09:50 +03:00
|
|
|
dolphin->event_queue = furi_message_queue_alloc(EVENT_QUEUE_SIZE, sizeof(DolphinEvent));
|
|
|
|
dolphin->event_loop = furi_event_loop_alloc();
|
|
|
|
|
|
|
|
dolphin->butthurt_timer = furi_event_loop_timer_alloc(
|
|
|
|
dolphin->event_loop,
|
|
|
|
dolphin_butthurt_timer_callback,
|
|
|
|
FuriEventLoopTimerTypePeriodic,
|
|
|
|
dolphin);
|
|
|
|
|
|
|
|
dolphin->flush_timer = furi_event_loop_timer_alloc(
|
|
|
|
dolphin->event_loop, dolphin_flush_timer_callback, FuriEventLoopTimerTypeOnce, dolphin);
|
|
|
|
|
|
|
|
dolphin->clear_limits_timer = furi_event_loop_timer_alloc(
|
|
|
|
dolphin->event_loop,
|
|
|
|
dolphin_clear_limits_timer_callback,
|
|
|
|
FuriEventLoopTimerTypePeriodic,
|
|
|
|
dolphin);
|
2021-04-13 21:06:25 +03:00
|
|
|
|
2020-12-18 23:15:29 +03:00
|
|
|
return dolphin;
|
|
|
|
}
|
|
|
|
|
2024-07-02 15:09:50 +03:00
|
|
|
static void dolphin_event_send_async(Dolphin* dolphin, DolphinEvent* event) {
|
2021-09-30 22:50:58 +03:00
|
|
|
furi_assert(dolphin);
|
|
|
|
furi_assert(event);
|
|
|
|
event->flag = NULL;
|
2022-07-20 13:56:33 +03:00
|
|
|
furi_check(
|
|
|
|
furi_message_queue_put(dolphin->event_queue, event, FuriWaitForever) == FuriStatusOk);
|
2021-09-30 22:50:58 +03:00
|
|
|
}
|
|
|
|
|
2024-07-02 15:09:50 +03:00
|
|
|
static void dolphin_event_send_wait(Dolphin* dolphin, DolphinEvent* event) {
|
2021-09-30 22:50:58 +03:00
|
|
|
furi_assert(dolphin);
|
|
|
|
furi_assert(event);
|
2024-06-10 20:04:29 +03:00
|
|
|
|
2022-07-20 13:56:33 +03:00
|
|
|
event->flag = furi_event_flag_alloc();
|
2021-09-30 22:50:58 +03:00
|
|
|
furi_check(
|
2022-07-20 13:56:33 +03:00
|
|
|
furi_message_queue_put(dolphin->event_queue, event, FuriWaitForever) == FuriStatusOk);
|
|
|
|
furi_check(
|
|
|
|
furi_event_flag_wait(
|
|
|
|
event->flag, DOLPHIN_LOCK_EVENT_FLAG, FuriFlagWaitAny, FuriWaitForever) ==
|
2021-09-30 22:50:58 +03:00
|
|
|
DOLPHIN_LOCK_EVENT_FLAG);
|
2022-07-20 13:56:33 +03:00
|
|
|
furi_event_flag_free(event->flag);
|
2021-09-30 22:50:58 +03:00
|
|
|
}
|
|
|
|
|
2024-07-02 15:09:50 +03:00
|
|
|
static void dolphin_event_release(DolphinEvent* event) {
|
2021-09-30 22:50:58 +03:00
|
|
|
if(event->flag) {
|
2022-07-20 13:56:33 +03:00
|
|
|
furi_event_flag_set(event->flag, DOLPHIN_LOCK_EVENT_FLAG);
|
2021-09-30 22:50:58 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-02 15:09:50 +03:00
|
|
|
static void dolphin_update_clear_limits_timer_period(void* context) {
|
|
|
|
furi_assert(context);
|
|
|
|
Dolphin* dolphin = context;
|
2021-11-24 19:21:12 +03:00
|
|
|
|
2024-07-02 15:09:50 +03:00
|
|
|
uint32_t time_to_clear_limits =
|
|
|
|
furi_event_loop_timer_get_remaining_time(dolphin->clear_limits_timer);
|
[FL-2183] [FL-2209] Dolphin Deeds, Level up, assets generation, refactoring (#965)
* Desktop: cleanup headers
* Get loader pubsub via record
* [FL-2183] Dolphin refactoring 2022.01
* Restruct animations assets structure
* Rename assets
* Cleanup headers
* Update Recording animation
* Add BadBattery animation
* Provide loader's pubsub via record
* Fix load/unload animations
* Scripts: add flipper format support, initial dolphin packager rework. Assets: internal and external dolphin.
* Sync internal meta.txt and manifest.txt
* Reorder, rename dolphin assets
* Split essential generated assets
* Add ReadMe for dolphin assets
* Separate essential blocking animations
* Scripts: full dolphin validation before packaging
* Assets, Scripts: dolphin external resources packer
* Github: update codeowners
* Scripts: proper slots handling in dolphin animation meta
* Scripts: correct frames enumeration and fix compiled assets.
* [FL-2209] Add Dolphin Deeds points and many more
* Remove excess frame_rate
* Change dolphin assets directory
* Scripts: add internal resource support to dolphin compiler
* Scripts: add internal assets generation, renaming
* Scripts: correct assert, renaming
* Code cleanup, documentation, fixes
* Update Levelup animations
* Rename essential -> blocking
* Fix Unlocked hint
* Scripts: rewrite Templite compiller, replace regexps with token parser, split block types into code and variable blocks. Update dolphin templates.
* Documentation: add key combos description and use information
* Scripts: cleanup templit, more debug info and add dev comment
Co-authored-by: あく <alleteam@gmail.com>
2022-01-29 12:20:41 +03:00
|
|
|
|
2024-07-02 15:09:50 +03:00
|
|
|
if(time_to_clear_limits > CLEAR_LIMITS_UPDATE_THRESHOLD_TICKS) {
|
2024-02-15 06:44:41 +03:00
|
|
|
DateTime date;
|
[FL-2183] [FL-2209] Dolphin Deeds, Level up, assets generation, refactoring (#965)
* Desktop: cleanup headers
* Get loader pubsub via record
* [FL-2183] Dolphin refactoring 2022.01
* Restruct animations assets structure
* Rename assets
* Cleanup headers
* Update Recording animation
* Add BadBattery animation
* Provide loader's pubsub via record
* Fix load/unload animations
* Scripts: add flipper format support, initial dolphin packager rework. Assets: internal and external dolphin.
* Sync internal meta.txt and manifest.txt
* Reorder, rename dolphin assets
* Split essential generated assets
* Add ReadMe for dolphin assets
* Separate essential blocking animations
* Scripts: full dolphin validation before packaging
* Assets, Scripts: dolphin external resources packer
* Github: update codeowners
* Scripts: proper slots handling in dolphin animation meta
* Scripts: correct frames enumeration and fix compiled assets.
* [FL-2209] Add Dolphin Deeds points and many more
* Remove excess frame_rate
* Change dolphin assets directory
* Scripts: add internal resource support to dolphin compiler
* Scripts: add internal assets generation, renaming
* Scripts: correct assert, renaming
* Code cleanup, documentation, fixes
* Update Levelup animations
* Rename essential -> blocking
* Fix Unlocked hint
* Scripts: rewrite Templite compiller, replace regexps with token parser, split block types into code and variable blocks. Update dolphin templates.
* Documentation: add key combos description and use information
* Scripts: cleanup templit, more debug info and add dev comment
Co-authored-by: あく <alleteam@gmail.com>
2022-01-29 12:20:41 +03:00
|
|
|
furi_hal_rtc_get_datetime(&date);
|
|
|
|
|
2024-07-02 15:09:50 +03:00
|
|
|
const uint32_t now_time_ticks = DATE_IN_TICKS(date.hour, date.minute, date.second);
|
|
|
|
|
|
|
|
if(date.hour < CLEAR_LIMITS_TIME_HOURS) {
|
|
|
|
time_to_clear_limits = CLEAR_LIMITS_TIME_TICKS - now_time_ticks;
|
[FL-2183] [FL-2209] Dolphin Deeds, Level up, assets generation, refactoring (#965)
* Desktop: cleanup headers
* Get loader pubsub via record
* [FL-2183] Dolphin refactoring 2022.01
* Restruct animations assets structure
* Rename assets
* Cleanup headers
* Update Recording animation
* Add BadBattery animation
* Provide loader's pubsub via record
* Fix load/unload animations
* Scripts: add flipper format support, initial dolphin packager rework. Assets: internal and external dolphin.
* Sync internal meta.txt and manifest.txt
* Reorder, rename dolphin assets
* Split essential generated assets
* Add ReadMe for dolphin assets
* Separate essential blocking animations
* Scripts: full dolphin validation before packaging
* Assets, Scripts: dolphin external resources packer
* Github: update codeowners
* Scripts: proper slots handling in dolphin animation meta
* Scripts: correct frames enumeration and fix compiled assets.
* [FL-2209] Add Dolphin Deeds points and many more
* Remove excess frame_rate
* Change dolphin assets directory
* Scripts: add internal resource support to dolphin compiler
* Scripts: add internal assets generation, renaming
* Scripts: correct assert, renaming
* Code cleanup, documentation, fixes
* Update Levelup animations
* Rename essential -> blocking
* Fix Unlocked hint
* Scripts: rewrite Templite compiller, replace regexps with token parser, split block types into code and variable blocks. Update dolphin templates.
* Documentation: add key combos description and use information
* Scripts: cleanup templit, more debug info and add dev comment
Co-authored-by: あく <alleteam@gmail.com>
2022-01-29 12:20:41 +03:00
|
|
|
} else {
|
2024-07-02 15:09:50 +03:00
|
|
|
time_to_clear_limits =
|
|
|
|
CLEAR_LIMITS_PERIOD_TICKS + CLEAR_LIMITS_TIME_TICKS - now_time_ticks;
|
[FL-2183] [FL-2209] Dolphin Deeds, Level up, assets generation, refactoring (#965)
* Desktop: cleanup headers
* Get loader pubsub via record
* [FL-2183] Dolphin refactoring 2022.01
* Restruct animations assets structure
* Rename assets
* Cleanup headers
* Update Recording animation
* Add BadBattery animation
* Provide loader's pubsub via record
* Fix load/unload animations
* Scripts: add flipper format support, initial dolphin packager rework. Assets: internal and external dolphin.
* Sync internal meta.txt and manifest.txt
* Reorder, rename dolphin assets
* Split essential generated assets
* Add ReadMe for dolphin assets
* Separate essential blocking animations
* Scripts: full dolphin validation before packaging
* Assets, Scripts: dolphin external resources packer
* Github: update codeowners
* Scripts: proper slots handling in dolphin animation meta
* Scripts: correct frames enumeration and fix compiled assets.
* [FL-2209] Add Dolphin Deeds points and many more
* Remove excess frame_rate
* Change dolphin assets directory
* Scripts: add internal resource support to dolphin compiler
* Scripts: add internal assets generation, renaming
* Scripts: correct assert, renaming
* Code cleanup, documentation, fixes
* Update Levelup animations
* Rename essential -> blocking
* Fix Unlocked hint
* Scripts: rewrite Templite compiller, replace regexps with token parser, split block types into code and variable blocks. Update dolphin templates.
* Documentation: add key combos description and use information
* Scripts: cleanup templit, more debug info and add dev comment
Co-authored-by: あく <alleteam@gmail.com>
2022-01-29 12:20:41 +03:00
|
|
|
}
|
|
|
|
|
2024-07-02 15:09:50 +03:00
|
|
|
furi_event_loop_timer_start(dolphin->clear_limits_timer, time_to_clear_limits);
|
[FL-2183] [FL-2209] Dolphin Deeds, Level up, assets generation, refactoring (#965)
* Desktop: cleanup headers
* Get loader pubsub via record
* [FL-2183] Dolphin refactoring 2022.01
* Restruct animations assets structure
* Rename assets
* Cleanup headers
* Update Recording animation
* Add BadBattery animation
* Provide loader's pubsub via record
* Fix load/unload animations
* Scripts: add flipper format support, initial dolphin packager rework. Assets: internal and external dolphin.
* Sync internal meta.txt and manifest.txt
* Reorder, rename dolphin assets
* Split essential generated assets
* Add ReadMe for dolphin assets
* Separate essential blocking animations
* Scripts: full dolphin validation before packaging
* Assets, Scripts: dolphin external resources packer
* Github: update codeowners
* Scripts: proper slots handling in dolphin animation meta
* Scripts: correct frames enumeration and fix compiled assets.
* [FL-2209] Add Dolphin Deeds points and many more
* Remove excess frame_rate
* Change dolphin assets directory
* Scripts: add internal resource support to dolphin compiler
* Scripts: add internal assets generation, renaming
* Scripts: correct assert, renaming
* Code cleanup, documentation, fixes
* Update Levelup animations
* Rename essential -> blocking
* Fix Unlocked hint
* Scripts: rewrite Templite compiller, replace regexps with token parser, split block types into code and variable blocks. Update dolphin templates.
* Documentation: add key combos description and use information
* Scripts: cleanup templit, more debug info and add dev comment
Co-authored-by: あく <alleteam@gmail.com>
2022-01-29 12:20:41 +03:00
|
|
|
}
|
2024-07-02 15:09:50 +03:00
|
|
|
|
|
|
|
FURI_LOG_D(TAG, "Daily limits reset in %lu ms", time_to_clear_limits);
|
[FL-2183] [FL-2209] Dolphin Deeds, Level up, assets generation, refactoring (#965)
* Desktop: cleanup headers
* Get loader pubsub via record
* [FL-2183] Dolphin refactoring 2022.01
* Restruct animations assets structure
* Rename assets
* Cleanup headers
* Update Recording animation
* Add BadBattery animation
* Provide loader's pubsub via record
* Fix load/unload animations
* Scripts: add flipper format support, initial dolphin packager rework. Assets: internal and external dolphin.
* Sync internal meta.txt and manifest.txt
* Reorder, rename dolphin assets
* Split essential generated assets
* Add ReadMe for dolphin assets
* Separate essential blocking animations
* Scripts: full dolphin validation before packaging
* Assets, Scripts: dolphin external resources packer
* Github: update codeowners
* Scripts: proper slots handling in dolphin animation meta
* Scripts: correct frames enumeration and fix compiled assets.
* [FL-2209] Add Dolphin Deeds points and many more
* Remove excess frame_rate
* Change dolphin assets directory
* Scripts: add internal resource support to dolphin compiler
* Scripts: add internal assets generation, renaming
* Scripts: correct assert, renaming
* Code cleanup, documentation, fixes
* Update Levelup animations
* Rename essential -> blocking
* Fix Unlocked hint
* Scripts: rewrite Templite compiller, replace regexps with token parser, split block types into code and variable blocks. Update dolphin templates.
* Documentation: add key combos description and use information
* Scripts: cleanup templit, more debug info and add dev comment
Co-authored-by: あく <alleteam@gmail.com>
2022-01-29 12:20:41 +03:00
|
|
|
}
|
|
|
|
|
2024-07-02 15:09:50 +03:00
|
|
|
static bool dolphin_process_event(FuriMessageQueue* queue, void* context) {
|
|
|
|
UNUSED(queue);
|
|
|
|
|
|
|
|
Dolphin* dolphin = context;
|
|
|
|
DolphinEvent event;
|
|
|
|
|
|
|
|
FuriStatus status = furi_message_queue_get(dolphin->event_queue, &event, 0);
|
|
|
|
furi_check(status == FuriStatusOk);
|
|
|
|
|
|
|
|
if(event.type == DolphinEventTypeDeed) {
|
|
|
|
dolphin_state_on_deed(dolphin->state, event.deed);
|
|
|
|
|
|
|
|
DolphinPubsubEvent event = DolphinPubsubEventUpdate;
|
|
|
|
furi_pubsub_publish(dolphin->pubsub, &event);
|
|
|
|
furi_event_loop_timer_start(dolphin->butthurt_timer, BUTTHURT_INCREASE_PERIOD_TICKS);
|
|
|
|
furi_event_loop_timer_start(dolphin->flush_timer, FLUSH_TIMEOUT_TICKS);
|
|
|
|
|
|
|
|
} else if(event.type == DolphinEventTypeStats) {
|
|
|
|
event.stats->icounter = dolphin->state->data.icounter;
|
|
|
|
event.stats->butthurt = 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 =
|
|
|
|
!dolphin_state_xp_to_levelup(dolphin->state->data.icounter);
|
|
|
|
|
|
|
|
} else if(event.type == DolphinEventTypeFlush) {
|
|
|
|
furi_event_loop_timer_start(dolphin->flush_timer, FLUSH_TIMEOUT_TICKS);
|
|
|
|
|
|
|
|
} else if(event.type == DolphinEventTypeLevel) {
|
|
|
|
dolphin_state_increase_level(dolphin->state);
|
|
|
|
furi_event_loop_timer_start(dolphin->flush_timer, FLUSH_TIMEOUT_TICKS);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
furi_crash();
|
|
|
|
}
|
|
|
|
|
|
|
|
dolphin_event_release(&event);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Application thread
|
|
|
|
|
2021-09-28 12:40:39 +03:00
|
|
|
int32_t dolphin_srv(void* p) {
|
2022-05-06 16:37:10 +03:00
|
|
|
UNUSED(p);
|
2023-02-26 18:15:26 +03:00
|
|
|
|
|
|
|
if(furi_hal_rtc_get_boot_mode() != FuriHalRtcBootModeNormal) {
|
|
|
|
FURI_LOG_W(TAG, "Skipping start in special boot mode");
|
2024-06-05 20:04:03 +03:00
|
|
|
|
|
|
|
furi_thread_suspend(furi_thread_get_current_id());
|
2023-02-26 18:15:26 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-12-18 23:15:29 +03:00
|
|
|
Dolphin* dolphin = dolphin_alloc();
|
2022-07-26 15:21:51 +03:00
|
|
|
furi_record_create(RECORD_DOLPHIN, dolphin);
|
2020-12-18 23:15:29 +03:00
|
|
|
|
2021-09-30 22:50:58 +03:00
|
|
|
dolphin_state_load(dolphin->state);
|
|
|
|
|
2024-07-02 15:09:50 +03:00
|
|
|
furi_event_loop_message_queue_subscribe(
|
|
|
|
dolphin->event_loop,
|
|
|
|
dolphin->event_queue,
|
|
|
|
FuriEventLoopEventIn,
|
|
|
|
dolphin_process_event,
|
|
|
|
dolphin);
|
2021-09-28 12:40:39 +03:00
|
|
|
|
2024-07-02 15:09:50 +03:00
|
|
|
furi_event_loop_timer_start(dolphin->butthurt_timer, BUTTHURT_INCREASE_PERIOD_TICKS);
|
|
|
|
furi_event_loop_timer_start(dolphin->clear_limits_timer, CLEAR_LIMITS_PERIOD_TICKS);
|
2021-09-30 22:50:58 +03:00
|
|
|
|
2024-07-02 15:09:50 +03:00
|
|
|
furi_event_loop_tick_set(
|
|
|
|
dolphin->event_loop,
|
|
|
|
CLEAR_LIMITS_UPDATE_PERIOD_TICKS,
|
|
|
|
dolphin_update_clear_limits_timer_period,
|
|
|
|
dolphin);
|
2021-11-24 19:21:12 +03:00
|
|
|
|
2024-07-02 15:09:50 +03:00
|
|
|
furi_event_loop_pend_callback(
|
|
|
|
dolphin->event_loop, dolphin_update_clear_limits_timer_period, dolphin);
|
2024-03-19 17:43:52 +03:00
|
|
|
|
2024-07-02 15:09:50 +03:00
|
|
|
furi_event_loop_run(dolphin->event_loop);
|
|
|
|
|
|
|
|
return 0;
|
2021-11-24 19:21:12 +03:00
|
|
|
}
|