-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
GamepadStorage.h
61 lines (49 loc) · 1.26 KB
/
GamepadStorage.h
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
#ifndef _PERSISTENT_STORAGE_
#define _PERSISTENT_STORAGE_
#define STORAGE_INPUT_MODE_INDEX 0
#define STORAGE_DPAD_MODE_INDEX 1
#define STORAGE_SOCD_MODE_INDEX 2
#include <EEPROM.h>
#include "GamepadState.h"
class GamepadStorage {
public:
DpadMode getDpadMode() {
DpadMode mode = DpadMode::DIGITAL;
get(STORAGE_DPAD_MODE_INDEX, mode);
return mode;
}
DpadMode setDpadMode(DpadMode mode) {
return set(STORAGE_DPAD_MODE_INDEX, mode);
}
InputMode getInputMode() {
InputMode mode = InputMode::XINPUT;
get(STORAGE_INPUT_MODE_INDEX, mode);
return mode;
}
InputMode setInputMode(InputMode mode) {
return set(STORAGE_INPUT_MODE_INDEX, mode);
}
SOCDMode getSOCDMode() {
SOCDMode mode = SOCDMode::UP_PRIORITY;
get(STORAGE_SOCD_MODE_INDEX, mode);
return mode;
}
SOCDMode setSOCDMode(SOCDMode mode) {
return set(STORAGE_SOCD_MODE_INDEX, mode);
}
protected:
/**
* Wrapper for "get" call to storage API
*/
template <typename T> T GamepadStorage::get(int index, T &value) {
return EEPROM.get(index, value);
}
/**
* Wrapper for "set" call to storage API
*/
template <typename T> T GamepadStorage::set(int index, const T &value) {
return EEPROM.put(index, value);
}
};
static GamepadStorage Storage;
#endif