-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsinegraph.cpp
More file actions
46 lines (37 loc) · 1.02 KB
/
sinegraph.cpp
File metadata and controls
46 lines (37 loc) · 1.02 KB
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
#include "sinegraph.h"
#include <QtMath>
SineGraph::SineGraph(TestSlaveData *pSlaveData, QObject *parent)
: QObject{parent}
{
_currentTick = 0;
_tickTime = 1;
_periodMs = 1000;
_pSlaveData = pSlaveData;
_address = 10;
connect(&_tickTimer, &QTimer::timeout, this, QOverload<>::of(&SineGraph::timerTick));
_tickTimer.start(_tickTime);
}
void SineGraph::timerTick()
{
_currentTick++;
_currentTick = _currentTick >= _periodMs ? 0: _currentTick;
const double angle = (2 * M_PI) * _currentTick / _periodMs;
double value = sin(angle)
+ sin(3 * angle) / 3
+ sin(5 * angle) / 5
+ sin(7 * angle) / 7
+ sin(9 * angle) / 9
+ sin(11 * angle) / 11
+ sin(13 * angle) / 13;
_pSlaveData->setRegisterValue(_address, value * 1000);
_tickTimer.start(_tickTime);
}
void SineGraph::setPeriod(uint32_t period)
{
_currentTick = 0;
_periodMs = period;
}
void SineGraph::setRegister(uint32_t address)
{
_address = address;
}