ANIM
Description
Performs linear interpolations and holds at specific milisecond periods to
animate an initial uint32_t
value. Use cases include LED vibrant
patterns and display flashes.
Design and development status
Feature-complete.
Changelog
Version |
Date* |
Author |
Comment |
---|---|---|---|
1.0.0 |
2022.9.7 |
sgermino |
Initial release. |
* Date format is Year.Month.Day.
API reference
-
ANIM_REPEAT_FOREVER
Pass this value on the
repeat
parameter ofANIM_Start()
to perpetually repeat an animation.
-
enum ANIM_Type
Specifies the animation flow to follow through
begin
,end
,delay
,phase
andduration
parameters ofANIM_Start()
.-
enumerator ANIM_Type_None
No animation / animation finished. Static value assigned.
-
enumerator ANIM_Type_Blink
Holds
vBegin
value untildelay
milliseconds passed. Then linear interpolatesvBegin
throughvEnd
inphase
milliseconds.vEnd
value is on hold until completion of the animation timeduration
also in milliseconds.
-
enumerator ANIM_Type_PingPong
Holds
vBegin
value untildelay
milliseconds passed. Then linear interpolatesvBegin
throughvEnd
inphase
milliseconds. Finally, there is a linear interpolation fromvEnd
tovBegin
through the rest of the animation timeduration
, also expressed inmilliseconds.
-
enumerator ANIM_Type_None
-
struct ANIM
The user should treat this as an opaque structure. No member should be directly accessed or modified.
-
void ANIM_Start(struct ANIM *const A, const enum ANIM_Type Type, const uint32_t VBegin, const uint32_t VEnd, const uint32_t Delay, const uint32_t Phase, const uint32_t Duration, const uint32_t Repeat)
Start to process an animation according to passed parameters.
- Parameters
Type – Animation flow to follow.
VBegin – Interpolated value initial state.
VEnd – Interpolated value end state.
Delay – Amount of milliseconds to stop at
VBegin
.Phase –
VBegin
toVEnd
period, in milliseconds.Duration – Total duration, including
Delay
andPhase
, in milliseconds. Depends on animation type, seeANIM_Type
.Repeat – Animation repeat count. For infinite repeats use
ANIM_REPEAT_FOREVER
.
-
void ANIM_TimeShift(struct ANIM *const A, const uint32_t Delta)
Used to fast-forward an animation. Repeatedly going back and forth in time may cause undefined behavior. You have been warned.
- Parameters
Delta – Amount of time to fast-forward the animation, in milliseconds.
-
void ANIM_Update(struct ANIM *const A)
Update animation state with millisecond granularity at most.
-
void ANIM_SetValue(struct ANIM *const A, const uint32_t Value)
Set a static current value. The animation type will be set to
ANIM_Type.ANIM_Type_None
. This is usually used to stop an ongoing animation.- Parameters
Value – New current, static value.
-
uint32_t ANIM_GetValue(struct ANIM *const A)
Get current value.
- Returns
Animation current value. Depends on
ANIM_Type
.
-
_Bool ANIM_Pending(struct ANIM *const A)
Get pending status. An animation is pending when its current type is other than
ANIM_Type.ANIM_Type_None
.- Returns
true
if pending,false
otherwise.