Accent color based on Blaster Mode

Hey! I’m still quite new to ProffieOS and particularly Lightsabers.

I have been trying to create a way for an accent LED to be in a different color depending on which mode you have selected (for example red = kill, green = auto, blue = stun). I tried searching the documentation and on here but couldn’t find it.

My thought was to perhaps get the current mode from the blaster.h file into a IsLessThan function in the blade style, but I haven’t been able to find a way to do that.

Do you guys have any ideas on how to do something like this, if possible.

Happy Easter!

That’s a blade style thing.
I don’t think I’ve ever seen it used before, but you should be able to use ColorSelect<> with EFFECT_MODE.
Try something like:


1 Like

EffectIncrementF might not line up if you switch styles.
It would be better to create a function that actually returns the mode.

1 Like

You mean switch presets? Ah, yeah mode persists so it would go out of sync unless you always cycle back to kill before switching. Not ideal.

1 Like

We already have BulletCountF and BlasterChargeF which only apply to blasters, so we should just do something similar I think.

1 Like

This got me on the right track! Thank you! But it did start to go out of sync after a few switches.

I started looking at those functions, but I have never written C++. But this is an excellent execuse to learn another programming language. :stuck_out_tongue:

The ProffieOS style templates are not exactly the easiest place in the world to start…

If you do want to understand those functions, you should probably also read this:

1 Like

lol. I would second this, do not try to start learning C++ with ProffieOS blade styles. Templating and meta programming is not exactly beginner friendly

is this the worst ever?

// blaster_mode.h


#include "props/blaster.h"

// Usage: BlasterModeF
// Returns the current blaster mode as an integer:
// 0 for MODE_STUN, 1 for MODE_KILL, 2 for MODE_AUTO
// This function should only be used when BLASTER_SHOTS_UNTIL_EMPTY is defined,
// indicating that the current prop is a Blaster.
// Example usage in a style:
// StylePtr<ColorSelect<BlasterModeF, TrInstant, Red, Green, Blue>>()

extern Blaster prop;

class BlasterModeSVF {
    void run(BladeBase* blade) {}
    int getInteger(int led) { return prop.blaster_mode; } 
    int calculate(BladeBase* blade) { return prop.blaster_mode; }

class SingleValueAdapter<BlasterModeSVF> : public BlasterModeSVF {};

using BlasterModeF = SingleValueAdapter<BlasterModeSVF>;



1 Like

Nope, not even a little bit.
However, there are a few issues:

  1. prop files have side effects and should only be included once, and only if that’s the prop file you want to use. To work around this, you can add a global function for getting the blaster mode. This function would be declared in this file, and defined in blaster.h, which would mean that you get a linker error if you try to use without the blaster prop.
  2. Not all blasters use BLASTER_SHOTS_UNTIL_EMPTY, so it’s not the best define to use to decide if we should have a BlasterModeSVF or not. In fact, we don’t need an #ifdef at all since we’ll get a linker error (see 1 above)
  3. It’s not a PR :slight_smile:
1 Like

It is now. Working well.

1 Like

Looks pretty good, just needs a couple of tweaks. :slight_smile:

1 Like

Oooh, thank you very much.

Is there anything I need to do besides creating a file in the functions folder called blaster_mode.h with this in it?

Yes not just that.
Once it’s added to the code on GitHub, you can download the latest development build there.

1 Like

I saw that it was added now. Thank you Profezzorn and NoSloppy for your help! I really appreciate it! :smiley:

1 Like