Comments (7)
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.
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.
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.
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.
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.
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.
(Transferring this to Discussions because I don't think it's a bug in the library.)
from aceroutine.
Related Issues (15)
- delayStartMillis should be a uint32_t instead of uint16_t HOT 2
- Resetting a coroutine HOT 10
- Function equivalent to PT_RESTART? HOT 2
- how to re use coroutine 【fixed】 HOT 1
- Proposal: remove the 2-argument COROUTINE(class, name) macro HOT 1
- restarting a Coroutine after it has finished HOT 9
- Stack overflow from CoroutineScheduler::list() after suspend() -> resume() HOT 5
- `reset()` causing coroutine to break somehow HOT 3
- COROUTINE_DELAY_SECONDS & COROUTINE_DELAY_MICROS not working HOT 5
- Setup() lifecycle method in Manual Routine method. HOT 6
- for loops inside COROUTINE don't seem to work HOT 2
- Examples don't set LED pinMode HOT 5
- CoRoutine will stop work when you make type conversion in it... HOT 6
- Microsecond Timing? HOT 15
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aceroutine.