Multi_prop.h, I feel I am getting closer to something usable but

So with suggestion from @profezzorn to create enum & switch, help from @ryryog25 to initiate enum & switch, and suggestion from @NoSloppy to use help from ChatGPT, I came up with this (with a lot of ChatGPT input and/or output):

This is my CONFIG_PROP

#ifdef CONFIG_PROP
#include "../props/multi_prop.h"
#include "../props/saber_fett263_buttons.h"
#include "../props/blaster.h"
//#include "../props/detonator.h" //detonator is commented out because it gives me even more errors.
#undef PROP_TYPE
#define PROP_TYPE MultiProp <Saber, Blaster>//, Detonator
#endif

This is my multi_prop.h
Edit: I am deleting it.
Which gives me these compile errors:

"I cropped the top part as it did not have errors there"


Compiling sketch...

"C:\\Users\\Olivier\\AppData\\Local\\Arduino15\\packages\\proffieboard\\tools\\arm-none-eabi-gcc\\9-2020-q2-update/bin/arm-none-eabi-g++" -mcpu=cortex-m4 -mthumb -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib -fno-rtti -fno-exceptions -MMD -flto -fdevirtualize-at-ltrans -D_SYSTEM_CORE_CLOCK_=80000000L -DARDUINO=10819 -DARDUINO_PROFFIEBOARD_V3 -DARDUINO_ARCH_STM32L4 -DSTM32L452xx -DPROFFIEBOARD_VERSION=3 -D__FPU_PRESENT=1 -march=armv7e-m -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mabi=aapcs -mslow-flash-data -fsingle-precision-constant -felide-constructors -ffast-math -DUSB_VID=0x1209 -DUSB_PID=0x6668 -DUSB_DID=0xffff "-DUSB_MANUFACTURER=\"hubbe.net\"" "-DUSB_PRODUCT=\"Proffieboard\"" -DUSB_TYPE=USB_TYPE_CDC_MSC_WEBUSB -DDOSFS_SDCARD=3 -DDOSFS_SFLASH=0 "-IC:\\Users\\Olivier\\AppData\\Local\\Arduino15\\packages\\proffieboard\\hardware\\stm32l4\\3.6/system/CMSIS/Include" "-IC:\\Users\\Olivier\\AppData\\Local\\Arduino15\\packages\\proffieboard\\hardware\\stm32l4\\3.6/system/CMSIS/Device/ST/STM32L4xx/Include" "-IC:\\Users\\Olivier\\AppData\\Local\\Arduino15\\packages\\proffieboard\\hardware\\stm32l4\\3.6/system/STM32L4xx/Include" "-IC:\\Users\\Olivier\\AppData\\Local\\Arduino15\\packages\\proffieboard\\hardware\\stm32l4\\3.6\\cores\\stm32l4" "-IC:\\Users\\Olivier\\AppData\\Local\\Arduino15\\packages\\proffieboard\\hardware\\stm32l4\\3.6\\variants\\STM32L452RE-ProffieboardV3" "-IC:\\Users\\Olivier\\AppData\\Local\\Arduino15\\packages\\proffieboard\\hardware\\stm32l4\\3.6\\libraries\\Wire\\src" "C:\\Users\\Olivier\\AppData\\Local\\Temp\\arduino_build_37787\\sketch\\ProffieOS_7.14.ino.cpp" -o "C:\\Users\\Olivier\\AppData\\Local\\Temp\\arduino_build_37787\\sketch\\ProffieOS_7.14.ino.cpp.o"

In file included from C:\Users\Olivier\Desktop\Lego Manuals\LightSabers\$Oli\ProffieOS_7.14\ProffieOS_7.14.ino:625:

C:\Users\Olivier\Desktop\Lego Manuals\LightSabers\$Oli\ProffieOS_7.14\config\olicomplex1.4.8_test_multi_prop.h:344:19: error: 'MultiProp' does not name a type; did you mean 'MultiPropClass'?

  344 | #define PROP_TYPE MultiProp <Saber, Blaster>//, Detonator

      |                   ^~~~~~~~~

