-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignals.h
71 lines (53 loc) · 2.17 KB
/
signals.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
#pragma once
#include <vector>
#include <stdexcept>
#define TOTAL_LENGTH (1 << 14)
class QSettings;
// some sort of an abstract signal with fixed length
struct Signal {
virtual ~Signal() {}
virtual void loadSettings(QSettings* settings) = 0;
virtual void saveSettings(QSettings* settings) = 0;
virtual void form(std::vector<bool>&) const = 0;
static void inverse(std::vector<bool>&);
virtual void changeRatio() = 0;
static unsigned int total_length;
static double ratio;
};
// "0" or "1"
struct Level : public Signal {
Level(bool invert = false) : inverted(invert) {}
virtual ~Level() {}
virtual void loadSettings(QSettings* settings);
virtual void saveSettings(QSettings* settings);
virtual void form(std::vector<bool>&) const;
virtual void changeRatio();
bool inverted; // logical level
};
// single pulse
struct Pulse : public Level {
Pulse( unsigned int pulse_offset = 0, unsigned int pulse_length = 0)
: Level(), offset(pulse_offset), length(pulse_length) {}
Pulse( bool signal_invert, unsigned int pulse_offset = 0, unsigned int pulse_length = 0)
: Level(signal_invert), offset(pulse_offset), length(pulse_length) {}
virtual ~Pulse() {}
virtual void loadSettings(QSettings* settings);
virtual void saveSettings(QSettings* settings);
virtual void form(std::vector<bool>&) const throw (std::overflow_error);
virtual void form( std::vector<bool>& vec, std::vector<bool>& pulse) const throw (std::overflow_error);
virtual void changeRatio();
unsigned int offset;
unsigned int length;
};
// clock, multiple pulses (repeated many times)
struct Clock : public Pulse {
Clock( bool signal_invert, unsigned int clock_offset, unsigned int pulse_offset, unsigned int pulse_length, unsigned int clock_times)
: Pulse( signal_invert, clock_offset), pulse( pulse_offset, pulse_length), times(clock_times) {}
virtual ~Clock() {}
virtual void loadSettings(QSettings* settings);
virtual void saveSettings(QSettings* settings);
virtual void form(std::vector<bool>&) const throw (std::overflow_error);
virtual void changeRatio();
Pulse pulse;
unsigned int times;
};