-
Notifications
You must be signed in to change notification settings - Fork 0
/
jitteryinput.cpp
32 lines (27 loc) · 956 Bytes
/
jitteryinput.cpp
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
#include "jitteryinput.h"
#include <cstdlib>
#include <iostream>
#include <ctime>
#define inttype uint16_t
char Nutzlast[] = "Das hier sollte alles auf einer Zeile stehen!!!\r\n";
char Outpout[128] = { 0 };
jitteryInput::jitteryInput(QObject *parent) : QObject(parent){
std::srand(std::time(nullptr));
QObject::connect(&this->tim, &QTimer::timeout, [&](){
static inttype cnt = 0;
static int l_pos = 0;
int random_variable = 1 + std::rand()/((RAND_MAX + 1u)/sizeof(Nutzlast));
int new_pos = ( l_pos + random_variable ) % ( sizeof(Nutzlast) -1 );
std::memset(Outpout, 0, sizeof Outpout);
for( int i = 0; l_pos != new_pos; i++ ){
Outpout[i] = Nutzlast[l_pos];
l_pos = ( l_pos + 1 ) % ( sizeof(Nutzlast) -1 );
}
cnt++;
QString message(Outpout);
emit newData(message);
});
}
void jitteryInput::start(int msec){
this->tim.start(msec);
}