@@ -325,28 +325,28 @@ struct joycon_imu_cal {
325
325
* All the controller's button values are stored in a u32.
326
326
* They can be accessed with bitwise ANDs.
327
327
*/
328
- static const u32 JC_BTN_Y = BIT (0 );
329
- static const u32 JC_BTN_X = BIT (1 );
330
- static const u32 JC_BTN_B = BIT (2 );
331
- static const u32 JC_BTN_A = BIT (3 );
332
- static const u32 JC_BTN_SR_R = BIT (4 );
333
- static const u32 JC_BTN_SL_R = BIT (5 );
334
- static const u32 JC_BTN_R = BIT (6 );
335
- static const u32 JC_BTN_ZR = BIT (7 );
336
- static const u32 JC_BTN_MINUS = BIT (8 );
337
- static const u32 JC_BTN_PLUS = BIT (9 );
338
- static const u32 JC_BTN_RSTICK = BIT (10 );
339
- static const u32 JC_BTN_LSTICK = BIT (11 );
340
- static const u32 JC_BTN_HOME = BIT (12 );
341
- static const u32 JC_BTN_CAP = BIT (13 ); /* capture button */
342
- static const u32 JC_BTN_DOWN = BIT (16 );
343
- static const u32 JC_BTN_UP = BIT (17 );
344
- static const u32 JC_BTN_RIGHT = BIT (18 );
345
- static const u32 JC_BTN_LEFT = BIT (19 );
346
- static const u32 JC_BTN_SR_L = BIT (20 );
347
- static const u32 JC_BTN_SL_L = BIT (21 );
348
- static const u32 JC_BTN_L = BIT (22 );
349
- static const u32 JC_BTN_ZL = BIT (23 );
328
+ #define JC_BTN_Y BIT(0)
329
+ #define JC_BTN_X BIT(1)
330
+ #define JC_BTN_B BIT(2)
331
+ #define JC_BTN_A BIT(3)
332
+ #define JC_BTN_SR_R BIT(4)
333
+ #define JC_BTN_SL_R BIT(5)
334
+ #define JC_BTN_R BIT(6)
335
+ #define JC_BTN_ZR BIT(7)
336
+ #define JC_BTN_MINUS BIT(8)
337
+ #define JC_BTN_PLUS BIT(9)
338
+ #define JC_BTN_RSTICK BIT(10)
339
+ #define JC_BTN_LSTICK BIT(11)
340
+ #define JC_BTN_HOME BIT(12)
341
+ #define JC_BTN_CAP BIT(13) /* capture button */
342
+ #define JC_BTN_DOWN BIT(16)
343
+ #define JC_BTN_UP BIT(17)
344
+ #define JC_BTN_RIGHT BIT(18)
345
+ #define JC_BTN_LEFT BIT(19)
346
+ #define JC_BTN_SR_L BIT(20)
347
+ #define JC_BTN_SL_L BIT(21)
348
+ #define JC_BTN_L BIT(22)
349
+ #define JC_BTN_ZL BIT(23)
350
350
351
351
enum joycon_msg_type {
352
352
JOYCON_MSG_TYPE_NONE ,
@@ -927,14 +927,27 @@ static int joycon_request_calibration(struct joycon_ctlr *ctlr)
927
927
*/
928
928
static void joycon_calc_imu_cal_divisors (struct joycon_ctlr * ctlr )
929
929
{
930
- int i ;
930
+ int i , divz = 0 ;
931
931
932
932
for (i = 0 ; i < 3 ; i ++ ) {
933
933
ctlr -> imu_cal_accel_divisor [i ] = ctlr -> accel_cal .scale [i ] -
934
934
ctlr -> accel_cal .offset [i ];
935
935
ctlr -> imu_cal_gyro_divisor [i ] = ctlr -> gyro_cal .scale [i ] -
936
936
ctlr -> gyro_cal .offset [i ];
937
+
938
+ if (ctlr -> imu_cal_accel_divisor [i ] == 0 ) {
939
+ ctlr -> imu_cal_accel_divisor [i ] = 1 ;
940
+ divz ++ ;
941
+ }
942
+
943
+ if (ctlr -> imu_cal_gyro_divisor [i ] == 0 ) {
944
+ ctlr -> imu_cal_gyro_divisor [i ] = 1 ;
945
+ divz ++ ;
946
+ }
937
947
}
948
+
949
+ if (divz )
950
+ hid_warn (ctlr -> hdev , "inaccurate IMU divisors (%d)\n" , divz );
938
951
}
939
952
940
953
static const s16 DFLT_ACCEL_OFFSET /*= 0*/ ;
@@ -1163,16 +1176,16 @@ static void joycon_parse_imu_report(struct joycon_ctlr *ctlr,
1163
1176
JC_IMU_SAMPLES_PER_DELTA_AVG ) {
1164
1177
ctlr -> imu_avg_delta_ms = ctlr -> imu_delta_samples_sum /
1165
1178
ctlr -> imu_delta_samples_count ;
1166
- /* don't ever want divide by zero shenanigans */
1167
- if (ctlr -> imu_avg_delta_ms == 0 ) {
1168
- ctlr -> imu_avg_delta_ms = 1 ;
1169
- hid_warn (ctlr -> hdev ,
1170
- "calculated avg imu delta of 0\n" );
1171
- }
1172
1179
ctlr -> imu_delta_samples_count = 0 ;
1173
1180
ctlr -> imu_delta_samples_sum = 0 ;
1174
1181
}
1175
1182
1183
+ /* don't ever want divide by zero shenanigans */
1184
+ if (ctlr -> imu_avg_delta_ms == 0 ) {
1185
+ ctlr -> imu_avg_delta_ms = 1 ;
1186
+ hid_warn (ctlr -> hdev , "calculated avg imu delta of 0\n" );
1187
+ }
1188
+
1176
1189
/* useful for debugging IMU sample rate */
1177
1190
hid_dbg (ctlr -> hdev ,
1178
1191
"imu_report: ms=%u last_ms=%u delta=%u avg_delta=%u\n" ,
0 commit comments