forked from odevices/er-301
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dispatcher.h
76 lines (62 loc) · 1.97 KB
/
Dispatcher.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#pragma once
#include <od/tasks/Task.h>
#include <hal/timing.h>
namespace teletype
{
class Dispatcher : public od::Task
{
public:
Dispatcher();
virtual ~Dispatcher();
void enable(uint32_t address);
void disable();
void setDefaultSlew(int ms);
// resets everything
void hardReset();
// preserves settings like pulse time and polarity
void softReset();
#ifndef SWIGLUA
void process(float *inputs, float *outputs);
void fillTRFrame(int port, float *out);
float fillCVFrame(int port, float *out, float lastValue);
// TR commands
void commandTRSet(int delay, int port, int level);
void commandTRToggle(int delay, int port);
void commandTRPulse(int delay, int port);
void commandTRPulseTime(int port, int ms);
void commandTRPolarity(int delay, int port, bool polarity);
// CV commands
void commandCV(int delay, int port, int value);
void commandCVSlew(int port, int ms);
void commandCVSet(int delay, int port, int value);
void commandCVOffset(int delay, int port, int value);
static const int PortCount = 101;
static const int MaxPort = PortCount - 1;
static const int MinPort = 1;
static const int NullPort = 0;
// TR state
float mTRLevel0[PortCount];
float mTRLevel1[PortCount];
int mTRDelays[PortCount];
bool mTRPolarity[PortCount];
int mTRPulseTime[PortCount];
int mTRPulseRemaining[PortCount];
bool mTRPulseActive[PortCount];
// CV state
float mCVTarget[PortCount];
float mCVCurrent[PortCount];
int mCVDelays[PortCount];
float mCVOffset[PortCount];
float mCVMaxDiff[PortCount];
bool mCVSlewEnabled[PortCount];
#endif
protected:
tick_t mLastTimestamp;
double mSamplesPerTick;
int mDefaultSlewTimeMs = 2;
bool mEnabled = false;
void updateTR();
void updateCV();
int ticksToSamples(tick_t nticks);
};
} // namespace teletype