OpenSourceSimWheelESP32
Open-source wireless steering wheel/button box for ESP32 boards
Loading...
Searching...
No Matches
ServiceMocks.hpp
Go to the documentation of this file.
1
12//-------------------------------------------------------------------
13// Imports
14//-------------------------------------------------------------------
15
16#include "SimWheelTypes.hpp"
17#include "InternalServices.hpp"
18
20
21//-------------------------------------------------------------------
22// Fake classes with user settings
23//-------------------------------------------------------------------
24
25class FakeInputService : public InputService
26{
27public:
28 inline static PulseWidthMultiplier _multiplier = PulseWidthMultiplier::_DEFAULT_VALUE;
29 inline static int _minLeft = 0;
30 inline static int _minRight = 0;
31 inline static int _maxLeft = 0;
32 inline static int _maxRight = 0;
33 inline static bool _leftAxisReversed = false;
34 inline static bool _rightAxisReversed = false;
35
36 static void resetToDefaults()
37 {
38 _multiplier = PulseWidthMultiplier::_DEFAULT_VALUE;
39 _minLeft = 0;
40 _minRight = 0;
41 _maxLeft = 0;
42 _maxRight = 0;
43 _leftAxisReversed = false;
44 _rightAxisReversed = false;
45 }
46
47 virtual void setRotaryPulseWidthMultiplier(
48 PulseWidthMultiplier multiplier,
49 bool save) override
50 {
51 _multiplier = multiplier;
52 if (save)
53 SaveSetting::notify(UserSetting::PULSE_WIDTH);
54 }
55
56 virtual PulseWidthMultiplier getRotaryPulseWidthMultiplier() override
57 {
58 return _multiplier;
59 }
60
61 virtual bool getAxisCalibration(
62 int &minLeft,
63 int &maxLeft,
64 int &minRight,
65 int &maxRight)
66 {
67 minLeft = _minLeft;
68 maxLeft = _maxLeft;
69 minRight = _minRight;
70 maxRight = _maxRight;
71 return true;
72 }
73
74 virtual void setAxisCalibration(
75 int minLeft,
76 int maxLeft,
77 int minRight,
78 int maxRight,
79 bool save)
80 {
81 _minLeft = minLeft;
82 _maxLeft = maxLeft;
83 _minRight = minRight;
84 _maxRight = maxRight;
85 if (save)
86 SaveSetting::notify(UserSetting::AXIS_CALIBRATION);
87 }
88
89 virtual void getAxisPolarity(
90 bool &leftAxisReversed,
91 bool &rightAxisReversed) override
92 {
93 leftAxisReversed = _leftAxisReversed;
94 rightAxisReversed = _rightAxisReversed;
95 }
96
97 virtual void setAxisPolarity(
98 bool leftAxisReversed,
99 bool rightAxisReversed,
100 bool save) override
101 {
102 _leftAxisReversed = leftAxisReversed;
103 _rightAxisReversed = rightAxisReversed;
104 if (save)
105 SaveSetting::notify(UserSetting::AXIS_POLARITY);
106 }
107};
108
109//-------------------------------------------------------------------
110
111class FakeInputHubService : public InputHubService
112{
113public:
114 inline static bool _securityLock = false;
115 inline static uint8_t _bitePoint = CLUTCH_NONE_VALUE;
116 inline static ClutchWorkingMode _clutchWorkingMode = ClutchWorkingMode::CLUTCH;
117 inline static AltButtonsWorkingMode _altButtonsWorkingMode = AltButtonsWorkingMode::ALT;
118 inline static DPadWorkingMode _dpadWorkingMode = DPadWorkingMode::Navigation;
119
120 static void resetToDefaults()
121 {
122 _securityLock = false;
123 _bitePoint = CLUTCH_NONE_VALUE;
124 _clutchWorkingMode = ClutchWorkingMode::CLUTCH;
125 _altButtonsWorkingMode = AltButtonsWorkingMode::ALT;
126 _dpadWorkingMode = DPadWorkingMode::Navigation;
127 }
128
129 virtual bool getSecurityLock() override
130 {
131 return _securityLock;
132 }
133
134 virtual uint8_t getBitePoint() override
135 {
136 return _bitePoint;
137 }
138
139 virtual ClutchWorkingMode getClutchWorkingMode() override
140 {
141 return _clutchWorkingMode;
142 }
143
144 virtual AltButtonsWorkingMode getAltButtonsWorkingMode() override
145 {
146 return _altButtonsWorkingMode;
147 }
148
149 virtual DPadWorkingMode getDPadWorkingMode() override
150 {
151 return _dpadWorkingMode;
152 }
153
154 virtual void setBitePoint(uint8_t value, bool save) override
155 {
156 _bitePoint = value;
157 OnBitePoint::notify(value);
158 if (save)
159 SaveSetting::notify(UserSetting::BITE_POINT);
160 }
161
162 virtual void setClutchWorkingMode(ClutchWorkingMode mode, bool save) override
163 {
164 _clutchWorkingMode = mode;
165 if (save)
166 SaveSetting::notify(UserSetting::CLUTCH_WORKING_MODE);
167 }
168
169 virtual void setAltButtonsWorkingMode(AltButtonsWorkingMode mode, bool save) override
170 {
171 _altButtonsWorkingMode = mode;
172 if (save)
173 SaveSetting::notify(UserSetting::ALT_WORKING_MODE);
174 }
175
176 virtual void setDPadWorkingMode(DPadWorkingMode mode, bool save) override
177 {
178 _dpadWorkingMode = mode;
179 if (save)
180 SaveSetting::notify(UserSetting::DPAD_WORKING_MODE);
181 }
182
183 virtual void setSecurityLock(bool value, bool save) override
184 {
185 _securityLock = value;
186 if (save)
187 SaveSetting::notify(UserSetting::SECURITY_LOCK);
188 }
189};
190
191//-------------------------------------------------------------------
192
193class FakeHidService : public HidService
194{
195public:
196 inline static uint16_t _customVID = 0;
197 inline static uint16_t _customPID = 0;
198
199 static void resetToDefaults()
200 {
201 _customVID = 0;
202 _customPID = 0;
203 }
204
205 virtual void getCustomHardwareID(uint16_t &customVID, uint16_t &customPID) override
206 {
207 customVID = _customVID;
208 customPID = _customPID;
209 }
210
211 virtual void setCustomHardwareID(uint16_t customVID, uint16_t customPID, bool save) override
212 {
213 _customVID = customVID;
214 _customPID = customPID;
215 if (save)
216 SaveSetting::notify(UserSetting::CUSTOM_HARDWARE_ID);
217 }
218};
219
220//-------------------------------------------------------------------
221
222class FakeBatteryCalibration : public BatteryCalibrationService
223{
224 inline static int _batteryLevel = 0;
225 inline static uint16_t _batteryCalibrationQuantum = 103;
226 inline static int _maxBatteryReadingEver = 0;
227
228 static void resetToDefaults()
229 {
230 _batteryLevel = 0;
231 _batteryCalibrationQuantum = 103;
232 _maxBatteryReadingEver = 0;
233 }
234
235 virtual int getBatteryLevel(int reading) override
236 {
237 return _batteryLevel;
238 }
239
240 virtual uint8_t getCalibrationDataCount() override
241 {
242 return 1;
243 }
244
245 virtual uint16_t getCalibrationData(uint8_t index) override
246 {
247 if (index == 0)
248 return _batteryCalibrationQuantum;
249 else
250 return 0;
251 }
252
253 virtual void setCalibrationData(uint8_t index, uint16_t data, bool save) override
254 {
255 if (index == 0)
256 {
257 _batteryCalibrationQuantum = data;
258 if (save)
259 SaveSetting::notify(UserSetting::BATTERY_CALIBRATION_DATA);
260 }
261 }
262
263 virtual int getAutoCalibrationParameter() override
264 {
265 return _maxBatteryReadingEver;
266 }
267
268 virtual void setAutoCalibrationParameter(int value, bool save) override
269 {
270 _maxBatteryReadingEver = value;
271 if (save)
272 SaveSetting::notify(UserSetting::BATTERY_AUTO_CALIBRATION);
273 }
274};
275
276//-------------------------------------------------------------------
277
278class FakeInputMapService : public InputMapService
279{
280 inline static uint8_t _user_defined = 0xFF;
281 inline static uint8_t _user_defined_alt = 0xFF;
282
283 static void resetToDefaults()
284 {
285 _user_defined = 0xFF;
286 _user_defined_alt = 0xFF;
287 }
288
289 virtual void setMap(
290 uint8_t firmware_defined,
291 uint8_t user_defined,
292 uint8_t user_defined_alt) override
293 {
294 _user_defined = user_defined;
295 _user_defined_alt = user_defined_alt;
296 }
297
298 virtual void getMap(
299 uint8_t firmware_defined,
300 uint8_t &user_defined,
301 uint8_t &user_defined_alt) override
302 {
303 if (firmware_defined < 64)
304 {
305 user_defined = _user_defined;
306 user_defined_alt = _user_defined_alt;
307 }
308 else
309 {
310 user_defined = 0xFF;
311 user_defined_alt = 0xFF;
312 }
313 }
314};
315
Internal service interfaces for dependency injection.
#define CLUTCH_NONE_VALUE
Value for a fully released clutch.
ClutchWorkingMode
User-selected working mode of the clutch paddles.
@ CLUTCH
F1-Style clutch. Must be the first in the enum: do not change.
PulseWidthMultiplier
User-selected pulse width multiplier.
AltButtonsWorkingMode
User-selected working mode of "ALT" buttons.
@ ALT
Engage or disengage alternate mode.
DPadWorkingMode
User-selected working mode of directional pads.
@ Navigation
Navigation control.
Types and constants required for custom firmware setup.
TelemetryData data
Received telemetry data.
static void notify(_Args... __args)
Invoke all subscribed callbacks.