@@ -313,25 +313,44 @@ static int get_frame_count(const uint8_t *buffer, struct sensor_chan_spec channe
313313
314314 switch (channel .chan_type ) {
315315 case SENSOR_CHAN_ACCEL_XYZ :
316- channel .chan_type = SENSOR_CHAN_ACCEL_X ;
317- break ;
318316 case SENSOR_CHAN_GYRO_XYZ :
319- channel .chan_type = SENSOR_CHAN_GYRO_X ;
320- break ;
321317 case SENSOR_CHAN_MAGN_XYZ :
322- channel .chan_type = SENSOR_CHAN_MAGN_X ;
323- break ;
324318 case SENSOR_CHAN_POS_DXYZ :
325- channel .chan_type = SENSOR_CHAN_POS_DX ;
319+ for (size_t i = 0 ; i < header -> num_channels ; ++ i ) {
320+ /* For 3-axis channels, we need to verify we have each individual axis */
321+ struct sensor_chan_spec channel_x = {
322+ .chan_type = channel .chan_type - 3 ,
323+ .chan_idx = channel .chan_idx ,
324+ };
325+ struct sensor_chan_spec channel_y = {
326+ .chan_type = channel .chan_type - 2 ,
327+ .chan_idx = channel .chan_idx ,
328+ };
329+ struct sensor_chan_spec channel_z = {
330+ .chan_type = channel .chan_type - 1 ,
331+ .chan_idx = channel .chan_idx ,
332+ };
333+
334+ /** The three axes don't need to be at the beginning of the header, but
335+ * they should be consecutive.
336+ */
337+ if (((header -> num_channels - i ) >= 3 ) &&
338+ sensor_chan_spec_eq (header -> channels [i ], channel_x ) &&
339+ sensor_chan_spec_eq (header -> channels [i + 1 ], channel_y ) &&
340+ sensor_chan_spec_eq (header -> channels [i + 2 ], channel_z )) {
341+ * frame_count = 1 ;
342+ return 0 ;
343+ }
344+ }
326345 break ;
327346 default :
328- break ;
329- }
330- for (size_t i = 0 ; i < header -> num_channels ; ++ i ) {
331- if (sensor_chan_spec_eq (header -> channels [i ], channel )) {
332- * frame_count = 1 ;
333- return 0 ;
347+ for (size_t i = 0 ; i < header -> num_channels ; ++ i ) {
348+ if (sensor_chan_spec_eq (header -> channels [i ], channel )) {
349+ * frame_count = 1 ;
350+ return 0 ;
351+ }
334352 }
353+ break ;
335354 }
336355
337356 return - ENOTSUP ;
@@ -348,21 +367,9 @@ int sensor_natively_supported_channel_size_info(struct sensor_chan_spec channel,
348367 }
349368
350369 switch (channel .chan_type ) {
351- case SENSOR_CHAN_ACCEL_X :
352- case SENSOR_CHAN_ACCEL_Y :
353- case SENSOR_CHAN_ACCEL_Z :
354370 case SENSOR_CHAN_ACCEL_XYZ :
355- case SENSOR_CHAN_GYRO_X :
356- case SENSOR_CHAN_GYRO_Y :
357- case SENSOR_CHAN_GYRO_Z :
358371 case SENSOR_CHAN_GYRO_XYZ :
359- case SENSOR_CHAN_MAGN_X :
360- case SENSOR_CHAN_MAGN_Y :
361- case SENSOR_CHAN_MAGN_Z :
362372 case SENSOR_CHAN_MAGN_XYZ :
363- case SENSOR_CHAN_POS_DX :
364- case SENSOR_CHAN_POS_DY :
365- case SENSOR_CHAN_POS_DZ :
366373 case SENSOR_CHAN_POS_DXYZ :
367374 * base_size = sizeof (struct sensor_three_axis_data );
368375 * frame_size = sizeof (struct sensor_three_axis_sample_data );
@@ -475,33 +482,21 @@ static int decode(const uint8_t *buffer, struct sensor_chan_spec chan_spec,
475482
476483 /* Check for 3d channel mappings */
477484 switch (chan_spec .chan_type ) {
478- case SENSOR_CHAN_ACCEL_X :
479- case SENSOR_CHAN_ACCEL_Y :
480- case SENSOR_CHAN_ACCEL_Z :
481485 case SENSOR_CHAN_ACCEL_XYZ :
482486 count = decode_three_axis (header , q , data_out , SENSOR_CHAN_ACCEL_X ,
483487 SENSOR_CHAN_ACCEL_Y , SENSOR_CHAN_ACCEL_Z ,
484488 chan_spec .chan_idx );
485489 break ;
486- case SENSOR_CHAN_GYRO_X :
487- case SENSOR_CHAN_GYRO_Y :
488- case SENSOR_CHAN_GYRO_Z :
489490 case SENSOR_CHAN_GYRO_XYZ :
490491 count = decode_three_axis (header , q , data_out , SENSOR_CHAN_GYRO_X ,
491492 SENSOR_CHAN_GYRO_Y , SENSOR_CHAN_GYRO_Z ,
492493 chan_spec .chan_idx );
493494 break ;
494- case SENSOR_CHAN_MAGN_X :
495- case SENSOR_CHAN_MAGN_Y :
496- case SENSOR_CHAN_MAGN_Z :
497495 case SENSOR_CHAN_MAGN_XYZ :
498496 count = decode_three_axis (header , q , data_out , SENSOR_CHAN_MAGN_X ,
499497 SENSOR_CHAN_MAGN_Y , SENSOR_CHAN_MAGN_Z ,
500498 chan_spec .chan_idx );
501499 break ;
502- case SENSOR_CHAN_POS_DX :
503- case SENSOR_CHAN_POS_DY :
504- case SENSOR_CHAN_POS_DZ :
505500 case SENSOR_CHAN_POS_DXYZ :
506501 count = decode_three_axis (header , q , data_out , SENSOR_CHAN_POS_DX ,
507502 SENSOR_CHAN_POS_DY , SENSOR_CHAN_POS_DZ ,
0 commit comments