Bela
Real-time, ultra-low-latency audio and sensor processing system for BeagleBone Black
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
Scope.h
1 /***** Scope.h *****/
2 #ifndef __Scope_H_INCLUDED__
3 #define __Scope_H_INCLUDED__
4 
5 #include <ne10/NE10_types.h>
6 #include <vector>
7 #include <map>
8 #include <string>
9 #include <AuxTaskNonRT.h>
10 #include <AuxTaskRT.h>
11 #include <cmath>
12 #include <memory>
13 
14 #define FRAMES_STORED 4
15 
16 #define TRIGGER_LOG_COUNT 16
17 
18 // forward declarations
19 class WSServer;
20 class JSONValue;
21 // typedef std::map<std::wstring, JSONValue*> JSONObject;
22 class AuxTaskRT;
23 
30 class Scope{
31  public:
32  typedef enum {
33  AUTO,
36  } TriggerMode;
37  typedef enum {
40  BOTH,
41  } TriggerSlope;
42 
43  Scope();
44  Scope(unsigned int numChannels, float sampleRate);
45  ~Scope();
58  void setup(unsigned int numChannels, float sampleRate);
59 
60  void cleanup();
68  void log(double chn1, ...);
69 
78  void log(const float* values);
79 
86  bool trigger();
87 
91  void setTrigger(TriggerMode mode, unsigned int channel = 0, TriggerSlope dir = BOTH, float level = 0);
92 
93  private:
94  typedef enum {
95  TIME_DOMAIN,
96  FREQ_DOMAIN,
97  } PlotMode;
98  void dealloc();
99  void start();
100  void stop();
101  void triggerTimeDomain();
102  void triggerFFT();
103  bool triggered();
104  bool prelog();
105  void postlog();
106  void setPlotMode();
107  void doFFT();
108  void setXParams();
109  void scope_control_connected();
110  void scope_control_data(const char* data);
111  void parse_settings(JSONValue* value);
112 
113  bool volatile isUsingOutBuffer;
114  bool volatile isUsingBuffer;
115  bool volatile isResizing;
116 
117  // settings
118  int numChannels;
119  float sampleRate;
120  int pixelWidth;
121  int frameWidth;
122  PlotMode plotMode = TIME_DOMAIN;
123  TriggerMode triggerMode;
124  unsigned int triggerChannel;
125  TriggerSlope triggerDir;
126  float triggerLevel;
127  int xOffset;
128  int xOffsetSamples;
129  int upSampling;
130  int downSampling;
131  float holdOff;
132 
133  int logCount;
134 
135  int channelWidth;
136  int downSampleCount;
137  int holdOffSamples;
138 
139  // buffers
140  std::vector<float> buffer;
141  std::vector<float> outBuffer;
142 
143  // pointers
144  int writePointer;
145  int readPointer;
146  int triggerPointer;
147  int customTriggerPointer;
148 
149  // trigger status
150  bool triggerPrimed;
151  bool triggerCollecting;
152  bool triggerWaiting;
153  int triggerCount;
154  int autoTriggerCount;
155  bool started;
156  bool customTriggered;
157 
158  // FFT
159  int FFTLength;
160  int newFFTLength;
161  float FFTScale;
162  float FFTLogOffset;
163  int pointerFFT;
164  bool collectingFFT;
165  float *windowFFT;
166  int FFTXAxis;
167  int FFTYAxis;
168 
169  ne10_fft_cpx_float32_t* inFFT;
170  ne10_fft_cpx_float32_t* outFFT;
171  ne10_fft_cfg_float32_t cfg;
172 
173  std::unique_ptr<AuxTaskRT> scopeTriggerTask;
174  void triggerTask();
175 
176  void setSetting(std::wstring setting, float value);
177 
178  std::unique_ptr<WSServer> ws_server;
179 
180  std::map<std::wstring, float> settings;
181 };
182 
183 #endif
Auto triggering.
Definition: Scope.h:33
void setup(unsigned int numChannels, float sampleRate)
Initialise the scope, setting the number of channels and the sample rate.
Definition: Scope.cpp:47
void log(double chn1,...)
Logs a frame of data to the scope.
Definition: Scope.cpp:158
Definition: AuxTaskRT.h:24
bool trigger()
Cause the scope to trigger when set to custom trigger mode.
Definition: Scope.cpp:205
Trigger on any crossing of the threshold.
Definition: Scope.h:40
Definition: WSServer.h:17
Definition: JSONValue.h:37
Trigger when crossing the threshold and the signal is increasing.
Definition: Scope.h:38
void setTrigger(TriggerMode mode, unsigned int channel=0, TriggerSlope dir=BOTH, float level=0)
Definition: Scope.cpp:472
Trigger when crossing the threshold and the signal is decreasing.
Definition: Scope.h:39
TriggerMode
Definition: Scope.h:32
Normal triggering.
Definition: Scope.h:34
Triggering when calling trigger()
Definition: Scope.h:35
TriggerSlope
Definition: Scope.h:37
An oscilloscope which allows data to be visualised in a browser in real time.
Definition: Scope.h:30