

Merge pull request #6 from HarvestX/features/ds3_ds4
add PS3 support
@6ce3bd94b888e4ec7a4950c58dca8f1496c2a044
--- p9n_interface/include/p9n_interface/ps3_dualshock3.hpp
+++ p9n_interface/include/p9n_interface/ps3_dualshock3.hpp
... | ... | @@ -16,5 +16,32 @@ |
16 | 16 |
|
17 | 17 |
namespace p9n_interface |
18 | 18 |
{ |
19 |
-// TODO: Implement it |
|
19 |
+enum class BUTTONS_DUALSHOCK3 |
|
20 |
+{ |
|
21 |
+ CROSS = 0, |
|
22 |
+ CIRCLE, |
|
23 |
+ TRIANGLE, |
|
24 |
+ SQUARE, |
|
25 |
+ L1, |
|
26 |
+ R1, |
|
27 |
+ L2, |
|
28 |
+ R2, |
|
29 |
+ SELECT, |
|
30 |
+ START, |
|
31 |
+ PS, |
|
32 |
+ UP = 13, |
|
33 |
+ DOWN, |
|
34 |
+ LEFT, |
|
35 |
+ RIGHT |
|
36 |
+}; |
|
37 |
+ |
|
38 |
+enum class AXES_DUALSHOCK3 |
|
39 |
+{ |
|
40 |
+ STICK_LX = 0, |
|
41 |
+ STICK_LY, |
|
42 |
+ L2, |
|
43 |
+ STICK_RX, |
|
44 |
+ STICK_RY, |
|
45 |
+ R2 |
|
46 |
+}; |
|
20 | 47 |
} // namespace p9n_interface |
--- p9n_interface/src/p9n_interface.cpp
+++ p9n_interface/src/p9n_interface.cpp
... | ... | @@ -69,7 +69,58 @@ |
69 | 69 |
|
70 | 70 |
switch (this->HW_TYPE_) { |
71 | 71 |
case HW_TYPE::DUALSHOCK3: |
72 |
- throw std::runtime_error("DualShock3 not supported yet."); |
|
72 |
+ { |
|
73 |
+ using BTN_IDX = BUTTONS_DUALSHOCK3; |
|
74 |
+ using AXES_IDX = AXES_DUALSHOCK3; |
|
75 |
+ |
|
76 |
+ this->btn_idx_->cross = |
|
77 |
+ static_cast<size_t>(BTN_IDX::CROSS); |
|
78 |
+ this->btn_idx_->circle = |
|
79 |
+ static_cast<size_t>(BTN_IDX::CIRCLE); |
|
80 |
+ this->btn_idx_->triangle = |
|
81 |
+ static_cast<size_t>(BTN_IDX::TRIANGLE); |
|
82 |
+ this->btn_idx_->square = |
|
83 |
+ static_cast<size_t>(BTN_IDX::SQUARE); |
|
84 |
+ |
|
85 |
+ this->btn_idx_->L1 = |
|
86 |
+ static_cast<size_t>(BTN_IDX::L1); |
|
87 |
+ this->btn_idx_->R1 = |
|
88 |
+ static_cast<size_t>(BTN_IDX::R1); |
|
89 |
+ this->btn_idx_->L2 = |
|
90 |
+ static_cast<size_t>(BTN_IDX::L2); |
|
91 |
+ this->btn_idx_->R2 = |
|
92 |
+ static_cast<size_t>(BTN_IDX::R2); |
|
93 |
+ |
|
94 |
+ this->btn_idx_->select = |
|
95 |
+ static_cast<size_t>(BTN_IDX::SELECT); |
|
96 |
+ this->btn_idx_->start = |
|
97 |
+ static_cast<size_t>(BTN_IDX::START); |
|
98 |
+ this->btn_idx_->PS = |
|
99 |
+ static_cast<size_t>(BTN_IDX::PS); |
|
100 |
+ |
|
101 |
+ this->btn_idx_->dpad_up = |
|
102 |
+ static_cast<size_t>(BTN_IDX::UP); |
|
103 |
+ this->btn_idx_->dpad_down = |
|
104 |
+ static_cast<size_t>(BTN_IDX::DOWN); |
|
105 |
+ this->btn_idx_->dpad_right = |
|
106 |
+ static_cast<size_t>(BTN_IDX::RIGHT); |
|
107 |
+ this->btn_idx_->dpad_left = |
|
108 |
+ static_cast<size_t>(BTN_IDX::LEFT); |
|
109 |
+ |
|
110 |
+ this->axes_idx_->stick_lx = |
|
111 |
+ static_cast<size_t>(AXES_IDX::STICK_LX); |
|
112 |
+ this->axes_idx_->stick_ly = |
|
113 |
+ static_cast<size_t>(AXES_IDX::STICK_LY); |
|
114 |
+ this->axes_idx_->stick_rx = |
|
115 |
+ static_cast<size_t>(AXES_IDX::STICK_RX); |
|
116 |
+ this->axes_idx_->stick_ry = |
|
117 |
+ static_cast<size_t>(AXES_IDX::STICK_RY); |
|
118 |
+ this->axes_idx_->R2_analog = |
|
119 |
+ static_cast<size_t>(AXES_IDX::R2); |
|
120 |
+ this->axes_idx_->L2_analog = |
|
121 |
+ static_cast<size_t>(AXES_IDX::L2); |
|
122 |
+ break; |
|
123 |
+ } |
|
73 | 124 |
case HW_TYPE::DUALSHOCK4: |
74 | 125 |
throw std::runtime_error("DualShock4 not supported yet."); |
75 | 126 |
case HW_TYPE::DUALSENSE: |
... | ... | @@ -289,9 +340,9 @@ |
289 | 340 |
} |
290 | 341 |
switch (this->HW_TYPE_) { |
291 | 342 |
case HW_TYPE::DUALSHOCK3: |
292 |
- if (this->joy_->buttons.at(this->btn_idx_->dpad_up)) { |
|
343 |
+ if (this->joy_->buttons.at(this->btn_idx_->dpad_left)) { |
|
293 | 344 |
return 1.0; |
294 |
- } else if (this->joy_->buttons.at(this->btn_idx_->dpad_down)) { |
|
345 |
+ } else if (this->joy_->buttons.at(this->btn_idx_->dpad_right)) { |
|
295 | 346 |
return -1.0; |
296 | 347 |
} else { |
297 | 348 |
return 0.0; |
... | ... | @@ -312,9 +363,9 @@ |
312 | 363 |
} |
313 | 364 |
switch (this->HW_TYPE_) { |
314 | 365 |
case HW_TYPE::DUALSHOCK3: |
315 |
- if (this->joy_->buttons.at(this->btn_idx_->dpad_right)) { |
|
366 |
+ if (this->joy_->buttons.at(this->btn_idx_->dpad_down)) { |
|
316 | 367 |
return -1.0; |
317 |
- } else if (this->joy_->buttons.at(this->btn_idx_->dpad_left)) { |
|
368 |
+ } else if (this->joy_->buttons.at(this->btn_idx_->dpad_up)) { |
|
318 | 369 |
return 1.0; |
319 | 370 |
} else { |
320 | 371 |
return 0.0; |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?