1
- /* Copyright (C) 2015-2018 by Jacob Alexander
1
+ /* Copyright (C) 2015-2019 by Jacob Alexander
2
2
*
3
3
* This file is free software: you can redistribute it and/or modify
4
4
* it under the terms of the GNU General Public License as published by
@@ -82,21 +82,25 @@ typedef enum PixelTest {
82
82
PixelTest_XY_Roll = 33 ,
83
83
} PixelTest ;
84
84
85
+
86
+
85
87
// ----- Variables -----
86
88
87
- #if Storage_Enable_define == 1
88
89
typedef struct {
89
- uint8_t animation_indices [Pixel_AnimationStackSize ];
90
+ uint8_t index ;
91
+ uint8_t pos ;
92
+ } PixelConfigElem ;
93
+
94
+ typedef struct {
95
+ PixelConfigElem animations [Pixel_AnimationStackSize ];
90
96
PixelPeriodConfig fade_periods [4 ][4 ];
91
97
} PixelConfig ;
92
98
93
- static PixelConfig defaults = {
94
- .animation_indices = {[0 ... Pixel_AnimationStackSize - 1 ] = 255 }, //Todo, use some kll define
95
- // .fade_periods initialized later
96
- };
97
-
98
99
static PixelConfig settings ;
99
100
101
+ #if Storage_Enable_define == 1
102
+ static PixelConfig defaults ;
103
+
100
104
static StorageModule PixelStorage = {
101
105
.name = "Pixel Map" ,
102
106
.settings = & settings ,
@@ -758,6 +762,49 @@ uint8_t Pixel_addAnimation( AnimationStackElement *element, CapabilityState csta
758
762
Pixel_clearAnimations ();
759
763
break ;
760
764
765
+ // Clear all current animations from stack before adding new animation
766
+ // Unless it's paused, and if it's paused do a replace if necessary
767
+ case AnimationReplaceType_ClearActive :
768
+ found = Pixel_lookupAnimation ( element -> index , 0 );
769
+ // If found, modify stack element
770
+ if ( found )
771
+ {
772
+ found -> pos = element -> pos ;
773
+ found -> subpos = element -> subpos ;
774
+ found -> loops = element -> loops ;
775
+ found -> pfunc = element -> pfunc ;
776
+ found -> ffunc = element -> ffunc ;
777
+ found -> framedelay = element -> framedelay ;
778
+ found -> frameoption = element -> frameoption ;
779
+ found -> replace = element -> replace ;
780
+ found -> state = element -> state ;
781
+ return 0 ;
782
+ }
783
+
784
+ // Iterate through stack, stopping animations that are not paused
785
+ // and ignoring the found animation
786
+ for ( uint16_t pos = 0 ; pos < Pixel_AnimationStack .size ; pos ++ )
787
+ {
788
+ // Ignore found animation
789
+ if ( Pixel_AnimationStack .stack [pos ] == found )
790
+ {
791
+ continue ;
792
+ }
793
+
794
+ // Ignore paused animations (single will be paused on the next frame)
795
+ if (
796
+ Pixel_AnimationStack .stack [pos ]-> state == AnimationPlayState_Pause ||
797
+ Pixel_AnimationStack .stack [pos ]-> state == AnimationPlayState_Single
798
+ )
799
+ {
800
+ continue ;
801
+ }
802
+
803
+ // Otherwise stop
804
+ Pixel_AnimationStack .stack [pos ]-> state = AnimationPlayState_Stop ;
805
+ }
806
+ break ;
807
+
761
808
default :
762
809
break ;
763
810
}
@@ -2016,13 +2063,9 @@ void Pixel_SecondaryProcessing_setup()
2016
2063
// Each of the periods
2017
2064
for ( uint8_t pr = 0 ; pr < 4 ; pr ++ )
2018
2065
{
2019
- // Lookup period using index
2020
- uint8_t period_index = Pixel_LED_FadePeriod_Defaults [pf ][pr ];
2021
- PixelPeriodConfig conf = Pixel_LED_FadePeriods [period_index ];
2022
-
2023
2066
// Set period to profile
2024
- Pixel_pixel_fade_profile_entries [pf ]. conf [pr ]. start = conf . start ;
2025
- Pixel_pixel_fade_profile_entries [pf ].conf [pr ]. end = conf . end ;
2067
+ PixelPeriodConfig conf = settings . fade_periods [pf ][pr ];
2068
+ Pixel_pixel_fade_profile_entries [pf ].conf [pr ] = conf ;
2026
2069
}
2027
2070
2028
2071
// Reset state
@@ -2245,23 +2288,21 @@ void Pixel_setAnimationControl( AnimationControl control )
2245
2288
// Starting Animation setup
2246
2289
void Pixel_initializeStartAnimations ()
2247
2290
{
2248
- // Iterate over starting animations
2249
- for ( uint32_t index = 0 ; index < Pixel_AnimationSettingsNum_KLL ; index ++ )
2291
+ // Animations
2292
+ for ( uint8_t pos = 0 ; pos < Pixel_AnimationStackSize ; pos ++ )
2250
2293
{
2251
- // Check if a starting animation
2252
- if ( Pixel_AnimationSettings [ index ].state == AnimationPlayState_Start )
2253
- {
2254
- // Default animations are noted by the TriggerMacro *trigger pointer being set to 1
2255
- if ( (uintptr_t )(Pixel_AnimationSettings [ index ].trigger ) == 1 )
2294
+ uint8_t index = settings .animations [pos ].index ;
2295
+ if (index != 255 ) {
2296
+ AnimationStackElement element = Pixel_AnimationSettings [ index ];
2297
+
2298
+ // Only update state if not already defined
2299
+ if ( element .state == AnimationPlayState_Pause )
2256
2300
{
2257
- // Start animation
2258
- if ( Pixel_addDefaultAnimation ( index ) == 0 )
2259
- {
2260
- warn_msg ("Failed to start starting animation index: " );
2261
- printInt32 ( index );
2262
- print ( NL );
2263
- }
2301
+ element .state = AnimationPlayState_Start ;
2264
2302
}
2303
+
2304
+ element .pos = settings .animations [pos ].pos ;
2305
+ Pixel_addAnimation ( & element , CapabilityState_None );
2265
2306
}
2266
2307
}
2267
2308
}
@@ -2649,14 +2690,58 @@ inline void Pixel_setup()
2649
2690
// Register Pixel CLI dictionary
2650
2691
CLI_registerDictionary ( pixelCLIDict , pixelCLIDictName );
2651
2692
2652
- // Register storage module
2693
+ // Iterate over starting animations
2694
+ uint8_t add_animations = 0 ;
2695
+ for ( uint32_t index = 0 ; index < Pixel_AnimationSettingsNum_KLL ; index ++ )
2696
+ {
2697
+ // Check if a starting animation
2698
+ if ( Pixel_AnimationSettings [ index ].state == AnimationPlayState_Start )
2699
+ {
2700
+ // Default animations are noted by the TriggerMacro *trigger pointer being set to 1
2701
+ if ( (uintptr_t )(Pixel_AnimationSettings [ index ].trigger ) == 1 )
2702
+ {
2703
+ // Add animation to the defaults stack
2704
+ #if Storage_Enable_define == 1
2705
+ defaults .animations [add_animations ].index = index ;
2706
+ defaults .animations [add_animations ].pos = Pixel_AnimationSettings [index ].pos ;
2707
+ #else
2708
+ settings .animations [add_animations ].index = index ;
2709
+ settings .animations [add_animations ].pos = Pixel_AnimationSettings [index ].pos ;
2710
+ #endif
2711
+ add_animations ++ ;
2712
+ }
2713
+ }
2714
+ }
2715
+
2716
+ // Fill in rest of stack
2717
+ for ( uint8_t animation = add_animations ; animation < Pixel_AnimationStackSize ; animation ++ )
2718
+ {
2719
+ #if Storage_Enable_define == 1
2720
+ defaults .animations [animation ].index = 255 ;
2721
+ defaults .animations [animation ].pos = 0 ;
2722
+ #else
2723
+ settings .animations [animation ].index = 255 ;
2724
+ settings .animations [animation ].pos = 0 ;
2725
+ #endif
2726
+ }
2727
+
2728
+ // Setup fade defaults
2729
+ for ( uint8_t profile = 0 ; profile < 4 ; profile ++ )
2730
+ {
2731
+ for ( uint8_t config = 0 ; config < 4 ; config ++ )
2732
+ {
2653
2733
#if Storage_Enable_define == 1
2654
- for (uint8_t profile = 0 ; profile < 4 ; profile ++ ) {
2655
- for (uint8_t config = 0 ; config < 4 ; config ++ ) {
2656
2734
defaults .fade_periods [profile ][config ] =
2657
2735
Pixel_LED_FadePeriods [Pixel_LED_FadePeriod_Defaults [profile ][config ]];
2736
+ #else
2737
+ settings .fade_periods [profile ][config ] =
2738
+ Pixel_LED_FadePeriods [Pixel_LED_FadePeriod_Defaults [profile ][config ]];
2739
+ #endif
2658
2740
}
2659
2741
}
2742
+
2743
+ // Register storage module
2744
+ #if Storage_Enable_define == 1
2660
2745
Storage_registerModule (& PixelStorage );
2661
2746
#endif
2662
2747
@@ -3201,27 +3286,13 @@ void cliFunc_rectDisp( char* args )
3201
3286
3202
3287
3203
3288
#if Storage_Enable_define == 1
3204
- void Pixel_loadConfig () {
3205
- // Animations
3206
- for ( uint8_t pos = 0 ; pos < Pixel_AnimationStackSize ; pos ++ )
3207
- {
3208
- uint8_t index = settings .animation_indices [pos ];
3209
- if (index != 255 ) {
3210
- AnimationStackElement element = Pixel_AnimationSettings [ index ];
3211
- element .state = AnimationPlayState_Start ;
3212
- Pixel_addAnimation ( & element , CapabilityState_None );
3213
- }
3214
- }
3289
+ void Pixel_loadConfig ()
3290
+ {
3291
+ // Animation setup
3292
+ Pixel_initializeStartAnimations ();
3215
3293
3216
3294
// Fade periods
3217
- for (uint8_t profile = 0 ; profile < 4 ; profile ++ )
3218
- {
3219
- for (uint8_t config = 0 ; config < 4 ; config ++ )
3220
- {
3221
- PixelPeriodConfig period_config = settings .fade_periods [profile ][config ];
3222
- Pixel_pixel_fade_profile_entries [profile ].conf [config ] = period_config ;
3223
- }
3224
- }
3295
+ Pixel_SecondaryProcessing_setup ();
3225
3296
}
3226
3297
3227
3298
void Pixel_saveConfig () {
@@ -3230,9 +3301,20 @@ void Pixel_saveConfig() {
3230
3301
{
3231
3302
if (pos < Pixel_AnimationStack .size ) {
3232
3303
AnimationStackElement * elem = Pixel_AnimationStack .stack [pos ];
3233
- settings .animation_indices [pos ] = elem -> index ;
3304
+ settings .animations [pos ].index = elem -> index ;
3305
+
3306
+ // Save position, only if paused
3307
+ if ( elem -> state == AnimationPlayState_Pause )
3308
+ {
3309
+ settings .animations [pos ].pos = elem -> pos - 1 ;
3310
+ }
3311
+ else
3312
+ {
3313
+ settings .animations [pos ].pos = 0 ;
3314
+ }
3234
3315
} else {
3235
- settings .animation_indices [pos ] = 255 ;
3316
+ settings .animations [pos ].index = 255 ;
3317
+ settings .animations [pos ].pos = 0 ;
3236
3318
}
3237
3319
}
3238
3320
@@ -3253,12 +3335,15 @@ void Pixel_printConfig() {
3253
3335
print (" \033[35mAnimations\033[0m" NL );
3254
3336
for ( uint8_t pos = 0 ; pos < Pixel_AnimationStackSize ; pos ++ )
3255
3337
{
3256
- uint8_t index = settings .animation_indices [pos ];
3338
+ uint8_t index = settings .animations [pos ].index ;
3339
+ uint8_t fpos = settings .animations [pos ].pos ;
3257
3340
if (index != 255 ) {
3258
3341
print ("AnimationStack.stack[" );
3259
3342
printInt8 (pos );
3260
3343
print ("]->index = " );
3261
3344
printInt8 (index );
3345
+ print ("; pos = " );
3346
+ printInt8 (fpos );
3262
3347
print (NL );
3263
3348
}
3264
3349
}
@@ -3278,6 +3363,7 @@ void Pixel_printConfig() {
3278
3363
printInt8 (period .start );
3279
3364
print (", " );
3280
3365
printInt8 (period .end );
3366
+ print ("}" );
3281
3367
print (NL );
3282
3368
}
3283
3369
}
0 commit comments