-
Notifications
You must be signed in to change notification settings - Fork 0
/
wg2dplot.h
92 lines (86 loc) · 2.17 KB
/
wg2dplot.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#ifndef WG2DPLOT_H
#define WG2DPLOT_H
#include "widget.h"
#include "debug.h"
#include "sensor.h"
#define MAX_TRACE_NUM 5
#define VALUES_BUFFER_SIZE 16
class wg2DPlot : public Widget
{
public:
wg2DPlot(uint8_t xarg, uint8_t yarg, uint8_t h, uint8_t w, Emitter* clock,uint8_t numDataPoints = 4 ) : Widget(xarg, yarg, h, w), _numDataPoints(numDataPoints)
{
_width = w;
_height = h;
_numTraces = 0;
_clock=clock;
if(_clock->getEmitterType() == EMITTER_TYPE_SENSOR)
dynamic_cast<Sensor*>(_clock)->addListener(this);
}
virtual void setValue(Emitter* emitter, uint32_t val)
{
if(emitter != _clock)
return;
for (uint8_t i = 0; i < _numTraces; i++)
{
_traces[i].setValue(_traces[i].sensor->getValue());
}
}
virtual uint16_t getPixel(int xcoord, int ycoord);
virtual uint32_t getValueWhenClicked(uint16_t ax, uint16_t ay) {return 0;}
void addTrace(Sensor* sens,uint16_t minVal, uint16_t maxVal, uint16_t color, bool dashed = false)
{
_traces[_numTraces].minValue = minVal;
_traces[_numTraces].maxValue = maxVal;
_traces[_numTraces].sensor = sens;
_traces[_numTraces].traceColor = color;
_traces[_numTraces]._maxNumValues = _numDataPoints+1;
_traces[_numTraces].traceDashed = dashed;
_numTraces++;
}
protected:
class Trace
{
public:
Sensor* sensor;
Trace()
{
_numValues = _valTail = _valHead = 0;
}
uint32_t maxValue;
uint32_t minValue;
uint16_t traceColor;
bool traceDashed;
uint16_t nextVal;
uint16_t currVal;
uint16_t getValue(int8_t index)
{
return _values[(_valTail+index+_numValues) % _numValues];
}
uint16_t getLastValue()
{
return _values[_valHead-1];
}
uint8_t getNumValues(){return _numValues;}
void setValue(uint16_t val)
{
_values[_valHead] = val;
//DEBUG.print("Value on index %d set to %d!\r\n",_valHead,val);
_valHead = (_valHead + 1) % _maxNumValues;
if(_numValues < _maxNumValues)
_numValues = _numValues + 1;
else
_valTail = _valHead;
}
uint16_t _values[VALUES_BUFFER_SIZE];
uint8_t _maxNumValues;
uint8_t _numValues;
uint8_t _valTail;
uint8_t _valHead;
};
Trace _traces[MAX_TRACE_NUM];
uint8_t _numTraces;
uint8_t _numDataPoints;
Emitter* _clock;
};
#endif // WG2DPLOT_H