C:\Users\Olivier\Desktop\Lego Manuals\LightSabers\$Oli\ProffieOS_7.14\ProffieOS_7.14.ino:632:1: note: in expansion of macro 'PROP_TYPE'

  632 | PROP_TYPE prop;

      | ^~~~~~~~~

In file included from C:\Users\Olivier\Desktop\Lego Manuals\LightSabers\$Oli\ProffieOS_7.14\ProffieOS_7.14.ino:651:

C:\Users\Olivier\Desktop\Lego Manuals\LightSabers\$Oli\ProffieOS_7.14\buttons\latching_button.h: In member function 'void LatchingButtonTemplate<BASE>::Loop()':

C:\Users\Olivier\Desktop\Lego Manuals\LightSabers\$Oli\ProffieOS_7.14\buttons\latching_button.h:33:7: error: 'prop' was not declared in this scope

   33 |       prop.Event(button_, EVENT_LATCH_ON);

      |       ^~~~

C:\Users\Olivier\Desktop\Lego Manuals\LightSabers\$Oli\ProffieOS_7.14\buttons\latching_button.h: In member function 'bool LatchingButtonTemplate<BASE>::Parse(const char*, const char*)':

C:\Users\Olivier\Desktop\Lego Manuals\LightSabers\$Oli\ProffieOS_7.14\buttons\latching_button.h:43:9: error: 'prop' was not declared in this scope

   43 |         prop.Event(button_, EVENT_LATCH_ON);

      |         ^~~~

C:\Users\Olivier\Desktop\Lego Manuals\LightSabers\$Oli\ProffieOS_7.14\buttons\latching_button.h:45:9: error: 'prop' was not declared in this scope

   45 |         prop.Event(button_, EVENT_LATCH_OFF);

      |         ^~~~

In file included from C:\Users\Olivier\Desktop\Lego Manuals\LightSabers\$Oli\ProffieOS_7.14\buttons\button.h:4,

                 from C:\Users\Olivier\Desktop\Lego Manuals\LightSabers\$Oli\ProffieOS_7.14\ProffieOS_7.14.ino:652:

C:\Users\Olivier\Desktop\Lego Manuals\LightSabers\$Oli\ProffieOS_7.14\buttons\button_base.h: In member function 'bool ButtonBase::Send(uint32_t)':

