Skip to content

Commit 874852a

Browse files
committed
Fixing single color animation save/load
- Storage stack was not saving position - On Kira when changing the key colors, then changing the underlighting while the key colors would stay the same (due to no animations manipulating them) the animation stack would be emptied so the storage stack would not know how to get that color * clearactive replace type was added to only remove moving animations - Resolves Issue #312 - Do not waste a storage block if saving the same data - If the storage is completely empty, raise the cleared_block flag (to handle defaults correctly) - Reworked how defaults are generated for brightness, fade and animations
1 parent a8c688c commit 874852a

File tree

6 files changed

+168
-74
lines changed

6 files changed

+168
-74
lines changed

Diff for: Keyboards/Pipfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ verify_ssl = true
44
name = "pypi"
55

66
[packages]
7-
kll = "==0.5.7.5"
7+
kll = "==0.5.7.6"
88

99
[dev-packages]
1010

Diff for: Lib/CMake/kll.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ endif ()
4343
message ( STATUS "Checking for kll" )
4444

4545
### XXX XXX XXX - Remember to update Pipfile as well when you change the version! ###
46-
set ( KLL_MIN_VERSION "0.5.7.5" )
46+
set ( KLL_MIN_VERSION "0.5.7.6" )
4747

4848
# 1) Check for environment variable
4949
if ( NOT DEFINED KLL_EXECUTABLE )

Diff for: Lib/storage.c

+15-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* Copyright (c) 2012 Atmel Corporation. All rights reserved.
3-
* Modified by Jacob Alexander 2018
3+
* Modified by Jacob Alexander 2018-2019
44
*
55
* Redistribution and use in source and binary forms, with or without
66
* modification, are permitted provided that the following conditions are met:
@@ -266,6 +266,12 @@ void storage_init()
266266
storage_buffer[i] = page_buffer[i + 449];
267267
#endif
268268
}
269+
270+
// If this is the first page, then set the cleared flag as no flash has been written
271+
if ( page_walker == 0 )
272+
{
273+
cleared_block = 1;
274+
}
269275
}
270276
// If the block is within a page, go to previous block and fetch the data
271277
else
@@ -350,6 +356,13 @@ uint8_t storage_write(uint8_t* data, uint16_t address, uint16_t size, uint8_t cl
350356
return 0;
351357
}
352358

359+
// Make sure this isn't the same data already set in flash
360+
// If so, just exit, no need to wear the flash any further
361+
if ( memcmp( storage_buffer, data, size ) == 0 )
362+
{
363+
return 1;
364+
}
365+
353366
// Set internal buffer to all 0xffs
354367
// This way it's possible to do partial writes to the page
355368
for ( int i = 0; i < STORAGE_FLASH_PAGE_SIZE; i++ )
@@ -482,16 +495,10 @@ int8_t storage_block_position()
482495
}
483496

484497
// Returns 1 if storage has been cleared and will not have conflicts when changing the block size
485-
// Or if there is no useful data in the non-volatile storage
498+
// Or if there is no useful data in the non-volatile storage (i.e. completely empty, fresh erase)
486499
// storage_init() must be called first
487500
uint8_t storage_is_storage_cleared()
488501
{
489-
// Check to see if this page is empty
490-
if ( !find_cleared_block(storage_buffer) )
491-
{
492-
return 1;
493-
}
494-
495502
return cleared_block;
496503
}
497504

Diff for: Macro/PixelMap/pixel.c

