1212#include "bluetooth/mon.h"
1313#include "sw2.h"
1414
15- //#define SW2_PRO
16- #define SW2_GC
17-
1815#define SW2_AXES_MAX 4
1916
2017enum {
5249// 0, 1, 2, 3, 4, 5
5350// };
5451
55- #ifdef SW2_PRO
5652static const struct ctrl_meta sw2_pro_axes_meta [ADAPTER_MAX_AXES ] =
5753{
5854 {.neutral = 0x800 , .abs_max = 1610 , .abs_min = 1610 },
@@ -62,9 +58,7 @@ static const struct ctrl_meta sw2_pro_axes_meta[ADAPTER_MAX_AXES] =
6258 {.neutral = 0x00 , .abs_max = 0xFF , .abs_min = 0x00 },
6359 {.neutral = 0x00 , .abs_max = 0xFF , .abs_min = 0x00 },
6460};
65- #endif
6661
67- #ifdef SW2_GC
6862static const struct ctrl_meta sw2_gc_axes_meta [ADAPTER_MAX_AXES ] =
6963{
7064 {.neutral = 0x800 , .abs_max = 1225 , .abs_min = 1225 },
@@ -74,7 +68,6 @@ static const struct ctrl_meta sw2_gc_axes_meta[ADAPTER_MAX_AXES] =
7468 {.neutral = 30 , .abs_max = 195 , .abs_min = 0x00 },
7569 {.neutral = 30 , .abs_max = 195 , .abs_min = 0x00 },
7670};
77- #endif
7871
7972struct sw2_map {
8073 uint8_t tbd [4 ];
@@ -86,7 +79,6 @@ struct sw2_map {
8679 uint8_t tbd3 ;
8780} __packed ;
8881
89- #ifdef SW2_PRO
9082static const uint32_t sw2_pro_mask [4 ] = {0xFFFF1FFF , 0x00000000 , 0x00000000 , 0x00000000 };
9183static const uint32_t sw2_pro_desc [4 ] = {0x000000FF , 0x00000000 , 0x00000000 , 0x00000000 };
9284static const uint32_t sw2_pro_btns_mask [32 ] = {
@@ -148,9 +140,7 @@ static void sw2_pro_to_generic(struct bt_data *bt_data, struct wireless_ctrl *ct
148140 ctrl_data -> axes [i ].value = axes [i ] - meta [i ].neutral ;
149141 }
150142}
151- #endif
152143
153- #ifdef SW2_GC
154144static const uint32_t sw2_gc_mask [4 ] = {0x77FF0FFF , 0x00000000 , 0x00000000 , 0x00000000 };
155145static const uint32_t sw2_gc_desc [4 ] = {0x110000FF , 0x00000000 , 0x00000000 , 0x00000000 };
156146static const uint32_t sw2_gc_btns_mask [32 ] = {
@@ -217,28 +207,21 @@ static void sw2_gc_to_generic(struct bt_data *bt_data, struct wireless_ctrl *ctr
217207 ctrl_data -> axes [i ].value = map -> triggers [i - 4 ] - meta [i ].neutral ;
218208 }
219209}
220- #endif
221210
222211int32_t sw2_to_generic (struct bt_data * bt_data , struct wireless_ctrl * ctrl_data ) {
223- #if defined(SW2_PRO )
224- sw2_pro_to_generic (bt_data , ctrl_data );
225- #elif defined(SW2_GC )
226- sw2_gc_to_generic (bt_data , ctrl_data );
227- #else
228- #error Not supported
229- #endif
230- // switch (bt_data->base.report_id) {
231- // case 0x11:
232- // sw2_pro_to_generic(bt_data, ctrl_data);
233- // break;
234- // case 0x31:
235- // sw2_gc_to_generic(bt_data, ctrl_data);
236- // break;
237- // default:
238- // printf("# Unknown report type: %02lX\n", bt_data->base.report_type);
239- // return -1;
240- // }
241-
212+ switch (bt_data -> base .pid ) {
213+ case 0x2066 :
214+ case 0x2067 :
215+ case 0x2069 :
216+ sw2_pro_to_generic (bt_data , ctrl_data );
217+ break ;
218+ case 0x2073 :
219+ sw2_gc_to_generic (bt_data , ctrl_data );
220+ break ;
221+ default :
222+ printf ("# Unknown pid : %04X\n" , bt_data -> base .pid );
223+ return -1 ;
224+ }
242225 return 0 ;
243226}
244227
0 commit comments