OpenCores
URL https://opencores.org/ocsvn/bw_tiff_compression/bw_tiff_compression/trunk

Subversion Repositories bw_tiff_compression

[/] [bw_tiff_compression/] [trunk/] [client_application/] [src/] [Kernel/] [CDevice.cpp] - Blame information for rev 16

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 16 amulder
/*
2
 * @file     Device.cpp
3
 * @date     May 14, 2012
4
 * @author   Aart Mulder
5
 */
6
 
7
#include <QTime>
8
 
9
#include "CDevice.h"
10
 
11
    /** @author Aart Mulder
12
     *  @version 1
13
     */
14
 
15
    /* {since=2011-12-09}*/
16
 
17
CDevice::CDevice(int nLoopTime, QString sName) : QThread(NULL), m_nLoopTime(nLoopTime), m_sName(sName)
18
{
19
        this->m_oDeviceState.SetDeviceState(DEVICE_STATE_WAIT_FOR_FIRST_START);
20
 
21
        this->start();
22
}
23
 
24
CDevice::~CDevice()
25
{
26
}
27
 
28
void CDevice::Start()
29
{
30
        if(this->m_oDeviceState.GetDeviceState() == DEVICE_STATE_WAIT_FOR_FIRST_START)
31
        {
32
                this->m_oDeviceState.SetDeviceState(DEVICE_STATE_RUN);
33
        }
34
}
35
 
36
void CDevice::Pause()
37
{
38
        if(this->m_oDeviceState.GetDeviceState() == DEVICE_STATE_RUN)
39
        {
40
                this->m_oDeviceState.SetDeviceState(DEVICE_STATE_PAUSE);
41
        }
42
}
43
 
44
void CDevice::Resume()
45
{
46
        if(this->m_oDeviceState.GetDeviceState() == DEVICE_STATE_PAUSE)
47
        {
48
                this->m_oDeviceState.SetDeviceState(DEVICE_STATE_RUN);
49
        }
50
}
51
 
52
void CDevice::Stop()
53
{
54
        this->m_oDeviceState.SetDeviceState(DEVICE_STATE_STOP);
55
}
56
 
57
int CDevice::GetLoopTime()
58
{
59
        return m_nLoopTime;
60
}
61
 
62
QString CDevice::GetName()
63
{
64
        return m_sName;
65
}
66
 
67
void CDevice::DelayMs(int delay)
68
{
69
        this->msleep(delay);
70
}
71
 
72
void CDevice::DeviceLoopWaitForStart()
73
{
74
 
75
}
76
 
77
/**
78
 *  Needs local variable to store the last timestamp that the deviceloop has been executed.
79
 */
80
void CDevice::run()
81
{
82
        QTime elapsedTimer;
83
 
84
        while(this->m_oDeviceState.GetDeviceState() == DEVICE_STATE_WAIT_FOR_FIRST_START)
85
        {
86
                DeviceLoopWaitForStart();
87
                this->msleep(this->m_nLoopTime);
88
        }
89
 
90
        this->BeforeDeviceLoop();
91
 
92
        try
93
        {
94
                while(this->m_oDeviceState.GetDeviceState() != DEVICE_STATE_STOP
95
                          && this->m_oDeviceState.GetDeviceState() != DEVICE_STATE_UNKNOWN)
96
                {
97
                        while(this->m_oDeviceState.GetDeviceState() == DEVICE_STATE_PAUSE)
98
                        {
99
                                this->msleep(this->m_nLoopTime);
100
                        }
101
 
102
                        while(this->m_oDeviceState.GetDeviceState() == DEVICE_STATE_RUN)
103
                        {
104
                                elapsedTimer.restart();
105
 
106
                                this->DeviceLoop();
107
 
108
                                int nSleep = (elapsedTimer.elapsed() < m_nLoopTime ? m_nLoopTime-elapsedTimer.elapsed() : 0);
109
 
110
                                this->msleep(nSleep);
111
                        }
112
                }
113
        }
114
        catch(...)
115
        {
116
                //Handle ERROR
117
        }
118
 
119
        this->AfterDeviceLoop();
120
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.