Plaquette
 
Loading...
Searching...
No Matches
PqCore.h
1/*
2 * PqCore.h
3 *
4 * (c) 2015 Sofian Audry :: info(@)sofianaudry(.)com
5 * (c) 2015 Thomas O Fredericks :: tof(@)t-o-f(.)info
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#ifndef PQ_CORE_H_
22#define PQ_CORE_H_
23
24#if (defined(ARDUINO) && ARDUINO >= 100) || defined(EPOXY_DUINO)
25#include <Arduino.h>
26#else
27#include <WProgram.h>
28#endif
29
30#include "pq_math.h"
31
32#include <stdint.h>
33#include <float.h>
34
35#include <limits.h>
36
37#include "HybridArrayList.h"
38#include "PqEvents.h"
39#include "pq_globals.h"
40#include "pq_constrain.h"
41#include "pq_map.h"
42#include "pq_phase_utils.h"
43#include "pq_random.h"
44#include "pq_time.h"
45
46namespace pq {
47
49enum {
50 DIRECT,
51 INVERTED,
52 INTERNAL_PULLUP,
53 SOURCE = DIRECT, // deprecated
54 SINK = INVERTED // deprecated
55};
56
57class Unit;
58
60class Engine {
61 friend class Unit;
62
63public:
64 Engine();
65 ~Engine();
66
68 void preBegin(unsigned long baudrate=PLAQUETTE_SERIAL_BAUD_RATE);
69
71 void postBegin();
72
74 inline void preStep();
75
80 inline bool timeStep();
81
83 inline void begin(unsigned long baudrate=PLAQUETTE_SERIAL_BAUD_RATE);
84
86 inline bool step();
87
92 inline void end();
93
95 size_t nUnits() { return _unitsEndIndex - _unitsBeginIndex; }
96
104 float seconds(bool referenceTime=true) const;
105
113 uint32_t milliSeconds(bool referenceTime=true) const;
114
122 uint64_t microSeconds(bool referenceTime=true) const;
123
125 unsigned long nSteps() const { return _nSteps; }
126
128 bool hasAutoSampleRate() const { return _autoSampleRate; }
129
131 void autoSampleRate();
132
134 void sampleRate(float sampleRate);
135
137 void samplePeriod(float samplePeriod);
138
140 float sampleRate() const { return _sampleRate; }
141
143 float samplePeriod() const { return (_samplePeriod ? _samplePeriod : (_samplePeriod = frequencyToPeriod(_sampleRate))); }
144
146 uint32_t deltaTimeMicroSeconds() const { return _deltaTimeMicroSeconds; }
147
149 float deltaTimeSecondsTimesFixed32Max() const { return _deltaTimeSecondsTimesFixed32Max; }
150
152 static Engine& primary();
153
155 bool isPrimary() const { return this == &primary(); }
156
167 bool randomTrigger(float timeWindow);
168
169private:
171 void add(Unit* component);
172
174 void remove(Unit* component);
175
176 // Internal use. Sets sample rate and sample period.
177 inline void _setSampleRate(float sampleRate);
178
179 // Internal use, needs to be called periodically. Updates _totalGlobalMicroSeconds.
180 static micro_seconds_t _updateGlobalMicroSeconds();
181
182private:
183 // Shared static container containing all units. Static because it is shared between all engines.
184 // Units from the primary engine are always located at the begnning, then units from other engines.
185 static HybridArrayList<Unit*, PLAQUETTE_MAX_UNITS>& units();
186
187 // Range of this engine's units within the _units array list.
188 size_t _unitsBeginIndex; // begin index
189 size_t _unitsEndIndex; // end index (= _unitsBeginIndex + nUnits())
190
191 // Sampling rate (ie. how many times per seconds step() is called).
192 float _sampleRate;
193
194 // Sampling period (ie. 1.0 / sampleRate()).
195 mutable float _samplePeriod;
196
197 // Whether the auto sample rate mode is activated.
198 float _targetSampleRate;
199
200 // Snapshot of time in seconds from current step.
201 micro_seconds_t _microSeconds;
202 // uint32_t _previousMicroSeconds; // This is the 32 first bits of microseconds used for inter-step calculations.
203
204 // Target time for next step (when using sampleRate(float)).
205 micro_seconds_t _targetTime;
206
207 // Step state for state machine to manage sample rate.
208 enum StepState {
209 STEP_INIT,
210 STEP_WAIT,
211 STEP_WAIT_OVERFLOW
212 };
213
214 // Current step state.
215 StepState _stepState;
216
217 // Number of microseconds between steps.
218 uint32_t _deltaTimeMicroSeconds;
219
220 // Number of seconds between steps time FIXED_32_MAX.
221 float _deltaTimeSecondsTimesFixed32Max;
222
223 // Number of microseconds between steps.
224 uint32_t _targetDeltaTimeMicroSeconds;
225
226 // Number of steps accomplished.
227 unsigned long _nSteps;
228
229 // True if using auto sample rate mode.
230 bool _autoSampleRate;
231
232 // True if begin has been completed..
233 bool _beginCompleted;
234
235 // True during first run.
236 bool _firstRun;
237
238 // Used to keep track of events.
239 EventManager _eventManager;
240
241 // Global time in microseconds.
242 static micro_seconds_t _totalGlobalMicroSeconds;
243
244private:
245 // Prevent copy-construction and assignment.
246 Engine(const Engine&);
247 Engine& operator=(const Engine&);
248};
249
251extern Engine& Plaquette;
252
254unsigned long nSteps();
255
257bool hasAutoSampleRate();
258
260void autoSampleRate();
261
263void sampleRate(float sampleRate);
264
266void samplePeriod(float samplePeriod);
267
269float sampleRate();
270
272float samplePeriod();
273
285bool randomTrigger(float timeWindow);
286
288void beginSerial(unsigned long baudRate);
289
291 private:
292 // Prevents assignation operations by making them private.
293 Chainable& operator=(bool);
294 Chainable& operator=(int);
295 Chainable& operator=(float);
296 Chainable& operator=(Chainable&);
297
298 public:
300 virtual float get() { return 0.0f; }
301
303 operator float() { return get(); }
304
307 virtual float mapTo(float toLow, float toHigh) { return constrain(get(), toLow, toHigh); } // default: just constrain
308
314 virtual float put(float value) { return get(); } // do nothing by default (read-only)
315
317 static bool analogToDigital(float f) { return (f >= 0.5); }
318
320 static float digitalToAnalog(bool b) { return (b ? 1.0f : 0.0f); }
321
322 public:
324 // NOTE: This operator is defined as explicit so that boolean expression like
325 // "if (obj)" use the bool() operator while other expressions can use the float() operator.
326 explicit operator bool() { return Chainable::analogToDigital(get()); }
327};
328
335class Unit : public Chainable {
336 friend class Engine;
337 friend class EventManager;
338
339protected:
340 virtual void begin() {}
341 virtual void step() {}
342
343public:
344 // Clears all event listeners.
345 virtual void clearEvents();
346
348 float seconds() const { return _engine->seconds(); }
349
351 uint32_t milliSeconds() const { return _engine->milliSeconds(); }
352
354 uint64_t microSeconds() const { return _engine->microSeconds(); }
355
357 unsigned long nSteps() const { return _engine->nSteps(); }
358
360 float sampleRate() const { return _engine->sampleRate(); }
361
363 float samplePeriod() const { return _engine->samplePeriod(); }
364
365protected:
368 virtual ~Unit();
369
371 virtual bool eventTriggered(EventType eventType) { return false; }
372
374 virtual void onEvent(EventCallback callback, EventType eventType);
375
376private:
377 // The engine that owns this unit.
378 Engine* _engine;
379
380protected:
382 Engine* engine() const { return _engine; }
383};
384
386class DigitalUnit : public Unit {
387protected:
390
391public:
393 virtual bool isOn() { return false; }
394
396 virtual bool isOff() { return !isOn(); }
397
399 virtual int getInt() { return isOn() ? 1 : 0; }
400
402 virtual float get() { return getInt(); }
403
405 virtual bool on() { return putOn(true); }
406
408 virtual bool off() { return putOn(false); }
409
415 virtual float put(float value) {
417 }
418
424 virtual bool putOn(bool value) { return isOn(); } // do nothing by default (read-only)
425
427 virtual float mapTo(float toLow, float toHigh) { return isOn() ? toHigh : toLow; }
428
430 operator bool() { return isOn(); }
431
432 // IMPORTANT: LEAVE COMMENTED
433 // virtual operator int() { return getInt(); }
434
435 // IMPORTANT: This operator is redefined as explicit to make default return a bool.
436 explicit operator float() { return Unit::operator float(); }
437};
438
444class AnalogSource : public Unit {
445public:
448 AnalogSource(float initialValue, Engine& engine = Engine::primary()) : Unit(engine) { _value = constrain01(initialValue); }
449 virtual ~AnalogSource() {}
450
452 virtual float get() { return _value; }
453
455 virtual float mapTo(float toLow, float toHigh) { return mapFrom01(get(), toLow, toHigh); }
456
457protected:
458 float _value;
459};
460
463public:
466 DigitalSource(bool initialValue, Engine& engine = Engine::primary()) : DigitalUnit(engine), _onValue(initialValue), _prevOnValue(initialValue), _changeState(0) {}
467
469 virtual bool isOn() { return _onValue; }
470
476 virtual bool putOn(bool value) { return (_onValue = value); } // do nothing by default (read-only)
477
479 virtual bool rose() { return changeState() > 0; }
480
482 virtual bool fell() { return changeState() < 0; }
483
485 virtual bool changed() { return changeState() != 0; }
486
488 virtual bool toggle() { return putOn(!isOn()); }
489
491 virtual int8_t changeState() { return _changeState; }
492
494 virtual void onRise(EventCallback callback) { onEvent(callback, EVENT_RISE); }
495
497 virtual void onFall(EventCallback callback) { onEvent(callback, EVENT_FALL); }
498
500 virtual void onChange(EventCallback callback) { onEvent(callback, EVENT_CHANGE); }
501
502protected:
503 void _updateChangeState() {
504 _changeState = (int8_t)_onValue - (int8_t)_prevOnValue;
505 _prevOnValue = _onValue;
506 }
507
509 virtual bool eventTriggered(EventType eventType) {
510 switch (eventType) {
511 case EVENT_CHANGE: return changed();
512 case EVENT_RISE: return rose();
513 case EVENT_FALL: return fell();
514 default: return DigitalUnit::eventTriggered(eventType);
515 }
516 }
517
518 // The value contained in the unit.
519 bool _onValue : 1;
520
521 // Previous value, used to compute change state.
522 bool _prevOnValue : 1;
523
524 // The change state contained in the unit.
525 int8_t _changeState : 2;
526
527 // Unused extra space.
528 uint8_t _data : 4;
529};
530
531// Value to unit operators ///////////////////////////////////////
532
533// Base value to unit operator.
534inline Chainable& operator>>(float value, Chainable& unit) {
535 unit.put(value);
536 return unit;
537}
538
539// NOTE: do not change the order of this operator (it needs to be set *after* the >>(float, Chainable&)).
540inline Chainable& operator>>(Chainable& source, Chainable& sink) {
541 return pq::operator>>(source.get(), sink);
542}
543
544inline Chainable& operator>>(double value, Chainable& unit) {
545 return pq::operator>>((float)value, unit);
546}
547
548inline Chainable& operator>>(bool value, Chainable& unit) {
549 return pq::operator>>(Chainable::digitalToAnalog(value), unit);
550}
551
552// This code is needed on the Curie and ARM chips.
553// Otherwise it causes an ambiguous operator error.
554#if defined(__arc__) || defined(__arm__)
555inline Chainable& operator>>(int value, Chainable& unit) {
556 return pq::operator>>((float)value, unit);
557}
558#endif
559
560inline Chainable& operator>>(int8_t value, Chainable& unit) {
561 return pq::operator>>((float)value, unit);
562}
563
564inline Chainable& operator>>(uint8_t value, Chainable& unit) {
565 return pq::operator>>((float)value, unit);
566}
567
568inline Chainable& operator>>(int16_t value, Chainable& unit) {
569 return pq::operator>>((float)value, unit);
570}
571
572inline Chainable& operator>>(uint16_t value, Chainable& unit) {
573 return pq::operator>>((float)value, unit);
574}
575
576inline Chainable& operator>>(int32_t value, Chainable& unit) {
577 return pq::operator>>((float)value, unit);
578}
579
580inline Chainable& operator>>(uint32_t value, Chainable& unit) {
581 return pq::operator>>((float)value, unit);
582}
583
584inline Chainable& operator>>(int64_t value, Chainable& unit) {
585 return pq::operator>>((float)value, unit);
586}
587
588inline Chainable& operator>>(uint64_t value, Chainable& unit) {
589 return pq::operator>>((float)value, unit);
590}
591
592// // Unit to value operators ///////////////////////////////////////
593// THIS PART IS COMMENTED OUT BECAUSE IT CAUSES AMBIGUOUS OPERATOR ERRORS
594
595// inline bool& operator>>(DigitalUnit& unit, bool& value) {
596// return (value = unit.isOn());
597// }
598
599// // This code is needed on the Curie-based AVRs.
600// #if defined(__arc__)
601// inline int& operator>>(DigitalUnit& unit, int& value) {
602// return (value = unit.getInt());
603// }
604// #endif
605
606// inline int8_t& operator>>(DigitalUnit& unit, int8_t& value) {
607// return (value = unit.getInt());
608// }
609
610// inline uint8_t& operator>>(DigitalUnit& unit, uint8_t& value) {
611// return (value = unit.getInt());
612// }
613
614// inline int16_t& operator>>(DigitalUnit& unit, int16_t& value) {
615// return (value = unit.getInt());
616// }
617
618// inline uint16_t& operator>>(DigitalUnit& unit, uint16_t& value) {
619// return (value = unit.getInt());
620// }
621
622// inline int32_t& operator>>(DigitalUnit& unit, int32_t& value) {
623// return (value = unit.getInt());
624// }
625
626// inline uint32_t& operator>>(DigitalUnit& unit, uint32_t& value) {
627// return (value = unit.getInt());
628// }
629
630// inline int64_t& operator>>(DigitalUnit& unit, int64_t& value) {
631// return (value = unit.getInt());
632// }
633
634// inline uint64_t& operator>>(DigitalUnit& unit, uint64_t& value) {
635// return (value = unit.getInt());
636// }
637
638// inline float& operator>>(Unit& unit, float& value) {
639// return (value = unit.get());
640// }
641
642// inline double& operator>>(Unit& unit, double& value) {
643// return (value = unit.get());
644// }
645
648public:
649 PinConfig(uint8_t pin, uint8_t mode) : _pin(pin), _mode(mode) {}
650 virtual ~PinConfig() {}
651
653 uint8_t pin() const { return _pin; }
654
656 uint8_t mode() const { return _mode; }
657
659 virtual void mode(uint8_t mode) { _mode = mode; }
660
661protected:
662 // The attached pin.
663 uint8_t _pin;
664
665 // The mode (varies according to context).
666 uint8_t _mode;
667};
668
669// Inline methods.
670
672 // Update every component.
673 for (size_t i=_unitsBeginIndex; i != _unitsEndIndex; i++) {
674 units()[i]->step();
675 }
676
677 // Look for events.
678 _eventManager.step();
679}
680
682 // Calculate true sample rate.
683 _updateGlobalMicroSeconds();
684
685 // Compute inter-step time.
686 _deltaTimeMicroSeconds = _totalGlobalMicroSeconds.micros32.base - _microSeconds.micros32.base;
687 float trueSampleRate = (_deltaTimeMicroSeconds ? SECONDS_TO_MICROS / _deltaTimeMicroSeconds : PLAQUETTE_MAX_SAMPLE_RATE);
688
689 // If autoSampleRate is off: wait in order to synchronize seconds with real time.
690 if (!_autoSampleRate) {
691
692 // Initilize step state.
693 if (_stepState == STEP_INIT) {
694 // Target time = current time + 1/_targetSampleRate
695 _targetTime = _microSeconds;
696 _targetTime.micros32.base += _targetDeltaTimeMicroSeconds;
697
698 // Check for overflow.
699 if (_targetTime.micros32.base >= _microSeconds.micros32.base) { // if target time is in the future: no overflow.
700 _stepState = STEP_WAIT;
701 }
702 else { // overflow
703 _targetTime.micros32.overflows++;
704 _stepState = STEP_WAIT_OVERFLOW;
705 }
706 }
707
708 // Process waiting state: will return false if still waiting, otherwise will complete the function.
709 if (_stepState == STEP_WAIT) {
710 // Still needs to wait.
711 if (_totalGlobalMicroSeconds.micros32.base < _targetTime.micros32.base)
712 return false; // break
713 }
714 else { // stepState == STEP_WAIT_OVERFLOW
715 // Still needs to wait.
716 if (_totalGlobalMicroSeconds.micros64 < _targetTime.micros64)
717 return false; // break
718 }
719
720 // Reset state.
721 _stepState = STEP_INIT;
722 }
723
724 // Update sample rate and current time to "true" / actual values.
725 _setSampleRate(trueSampleRate);
726
727 // Calculate delta time in fixed point.
728 uint64_t deltaTimeMicroSeconds64 = (uint64_t)_deltaTimeMicroSeconds;
729 _deltaTimeSecondsTimesFixed32Max = ((deltaTimeMicroSeconds64 << 32) - deltaTimeMicroSeconds64) * MICROS_TO_SECONDS;
730
731 // Sync reference time with global (true) time.
732 _microSeconds = _totalGlobalMicroSeconds;
733
734 // Increment step.
735 _nSteps++;
736
737 return true;
738}
739
740void Engine::begin(unsigned long baudrate) {
741 preBegin(baudrate);
742}
743
745 // On first run: do a post-begin.
746 if (_firstRun) { // the compiler should make this branching step effectively CPU-free
747 postBegin();
748 _firstRun = false;
749 return false;
750 }
751
752 // Otherwise: do a step.
753 else if (timeStep()) { // timeStep() will return false if we need to wait due to restrictive sampleRate(float)
754 // Do the pre-step.
755 preStep();
756 return true;
757 }
758 else
759 return false;
760}
761
762void Engine::_setSampleRate(float sampleRate) {
763 _sampleRate = max(sampleRate, FLT_MIN); // cannot be zero
764 _samplePeriod = 0; // set to zero to reset cache
765}
766
767} // namespace pq
768
769#endif
An analog analog source that contains a value constrained to a finite range (typically in [0,...
Definition PqCore.h:444
virtual float mapTo(float toLow, float toHigh)
Maps value to new range.
Definition PqCore.h:455
virtual float get()
Returns value in [0, 1].
Definition PqCore.h:452
AnalogSource(Engine &engine=Engine::primary())
Constructor.
Definition PqCore.h:447
Definition PqCore.h:290
virtual float get()
Returns value (typically between 0 and 1, may vary depending on class).
Definition PqCore.h:300
virtual float mapTo(float toLow, float toHigh)
Maps value to new range.
Definition PqCore.h:307
static float digitalToAnalog(bool b)
Converts digital (bool) value to analog (float) value.
Definition PqCore.h:320
static bool analogToDigital(float f)
Converts analog (float) value to digital (bool) value.
Definition PqCore.h:317
virtual float put(float value)
Pushes value into the unit.
Definition PqCore.h:314
A digital source that contains a true/false value.
Definition PqCore.h:462
virtual bool eventTriggered(EventType eventType)
Returns true iff an event of a certain type has been triggered.
Definition PqCore.h:509
virtual bool putOn(bool value)
Pushes value into the unit.
Definition PqCore.h:476
virtual void onRise(EventCallback callback)
Registers event callback on rise event.
Definition PqCore.h:494
DigitalSource(Engine &engine=Engine::primary())
Constructor.
Definition PqCore.h:465
virtual void onFall(EventCallback callback)
Registers event callback on fall event.
Definition PqCore.h:497
virtual bool rose()
Returns true if the value rose.
Definition PqCore.h:479
virtual int8_t changeState()
Difference between current and previous value of the unit.
Definition PqCore.h:491
virtual bool toggle()
Switches between on and off.
Definition PqCore.h:488
virtual bool changed()
Returns true if the value changed.
Definition PqCore.h:485
virtual bool isOn()
Returns true iff the input is "on".
Definition PqCore.h:469
virtual bool fell()
Returns true if the value fell.
Definition PqCore.h:482
virtual void onChange(EventCallback callback)
Registers event callback on change event.
Definition PqCore.h:500
A generic class representing a simple digital (true/false)unit.
Definition PqCore.h:386
DigitalUnit(Engine &engine=Engine::primary())
Constructor.
Definition PqCore.h:389
virtual bool putOn(bool value)
Pushes value into the unit.
Definition PqCore.h:424
virtual int getInt()
Returns value as integer (0 or 1).
Definition PqCore.h:399
virtual float get()
Returns value as float (either 0.0 or 1.0).
Definition PqCore.h:402
virtual float mapTo(float toLow, float toHigh)
Maps value to new range.
Definition PqCore.h:427
virtual bool off()
Sets output to "off" (ie. false, 0).
Definition PqCore.h:408
virtual bool isOn()
Returns true iff the input is "on".
Definition PqCore.h:393
virtual float put(float value)
Pushes value into the unit.
Definition PqCore.h:415
virtual bool isOff()
Returns true iff the input is "off".
Definition PqCore.h:396
virtual bool on()
Sets output to "on" (ie. true, 1).
Definition PqCore.h:405
The main Plaquette static class containing all the units.
Definition PqCore.h:60
void preStep()
Updates all components (calls step() on all of them).
Definition PqCore.h:671
uint64_t microSeconds(bool referenceTime=true) const
Returns time in microseconds.
Definition PqCore.cpp:107
size_t nUnits()
Returns the current number of units.
Definition PqCore.h:95
bool timeStep()
Performs additional tasks after the class to step().
Definition PqCore.h:681
static Engine & primary()
Returns the main instance of Plaquette.
Definition PqCore.cpp:31
float sampleRate() const
Returns sample rate.
Definition PqCore.h:140
bool step()
Function to be used within the PlaquetteLib context (needs to be called at top of loop() method).
Definition PqCore.h:744
float deltaTimeSecondsTimesFixed32Max() const
Returns time between steps, expressed in fixed point propotion.
Definition PqCore.h:149
uint32_t deltaTimeMicroSeconds() const
Returns time between steps (in microseconds).
Definition PqCore.h:146
bool isPrimary() const
Returns true if this Engine is the main.
Definition PqCore.h:155
bool randomTrigger(float timeWindow)
Randomly triggers an event about once per time window, on average.
Definition PqCore.cpp:213
void end()
Optional function to be used within the PlaquetteLib context.
Definition PqCore.cpp:90
void sampleRate(float sampleRate)
Sets sample rate to a fixed value, thus disabling auto sampling rate.
Definition PqCore.cpp:200
void autoSampleRate()
Enables auto sample rate mode (default).
Definition PqCore.cpp:190
void postBegin()
Performs additional tasks after the class to begin().
Definition PqCore.cpp:82
float seconds(bool referenceTime=true) const
Returns time in seconds.
Definition PqCore.cpp:99
float samplePeriod() const
Returns sample period.
Definition PqCore.h:143
uint32_t milliSeconds(bool referenceTime=true) const
Returns time in milliseconds.
Definition PqCore.cpp:103
void preBegin(unsigned long baudrate=PLAQUETTE_SERIAL_BAUD_RATE)
Initializes all components (calls begin() on all of them).
Definition PqCore.cpp:55
void samplePeriod(float samplePeriod)
Sets sample period to a fixed value, thus disabling auto sampling rate.
Definition PqCore.cpp:209
bool hasAutoSampleRate() const
Returns true iff the auto sample rate mode is enabled (default).
Definition PqCore.h:128
unsigned long nSteps() const
Returns number of steps.
Definition PqCore.h:125
void begin(unsigned long baudrate=PLAQUETTE_SERIAL_BAUD_RATE)
Function to be used within the PlaquetteLib context (needs to be called at top of setup() method).
Definition PqCore.h:740
Manages event listeners for Plaquette units.
Definition PqEvents.h:44
void step()
Performs a single step of the event manager.
Definition PqEvents.cpp:40
Superclass for pin-based components.
Definition PqCore.h:647
uint8_t pin() const
Returns the pin this component is attached to.
Definition PqCore.h:653
virtual void mode(uint8_t mode)
Changes the mode of the component.
Definition PqCore.h:659
uint8_t mode() const
Returns the mode of the component.
Definition PqCore.h:656
A generic class representing a unit in the system.
Definition PqCore.h:335
uint32_t milliSeconds() const
Returns engine time in milliseconds.
Definition PqCore.h:351
uint64_t microSeconds() const
Returns engine time in microseconds.
Definition PqCore.h:354
float seconds() const
Returns engine time in seconds.
Definition PqCore.h:348
unsigned long nSteps() const
Returns number of engine steps.
Definition PqCore.h:357
virtual void onEvent(EventCallback callback, EventType eventType)
Registers event callback.
Definition PqCore.cpp:246
virtual bool eventTriggered(EventType eventType)
Returns true iff an event of a certain type has been triggered.
Definition PqCore.h:371
Engine * engine() const
Returns the engine that owns this unit.
Definition PqCore.h:382
float samplePeriod() const
Returns enginesample period.
Definition PqCore.h:363
float sampleRate() const
Returns engine sample rate.
Definition PqCore.h:360
Definition pq_time.h:55