# Sometimes automatic switching between Presets, using Blade ID or Blade Detection and SAVE\_STATE define, doesn’t work properly

**URL:** <https://crucible.hubbe.net/t/sometimes-automatic-switching-between-presets-using-blade-id-or-blade-detection-and-save-state-define-doesn-t-work-properly/241>\
**Category:** ProffieOS\
**Created:** [April 11, 2021, 6:17am UTC](https://crucible.hubbe.net/t/sometimes-automatic-switching-between-presets-using-blade-id-or-blade-detection-and-save-state-define-doesn-t-work-properly/241 "2021-04-11T06:17:40Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![ShtokyD](https://crucible.hubbe.net/user_avatar/crucible.hubbe.net/shtokyd/32/6744_2.png) [@ShtokyD](https://crucible.hubbe.net/u/ShtokyD)\
**Post date:** [April 11, 2021, 6:17am UTC](https://crucible.hubbe.net/t/sometimes-automatic-switching-between-presets-using-blade-id-or-blade-detection-and-save-state-define-doesn-t-work-properly/241/1 "2021-04-11T06:17:40Z")

</div>

I noticed it long time ago but writing only now about this issue:

so I have define SAVE\_STATE in my config and it works perfectly for some time after first code upload, but as I use the saber more, switching presets, changing volume, colors, changing Presets by using Blade ID or Blade Detection etc., at some moment it gets messed up and doesn’t switch to a proper Preset anymore when I insert the blade or remove it. Deleting the saved temporary files from SD card root solves it, it resets to the default state and works as normal. So looks like something with the SAVE\_STATE thing.

---

<div class="post-metadata">

**Author:** ![profezzorn](https://crucible.hubbe.net/user_avatar/crucible.hubbe.net/profezzorn/32/8_2.png) [@profezzorn](https://crucible.hubbe.net/u/profezzorn)\
**Post date:** [April 11, 2021, 7:03am UTC](https://crucible.hubbe.net/t/sometimes-automatic-switching-between-presets-using-blade-id-or-blade-detection-and-save-state-define-doesn-t-work-properly/241/2 "2021-04-11T07:03:24Z")

</div>

So it sounds like disconnecting/reconnecting power doesn’t help, right?  
Which file(s) do you actually delete to fix it?  
What’s actually in that file when it doesn’t work?

---

<div class="post-metadata">

**Author:** ![ShtokyD](https://crucible.hubbe.net/user_avatar/crucible.hubbe.net/shtokyd/32/6744_2.png) [@ShtokyD](https://crucible.hubbe.net/u/ShtokyD)\
**Post date:** [April 11, 2021, 10:52am UTC](https://crucible.hubbe.net/t/sometimes-automatic-switching-between-presets-using-blade-id-or-blade-detection-and-save-state-define-doesn-t-work-properly/241/3 "2021-04-11T10:52:16Z")

</div>

Correct, rebooting the board by power reconnecting doesn’t help, only deleting the temporary save files from SD:

curstate.ini  
curstate.tmp  
global.ini  
global.tmp  
presets.ini  
presets.tmp

deleting just the “presets.ini” and “presets.tmp” fixes it.

also looks like volume change doesn’t save after board power reboot… color change saves.

---

<div class="post-metadata">

**Author:** ![profezzorn](https://crucible.hubbe.net/user_avatar/crucible.hubbe.net/profezzorn/32/8_2.png) [@profezzorn](https://crucible.hubbe.net/u/profezzorn)\
**Post date:** [April 11, 2021, 7:11pm UTC](https://crucible.hubbe.net/t/sometimes-automatic-switching-between-presets-using-blade-id-or-blade-detection-and-save-state-define-doesn-t-work-properly/241/4 "2021-04-11T19:11:06Z")

</div>

Some changes (like volume) don’t save until the blade is retracted and all sound has stopped.  
This is because saving while things are on can cause minor audio glitches. Is that what you mean by “doesn’t save”, or is it something else?

When your saber is exhibiting these problems, could you just attach all the ini and tmp files to this thread so I can check what’s in them?

---

<div class="post-metadata">

**Author:** ![ShtokyD](https://crucible.hubbe.net/user_avatar/crucible.hubbe.net/shtokyd/32/6744_2.png) [@ShtokyD](https://crucible.hubbe.net/u/ShtokyD)\
**Post date:** [April 13, 2021, 5:52pm UTC](https://crucible.hubbe.net/t/sometimes-automatic-switching-between-presets-using-blade-id-or-blade-detection-and-save-state-define-doesn-t-work-properly/241/5 "2021-04-13T17:52:35Z")

</div>

So volume level doesn’t save if I’m using automatic presets switching by Blade Detection or Blade ID. I set the volume to 3000, turn the blade OFF, remove the battery, insert the battery again, turn the saber ON and volume is back to its default 500…  
Blade styles of my “NO\_BLADE” config array stop working when I’m changing the color wheel in my other “BLADE” config array presets and the temporary “presets” files are created on SD. Deleting those temporary files solves the issue.

[global.ini](https://crucible.hubbe.net/uploads/short-url/2sw3ndX5ro4tj40rkVP6vgtRlfm.ini) (48 Bytes)  
[curstate.ini](https://crucible.hubbe.net/uploads/short-url/iW5oIfMrQlZMOTHFIEIFmne5jVl.ini) (46 Bytes)  
[presets.ini](https://crucible.hubbe.net/uploads/short-url/qy5myvgCQJ6ksKhkwMbhhvAn8dE.ini) (2.9 KB)

.tmp files are not supported for upload here…

---

<div class="post-metadata">

**Author:** ![profezzorn](https://crucible.hubbe.net/user_avatar/crucible.hubbe.net/profezzorn/32/8_2.png) [@profezzorn](https://crucible.hubbe.net/u/profezzorn)\
**Post date:** [April 13, 2021, 6:09pm UTC](https://crucible.hubbe.net/t/sometimes-automatic-switching-between-presets-using-blade-id-or-blade-detection-and-save-state-define-doesn-t-work-properly/241/6 "2021-04-13T18:09:51Z")

</div>

I’ve added .tmp files to the set of supported upload extensions.  
I’ll look into the preset switching by blade detect, maybe there is a trysave missing in there somewhere.  
What version of ProffieOS are you using? Do you have any modified files?

---

<div class="post-metadata">

**Author:** ![ShtokyD](https://crucible.hubbe.net/user_avatar/crucible.hubbe.net/shtokyd/32/6744_2.png) [@ShtokyD](https://crucible.hubbe.net/u/ShtokyD)\
**Post date:** [April 13, 2021, 6:18pm UTC](https://crucible.hubbe.net/t/sometimes-automatic-switching-between-presets-using-blade-id-or-blade-detection-and-save-state-define-doesn-t-work-properly/241/7 "2021-04-13T18:18:39Z")

</div>

I’m using 5.7. Yes, I modified battery\_monitor.h to adjust better voltage indication for the OLED display, and I also changed something you told me to change when I had issues with motion activation timeout in my config not working.

---

<div class="post-metadata">

**Author:** ![profezzorn](https://crucible.hubbe.net/user_avatar/crucible.hubbe.net/profezzorn/32/8_2.png) [@profezzorn](https://crucible.hubbe.net/u/profezzorn)\
**Post date:** [April 14, 2021, 6:29pm UTC](https://crucible.hubbe.net/t/sometimes-automatic-switching-between-presets-using-blade-id-or-blade-detection-and-save-state-define-doesn-t-work-properly/241/8 "2021-04-14T18:29:01Z")

</div>

Could you attach the tmp files too? (should work now)

---

<div class="post-metadata">

**Author:** ![profezzorn](https://crucible.hubbe.net/user_avatar/crucible.hubbe.net/profezzorn/32/8_2.png) [@profezzorn](https://crucible.hubbe.net/u/profezzorn)\
**Post date:** [April 14, 2021, 6:33pm UTC](https://crucible.hubbe.net/t/sometimes-automatic-switching-between-presets-using-blade-id-or-blade-detection-and-save-state-define-doesn-t-work-properly/241/9 "2021-04-14T18:33:12Z")

</div>

I looked at the ini files that you attached earlier, and I didn’t see anything wrong with them. Was the saber really having a problem with starting up properly with these files?

---

<div class="post-metadata">

**Author:** ![ShtokyD](https://crucible.hubbe.net/user_avatar/crucible.hubbe.net/shtokyd/32/6744_2.png) [@ShtokyD](https://crucible.hubbe.net/u/ShtokyD)\
**Post date:** [April 14, 2021, 7:17pm UTC](https://crucible.hubbe.net/t/sometimes-automatic-switching-between-presets-using-blade-id-or-blade-detection-and-save-state-define-doesn-t-work-properly/241/10 "2021-04-14T19:17:31Z")

</div>

Everything works until I change colors with the blade attached, and then “presets.ini” is created on SD. After that when I remove the blade and it switches to the NO\_BLADE Preset, non of the blade styles work, nothing lights up, but sound plays.

---

<div class="post-metadata">

**Author:** ![profezzorn](https://crucible.hubbe.net/user_avatar/crucible.hubbe.net/profezzorn/32/8_2.png) [@profezzorn](https://crucible.hubbe.net/u/profezzorn)\
**Post date:** [April 14, 2021, 7:34pm UTC](https://crucible.hubbe.net/t/sometimes-automatic-switching-between-presets-using-blade-id-or-blade-detection-and-save-state-define-doesn-t-work-properly/241/11 "2021-04-14T19:34:42Z")

</div>

Can you post your config file?

---

<div class="post-metadata">

**Author:** ![ShtokyD](https://crucible.hubbe.net/user_avatar/crucible.hubbe.net/shtokyd/32/6744_2.png) [@ShtokyD](https://crucible.hubbe.net/u/ShtokyD)\
**Post date:** [April 16, 2021, 6:13am UTC](https://crucible.hubbe.net/t/sometimes-automatic-switching-between-presets-using-blade-id-or-blade-detection-and-save-state-define-doesn-t-work-properly/241/12 "2021-04-16T06:13:38Z")

</div>

When I’m adding .tmp files it uploads same .ini file.

Here is a video describing the issue:

> **[IMG\_1980.MOV (video)](https://drive.google.com/file/d/1cJ1lA9kC4qImijWuHJXuz6m_RZsSNNGG/view?usp=drivesdk)**
>
> Google Drive file.

Config file:  
[jedikiller\_proffie\_config.h](https://crucible.hubbe.net/uploads/short-url/clBOEhjKwb0rQJaK2slX5PLLah9.h) (19.6 KB)

---

<div class="post-metadata">

**Author:** ![profezzorn](https://crucible.hubbe.net/user_avatar/crucible.hubbe.net/profezzorn/32/8_2.png) [@profezzorn](https://crucible.hubbe.net/u/profezzorn)\
**Post date:** [April 16, 2021, 6:22am UTC](https://crucible.hubbe.net/t/sometimes-automatic-switching-between-presets-using-blade-id-or-blade-detection-and-save-state-define-doesn-t-work-properly/241/13 "2021-04-16T06:22:50Z")

</div>

Since you have multiple different preset arrays, you need to set up separate save directories for them. Basically, create two directories on your sd card: blade and noblade then in your config, add the save directory after the CONFIGARRAY(), like this:

```auto
 { 700,
     WS281XBladePtr<133, bladePin, Color8::GRB, PowerPINS<bladePowerPin2, bladePowerPin3> >(),
     WS281XBladePtr<5, blade4Pin, Color8::GRB, PowerPINS<bladePowerPin2, bladePowerPin3> >(),                  
     WS281XBladePtr<1, blade2Pin, Color8::GRB, PowerPINS<bladePowerPin4> >(),
     WS281XBladePtr<1, blade3Pin, Color8::GRB, PowerPINS<bladePowerPin5> >(), 
     CONFIGARRAY(blade), "blade" },

```

By doing this, it will use different preset.ini files for the “blade” and “noblade” cases, which should hopefully make things work better.

---

<div class="post-metadata">

**Author:** ![ShtokyD](https://crucible.hubbe.net/user_avatar/crucible.hubbe.net/shtokyd/32/6744_2.png) [@ShtokyD](https://crucible.hubbe.net/u/ShtokyD)\
**Post date:** [April 16, 2021, 7:31am UTC](https://crucible.hubbe.net/t/sometimes-automatic-switching-between-presets-using-blade-id-or-blade-detection-and-save-state-define-doesn-t-work-properly/241/15 "2021-04-16T07:31:00Z")

</div>

Hmm, looks like my Arduino doesn’t compile anything at all and not even giving any error descriptions…

---

<div class="post-metadata">

**Author:** ![profezzorn](https://crucible.hubbe.net/user_avatar/crucible.hubbe.net/profezzorn/32/8_2.png) [@profezzorn](https://crucible.hubbe.net/u/profezzorn)\
**Post date:** [April 16, 2021, 7:36am UTC](https://crucible.hubbe.net/t/sometimes-automatic-switching-between-presets-using-blade-id-or-blade-detection-and-save-state-define-doesn-t-work-properly/241/16 "2021-04-16T07:36:51Z")

</div>

Weird. Hope a reboot or something fixes it.

---

<div class="post-metadata">

**Author:** ![ShtokyD](https://crucible.hubbe.net/user_avatar/crucible.hubbe.net/shtokyd/32/6744_2.png) [@ShtokyD](https://crucible.hubbe.net/u/ShtokyD)\
**Post date:** [April 16, 2021, 7:41am UTC](https://crucible.hubbe.net/t/sometimes-automatic-switching-between-presets-using-blade-id-or-blade-detection-and-save-state-define-doesn-t-work-properly/241/17 "2021-04-16T07:41:49Z")

</div>

Ok, works now, had to restart my PC lol. That works now properly, nice! But volume changing still doesn’t save…

---

<div class="post-metadata">

**Author:** ![profezzorn](https://crucible.hubbe.net/user_avatar/crucible.hubbe.net/profezzorn/32/8_2.png) [@profezzorn](https://crucible.hubbe.net/u/profezzorn)\
**Post date:** [April 16, 2021, 7:55am UTC](https://crucible.hubbe.net/t/sometimes-automatic-switching-between-presets-using-blade-id-or-blade-detection-and-save-state-define-doesn-t-work-properly/241/18 "2021-04-16T07:55:42Z")

</div>

Maybe if you insert

```
SaveVolumeIfNeeded();

```

here:

> <https://github.com/profezzorn/ProffieOS/blob/007f7244630a689f6be6162ee7ec4cb47f26121d/props/prop_base.h#L591>

(May be a different line number in your prop\_base.h)

---

<div class="post-metadata">

**Author:** ![profezzorn](https://crucible.hubbe.net/user_avatar/crucible.hubbe.net/profezzorn/32/8_2.png) [@profezzorn](https://crucible.hubbe.net/u/profezzorn)\
**Post date:** [May 4, 2021, 5:45pm UTC](https://crucible.hubbe.net/t/sometimes-automatic-switching-between-presets-using-blade-id-or-blade-detection-and-save-state-define-doesn-t-work-properly/241/19 "2021-05-04T17:45:23Z")

</div>

Did anybody try this?  
Did it work?

---

<div class="post-metadata">

**Author:** ![ShtokyD](https://crucible.hubbe.net/user_avatar/crucible.hubbe.net/shtokyd/32/6744_2.png) [@ShtokyD](https://crucible.hubbe.net/u/ShtokyD)\
**Post date:** [May 9, 2021, 4:40pm UTC](https://crucible.hubbe.net/t/sometimes-automatic-switching-between-presets-using-blade-id-or-blade-detection-and-save-state-define-doesn-t-work-properly/241/20 "2021-05-09T16:40:42Z")

</div>

That change for the volume isn’t needed, all works as it should now, no idea why it didn’t recently…

---

<div class="post-metadata">

**Author:** ![profezzorn](https://crucible.hubbe.net/user_avatar/crucible.hubbe.net/profezzorn/32/8_2.png) [@profezzorn](https://crucible.hubbe.net/u/profezzorn)\
**Post date:** [May 9, 2021, 6:27pm UTC](https://crucible.hubbe.net/t/sometimes-automatic-switching-between-presets-using-blade-id-or-blade-detection-and-save-state-define-doesn-t-work-properly/241/21 "2021-05-09T18:27:58Z")

</div>

Thanks for testing, let me know if it starts happening again.