+139-53
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2015-2018 by Jacob Alexander
1+
/* Copyright (C) 2015-2019 by Jacob Alexander
22
*
33
* This file is free software: you can redistribute it and/or modify
44
* it under the terms of the GNU General Public License as published by
@@ -82,21 +82,25 @@ typedef enum PixelTest {
8282
PixelTest_XY_Roll = 33,
8383
} PixelTest;
8484

85+
86+
8587
// ----- Variables -----
8688

87-
#if Storage_Enable_define == 1
8889
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];
9096
PixelPeriodConfig fade_periods[4][4];
9197
} PixelConfig;
9298

93-
static PixelConfig defaults = {
94-
.animation_indices = {[0 ... Pixel_AnimationStackSize-1] = 255}, //Todo, use some kll define
95-
// .fade_periods initialized later
96-
};
97-
9899
static PixelConfig settings;
99100

101+
#if Storage_Enable_define == 1
102+
static PixelConfig defaults;
103+
100104
static StorageModule PixelStorage = {
101105
.name = "Pixel Map",
102106
.settings = &settings,
@@ -758,6 +762,49 @@ uint8_t Pixel_addAnimation( AnimationStackElement *element, CapabilityState csta
758762
Pixel_clearAnimations();
759763
break;
760764

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+
761808
default:
762809
break;
763810
}
@@ -2016,13 +2063,9 @@ void Pixel_SecondaryProcessing_setup()
20162063
// Each of the periods
20172064
for ( uint8_t pr = 0; pr < 4; pr++ )
20182065
{
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-
20232066
// 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;
20262069
}
20272070

20282071
// Reset state
@@ -2245,23 +2288,21 @@ void Pixel_setAnimationControl( AnimationControl control )
22452288
// Starting Animation setup
22462289
void Pixel_initializeStartAnimations()
22472290
{
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++ )
22502293
{
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 )
22562300
{
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;
22642302
}
2303+
2304+
element.pos = settings.animations[pos].pos;
2305+
Pixel_addAnimation( &element, CapabilityState_None );
22652306
}
22662307
}
22672308
}
@@ -2649,14 +2690,58 @@ inline void Pixel_setup()
26492690
// Register Pixel CLI dictionary
26502691
CLI_registerDictionary( pixelCLIDict, pixelCLIDictName );
26512692

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+
{
26532733
#if Storage_Enable_define == 1
2654-
for (uint8_t profile=0; profile<4; profile++) {
2655-
for (uint8_t config=0; config<4; config++) {
26562734
defaults.fade_periods[profile][config] =
26572735
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
26582740
}
26592741
}
2742+
2743+
// Register storage module
2744+
#if Storage_Enable_define == 1
26602745
Storage_registerModule(&PixelStorage);
26612746
#endif
26622747

@@ -3201,27 +3286,13 @@ void cliFunc_rectDisp( char* args )
32013286

32023287

32033288
#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();
32153293

32163294
// 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();
32253296
}
32263297

32273298
void Pixel_saveConfig() {
@@ -3230,9 +3301,20 @@ void Pixel_saveConfig() {
32303301
{
32313302
if (pos < Pixel_AnimationStack.size) {
32323303
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+
}
32343315
} else {
3235-
settings.animation_indices[pos] = 255;
3316+
settings.animations[pos].index = 255;
3317+
settings.animations[pos].pos = 0;
32363318
}
32373319
}
32383320

@@ -3253,12 +3335,15 @@ void Pixel_printConfig() {
32533335
print(" \033[35mAnimations\033[0m" NL);
32543336
for ( uint8_t pos = 0; pos < Pixel_AnimationStackSize; pos++ )
32553337
{
3256-
uint8_t index = settings.animation_indices[pos];
3338+
uint8_t index = settings.animations[pos].index;
3339+
uint8_t fpos = settings.animations[pos].pos;
32573340
if (index != 255) {
32583341
print("AnimationStack.stack[");
32593342
printInt8(pos);
32603343
print("]->index = ");
32613344
printInt8(index);
3345+
print("; pos = ");
3346+
printInt8(fpos);
32623347
print(NL);
32633348
}
32643349
}
@@ -3278,6 +3363,7 @@ void Pixel_printConfig() {
32783363
printInt8(period.start);
32793364
print(", ");
32803365
printInt8(period.end);
3366+
print("}");
32813367
print(NL);
32823368
}
32833369
}

Diff for: Macro/PixelMap/pixel.h

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2015-2018 by Jacob Alexander
1+
/* Copyright (C) 2015-2019 by Jacob Alexander
22
*
33
* This file is free software: you can redistribute it and/or modify
44
* it under the terms of the GNU General Public License as published by
@@ -104,11 +104,12 @@ typedef enum PixelAddressType {
104104

105105
// Animation Replace Type
106106
typedef enum AnimationReplaceType {
107-
AnimationReplaceType_None = 0, // Don't replace (add new animation to stack if not full)
108-
AnimationReplaceType_Basic = 1, // Replace only if the same trigger initiated
109-
AnimationReplaceType_All = 2, // Replace no matter what trigger initiated
110-
AnimationReplaceType_State = 3, // Using same trigger, start on Activate/Press, stop on Deactivate/Release
111-
AnimationReplaceType_Clear = 4, // Clear all other animations before addi
107+
AnimationReplaceType_None = 0, // Don't replace (add new animation to stack if not full)
108+
AnimationReplaceType_Basic = 1, // Replace only if the same trigger initiated
109+
AnimationReplaceType_All = 2, // Replace no matter what trigger initiated
110+
AnimationReplaceType_State = 3, // Using same trigger, start on Activate/Press, stop on Deactivate/Release
111+
AnimationReplaceType_Clear = 4, // Clear all other animations before adding
112+
AnimationReplaceType_ClearActive = 5, // Clear all other animations before adding, except paused (replace those)
112113
} AnimationReplaceType;
113114

114115
// Animation Play State

0 commit comments

Comments
 (0)