GithubHelp home page GithubHelp logo

Comments (7)

bxparks avatar bxparks commented on August 31, 2024

Thanks for the encouraging words!

With regards to the error message, I have not seen this. Can you send information on how to reproduce? What board? What tool chain?

from aceroutine.

Code-Assembly avatar Code-Assembly commented on August 31, 2024

Hi silly of me not to include details:

Platform is STM32Duino on Platform IO the board is a RobotDyn APM32F103CB ( Effectively an STM32F103CB clone with 96MHz 128k Flash and 20k RAM )

I'm sure the issue is in my implementation so I'm rather hoping we can get an example that has a separate files but here is my non working implementation

SoundManager.h

#ifndef SoundManager_H
#define SoundManager_H

#include <Arduino.h>
#include <AceRoutine.h>

using namespace ace_routine;

enum Sound
{
    MUTE,
    NOTIFICATION,
    ALERT,
    WARNING,
    DANGER,
};

class SoundManager : public Coroutine
{
private:
    uint8_t _audioOutputPin;
    Sound _currentSound = MUTE;
    bool _loop;

public:
    void begin(uint8_t audioOutputPin);
    int virtual runCoroutine();
    void play(Sound sound, bool loop = false);
    void mute();
};

#endif

SoundManager.cpp

#include <Arduino.h>
#include "SoundManager.h"
#include "AudioNotes.h"

void SoundManager::begin(uint8_t audioOutputPin)
{
    _audioOutputPin = audioOutputPin;
}

int SoundManager::runCoroutine()
{
    COROUTINE_LOOP()
    {
        switch (_currentSound)
        {
        case Sound::NOTIFICATION:
            tone(_audioOutputPin, NOTE_B4);
            COROUTINE_DELAY(500);
            noTone(_audioOutputPin);
            COROUTINE_DELAY(125);

            tone(_audioOutputPin, NOTE_D4);
            COROUTINE_DELAY(125);
            noTone(_audioOutputPin);
            COROUTINE_DELAY(125 * 1.05);
            break;
        case Sound::ALERT:
            break;
        case Sound::WARNING:
            break;
        case Sound::DANGER:
            break;
        case Sound::MUTE:
            mute();
            break;
        }

        if (!_loop)
            mute();
    }
}

void SoundManager::play(Sound sound, bool loop)
{
    _currentSound = sound;
    _loop = loop;
}

void SoundManager::mute()
{
    _currentSound = Sound::MUTE;
    noTone(_audioOutputPin);
}

Main.cpp

#include <Arduino.h>
#include <AceCommon.h>
#include <AceRoutine.h>

#include "../lib/WLCConfig.h"
#include "../lib/SoundManager.h"

SoundManager soundManager;

void setup()
{
    pinMode(WLC::Pins::AUDIO_PWM_OUT, OUTPUT);
    soundManager.begin(WLC::Pins::AUDIO_PWM_OUT);
    soundManager.play(Sound::NOTIFICATION, true);
}

void loop()
{
    soundManager.runCoroutine();
}

from aceroutine.

Code-Assembly avatar Code-Assembly commented on August 31, 2024

Working implementation everything in one file

SoundManager.h

#ifndef SoundManager_H
#define SoundManager_H

#include <Arduino.h>
#include <AceRoutine.h>
#include "AudioNotes.h"

using namespace ace_routine;

enum Sound
{
    MUTE,
    NOTIFICATION,
    ALERT,
    WARNING,
    DANGER,
};

class SoundManager : public Coroutine
{
private:
    uint8_t _audioOutputPin;
    Sound _currentSound = MUTE;
    bool _loop;

public:
    void begin(uint8_t audioOutputPin)
    {
        _audioOutputPin = audioOutputPin;
    }

    int runCoroutine() override
    {
        COROUTINE_LOOP()
        {
            switch (_currentSound)
            {
            case Sound::NOTIFICATION:
                tone(_audioOutputPin, NOTE_B4);
                COROUTINE_DELAY(500);
                noTone(_audioOutputPin);
                COROUTINE_DELAY(125);
                
                tone(_audioOutputPin, NOTE_D4);
                COROUTINE_DELAY(125);
                noTone(_audioOutputPin);
                COROUTINE_DELAY(125 * 1.05);

                // COROUTINE_DELAY(1000);
                break;
            case Sound::ALERT:
                break;
            case Sound::WARNING:
                break;
            case Sound::DANGER:
                break;
            case Sound::MUTE:
                mute();
                break;
            }

            if (!_loop)
                mute();
        }
    }

    void play(Sound sound, bool loop = false)
    {
        _currentSound = sound;
        _loop = loop;
    }

    void mute()
    {
        _currentSound = Sound::MUTE;
        noTone(_audioOutputPin);
    }
};

#endif

from aceroutine.

bxparks avatar bxparks commented on August 31, 2024

I don't use PlatformIO, so I can't provide official support for it. But can you paste in the exact error message from the compiler? Maybe I can see something obvious.

Also, you have tried compiling your program with the Arduino IDE or CLI? I have used AceRoutine coroutines defined in separate *.h and *.cpp files without problems in many personal projects.

from aceroutine.

Code-Assembly avatar Code-Assembly commented on August 31, 2024

The error i receive is

Building in release mode
Linking .pio/build/LaunchController/firmware.elf
/Users/aadil.cachalia/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: .pio/build/LaunchController/src/main.cpp.o: in function `_GLOBAL__sub_I_soundManager':
main.cpp:(.text.startup._GLOBAL__sub_I_soundManager+0x24): undefined reference to `vtable for SoundManager'
collect2: error: ld returned 1 exit status
*** [.pio/build/LaunchController/firmware.elf] Error 1

have used AceRoutine coroutines defined in separate *.h and *.cpp files without problems in many personal projects.

I'd really appreciate it I could see an example of how you do it. My limitation is likely in my lack of c++ knowledge, of file linking and language syntax ect. that is the root of the issue.

from aceroutine.

bxparks avatar bxparks commented on August 31, 2024

I don't know the PlatformIO environment, but the main.cpp.o seems strange to me. Usually the object file is named main.o. Did you try compiling from a clean, i.e. wiping out *.o files and any compiler cache?

I looked at my projects where I defined coroutines in separate *.h and *.cpp files, but unfortunately almost all of them are in private repos. The one example that is in a public repo is waaay too complicated to use as an example.

So I just submitted 40a5d55 where I extracted the SoundManagerRoutine and SoundRoutine in the examples/SoundManager directory into separate files. Take a look in my develop branch. I verified that this works under both Arduino IDE, Arduino CLI and under Linux (using EpoxyDuino). It ought work under PlatformIO if you configure it properly.

from aceroutine.

bxparks avatar bxparks commented on August 31, 2024

(Transferring this to Discussions because I don't think it's a bug in the library.)

from aceroutine.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.