-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlinuxffbconditioneffect.cpp
More file actions
142 lines (124 loc) · 5.1 KB
/
linuxffbconditioneffect.cpp
File metadata and controls
142 lines (124 loc) · 5.1 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
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
142
#include "linuxffbconditioneffect.h"
#include "globalsettings.h"
LinuxFFBConditionEffect::LinuxFFBConditionEffect() :
LinuxFFBEffect(FFBEffectTypes::CONDITION)
{}
struct ff_effect* LinuxFFBConditionEffect::createFFStruct()
{
struct ff_effect* eff = LinuxFFBEffect::createFFStruct(m_params);
eff->u.condition[0].center = m_params->center[FFBConditionEffectParameters::Axis::X];
eff->u.condition[0].deadband = m_params->deadband[FFBConditionEffectParameters::Axis::X];
eff->u.condition[0].left_coeff = m_params->leftCoeff[FFBConditionEffectParameters::Axis::X];
eff->u.condition[0].right_coeff = m_params->rightCoeff[FFBConditionEffectParameters::Axis::X];
eff->u.condition[0].left_saturation = m_params->leftSat[FFBConditionEffectParameters::Axis::X];
eff->u.condition[0].right_saturation = m_params->rightSat[FFBConditionEffectParameters::Axis::X];
eff->u.condition[1].center = m_params->center[FFBConditionEffectParameters::Axis::Y];
eff->u.condition[1].deadband = m_params->deadband[FFBConditionEffectParameters::Axis::Y];
eff->u.condition[1].left_coeff = m_params->leftCoeff[FFBConditionEffectParameters::Axis::Y];
eff->u.condition[1].right_coeff = m_params->rightCoeff[FFBConditionEffectParameters::Axis::Y];
eff->u.condition[1].left_saturation = m_params->leftSat[FFBConditionEffectParameters::Axis::Y];
eff->u.condition[1].right_saturation = m_params->rightSat[FFBConditionEffectParameters::Axis::Y];
switch (m_params->subtype) {
case ConditionSubtypes::DAMPER:
eff->type = FF_DAMPER;
break;
case ConditionSubtypes::FRICTION:
eff->type = FF_FRICTION;
break;
case ConditionSubtypes::INERTIA:
eff->type = FF_INERTIA;
break;
case ConditionSubtypes::SPRING:
eff->type = FF_SPRING;
break;
default:
qCritical("Unknown subtype");
delete eff;
return nullptr;
}
return eff;
}
bool LinuxFFBConditionEffect::setParameters(const std::shared_ptr<FFBEffectParameters> params)
{
try {
return setParameters(std::dynamic_pointer_cast<FFBConditionEffectParameters>(params));
} catch (const std::bad_cast& ex) {
qCritical("%s\n", ex.what());
return false;
}
return false;
}
bool LinuxFFBConditionEffect::setParameters(const std::shared_ptr<FFBConditionEffectParameters> params)
{
if (!GlobalSettings::GS()->doSanityChecks)
return true;
if (!checkGenericParameters(params))
return false;
if (!checkBoundsInclusive(params->center[FFBConditionEffectParameters::Axis::X], -0x7FFF, 0x7FFF)) {
reportError("Center X must be within <-32767; 32767>");
return false;
}
if (!checkBoundsInclusive(params->center[FFBConditionEffectParameters::Axis::Y], -0x7FFF, 0x7FFF)) {
reportError("Center Y must be within <-32767; 32767>");
return false;
}
if (!checkBoundsInclusive(params->deadband[FFBConditionEffectParameters::Axis::X], 0, 0xFFFF)) {
reportError("Deadband X must be within <0; 65535>");
return false;
}
if (!checkBoundsInclusive(params->deadband[FFBConditionEffectParameters::Axis::Y], 0, 0xFFFF)) {
reportError("Deadband Ymust be within <0; 65535>");
return false;
}
if (!checkBoundsInclusive(params->leftCoeff[FFBConditionEffectParameters::Axis::X], -0x7FFF, 0x7FFF)) {
reportError("Left coefficient X must be within <-32767; 32767>");
return false;
}
if (!checkBoundsInclusive(params->leftCoeff[FFBConditionEffectParameters::Axis::Y], -0x7FFF, 0x7FFF)) {
reportError("Left coefficient Y must be within <-32767; 32767>");
return false;
}
if (!checkBoundsInclusive(params->rightCoeff[FFBConditionEffectParameters::Axis::X], -0x7FFF, 0x7FFF)) {
reportError("Right coefficient X must be within <-32767; 32767>");
return false;
}
if (!checkBoundsInclusive(params->rightCoeff[FFBConditionEffectParameters::Axis::Y], -0x7FFF, 0x7FFF)) {
reportError("Right coefficient Y must be within <-32767; 32767>");
return false;
}
if (!checkBoundsInclusive(params->leftSat[FFBConditionEffectParameters::Axis::X], 0, 0xFFFF)) {
reportError("Left saturation X must be within <0; 65535>");
return false;
}
if (!checkBoundsInclusive(params->leftSat[FFBConditionEffectParameters::Axis::Y], 0, 0xFFFF)) {
reportError("Left saturation Y must be within <0; 65535>");
return false;
}
if (!checkBoundsInclusive(params->rightSat[FFBConditionEffectParameters::Axis::X], 0, 0xFFFF)) {
reportError("Right saturation X must be within <0; 65535>");
return false;
}
if (!checkBoundsInclusive(params->rightSat[FFBConditionEffectParameters::Axis::Y], 0, 0xFFFF)) {
reportError("Right saturation Y must be within <0; 65535>");
return false;
}
if (params->subtype == ConditionSubtypes::NONE) {
reportError("Invalid subtype");
return false;
}
m_params = params;
return true;
}
bool LinuxFFBConditionEffect::operator==(const FFBEffect& other) const
{
if (this->type() != other.type())
return false;
else {
try {
const LinuxFFBConditionEffect& cother = dynamic_cast<const LinuxFFBConditionEffect&>(other);
return this->m_params->subtype == cother.m_params->subtype;
} catch (std::bad_cast&) {
return false;
}
}
}