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 <string>
8 #include <AuxTaskNonRT.h>
9 #include <AuxTaskRT.h>
10 
11 #define FRAMES_STORED 4
12 
13 #define TRIGGER_LOG_COUNT 16
14 
21 class Scope{
22  public:
23  Scope();
24  ~Scope();
25 
41  void setup(unsigned int numChannels, float sampleRate, int numSliders = 0);
42 
50  void log(double chn1, ...);
51 
60  void log(const float* values);
61 
68  bool trigger();
69 
79  float getSliderValue(int slider);
80 
89  bool sliderChanged(int slider);
90 
105  void setSlider(int slider, float min, float max, float step, float value, std::string name = "Slider");
106 
121  void setTrigger(int mode, int channel, int dir, float level);
122 
123  private:
124 
125  void dealloc();
126  void start();
127  void stop();
128  void triggerTimeDomain();
129  void triggerFFT();
130  bool triggered();
131  bool prelog();
132  void postlog();
133  void setPlotMode();
134  void doFFT();
135  void setXParams();
136 
137  bool volatile isUsingOutBuffer;
138  bool volatile isUsingBuffer;
139  bool volatile isResizing;
140 
141  // settings
142  int numChannels;
143  float sampleRate;
144  int pixelWidth;
145  int frameWidth;
146  int plotMode = 0;
147  int triggerMode;
148  int triggerChannel;
149  int triggerDir;
150  float triggerLevel;
151  int xOffset;
152  int xOffsetSamples;
153  int upSampling;
154  int downSampling;
155  float holdOff;
156 
157  int logCount;
158 
159  int channelWidth;
160  int downSampleCount;
161  int holdOffSamples;
162 
163  // buffers
164  std::vector<float> buffer;
165  std::vector<float> outBuffer;
166 
167  // pointers
168  int writePointer;
169  int readPointer;
170  int triggerPointer;
171  int customTriggerPointer;
172 
173  // sliders
174  int numSliders;
175  struct ScopeSlider{
176  float value;
177  bool changed = false;
178  };
179  std::vector<ScopeSlider> sliders;
180 
181  // trigger status
182  bool triggerPrimed;
183  bool triggerCollecting;
184  bool triggerWaiting;
185  bool triggering;
186  int triggerCount;
187  int autoTriggerCount;
188  bool started;
189  bool settingUp;
190  bool customTriggered;
191 
192  // FFT
193  int FFTLength;
194  int newFFTLength;
195  float FFTScale;
196  float FFTLogOffset;
197  int pointerFFT;
198  bool collectingFFT;
199  float *windowFFT;
200  int FFTXAxis;
201  int FFTYAxis;
202 
203  ne10_fft_cpx_float32_t* inFFT;
204  ne10_fft_cpx_float32_t* outFFT;
205  ne10_fft_cfg_float32_t cfg;
206 
207  AuxTaskNonRT sendBufferTask;
208  AuxTaskRT scopeTriggerTask;
209  static void triggerTask(void* ptr);
210 
211  void setSetting(std::wstring setting, float value);
212  friend struct ScopeControlHandler;
213 
214 };
215 
216 void scope_ws_setup(Scope* _scope);
217 void scope_ws_send(void* buf, int size);
218 void scope_ws_set_slider(int slider, float min, float max, float step, float value, std::string name);
219 void scope_ws_set_setting(std::wstring setting, float value);
220 void scope_ws_cleanup();
221 
222 #endif
void setup(unsigned int numChannels, float sampleRate, int numSliders=0)
Initialise the scope, setting the number of channels and the sample rate.
void log(double chn1,...)
Logs a frame of data to the scope.
float getSliderValue(int slider)
Read the value of a slider.
Definition: AuxTaskRT.h:22
void setTrigger(int mode, int channel, int dir, float level)
Initialise a slider's value and parameters.
bool trigger()
Cause the scope to trigger when set to custom trigger mode.
bool sliderChanged(int slider)
Check if the value of a slider has changed.
static float min(float x, float y)
Returns the maximum of two numbers.
Definition: Utilities.h:543
static float max(float x, float y)
Returns the minimum of two numbers.
Definition: Utilities.h:539
Definition: AuxTaskNonRT.h:17
void setSlider(int slider, float min, float max, float step, float value, std::string name="Slider")
Initialise a slider's value and parameters.
An oscilloscope which allows data to be visualised in a browser in real time.
Definition: Scope.h:21