Is this a crazy idea...?

In the spirit of the Prof’s “Crazy Idea of the Day” threads, I have one I’d like to run by people…

I’ve just built a KR Scavenger hilt. It’s an amazing hilt, but the nature and complexity of the mechanicals that drive the emitter petals is such that’s hard to feel the tactile switch working.

So my idea is to load a low-level wav file with a click on it onto the SD card, then tweak the config so that every time the tactile switch is actuated or released, the click wav plays. This would help you navigate (if that’s the right word) the operation of the switch.

So two questions:

  1. How difficult would this be to implement and what’s involved to make it work;
  2. Am I crazy, or is it actually a sound idea (pun fully intended! LOL!).

Thoughts welcome.
:slight_smile:

It might work pretty well.
You’ll need to add some code to the prop to do it though, just modifying the config file is not going to be enough.

1 Like

Thanks Prof.
Yeh I thought it might be a Prop file thing. Just not sure how to define the point at which the contact closes or opens as an event to tie it to the wav. Like all these things, I suspect it needs more under-the-hood tweaks to the OS to make it work.

There are already events for that: EVENT_PRESSED and EVENT_RELEASED.

All you need is something like:

// Add this function somewhere

   void PlaySound(const char* sound) {
            RefPtr<BufferedWavPlayer> player = GetFreeWavPlayer();
           if (player) {
              if (!player->PlayInCurrentDir(sound))
                 player->Play(spimd);
           }
   }


  // Then add this in Event2
   case EVENTID(BUTTON_POWER, EVENT_PRESSED, MODE_ANY):
      PlaySound("press.wav");
      return false;
   case EVENTID(BUTTON_POWER, EVENT_RELEASED, MODE_ANY):
      PlaySounf("release.wav");
      return false;

Thanks for this Prof. I’ll have a play adding these to my Prop file when I get home from work this afternoon. Will report back on how it goes.
Thanks again.
:+1:

Sorry Prof - unfortunately the code you posted is throwing an error.

This is the SA22C prop file with your modifications (you can find where I’ve put them easily because I’ve added rows of struck out asterisks):

And this is the error from Arduino:

I also tried it in the standard saber.h prop file, but it still threw up errors.

Forgive me if I’ve done something blindingly obvious, but I’m afraid the extent of my coding is limited to cutting and pasting stuff written by geniuses like yourself in the saber community (for which I am eternally grateful!).

Well, I was obviously tired when I typed that.
First up; where it says spimd it supposed to say sound.
And where it says MODE_ANY, it should say MODE_ANY_BUTTON.
Also, you probably need to duplicate the cases for ON and OFF cases, like this:

Alternatively, it might be easier to detect this event before the switch() in event2.

Maybe a sound like this, where there’s some body to it so you feel vibration as tactile feedback, with a subtle"click" thrown in?
Volume of the file itself will likely need to be regulated so it’s not overpowering, but maybe a starting point for you:

I would venture to say a “released” sound might not be needed.

Thanks for the code mods Prof. The new code compiles better but unfortunately the release event line is doubled up on the SA22C buttons as it also serves to play the end lockup effect, so I need to figure out how to get round that. I’m sure there’s an “else” command that would work, as in - automatically play the release sound unless the blade is in lockup mode in which case play the lockup end sound.

And thanks Brian for the click. I didn’t want to go too hefty as I didn’t want it to intrude, but the clicks I’ve come up with aren’t a million miles from what you’ve done. And yes, the level needs to be managed somewhat, but early experiments suggest I’m in the right ball park.

As for the release not being needed, if I can’t get the doubled up line sorted I may have to settle for it, but I think it would be useful for stuff like mid-length clicks to change presets and stuff. I’ve made my release click slightly lower pitch than the press click to further help with button navigation. If I can make it work, I think it will be very effective.

When lockup mode is active, this is true:

SaberBase::Lockup()
So to only do something when NOT in lockup, otherwise do something else (when lockup is true) you’d do:

     if (!SaberBase::Lockup()) {
          Do your non-lockup state thing here;
        } else {
          Do something else because lockup is active;
        }

Of course the true case could come first instead :

     if (SaberBase::Lockup()) {
          Do your lockup state thing here;
        } else {
          Do something else because lockup is NOT active;
        }

Thanks for the examples Brian.
Unfortunately I had a play around with it this afternoon, and I think I may need to concede defeat. I haven’t been able to get the ‘press’ click working at all, and when I’ve managed to get the ‘release’ click working, it messes up the lockup exit and makes it impossible to come out of blade lockup. I suspect it might be more involved to make it work that we initially thought.

Are you working with the stock sa22c prop from OS6.7?

Why would we return false here?

If you don’t return false the Events using any button presses won’t run.

Ahh of course. Cool, thanks @Fett263 .
@Sabersense Does this not work for you?
saber_sa22c_buttons_press.h (25.0 KB)

Sorry for the slow response…

Brian,

Yes, been using SA22C buttons but within 5.9. But I just downloaded a new copy of 6.7 and dropped your modded SA22C button prop file in there and tried it.

The good news is both clicks now seem to work - the bad news is once you’re in lockup you still can’t get out of it. It’s a one button hilt and I notice you removed the EventID line at around 800, which I guess means that there isn’t a line to tell the lockup to end. In terms of coding, I’m already in over my head, so I have no idea if the fix to this is simple or not. But my sincere thanks to you, Fredrik and Fernando for getting us this far.

:slight_smile:

EVENT at line 800 was oh duh. Sorry, multitasking over here. I totally disregarded the previous posts regarding the if clause lol. Sorry.
And looking now, you probably wouldn’t actually want an if-else. Rather, you’d want the sound to play regardless, you just need the end lockup. Does that sound right?
Try this:
saber_sa22c_buttons_press.h (25.2 KB)

Yes that does sound right. I’ll give that a go. Thanks.
However doing some more tests with the first version you sent, weirdly I’m finding that it doesn’t always play the ‘press’ click, especially when the blade is OFF, pretty much always plays the ‘release’ click.
Note sure why that would be, but I’ll try your second prop and will report back in a few minutes. :slight_smile: Thanks again.

OK getting warmer! LOL! That’s fixed the lockup! Many thanks.
The only thing now is that the press click doesn’t seem to play when the blade is off, but it works when the blade is lit. Release seems to work all the time.
If we can manage to get over this last hurdle it would be amazing, and definitely a feature I’ll keep in the toolbox for similar future builds.
:slight_smile:

Hmm, maybe it has something to do with this

I don’t get the hint here to detect “before”, as a case would need to be inside a switch().

Either way, maybe let’s try triggering the sounds more “traditionally” as an effect using PlayCommon(). This would also allow you to include a slight variety of sounds if you wanted, randomly chosen from press01, 02 etc…
saber_sa22c_buttons_press.h (25.4 KB)