Bela
Real-time, ultra-low-latency audio and sensor processing system for BeagleBone Black
 All Classes Files Functions Variables Typedefs 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  Scope();
33  Scope(unsigned int numChannels, float sampleRate);
34  ~Scope();
47  void setup(unsigned int numChannels, float sampleRate);
48 
49  void cleanup();
57  void log(double chn1, ...);
58 
67  void log(const float* values);
68 
75  bool trigger();
76 
80  void setTrigger(int mode, int channel, int dir, float level);
81 
82  private:
83 
84  void dealloc();
85  void start();
86  void stop();
87  void triggerTimeDomain();
88  void triggerFFT();
89  bool triggered();
90  bool prelog();
91  void postlog();
92  void setPlotMode();
93  void doFFT();
94  void setXParams();
95  void scope_control_connected();
96  void scope_control_data(const char* data);
97  void parse_settings(JSONValue* value);
98 
99  bool volatile isUsingOutBuffer;
100  bool volatile isUsingBuffer;
101  bool volatile isResizing;
102 
103  // settings
104  int numChannels;
105  float sampleRate;
106  int pixelWidth;
107  int frameWidth;
108  int plotMode = 0;
109  int triggerMode;
110  int triggerChannel;
111  int triggerDir;
112  float triggerLevel;
113  int xOffset;
114  int xOffsetSamples;
115  int upSampling;
116  int downSampling;
117  float holdOff;
118 
119  int logCount;
120 
121  int channelWidth;
122  int downSampleCount;
123  int holdOffSamples;
124 
125  // buffers
126  std::vector<float> buffer;
127  std::vector<float> outBuffer;
128 
129  // pointers
130  int writePointer;
131  int readPointer;
132  int triggerPointer;
133  int customTriggerPointer;
134 
135  // trigger status
136  bool triggerPrimed;
137  bool triggerCollecting;
138  bool triggerWaiting;
139  int triggerCount;
140  int autoTriggerCount;
141  bool started;
142  bool customTriggered;
143 
144  // FFT
145  int FFTLength;
146  int newFFTLength;
147  float FFTScale;
148  float FFTLogOffset;
149  int pointerFFT;
150  bool collectingFFT;
151  float *windowFFT;
152  int FFTXAxis;
153  int FFTYAxis;
154 
155  ne10_fft_cpx_float32_t* inFFT;
156  ne10_fft_cpx_float32_t* outFFT;
157  ne10_fft_cfg_float32_t cfg;
158 
159  std::unique_ptr<AuxTaskRT> scopeTriggerTask;
160  void triggerTask();
161 
162  void setSetting(std::wstring setting, float value);
163 
164  std::unique_ptr<WSServer> ws_server;
165 
166  std::map<std::wstring, float> settings;
167 };
168 
169 #endif
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:156
Definition: AuxTaskRT.h:24
void setTrigger(int mode, int channel, int dir, float level)
Definition: Scope.cpp:466
bool trigger()
Cause the scope to trigger when set to custom trigger mode.
Definition: Scope.cpp:203
Definition: WSServer.h:18
Definition: JSONValue.h:37
An oscilloscope which allows data to be visualised in a browser in real time.
Definition: Scope.h:30