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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
* UBReply2005VotingSystem.cpp
*
* Created on: 12 feb. 2010
* Author: Luc
*/
#include "UBReply2005VotingSystem.h"
#include "core/UBSettings.h"
UBReply2005VotingSystem::UBReply2005VotingSystem(QWidget *parent)
: UBAbstractVotingSystem(parent)
, mParent(parent)
, mReplyVotingSystem(0)
, mMaxKeyValue(99)
{
// NOOP
}
UBReply2005VotingSystem::~UBReply2005VotingSystem()
{
if (mReplyVotingSystem)
delete mReplyVotingSystem;
}
bool UBReply2005VotingSystem::isVotingSystemAvailable()
{
if (!mReplyVotingSystem)
mReplyVotingSystem = new ReplyXControl1::ReplyX(mParent);
return (!mReplyVotingSystem->isNull());
}
bool UBReply2005VotingSystem::connectToVotingSystem()
{
bool result = false;
if (isVotingSystemAvailable())
{
connect(mReplyVotingSystem, SIGNAL(OnKeypadDataReceived(int, int)),
this, SLOT(keypadDataReceived(int, int)));
mReplyVotingSystem->SetSerialPort(UBSettings::settings()->replyWWSerialPort->get().toInt());
mReplyVotingSystem->SetReplyModel(ReplyXControl1::mReply2005);
result = mReplyVotingSystem->Connect();
if (!result)
setLastError("Cannot connect to voting system");
}
else
{
setLastError("Reply2005 driver not available");
}
return result;
}
void UBReply2005VotingSystem::keypadDataReceived(int keyPadID, int val)
{
qDebug() << "received vote from " << keyPadID << " : " << val;
mVotes.insert(keyPadID, val);
emit voteReceived(keyPadID, val);
}
bool UBReply2005VotingSystem::startPolling()
{
mVotes.clear();
if (isVotingSystemAvailable())
{
mReplyVotingSystem->StartPolling();
}
else
{
setLastError("Reply2005 driver not available");
}
return true;
}
bool UBReply2005VotingSystem::stopPolling()
{
if (isVotingSystemAvailable())
{
mReplyVotingSystem->StopPolling();
}
else
{
setLastError("Reply2005 driver not available");
}
return true;
}
bool UBReply2005VotingSystem::disconnectFromVotingSystem()
{
if (isVotingSystemAvailable())
{
mReplyVotingSystem->Disconnect();
}
else
{
setLastError("Reply2005 driver not available");
}
return true;
}
QMap<int, int> UBReply2005VotingSystem::votingState()
{
QMap<int, int> results;
for(int i = 0; i < mMaxKeyValue; i++)
{
results.insert(i, 0);
}
foreach(int vote, mVotes.values())
{
int voteCount = 0;
if(results.keys().contains(vote))
{
voteCount = results.value(vote);
voteCount++;
results.insert(vote, voteCount);
}
}
return results;
}