@@ -24,85 +24,51 @@ std::shared_ptr<ControllerLEDMapping> LEDMappingFactory::CreateLEDMappingFromCon
24
24
}
25
25
26
26
if (mappingClass == " SDLLEDMapping" ) {
27
- int32_t shipDeviceIndex =
28
- CVarGetInteger (StringHelper::Sprintf (" %s.ShipDeviceIndex" , mappingCvarKey.c_str ()).c_str (), -1 );
29
-
30
- if (shipDeviceIndex < 0 ) {
31
- // something about this mapping is invalid
32
- CVarClear (mappingCvarKey.c_str ());
33
- CVarSave ();
34
- return nullptr ;
35
- }
36
-
37
27
return std::make_shared<SDLLEDMapping>(portIndex, colorSource, savedColor);
38
28
}
39
29
40
30
return nullptr ;
41
31
}
42
32
43
33
std::shared_ptr<ControllerLEDMapping> LEDMappingFactory::CreateLEDMappingFromSDLInput (uint8_t portIndex) {
44
- std::unordered_map<PhysicalDeviceType, SDL_GameController*> sdlControllersWithLEDs;
45
34
std::shared_ptr<ControllerLEDMapping> mapping = nullptr ;
46
35
47
- // todo: LED
48
- // for (auto [lusIndex, indexMapping] :
49
- // Context::GetInstance()->GetControlDeck()->GetDeviceIndexMappingManager()->GetAllDeviceIndexMappings()) {
50
- // auto sdlIndexMapping = std::dynamic_pointer_cast<ShipDeviceIndexToSDLDeviceIndexMapping>(indexMapping);
51
-
52
- // if (sdlIndexMapping == nullptr) {
53
- // // this LUS index isn't mapped to an SDL index
54
- // continue;
55
- // }
56
-
57
- // auto sdlIndex = sdlIndexMapping->GetSDLDeviceIndex();
58
-
59
- // if (!SDL_IsGameController(sdlIndex)) {
60
- // // this SDL device isn't a game controller
61
- // continue;
62
- // }
63
-
64
- // auto controller = SDL_GameControllerOpen(sdlIndex);
65
- // if (SDL_GameControllerHasLED(controller)) {
66
- // sdlControllersWithLEDs[lusIndex] = SDL_GameControllerOpen(sdlIndex);
67
- // } else {
68
- // SDL_GameControllerClose(controller);
69
- // }
70
- // }
71
-
72
- // for (auto [lusIndex, controller] : sdlControllersWithLEDs) {
73
- // for (int32_t button = SDL_CONTROLLER_BUTTON_A; button < SDL_CONTROLLER_BUTTON_MAX; button++) {
74
- // if (SDL_GameControllerGetButton(controller, static_cast<SDL_GameControllerButton>(button))) {
75
- // mapping = std::make_shared<SDLLEDMapping>(portIndex, 0, Color_RGB8({ 0, 0, 0 }));
76
- // break;
77
- // }
78
- // }
79
-
80
- // if (mapping != nullptr) {
81
- // break;
82
- // }
83
-
84
- // for (int32_t i = SDL_CONTROLLER_AXIS_LEFTX; i < SDL_CONTROLLER_AXIS_MAX; i++) {
85
- // const auto axis = static_cast<SDL_GameControllerAxis>(i);
86
- // const auto axisValue = SDL_GameControllerGetAxis(controller, axis) / 32767.0f;
87
- // int32_t axisDirection = 0;
88
- // if (axisValue < -0.7f) {
89
- // axisDirection = NEGATIVE;
90
- // } else if (axisValue > 0.7f) {
91
- // axisDirection = POSITIVE;
92
- // }
36
+ for (auto [lusIndex, controller] :
37
+ Context::GetInstance ()->GetControlDeck ()->GetConnectedPhysicalDeviceManager ()->GetConnectedSDLGamepadsForPort (
38
+ portIndex)) {
39
+ if (!SDL_GameControllerHasLED (controller)) {
40
+ continue ;
41
+ }
93
42
94
- // if (axisDirection == 0) {
95
- // continue;
96
- // }
43
+ for (int32_t button = SDL_CONTROLLER_BUTTON_A; button < SDL_CONTROLLER_BUTTON_MAX; button++) {
44
+ if (SDL_GameControllerGetButton (controller, static_cast <SDL_GameControllerButton>(button))) {
45
+ mapping = std::make_shared<SDLLEDMapping>(portIndex, 0 , Color_RGB8 ({ 0 , 0 , 0 }));
46
+ break ;
47
+ }
48
+ }
97
49
98
- // mapping = std::make_shared<SDLLEDMapping>(portIndex, 0, Color_RGB8({ 0, 0, 0 }));
99
- // break;
100
- // }
101
- // }
50
+ if (mapping != nullptr ) {
51
+ break ;
52
+ }
102
53
103
- // for (auto [i, controller] : sdlControllersWithLEDs) {
104
- // SDL_GameControllerClose(controller);
105
- // }
54
+ for (int32_t i = SDL_CONTROLLER_AXIS_LEFTX; i < SDL_CONTROLLER_AXIS_MAX; i++) {
55
+ const auto axis = static_cast <SDL_GameControllerAxis>(i);
56
+ const auto axisValue = SDL_GameControllerGetAxis (controller, axis) / 32767 .0f ;
57
+ int32_t axisDirection = 0 ;
58
+ if (axisValue < -0 .7f ) {
59
+ axisDirection = NEGATIVE;
60
+ } else if (axisValue > 0 .7f ) {
61
+ axisDirection = POSITIVE;
62
+ }
63
+
64
+ if (axisDirection == 0 ) {
65
+ continue ;
66
+ }
67
+
68
+ mapping = std::make_shared<SDLLEDMapping>(portIndex, 0 , Color_RGB8 ({ 0 , 0 , 0 }));
69
+ break ;
70
+ }
71
+ }
106
72
107
73
return mapping;
108
74
}
0 commit comments