C:\Users\Olivier\Desktop\Lego Manuals\LightSabers\$Oli\ProffieOS_7.14\buttons\button_base.h:51:10: error: 'prop' was not declared in this scope

   51 |     if (!prop.Event(button_, (EVENT)(event + (EVENT_SECOND_PRESSED - EVENT_FIRST_PRESSED) * press_count_))) {

      |          ^~~~

In file included from C:\Users\Olivier\Desktop\Lego Manuals\LightSabers\$Oli\ProffieOS_7.14\ProffieOS_7.14.ino:659:

C:\Users\Olivier\Desktop\Lego Manuals\LightSabers\$Oli\ProffieOS_7.14\buttons\rotary.h: In member function 'virtual void ChangePresetRotaryReceiver::Update(int)':

C:\Users\Olivier\Desktop\Lego Manuals\LightSabers\$Oli\ProffieOS_7.14\buttons\rotary.h:12:21: error: 'prop' was not declared in this scope

   12 |     if (delta == 1) prop.next_preset();

      |                     ^~~~

C:\Users\Olivier\Desktop\Lego Manuals\LightSabers\$Oli\ProffieOS_7.14\buttons\rotary.h:13:22: error: 'prop' was not declared in this scope

   13 |     if (delta == -1) prop.previous_preset();

      |                      ^~~~

In file included from C:\Users\Olivier\Desktop\Lego Manuals\LightSabers\$Oli\ProffieOS_7.14\ProffieOS_7.14.ino:1412:

C:\Users\Olivier\Desktop\Lego Manuals\LightSabers\$Oli\ProffieOS_7.14\display\ssd1306.h: In member function 'int WriteBulletCountOp<x, y, digits>::Controller<Width, col_t>::FillFrameBuffer(bool)':

C:\Users\Olivier\Desktop\Lego Manuals\LightSabers\$Oli\ProffieOS_7.14\display\ssd1306.h:205:12: error: 'prop' was not declared in this scope

  205 |       itoa(prop.GetBulletCount(), tmp+digits, 10);

      |            ^~~~

C:\Users\Olivier\Desktop\Lego Manuals\LightSabers\$Oli\ProffieOS_7.14\display\ssd1306.h: In member function 'void StandardDisplayController<Width, col_t>::SB_Effect2(EffectType, float)':

C:\Users\Olivier\Desktop\Lego Manuals\LightSabers\$Oli\ProffieOS_7.14\display\ssd1306.h:512:19: error: 'prop' was not declared in this scope

  512 |        } else if (prop.current_preset_name()) {

      |                   ^~~~

In file included from C:\Users\Olivier\Desktop\Lego Manuals\LightSabers\$Oli\ProffieOS_7.14\ProffieOS_7.14.ino:1418:

C:\Users\Olivier\Desktop\Lego Manuals\LightSabers\$Oli\ProffieOS_7.14\motion\mpu6050.h: In member function 'virtual void MPU6050::Loop()':

C:\Users\Olivier\Desktop\Lego Manuals\LightSabers\$Oli\ProffieOS_7.14\motion\mpu6050.h:243:13: error: 'prop' was not declared in this scope

  243 |             prop.DoAccel(

      |             ^~~~

C:\Users\Olivier\Desktop\Lego Manuals\LightSabers\$Oli\ProffieOS_7.14\motion\mpu6050.h:251:13: error: 'prop' was not declared in this scope

  251 |             prop.DoMotion(

      |             ^~~~

In file included from C:\Users\Olivier\Desktop\Lego Manuals\LightSabers\$Oli\ProffieOS_7.14\ProffieOS_7.14.ino:1419:

C:\Users\Olivier\Desktop\Lego Manuals\LightSabers\$Oli\ProffieOS_7.14\motion\lsm6ds3h.h: In member function 'void LSM6DS3H::DataReceived2()':

C:\Users\Olivier\Desktop\Lego Manuals\LightSabers\$Oli\ProffieOS_7.14\motion\lsm6ds3h.h:326:5: error: 'prop' was not declared in this scope

  326 |     prop.DoMotion(MotionUtil::FromData(databuffer, 2000.0 / 32768.0,  // 2000 dps

      |     ^~~~

In file included from C:\Users\Olivier\Desktop\Lego Manuals\LightSabers\$Oli\ProffieOS_7.14\ProffieOS_7.14.ino:1420:

C:\Users\Olivier\Desktop\Lego Manuals\LightSabers\$Oli\ProffieOS_7.14\motion\fxos8700.h: In member function 'virtual void FXOS8700::Loop()':

C:\Users\Olivier\Desktop\Lego Manuals\LightSabers\$Oli\ProffieOS_7.14\motion\fxos8700.h:169:6: error: 'prop' was not declared in this scope

  169 |      prop.DoAccel(

      |      ^~~~

In file included from C:\Users\Olivier\Desktop\Lego Manuals\LightSabers\$Oli\ProffieOS_7.14\ProffieOS_7.14.ino:1421:

C:\Users\Olivier\Desktop\Lego Manuals\LightSabers\$Oli\ProffieOS_7.14\motion\fxas21002.h: In member function 'virtual void FXAS21002::Loop()':

C:\Users\Olivier\Desktop\Lego Manuals\LightSabers\$Oli\ProffieOS_7.14\motion\fxas21002.h:72:6: error: 'prop' was not declared in this scope

   72 |      prop.DoMotion(MotionUtil::FromData(databuffer,

      |      ^~~~

In file included from C:\Users\Olivier\Desktop\Lego Manuals\LightSabers\$Oli\ProffieOS_7.14\ProffieOS_7.14.ino:1439:

C:\Users\Olivier\Desktop\Lego Manuals\LightSabers\$Oli\ProffieOS_7.14\common\booster.h: In member function 'bool Booster::Active()':

C:\Users\Olivier\Desktop\Lego Manuals\LightSabers\$Oli\ProffieOS_7.14\common\booster.h:20:9: error: 'prop' was not declared in this scope

   20 |     if (prop.NeedsPower()) return true;

      |         ^~~~

C:\Users\Olivier\Desktop\Lego Manuals\LightSabers\$Oli\ProffieOS_7.14\ProffieOS_7.14.ino: In function 'void setup()':

ProffieOS_7.14:1520:3: error: 'prop' was not declared in this scope

 1520 |   prop.FindBlade();

      |   ^~~~

In file included from C:\Users\Olivier\Desktop\Lego Manuals\LightSabers\$Oli\ProffieOS_7.14\ProffieOS_7.14.ino:1549:

C:\Users\Olivier\Desktop\Lego Manuals\LightSabers\$Oli\ProffieOS_7.14\common\clock_control.h: In member function 'virtual void ClockControl::Loop()':

C:\Users\Olivier\Desktop\Lego Manuals\LightSabers\$Oli\ProffieOS_7.14\common\clock_control.h:16:5: error: 'prop' was not declared in this scope

   16 |  || prop.NeedsPower()

      |     ^~~~

Using library Wire at version 1.0 in folder: C:\Users\Olivier\AppData\Local\Arduino15\packages\proffieboard\hardware\stm32l4\3.6\libraries\Wire 

exit status 1

'prop' was not declared in this scope


I do not understand what this means. And the answer from ChatGPT is as confusing (I feel like I am walking in a circle):

//The error message you're seeing in your Arduino IDE is related to the C++ code you're trying to compile for the Proffieboard. It indicates that there is an issue with the variable or object named prop, which is not recognized by the compiler within the scope where it is being used. Let's break down the main points:
//Key Issues:

    //1. Undefined Type MultiProp:
        /*- The error suggests that */MultiProp/* is not defined or not included correctly. The compiler is suggesting */MultiPropClass/* instead, which may be the correct type or a similar one.
          - The specific error is:*/

    error: 'MultiProp' does not name a type; did you mean 'MultiPropClass'?

        /*- This might be due to missing includes, or a typo in the type name.

    /*2. Undeclared */prop/* Variable:

        /*- The error message indicates that the variable */prop/* is not declared in the scope where it's being used.
        /*- The specific error is:*/

        'prop' was not declared in this scope

        /*- This error appears in multiple places throughout your code, indicating that the */prop/* variable is either missing its declaration or not properly instantiated before being used.

Potential Causes:

        - Incorrect or Missing Includes: The necessary header files that define */MultiProp/* or the */prop/* variable might not be included or may be incorrect. Ensure all required headers are included at the beginning of your */.ino/* or header files.

        - Typo or Misconfiguration in the Config File: The line */#define PROP_TYPE MultiProp <Saber, Blaster>/*, Detonator could have a typo or be incorrectly configured. Ensure that */MultiProp/* is correctly defined or referenced.

        - Misplaced Variable Declaration: The */prop/* variable might not be declared globally or within the correct scope. Ensure that */prop/* is declared before it is used in the various functions and classes.

How to Fix:

    1. Check for Correct Includes:
        - Ensure that all the necessary header files are included at the top of your code where */MultiProp/* and */prop/* should be defined.

    2. Correct the Type Name:
        - Double-check the type name */MultiProp/*. If */MultiPropClass/* is the correct type, modify the */#define/* statement accordingly:

    */#define PROP_TYPE MultiPropClass<Saber, Blaster>/*, Detonator

    3. Ensure */prop/* is Declared:

        - Make sure that */prop/* is declared and initialized properly before it is used in your code. If it's supposed to be an instance of */PROP_TYPE/*, ensure that it is declared like this:

        */PROP_TYPE prop;/*

    4. Check Config and Class Files:
        Ensure that the configuration in */olicomplex1.4.8_test_multi_prop.h/* and related files correctly defines the types and variables you're using.

By addressing these points, you should be able to resolve the compilation errors. If the problem persists, consider reviewing the code around where */prop/* is used to ensure it's in the correct context and that the related libraries are correctly included and configured.

What am I missing now ? Can you help me ?

Thank you for spending your valuable time just reading this.

Cheers.

Well. You’ve named the class “MultiPropClass” inside the multi prop file, however you’re trying to use it as “MultiProp” in the config.

Additionally, you probably want to specify props that exist in the MultiProp template. Saber isn’t a prop class that exists. Given you’re including fetts, I think you mean to put his prop class in the template parameters? Don’t know them off the top of my head but you can find it in the file.

Wherever he sets PROP _TYPE

1 Like

First and foremost, please change that folder name to not be `$Oli’ !!
This has nothing to do with everything else in your post. However, don’t use special characters like that in file or directory names, anywhere, like ever. :wink:

The dollar sign is a windows convention iirc

So change this:
class MultiPropClass : public virtual Saber, public virtual Blaster /*, public virtual Detonator*/ {
to this ?
class MultiProp : public virtual Saber, public virtual Blaster /*, public virtual Detonator*/ {

That is fixed, I was trying with saber.h earlier to see if I would get better results and forgot to change it back.

Done for my Lightsaber folder.

I use “$” in many folder names all the time so they appear at the top and I don’t need to look for them. Sometime I use “$$$*" or "###*” or a combination depending on the mood. :grin:
I will do all I can so you don’t see it in my posts from now on.

Alternately, you can use something like and underscore “_”.

It works the same but is not considered a special character (to my knowledge).

This thought came from older times where computer languages recognized those as parts of commands. You could.nt have spaces, periods, etc. either. So, people just got used to it, and it helps compatibility with other operating systems.

1 Like

I will use “_” from now on, at least in my Lightsaber folder. Thanks

Yeah, I use “a_” to prepend files I want to stay up top.
Look at the Voicepacks :slight_smile:

ugh. Lock files, designated as to not be visible to sharing services . smh

That would work

1 Like

It was bad (really bad) and missing many things. I was too tired last night when I posted. If I end-up getting something much better, I will re-post it.

Now I am getting close (at least for switching between saber & blaster). I only get 1 compile error about “Event2” but I do not know what is Event2 ?

Eddit: file deleted since I have posted a working one below/
& Error Log:

In file included from C:\Users\Olivier\Desktop\LightSabers\ProffieOS_7.14\config\olicomplex1.5.005_test_multi_prop.h:143,
                 from C:\Users\Olivier\Desktop\LightSabers\ProffieOS_7.14\ProffieOS_7.14.ino:522:
C:\Users\Olivier\Desktop\LightSabers\ProffieOS_7.14\props\multi_prop.h: In instantiation of 'class MultiProp<SaberFett263Buttons, Blaster>':
C:\Users\Olivier\Desktop\LightSabers\ProffieOS_7.14\ProffieOS_7.14.ino:529:11:   required from here
C:\Users\Olivier\Desktop\LightSabers\ProffieOS_7.14\props\multi_prop.h:64:7: error: no unique final overrider for 'virtual bool PropBase::Event2(BUTTON, EVENT, uint32_t)' in 'MultiProp<SaberFett263Buttons, Blaster>'
   64 | class MultiProp : public virtual Saber, public virtual Blaster {            //, public virtual Detonator
      |       ^~~~~~~~~
Using library Wire at version 1.0 in folder: C:\Users\Olivier\AppData\Local\Arduino15\packages\proffieboard\hardware\stm32l4\3.6\libraries\Wire 
exit status 1
Error compiling for board Proffieboard V3.

My CONFIG_PROP is commented out, in multi_prop.h file.

Thank you for any help.

I think it’s just telling you that you need to add an Event2 function which then selects which Event2 function to call.

Yes it seems I must add Event2, but what is it supposed to do ?

Or what is the event Event2 ?

There is an Event2 in every prop file but I do not understand how an Event2 is relevant in multi_prop.h since it only use TWO_BUTTONS_X_LONG_PUSH which is one event and not two ?

May I make it do nothing ?

Sorry I fail to grasp the concept of it’s necessity.

Basically you should forward the inputs to your base classes based on the switched mode.

So in Event2 switch on mode, then call, for example, Saber::Event2(…)

You just have to give all the events to the underlying prop.

This is what I believe I understand (please correct me if I am wrong):

Event and Event2 come from the other props (aka saber_fett263_buttons.h or blaster.h).

I need to tell multi_prop.h how to handle Event & Event2 from the other props.

Finally, it is compiling at least for the first two props (SaberFett263Buttons & Blaster)

Edit: file deleted, newer version can be found further (much further) down bellow.

Sketch uses 212048 bytes (41%) of program storage space. Maximum is 507904 bytes.

I have no way yet to test if it works as intended since my chassis, Proffie board & soldering iron are still packed somewhere after my house move.

I would love if one of you kind gentlemen would test it for me.

Now I will try to add the detonator & test with the other sabers & blasters.

Thank you for your help so far.

I don’t know if it will work, but it looks fairly reasonable, and the Event2 you added seems like it’s doing the right thing.

1 Like

I can chime in on this part:

    // Provide feedback for mode switch (sound, LED, etc.)
    // I would like a computer female voice prompt saying: "Saber mode", "Blaster mode", "Detonator mode", "... mode"
    //

right after your #include "prop_base.h" you can define custom sound effects something like:

EFFECT(blastermode); 
EFFECT(sabermode); 
EFFECT(detmode); 

then in your SbEffect() switch cases you can play them like:

    void SB_Effect(EffectType effect, float location) override {
        switch (currentMode) {
            case PropMode::SABER:
                hybrid_font.PlayPolyphonic(&SFX_sabermode);
                Saber::SB_Effect(effect, location);
                break;
            case PropMode::BLASTER:
                hybrid_font.PlayPolyphonic(&SFX_blastermode);
                Blaster::SB_Effect(effect, location);
                break;
            //case PropMode::DETONATOR:
            // hybrid_font.PlayPolyphonic(&SFX_detmode);
            //    Detonator::SB_Effect(effect, location);
            //    break;
       }

You should probably have a backup plan for if those sounds don’t exist, maybe like:

  if (!hybrid_font.PlayPolyphonic(&SFX_blastermode)) {
    beeper.Beep(0.05, 2000);
    beeper.Silence(0.05);
    beeper.Beep(0.05, 2000);
}

Of course then you need sounds for them.


2 Likes

Very cool!

Thank you, thank you, thank you.

Sound files already added to my common folder.

And your code has been mostly integrated except for:

Do I add it like this:

     void SB_Effect(EffectType effect, float location) override {
        switch (currentMode) {
           case PropMode::BLASTER:
                if (!hybrid_font.PlayPolyphonic(&SFX_blastermode)) {
                    beeper.Beep(0.05, 2000);
                    beeper.Silence(0.05);
                    beeper.Beep(0.05, 2000);
                else
                hybrid_font.PlayPolyphonic(&SFX_blastermode);
                }
                Blaster::SB_Effect(effect, location);
                break;
...

Is this correct ?

Also, since multi_prop.h needs 2 buttons, I think I should add this:

#ifdef NUM_BUTTONS < 2
#error Your prop NEEDS 2 or more buttons
#endif

Is this correct coding ?