forked from sehraf/Lua4RS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLua4RSTickThread.cpp
55 lines (44 loc) · 1.29 KB
/
Lua4RSTickThread.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <ctime>
#include <unistd.h>
#include "Lua4RSTickThread.h"
#include "Lua/LuaCore.h"
#include "Lua/LuaEvent.h"
uint tickIntervalInSeconds = 1;
uint sleepPeriodInMilliseconds = 50;
uint secondsToStarUpEvent = 5;
Lua4RSTickThread::Lua4RSTickThread() :
RsThread(),
_lastRun( time(0) ),
_initTime( time(0) ),
_startUpEventTriggered( false ),
_counter( 0 )
{
}
void Lua4RSTickThread::run()
{
while(isRunning())
{
// tick each X second
if(_lastRun + tickIntervalInSeconds <= time(0) && _startUpEventTriggered)
{
LuaEvent e;
e.eventId = L4R_TIMERTICK;
e.timeStamp = QDateTime::currentDateTime();
e.dataParm->setValue("u32counter", _counter);
LuaCore::getInstance()->processEvent(e);
_lastRun = time(0);
_counter++;
}
// start up event
if(!_startUpEventTriggered && _initTime + secondsToStarUpEvent <= time(0))
{
LuaEvent e;
e.eventId = L4R_STARTUP;
e.timeStamp = QDateTime::currentDateTime();
LuaCore::getInstance()->processEvent(e);
_startUpEventTriggered = true;
}
// sleep X ms
usleep(1000 * sleepPeriodInMilliseconds);
}
}