Benoît GEISLER
/
ActivateOutput
Activation of outputs using serial and user button on ticker interrupt
Engine.h@6:63c1ee4fb6be, 2014-06-05 (annotated)
- Committer:
- ggmero67
- Date:
- Thu Jun 05 18:41:34 2014 +0000
- Revision:
- 6:63c1ee4fb6be
- Parent:
- 4:038c13df0c2c
Rename SerialPort into PC_Com + find bug in write function
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ggmero67 | 2:63a88ccbf0b9 | 1 | #pragma once |
ggmero67 | 1:f23460f7574d | 2 | #include "mbed.h" |
ggmero67 | 1:f23460f7574d | 3 | #include <map> |
ggmero67 | 6:63c1ee4fb6be | 4 | #include "PC_Com.h" |
ggmero67 | 1:f23460f7574d | 5 | #include "Note.h" |
ggmero67 | 1:f23460f7574d | 6 | |
ggmero67 | 1:f23460f7574d | 7 | |
ggmero67 | 1:f23460f7574d | 8 | |
ggmero67 | 1:f23460f7574d | 9 | typedef enum { |
ggmero67 | 1:f23460f7574d | 10 | ON_COMMAND, ///< The command is directly done |
ggmero67 | 1:f23460f7574d | 11 | ON_TICK ///< Perform changes every time applyChanges is called |
ggmero67 | 1:f23460f7574d | 12 | } e_modeOfUsing; |
ggmero67 | 1:f23460f7574d | 13 | |
ggmero67 | 1:f23460f7574d | 14 | class Engine |
ggmero67 | 1:f23460f7574d | 15 | { |
ggmero67 | 1:f23460f7574d | 16 | public: |
ggmero67 | 1:f23460f7574d | 17 | /** Create the engine in charge of handling note activation |
ggmero67 | 1:f23460f7574d | 18 | * |
ggmero67 | 1:f23460f7574d | 19 | * @param mode select if we directly apply the command or wait for a tick |
ggmero67 | 1:f23460f7574d | 20 | */ |
ggmero67 | 6:63c1ee4fb6be | 21 | Engine(e_modeOfUsing mode = ON_COMMAND); |
ggmero67 | 1:f23460f7574d | 22 | ~Engine(); |
ggmero67 | 6:63c1ee4fb6be | 23 | |
ggmero67 | 4:038c13df0c2c | 24 | /**Starts the engine*/ |
ggmero67 | 4:038c13df0c2c | 25 | void start(void); |
ggmero67 | 4:038c13df0c2c | 26 | /**Changes the Tempo |
ggmero67 | 4:038c13df0c2c | 27 | * This will stops the timer, you have to restart it |
ggmero67 | 4:038c13df0c2c | 28 | */ |
ggmero67 | 4:038c13df0c2c | 29 | void changeTempo(int newTempo); |
ggmero67 | 4:038c13df0c2c | 30 | /**Stops the engine*/ |
ggmero67 | 4:038c13df0c2c | 31 | void stop(void); |
ggmero67 | 4:038c13df0c2c | 32 | |
ggmero67 | 1:f23460f7574d | 33 | /** Start playing a note*/ |
ggmero67 | 1:f23460f7574d | 34 | bool startNote(e_NoteName noteToStart); |
ggmero67 | 1:f23460f7574d | 35 | /** Stop playing a note*/ |
ggmero67 | 1:f23460f7574d | 36 | bool stopNote(e_NoteName noteToStop); |
ggmero67 | 1:f23460f7574d | 37 | |
ggmero67 | 1:f23460f7574d | 38 | private: |
ggmero67 | 6:63c1ee4fb6be | 39 | |
ggmero67 | 6:63c1ee4fb6be | 40 | Ticker tick; ///< link the note name with their instance |
ggmero67 | 1:f23460f7574d | 41 | e_modeOfUsing modeOfUsing; |
ggmero67 | 4:038c13df0c2c | 42 | float tempo; |
ggmero67 | 6:63c1ee4fb6be | 43 | Note notes[NB_NOTES]; ///< link the note name with their instance |
ggmero67 | 1:f23460f7574d | 44 | std::map<e_NoteName, Note>::iterator notesIterator; |
ggmero67 | 6:63c1ee4fb6be | 45 | |
ggmero67 | 6:63c1ee4fb6be | 46 | /** Converts a tempo into millisec |
ggmero67 | 6:63c1ee4fb6be | 47 | * Used for defining the the timer tick |
ggmero67 | 6:63c1ee4fb6be | 48 | */ |
ggmero67 | 6:63c1ee4fb6be | 49 | float ConvertTempo(int tempo); |
ggmero67 | 6:63c1ee4fb6be | 50 | |
ggmero67 | 6:63c1ee4fb6be | 51 | /** Cyclic function that will be called if mode = ON_TICK |
ggmero67 | 6:63c1ee4fb6be | 52 | * this will apply all the changes done during 2 consecutives calls |
ggmero67 | 6:63c1ee4fb6be | 53 | */ |
ggmero67 | 6:63c1ee4fb6be | 54 | void applyChanges(void); |
ggmero67 | 6:63c1ee4fb6be | 55 | }; |