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#include "pq_traits.h"
32
33#include <stdint.h>
34#include <float.h>
35
36#include <limits.h>
37
38#include "HybridArrayList.h"
39#include "PqEvents.h"
40#include "pq_globals.h"
41#include "pq_constrain.h"
42#include "pq_map.h"
43#include "pq_phase_utils.h"
44#include "pq_print.h"
45#include "pq_random.h"
46#include "pq_serial.h"
47#include "pq_time.h"
48
49namespace pq {
50
52enum {
53 DIRECT,
54 INVERTED,
55 INTERNAL_PULLUP,
56 SOURCE = DIRECT, // deprecated
57 SINK = INVERTED // deprecated
58};
59
60class Unit;
61
63class Engine {
64 friend class Unit;
65
66public:
67 Engine();
68 ~Engine();
69
71 void preBegin();
72
74 void postBegin();
75
77 inline void preStep();
78
83 inline bool timeStep();
84
86 inline void begin();
87
89 inline bool step();
90
95 inline void end();
96
98 size_t nUnits() { return _unitsEndIndex - _unitsBeginIndex; }
99
107 float seconds(bool referenceTime=true) const;
108
116 uint32_t milliSeconds(bool referenceTime=true) const;
117
125 uint64_t microSeconds(bool referenceTime=true) const;
126
128 unsigned long nSteps() const { return _nSteps; }
129
131 bool hasAutoSampleRate() const { return _autoSampleRate; }
132
134 void autoSampleRate();
135
137 void sampleRate(float sampleRate);
138
140 void samplePeriod(float samplePeriod);
141
143 float sampleRate() const { return _sampleRate; }
144
146 float samplePeriod() const { return (_samplePeriod ? _samplePeriod : (_samplePeriod = frequencyToPeriod(_sampleRate))); }
147
149 uint32_t deltaTimeMicroSeconds() const { return _deltaTimeMicroSeconds; }
150
152 float deltaTimeSecondsTimesFixed32Max() const { return _deltaTimeSecondsTimesFixed32Max; }
153
155 static Engine& primary();
156
158 bool isPrimary() const { return this == &primary(); }
159
170 bool randomTrigger(float timeWindow);
171
174 void referenceClock(unsigned long (*clockFunction)());
175
176private:
178 void add(Unit* component);
179
181 void remove(Unit* component);
182
183 // Internal use. Sets sample rate and sample period.
184 inline void _setSampleRate(float sampleRate);
185
186 // Returns current reference time in microseconds.
187 unsigned long _clock() const { return _clockFunction ? _clockFunction() : micros(); }
188
189 // Internal use, needs to be called periodically. Updates _totalGlobalMicroSeconds.
190 micro_seconds_t _updateGlobalMicroSeconds() const;
191
192private:
193 // Shared static container containing all units. Static because it is shared between all engines.
194 // Units from the primary engine are always located at the begnning, then units from other engines.
195 static HybridArrayList<Unit*, PLAQUETTE_MAX_UNITS>& units();
196
197 // Range of this engine's units within the _units array list.
198 size_t _unitsBeginIndex; // begin index
199 size_t _unitsEndIndex; // end index (= _unitsBeginIndex + nUnits())
200
201 // Sampling rate (ie. how many times per seconds step() is called).
202 float _sampleRate;
203
204 // Sampling period (ie. 1.0 / sampleRate()).
205 mutable float _samplePeriod;
206
207 // Whether the auto sample rate mode is activated.
208 float _targetSampleRate;
209
210 // Snapshot of time in seconds from current step.
211 micro_seconds_t _microSeconds;
212 // uint32_t _previousMicroSeconds; // This is the 32 first bits of microseconds used for inter-step calculations.
213
214 // Target time for next step (when using sampleRate(float)).
215 micro_seconds_t _targetTime;
216
217 // Step state for state machine to manage sample rate.
218 enum StepState {
219 STEP_INIT,
220 STEP_WAIT,
221 STEP_WAIT_OVERFLOW
222 };
223
224 // Current step state.
225 StepState _stepState;
226
227 // Number of microseconds between steps.
228 uint32_t _deltaTimeMicroSeconds;
229
230 // Number of seconds between steps time FIXED_32_MAX.
231 float _deltaTimeSecondsTimesFixed32Max;
232
233 // Number of microseconds between steps.
234 uint32_t _targetDeltaTimeMicroSeconds;
235
236 // Number of steps accomplished.
237 unsigned long _nSteps;
238
239 // True if using auto sample rate mode.
240 bool _autoSampleRate;
241
242 // True if begin has been completed..
243 bool _beginCompleted;
244
245 // True during first run.
246 bool _firstRun;
247
248 // Used to keep track of events.
249 EventManager _eventManager;
250
251 // Global time in microseconds.
252 mutable micro_seconds_t _totalGlobalMicroSeconds;
253
254 // Functions that return time in microseconds (default: micros()).
255 unsigned long (*_clockFunction)();
256
257private:
258 // Prevent copy-construction and assignment.
259 Engine(const Engine&);
260 Engine& operator=(const Engine&);
261};
262
264extern Engine& Plaquette;
265
267void referenceClock(unsigned long (*clockFunction)());
268
270unsigned long nSteps();
271
273bool hasAutoSampleRate();
274
276void autoSampleRate();
277
279void sampleRate(float sampleRate);
280
282void samplePeriod(float samplePeriod);
283
285float sampleRate();
286
288float samplePeriod();
289
301bool randomTrigger(float timeWindow);
302
303class Flowable {
304private:
305 // Prevents assignation operations by making them private.
306 Flowable& operator=(bool);
307 Flowable& operator=(int);
308 Flowable& operator=(float);
309 Flowable& operator=(Flowable&);
310
311public:
313 virtual float get() { return 0.0f; }
314
316 operator float() { return get(); }
317
320 virtual float mapTo(float toLow, float toHigh) { return constrain(get(), toLow, toHigh); } // default: just constrain
321
327 virtual float put([[maybe_unused]] float value) { return get(); } // do nothing by default (read-only)
328
330 static bool analogToDigital(float f) { return (f >= 0.5); }
331
333 static float digitalToAnalog(bool b) { return (b ? 1.0f : 0.0f); }
334
335public:
337 // NOTE: This operator is defined as explicit so that boolean expression like
338 // "if (obj)" use the bool() operator while other expressions can use the float() operator.
339 explicit operator bool() { return Flowable::analogToDigital(get()); }
340};
341
342template <class Obj>
343class ParameterSlot : public Flowable {
344public:
345 using Setter = void (Obj::*)(float);
346 using Getter = float (Obj::*)() const;
347
348 ParameterSlot(Obj* obj, Setter set, Getter get)
349 : _obj(obj), _set(set), _get(get) {}
350
351 float get() override {
352 return (_obj->*_get)();
353 }
354
355 float put(float v) override {
356 (_obj->*_set)(v);
357 return get();
358 }
359
360private:
361 Obj* _obj;
362 Setter _set;
363 Getter _get; // optional; can be compiled out if you make two types
364};
365
366
373class Unit : public Flowable {
374 friend class Engine;
375 friend class EventManager;
376
377protected:
378 virtual void begin() {}
379 virtual void step() {}
380
381public:
382 // Clears all event listeners.
383 virtual void clearEvents();
384
386 float seconds() const { return _engine->seconds(); }
387
389 uint32_t milliSeconds() const { return _engine->milliSeconds(); }
390
392 uint64_t microSeconds() const { return _engine->microSeconds(); }
393
395 unsigned long nSteps() const { return _engine->nSteps(); }
396
398 float sampleRate() const { return _engine->sampleRate(); }
399
401 float samplePeriod() const { return _engine->samplePeriod(); }
402
403protected:
406 virtual ~Unit();
407
409 virtual bool eventTriggered([[maybe_unused]] EventType eventType) { return false; }
410
412 virtual void onEvent(EventCallback callback, EventType eventType);
413
414private:
415 // The engine that owns this unit.
416 Engine* _engine;
417
418protected:
420 Engine* engine() const { return _engine; }
421};
422
424class DigitalUnit : public Unit {
425protected:
428
429public:
431 virtual bool isOn() { return false; }
432
434 virtual bool isOff() { return !isOn(); }
435
437 virtual int getInt() { return isOn() ? 1 : 0; }
438
440 virtual float get() { return getInt(); }
441
443 virtual bool on() { return putOn(true); }
444
446 virtual bool off() { return putOn(false); }
447
453 virtual float put(float value) {
455 }
456
462 virtual bool putOn([[maybe_unused]] bool value) { return isOn(); } // do nothing by default (read-only)
463
465 virtual float mapTo(float toLow, float toHigh) { return isOn() ? toHigh : toLow; }
466
468 operator bool() { return isOn(); }
469
470 // IMPORTANT: LEAVE COMMENTED
471 // virtual operator int() { return getInt(); }
472
473 // IMPORTANT: This operator is redefined as explicit to make default return a bool.
474 explicit operator float() { return Unit::operator float(); }
475};
476
482class AnalogSource : public Unit {
483public:
486 AnalogSource(float initialValue, Engine& engine) : Unit(engine) { _value = constrain01(initialValue); }
487 virtual ~AnalogSource() {}
488
490 virtual float get() { return _value; }
491
493 virtual float mapTo(float toLow, float toHigh) { return mapFrom01(get(), toLow, toHigh); }
494
495protected:
496 float _value;
497};
498
501public:
504 DigitalSource(bool initialValue, Engine& engine) : DigitalUnit(engine), _onValue(initialValue), _prevOnValue(initialValue), _changeState(0) {}
505
507 virtual bool isOn() { return _onValue; }
508
514 virtual bool putOn(bool value) { return (_onValue = value); } // do nothing by default (read-only)
515
517 virtual bool rose() { return changeState() > 0; }
518
520 virtual bool fell() { return changeState() < 0; }
521
523 virtual bool changed() { return changeState() != 0; }
524
526 virtual bool toggle() { return putOn(!isOn()); }
527
529 virtual int8_t changeState() { return _changeState; }
530
532 virtual void onRise(EventCallback callback) { onEvent(callback, EVENT_RISE); }
533
535 virtual void onFall(EventCallback callback) { onEvent(callback, EVENT_FALL); }
536
538 virtual void onChange(EventCallback callback) { onEvent(callback, EVENT_CHANGE); }
539
540protected:
541 void _updateChangeState() {
542 _changeState = (int8_t)_onValue - (int8_t)_prevOnValue;
543 _prevOnValue = _onValue;
544 }
545
547 virtual bool eventTriggered(EventType eventType) {
548 switch (eventType) {
549 case EVENT_CHANGE: return changed();
550 case EVENT_RISE: return rose();
551 case EVENT_FALL: return fell();
552 default: return DigitalUnit::eventTriggered(eventType);
553 }
554 }
555
556 // The value contained in the unit.
557 bool _onValue : 1;
558
559 // Previous value, used to compute change state.
560 bool _prevOnValue : 1;
561
562 // The change state contained in the unit.
563 int8_t _changeState : 2;
564
565 // Unused extra space.
566 uint8_t _data : 4;
567};
568
569// Value to unit operators ///////////////////////////////////////
570
571// Trait: true if T derives from Flowable.
572template <typename T>
574private:
575 typedef typename remove_cvref<T>::type U;
576
577 static char test(Flowable*);
578 static int test(...);
579
580 static U* make();
581
582public:
583 enum { value = (sizeof(test(make())) == sizeof(char)) };
584};
585
586// Provides informative compile-time error message when trying to use the >> operator wrongly.
587#define PQ_FLOW_OPERATOR_ERROR \
588 "Invalid use of operator>>: right-hand operand must be a Plaquette flowable object such as a unit or parameter."
589
590// Catch operations such as: flowable >> nonFlowable;
591template <typename T>
593 static_assert(always_false<T>::value, PQ_FLOW_OPERATOR_ERROR);
594};
595
596template <typename L, typename R,
597 enable_if_t< is_flowable<L>::value &&
598 !is_flowable<R>::value, int> = 0>
599inline void operator>>(L&&, R&&) {
600 // The error is tied to instantiating this dependent type.
601 (void)sizeof(flow_error<R>);
602}
603
604// Catch operations such as: value >> nonFlowable;
605template <typename T, enable_if_t<!is_flowable<T>::value, int> = 0>
606inline void operator>>(float, T&&) {
607 static_assert(always_false<T>::value, PQ_FLOW_OPERATOR_ERROR);
608}
609
610template <typename T, enable_if_t<!is_flowable<T>::value, int> = 0>
611inline void operator>>(double, T&&) {
612 static_assert(always_false<T>::value, PQ_FLOW_OPERATOR_ERROR);
613}
614
615// Base value to unit operator.
616inline float operator>>(float value, Flowable& unit) {
617 return unit.put(value);
618}
619
620// NOTE: do not change the order of this operator (it needs to be set *after* the >>(float, Flowable&)).
621inline float operator>>(Flowable& source, Flowable& sink) {
622 return pq::operator>>(source.get(), sink);
623}
624
625inline float operator>>(double value, Flowable& unit) {
626 return pq::operator>>(static_cast<float>(value), unit);
627}
628
629inline float operator>>(bool value, Flowable& unit) {
630 return pq::operator>>(Flowable::digitalToAnalog(value), unit);
631}
632
633
634// 1) float -> temporary Flowable sink (e.g., parameter slot)
635inline float operator>>(float v, Flowable&& dst) {
636 return dst.put(v);
637}
638
639// 2) Flowable -> temporary Flowable sink
640inline float operator>>(Flowable& src, Flowable&& dst) {
641 return dst.put(src.get());
642}
643
644// (Optional) const Flowable source
645inline float operator>>(const Flowable& src, Flowable&& dst) {
646 return dst.put(const_cast<Flowable&>(src).get()); // or change get() const if you can
647}
648
649// // This code is needed on the Curie and ARM chips.
650// // Otherwise it causes an ambiguous operator error.
651// #if defined(__arc__) || defined(__arm__)
652// inline Flowable& operator>>(int value, Flowable& unit) {
653// return pq::operator>>((float)value, unit);
654// }
655// #endif
656
657// Integral -> lvalue sink
658template <typename I, pq::enable_if_t<pq::is_integral<I>::value, int> = 0>
659inline float operator>>(I value, Flowable& unit) {
660 return unit.put(static_cast<float>(value));
661}
662
663// Integral -> rvalue sink (for inline chainables such as parameter slots)
664template <typename I, pq::enable_if_t<pq::is_integral<I>::value, int> = 0>
665inline float operator>>(I value, Flowable&& unit) {
666 return unit.put(static_cast<float>(value));
667}
668
669// // Unit to value operators ///////////////////////////////////////
670// THIS PART IS COMMENTED OUT BECAUSE IT CAUSES AMBIGUOUS OPERATOR ERRORS
671
672// inline bool& operator>>(DigitalUnit& unit, bool& value) {
673// return (value = unit.isOn());
674// }
675
676// // This code is needed on the Curie-based AVRs.
677// #if defined(__arc__)
678// inline int& operator>>(DigitalUnit& unit, int& value) {
679// return (value = unit.getInt());
680// }
681// #endif
682
683// inline int8_t& operator>>(DigitalUnit& unit, int8_t& value) {
684// return (value = unit.getInt());
685// }
686
687// inline uint8_t& operator>>(DigitalUnit& unit, uint8_t& value) {
688// return (value = unit.getInt());
689// }
690
691// inline int16_t& operator>>(DigitalUnit& unit, int16_t& value) {
692// return (value = unit.getInt());
693// }
694
695// inline uint16_t& operator>>(DigitalUnit& unit, uint16_t& value) {
696// return (value = unit.getInt());
697// }
698
699// inline int32_t& operator>>(DigitalUnit& unit, int32_t& value) {
700// return (value = unit.getInt());
701// }
702
703// inline uint32_t& operator>>(DigitalUnit& unit, uint32_t& value) {
704// return (value = unit.getInt());
705// }
706
707// inline int64_t& operator>>(DigitalUnit& unit, int64_t& value) {
708// return (value = unit.getInt());
709// }
710
711// inline uint64_t& operator>>(DigitalUnit& unit, uint64_t& value) {
712// return (value = unit.getInt());
713// }
714
715// inline float& operator>>(Unit& unit, float& value) {
716// return (value = unit.get());
717// }
718
719// inline double& operator>>(Unit& unit, double& value) {
720// return (value = unit.get());
721// }
722
725public:
726 PinConfig(uint8_t pin, uint8_t mode) : _pin(pin), _mode(mode) {}
727 virtual ~PinConfig() {}
728
730 uint8_t pin() const { return _pin; }
731
733 uint8_t mode() const { return _mode; }
734
736 virtual void mode(uint8_t mode) { _mode = mode; }
737
738protected:
739 // The attached pin.
740 uint8_t _pin;
741
742 // The mode (varies according to context).
743 uint8_t _mode;
744};
745
746// Inline methods.
747
749 // Update every component.
750 for (size_t i=_unitsBeginIndex; i != _unitsEndIndex; i++) {
751 units()[i]->step();
752 }
753
754 // Look for events.
755 _eventManager.step();
756}
757
759 // Calculate true sample rate.
760 _updateGlobalMicroSeconds();
761
762 // Compute inter-step time.
763 _deltaTimeMicroSeconds = _totalGlobalMicroSeconds.micros32.base - _microSeconds.micros32.base;
764 float trueSampleRate = (_deltaTimeMicroSeconds ? SECONDS_TO_MICROS / _deltaTimeMicroSeconds : PLAQUETTE_MAX_SAMPLE_RATE);
765
766 // If autoSampleRate is off: wait in order to synchronize seconds with real time.
767 if (!_autoSampleRate) {
768
769 // Initilize step state.
770 if (_stepState == STEP_INIT) {
771 // Target time = current time + 1/_targetSampleRate
772 _targetTime = _microSeconds;
773 _targetTime.micros32.base += _targetDeltaTimeMicroSeconds;
774
775 // Check for overflow.
776 if (_targetTime.micros32.base >= _microSeconds.micros32.base) { // if target time is in the future: no overflow.
777 _stepState = STEP_WAIT;
778 }
779 else { // overflow
780 _targetTime.micros32.overflows++;
781 _stepState = STEP_WAIT_OVERFLOW;
782 }
783 }
784
785 // Process waiting state: will return false if still waiting, otherwise will complete the function.
786 if (_stepState == STEP_WAIT) {
787 // Still needs to wait.
788 if (_totalGlobalMicroSeconds.micros32.base < _targetTime.micros32.base)
789 return false; // break
790 }
791 else { // stepState == STEP_WAIT_OVERFLOW
792 // Still needs to wait.
793 if (_totalGlobalMicroSeconds.micros64 < _targetTime.micros64)
794 return false; // break
795 }
796
797 // Reset state.
798 _stepState = STEP_INIT;
799 }
800
801 // Update sample rate and current time to "true" / actual values.
802 _setSampleRate(trueSampleRate);
803
804 // Calculate delta time in fixed point.
805 uint64_t deltaTimeMicroSeconds64 = (uint64_t)_deltaTimeMicroSeconds;
806 _deltaTimeSecondsTimesFixed32Max = ((deltaTimeMicroSeconds64 << 32) - deltaTimeMicroSeconds64) * MICROS_TO_SECONDS;
807
808 // Sync reference time with global (true) time.
809 _microSeconds = _totalGlobalMicroSeconds;
810
811 // Increment step.
812 _nSteps++;
813
814 return true;
815}
816
818 preBegin();
819}
820
822 // On first run: do a post-begin.
823 if (_firstRun) { // the compiler should make this branching step effectively CPU-free
824 postBegin();
825 _firstRun = false;
826 return false;
827 }
828
829 // Otherwise: do a step.
830 else if (timeStep()) { // timeStep() will return false if we need to wait due to restrictive sampleRate(float)
831 // Do the pre-step.
832 preStep();
833 return true;
834 }
835 else
836 return false;
837}
838
839void Engine::_setSampleRate(float sampleRate) {
840 _sampleRate = max(sampleRate, FLT_MIN); // cannot be zero
841 _samplePeriod = 0; // set to zero to reset cache
842}
843
844} // namespace pq
845
846#endif
An analog analog source that contains a value constrained to a finite range (typically in [0,...
Definition PqCore.h:482
AnalogSource(Engine &engine)
Constructor.
Definition PqCore.h:485
virtual float mapTo(float toLow, float toHigh)
Maps value to new range.
Definition PqCore.h:493
virtual float get()
Returns value in [0, 1].
Definition PqCore.h:490
A digital source that contains a true/false value.
Definition PqCore.h:500
virtual bool eventTriggered(EventType eventType)
Returns true iff an event of a certain type has been triggered.
Definition PqCore.h:547
virtual bool putOn(bool value)
Pushes value into the unit.
Definition PqCore.h:514
virtual void onRise(EventCallback callback)
Registers event callback on rise event.
Definition PqCore.h:532
virtual void onFall(EventCallback callback)
Registers event callback on fall event.
Definition PqCore.h:535
virtual bool rose()
Returns true if the value rose.
Definition PqCore.h:517
virtual int8_t changeState()
Difference between current and previous value of the unit.
Definition PqCore.h:529
DigitalSource(Engine &engine)
Constructor.
Definition PqCore.h:503
virtual bool toggle()
Switches between on and off.
Definition PqCore.h:526
virtual bool changed()
Returns true if the value changed.
Definition PqCore.h:523
virtual bool isOn()
Returns true iff the input is "on".
Definition PqCore.h:507
virtual bool fell()
Returns true if the value fell.
Definition PqCore.h:520
virtual void onChange(EventCallback callback)
Registers event callback on change event.
Definition PqCore.h:538
A generic class representing a simple digital (true/false)unit.
Definition PqCore.h:424
virtual bool putOn(bool value)
Pushes value into the unit.
Definition PqCore.h:462
virtual int getInt()
Returns value as integer (0 or 1).
Definition PqCore.h:437
virtual float get()
Returns value as float (either 0.0 or 1.0).
Definition PqCore.h:440
virtual float mapTo(float toLow, float toHigh)
Maps value to new range.
Definition PqCore.h:465
virtual bool off()
Sets output to "off" (ie. false, 0).
Definition PqCore.h:446
DigitalUnit(Engine &engine)
Constructor.
Definition PqCore.h:427
virtual bool isOn()
Returns true iff the input is "on".
Definition PqCore.h:431
virtual float put(float value)
Pushes value into the unit.
Definition PqCore.h:453
virtual bool isOff()
Returns true iff the input is "off".
Definition PqCore.h:434
virtual bool on()
Sets output to "on" (ie. true, 1).
Definition PqCore.h:443
The main Plaquette static class containing all the units.
Definition PqCore.h:63
void preStep()
Updates all components (calls step() on all of them).
Definition PqCore.h:748
uint64_t microSeconds(bool referenceTime=true) const
Returns time in microseconds.
Definition PqCore.cpp:104
size_t nUnits()
Returns the current number of units.
Definition PqCore.h:98
bool timeStep()
Performs additional tasks after the class to step().
Definition PqCore.h:758
static Engine & primary()
Returns the main instance of Plaquette.
Definition PqCore.cpp:30
float sampleRate() const
Returns sample rate.
Definition PqCore.h:143
bool step()
Function to be used within the PlaquetteLib context (needs to be called at top of loop() method).
Definition PqCore.h:821
float deltaTimeSecondsTimesFixed32Max() const
Returns time between steps, expressed in fixed point propotion.
Definition PqCore.h:152
uint32_t deltaTimeMicroSeconds() const
Returns time between steps (in microseconds).
Definition PqCore.h:149
bool isPrimary() const
Returns true if this Engine is the main.
Definition PqCore.h:158
bool randomTrigger(float timeWindow)
Randomly triggers an event about once per time window, on average.
Definition PqCore.cpp:208
void end()
Optional function to be used within the PlaquetteLib context.
Definition PqCore.cpp:87
void sampleRate(float sampleRate)
Sets sample rate to a fixed value, thus disabling auto sampling rate.
Definition PqCore.cpp:195
void autoSampleRate()
Enables auto sample rate mode (default).
Definition PqCore.cpp:185
void postBegin()
Performs additional tasks after the class to begin().
Definition PqCore.cpp:79
float seconds(bool referenceTime=true) const
Returns time in seconds.
Definition PqCore.cpp:96
void referenceClock(unsigned long(*clockFunction)())
Sets base function returning microseconds.
Definition PqCore.cpp:212
void begin()
Function to be used within the PlaquetteLib context (needs to be called at top of setup() method).
Definition PqCore.h:817
float samplePeriod() const
Returns sample period.
Definition PqCore.h:146
uint32_t milliSeconds(bool referenceTime=true) const
Returns time in milliseconds.
Definition PqCore.cpp:100
void samplePeriod(float samplePeriod)
Sets sample period to a fixed value, thus disabling auto sampling rate.
Definition PqCore.cpp:204
bool hasAutoSampleRate() const
Returns true iff the auto sample rate mode is enabled (default).
Definition PqCore.h:131
unsigned long nSteps() const
Returns number of steps.
Definition PqCore.h:128
void preBegin()
Initializes all components (calls begin() on all of them).
Definition PqCore.cpp:56
Manages event listeners for Plaquette units.
Definition PqEvents.h:48
void step()
Performs a single step of the event manager.
Definition PqEvents.cpp:40
Definition PqCore.h:303
static float digitalToAnalog(bool b)
Converts digital (bool) value to analog (float) value.
Definition PqCore.h:333
static bool analogToDigital(float f)
Converts analog (float) value to digital (bool) value.
Definition PqCore.h:330
virtual float mapTo(float toLow, float toHigh)
Maps value to new range.
Definition PqCore.h:320
virtual float get()
Returns value (typically between 0 and 1, may vary depending on class).
Definition PqCore.h:313
virtual float put(float value)
Pushes value into the unit.
Definition PqCore.h:327
Definition PqCore.h:343
float put(float v) override
Pushes value into the unit.
Definition PqCore.h:355
float get() override
Returns value (typically between 0 and 1, may vary depending on class).
Definition PqCore.h:351
Superclass for pin-based components.
Definition PqCore.h:724
uint8_t pin() const
Returns the pin this component is attached to.
Definition PqCore.h:730
virtual void mode(uint8_t mode)
Changes the mode of the component.
Definition PqCore.h:736
uint8_t mode() const
Returns the mode of the component.
Definition PqCore.h:733
A generic class representing a unit in the system.
Definition PqCore.h:373
uint32_t milliSeconds() const
Returns engine time in milliseconds.
Definition PqCore.h:389
uint64_t microSeconds() const
Returns engine time in microseconds.
Definition PqCore.h:392
float seconds() const
Returns engine time in seconds.
Definition PqCore.h:386
unsigned long nSteps() const
Returns number of engine steps.
Definition PqCore.h:395
virtual void onEvent(EventCallback callback, EventType eventType)
Registers event callback.
Definition PqCore.cpp:240
virtual bool eventTriggered(EventType eventType)
Returns true iff an event of a certain type has been triggered.
Definition PqCore.h:409
Engine * engine() const
Returns the engine that owns this unit.
Definition PqCore.h:420
float samplePeriod() const
Returns enginesample period.
Definition PqCore.h:401
float sampleRate() const
Returns engine sample rate.
Definition PqCore.h:398
Definition pq_traits.h:109
Definition PqCore.h:592
Definition PqCore.h:573