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 #pragma once
2 #include <ne10/NE10_types.h>
3 #include <vector>
4 #include <map>
5 #include <memory>
6 
7 #define FRAMES_STORED 4
8 
9 #define TRIGGER_LOG_COUNT 16
10 
11 // forward declarations
12 class WSServer;
13 class JSONValue;
14 // typedef std::map<std::wstring, JSONValue*> JSONObject;
15 class AuxTaskRT;
16 
23 class Scope{
24  public:
25  typedef enum {
26  AUTO,
29  } TriggerMode;
30  typedef enum {
33  BOTH,
34  } TriggerSlope;
35 
36  Scope();
37  Scope(unsigned int numChannels, float sampleRate);
38  ~Scope();
51  void setup(unsigned int numChannels, float sampleRate);
52 
53  void cleanup();
61  void log(double chn1, ...);
62 
71  void log(const float* values);
72 
79  bool trigger();
80 
84  void setTrigger(TriggerMode mode, unsigned int channel = 0, TriggerSlope dir = BOTH, float level = 0);
85 
86  private:
87  typedef enum {
88  TIME_DOMAIN,
89  FREQ_DOMAIN,
90  } PlotMode;
91  void dealloc();
92  void start();
93  void stop();
94  void triggerTimeDomain();
95  void triggerFFT();
96  bool triggered();
97  bool prelog();
98  void postlog();
99  void setPlotMode();
100  void doFFT();
101  void setXParams();
102  void scope_control_connected();
103  void scope_control_data(const char* data);
104  void parse_settings(JSONValue* value);
105 
106  bool volatile isUsingOutBuffer;
107  bool volatile isUsingBuffer;
108  bool volatile isResizing;
109 
110  // settings
111  int numChannels;
112  float sampleRate;
113  int pixelWidth;
114  int frameWidth;
115  PlotMode plotMode = TIME_DOMAIN;
116  TriggerMode triggerMode;
117  unsigned int triggerChannel;
118  TriggerSlope triggerDir;
119  float triggerLevel;
120  int xOffset;
121  int xOffsetSamples;
122  int upSampling;
123  int downSampling;
124  float holdOff;
125 
126  int logCount;
127 
128  int channelWidth;
129  int downSampleCount;
130  int holdOffSamples;
131 
132  // buffers
133  std::vector<float> buffer;
134  std::vector<float> outBuffer;
135 
136  // pointers
137  int writePointer;
138  int readPointer;
139  int triggerPointer;
140  int customTriggerPointer;
141 
142  // trigger status
143  bool triggerPrimed;
144  bool triggerCollecting;
145  bool triggerWaiting;
146  int triggerCount;
147  int autoTriggerCount;
148  bool started;
149  bool customTriggered;
150 
151  // FFT
152  int FFTLength;
153  int newFFTLength;
154  float FFTScale;
155  float FFTLogOffset;
156  int pointerFFT;
157  bool collectingFFT;
158  float *windowFFT;
159  int FFTXAxis;
160  int FFTYAxis;
161 
162  ne10_fft_cpx_float32_t* inFFT;
163  ne10_fft_cpx_float32_t* outFFT;
164  ne10_fft_cfg_float32_t cfg;
165 
166  std::unique_ptr<AuxTaskRT> scopeTriggerTask;
167  void triggerTask();
168 
169  void setSetting(std::wstring setting, float value);
170 
171  std::unique_ptr<WSServer> ws_server;
172 
173  std::map<std::wstring, float> settings;
174 };
Auto triggering.
Definition: Scope.h:26
void setup(unsigned int numChannels, float sampleRate)
Initialise the scope, setting the number of channels and the sample rate.
Definition: Scope.cpp:48
void log(double chn1,...)
Logs a frame of data to the scope.
Definition: Scope.cpp:159
Definition: AuxTaskRT.h:24
bool trigger()
Cause the scope to trigger when set to custom trigger mode.
Definition: Scope.cpp:206
Trigger on any crossing of the threshold.
Definition: Scope.h:33
Definition: WSServer.h:17
Definition: JSONValue.h:37
Trigger when crossing the threshold and the signal is increasing.
Definition: Scope.h:31
void setTrigger(TriggerMode mode, unsigned int channel=0, TriggerSlope dir=BOTH, float level=0)
Definition: Scope.cpp:473
Trigger when crossing the threshold and the signal is decreasing.
Definition: Scope.h:32
TriggerMode
Definition: Scope.h:25
Normal triggering.
Definition: Scope.h:27
Triggering when calling trigger()
Definition: Scope.h:28
TriggerSlope
Definition: Scope.h:30
An oscilloscope which allows data to be visualised in a browser in real time.
Definition: Scope.h:23