flipperzero-firmware/applications/services/gui/icon_animation.c
SG b9a766d909 [FL-2627] Flipper applications: SDK, build and debug system (#1387)
* Added support for running applications from SD card (FAPs - Flipper Application Packages)
* Added plugin_dist target for fbt to build FAPs
* All apps of type FlipperAppType.EXTERNAL and FlipperAppType.PLUGIN are built as FAPs by default
* Updated VSCode configuration for new fbt features - re-deploy stock configuration to use them
* Added debugging support for FAPs with fbt debug & VSCode
* Added public firmware API with automated versioning

Co-authored-by: hedger <hedger@users.noreply.github.com>
Co-authored-by: SG <who.just.the.doctor@gmail.com>
Co-authored-by: あく <alleteam@gmail.com>
2022-09-15 02:21:03 +09:00

90 lines
2.5 KiB
C

#include "icon_animation_i.h"
#include "icon_i.h"
#include <furi.h>
IconAnimation* icon_animation_alloc(const Icon* icon) {
furi_assert(icon);
IconAnimation* instance = malloc(sizeof(IconAnimation));
instance->icon = icon;
instance->timer =
furi_timer_alloc(icon_animation_timer_callback, FuriTimerTypePeriodic, instance);
return instance;
}
void icon_animation_free(IconAnimation* instance) {
furi_assert(instance);
icon_animation_stop(instance);
while(xTimerIsTimerActive(instance->timer) == pdTRUE) furi_delay_tick(1);
furi_timer_free(instance->timer);
free(instance);
}
void icon_animation_set_update_callback(
IconAnimation* instance,
IconAnimationCallback callback,
void* context) {
furi_assert(instance);
instance->callback = callback;
instance->callback_context = context;
}
const uint8_t* icon_animation_get_data(IconAnimation* instance) {
return instance->icon->frames[instance->frame];
}
void icon_animation_next_frame(IconAnimation* instance) {
furi_assert(instance);
instance->frame = (instance->frame + 1) % instance->icon->frame_count;
}
void icon_animation_timer_callback(void* context) {
furi_assert(context);
IconAnimation* instance = context;
if(!instance->animating) return;
icon_animation_next_frame(instance);
if(instance->callback) {
instance->callback(instance, instance->callback_context);
}
}
uint8_t icon_animation_get_width(IconAnimation* instance) {
furi_assert(instance);
return instance->icon->width;
}
uint8_t icon_animation_get_height(IconAnimation* instance) {
furi_assert(instance);
return instance->icon->height;
}
void icon_animation_start(IconAnimation* instance) {
furi_assert(instance);
if(!instance->animating) {
instance->animating = true;
furi_assert(instance->icon->frame_rate);
furi_check(
xTimerChangePeriod(
instance->timer,
(furi_kernel_get_tick_frequency() / instance->icon->frame_rate),
portMAX_DELAY) == pdPASS);
}
}
void icon_animation_stop(IconAnimation* instance) {
furi_assert(instance);
if(instance->animating) {
instance->animating = false;
furi_check(xTimerStop(instance->timer, portMAX_DELAY) == pdPASS);
instance->frame = 0;
}
}
bool icon_animation_is_last_frame(IconAnimation* instance) {
furi_assert(instance);
return instance->icon->frame_count - instance->frame <= 1;
}