Rogue Button Release Tripping the System Up?

In the course of tidying up my prop file, I’ve come across a blip that I’m struggling to solve…

I have a chunk of code that removes all the save files from the SD card (restore factory defaults as it were). The system is set to play a reset.wav file and then reboot itself, but obviously I need to make provision for systems with no reset.wav file on the SD card.

My button press is four presses of POWER then hold the button down on the last press.

If a reset file is present, this works fine because as the reset sound plays, you naturally release the button while it’s playing, and the system just does its thing. But if there’s no reset sound on the SD card and it goes straight to rebooting, you end up releasing the button partway through the boot sound, which confuses the system because it receives a button release when it isn’t expecting one, which in turn cuts the boot sound off and lights the blade, which is kinda clunky.

I’ve tried the obvious which is adding a delay after the STM32.reset command, but it just got ignored, which suggests to me that anything coded after the STM32.reset will also get ignored.

Any suggestions for what I could try to fix this?

Here’s the code:

      LOCK_SD(false);

      if (SFX_reset) {  // Optional confirmation sound file 'reset'.
        hybrid_font.PlayCommon(&SFX_reset);
          while (IsResetSoundPlaying());  // Lock system while sound finishes...
        }
      STM32.reset(); // ...then reboot saber.
      break;
    }

Ignore the above - I think I found a better solution that naturally prompts the user to release the button before reboot:

    if (SFX_reset) {  // Optional confirmation sound file 'reset'.
      hybrid_font.PlayCommon(&SFX_reset);
      while(IsResetSoundPlaying());  // Lock system while sound finishes.
    } else {
      beeper.Beep(0.5, 2000); // Generate beep to prompt user to release button.
      delay(1200); // Give time for slow users to release button, avoids boot conflicts.
    }
    STM32.reset(); // Reboot saber.
  }
  break;

You could also put a delay at boot so buttons don’t do anything until boot.wav is finished :wink:

Yeh, I thought about that, but I didn’t really want to make any changes system-wide - whatever solution I use, I only want it to affect this reset specifically.

It would go in your prop.
Right at the top of your button controls in Event2

  bool Event2(enum BUTTON button, EVENT event, uint32_t modifiers) override {
    if (GetWavPlayerPlaying(&SFX_boot)) return false;
    switch (EVENTID(button, event, modifiers)) {
........................
1 Like

Ah! I see what you mean.
Actually that does look pretty slick. :smiley:
Will try it when I get home today. :+1:
Thanks as always Brian. :pray: :slight_smile: