@@ -405,9 +405,10 @@ static struct {
405405 * since it's used to produce sub-drivers "stub" using
406406 * scripts/subdriver/gen-usbhid-subdriver.sh
407407 */
408- void HIDDumpTree (hid_dev_handle_t udev , HIDDevice_t * hd , usage_tables_t * utab )
408+ void HIDDumpTree (hid_dev_handle_t udev , HIDDevice_t * hd , usage_tables_t * utab , int force_fetch )
409409{
410410 size_t i ;
411+ int should_output_debug = (nut_debug_level >= 1 );
411412#if (defined SHUT_MODE ) && SHUT_MODE
412413 NUT_UNUSED_VARIABLE (hd );
413414#else /* !SHUT_MODE => USB */
@@ -416,16 +417,18 @@ void HIDDumpTree(hid_dev_handle_t udev, HIDDevice_t *hd, usage_tables_t *utab)
416417 int productID = hd -> ProductID ;
417418#endif /* SHUT_MODE / USB */
418419
419- /* Do not go further if we already know nothing will be displayed.
420- * Some reports take a while before they timeout, so if these are
420+ /* Some reports take a while before they timeout, so if these are
421421 * not used in the driver, they should only be fetched when we're
422- * in debug mode
422+ * in debug mode OR when force_fetch is enabled (needed for some
423+ * devices like CPS 0x0601 to properly initialize report buffer cache).
423424 */
424- if (nut_debug_level < 1 ) {
425+ if (! should_output_debug && ! force_fetch ) {
425426 return ;
426427 }
427428
428- upsdebugx (1 , "%" PRIuSIZE " HID objects found" , pDesc -> nitems );
429+ if (should_output_debug ) {
430+ upsdebugx (1 , "%" PRIuSIZE " HID objects found" , pDesc -> nitems );
431+ }
429432
430433 for (i = 0 ; i < pDesc -> nitems ; i ++ )
431434 {
@@ -452,18 +455,24 @@ void HIDDumpTree(hid_dev_handle_t udev, HIDDevice_t *hd, usage_tables_t *utab)
452455 }
453456#endif /* SHUT_MODE / USB */
454457
455- /* Get data value */
458+ /* Get data value - always fetch to populate report buffer cache */
456459 if (HIDGetDataValue (udev , pData , & value , MAX_TS ) == 1 ) {
457- upsdebugx (1 , "Path: %s, Type: %s, ReportID: 0x%02x, Offset: %i, Size: %i, Value: %g" ,
458- HIDGetDataItem (pData , utab ), HIDDataType (pData ), pData -> ReportID , pData -> Offset , pData -> Size , value );
460+ if (should_output_debug ) {
461+ upsdebugx (1 , "Path: %s, Type: %s, ReportID: 0x%02x, Offset: %i, Size: %i, Value: %g" ,
462+ HIDGetDataItem (pData , utab ), HIDDataType (pData ), pData -> ReportID , pData -> Offset , pData -> Size , value );
463+ }
459464 continue ;
460465 }
461466
462- upsdebugx (1 , "Path: %s, Type: %s, ReportID: 0x%02x, Offset: %i, Size: %i" ,
463- HIDGetDataItem (pData , utab ), HIDDataType (pData ), pData -> ReportID , pData -> Offset , pData -> Size );
467+ if (should_output_debug ) {
468+ upsdebugx (1 , "Path: %s, Type: %s, ReportID: 0x%02x, Offset: %i, Size: %i" ,
469+ HIDGetDataItem (pData , utab ), HIDDataType (pData ), pData -> ReportID , pData -> Offset , pData -> Size );
470+ }
464471 }
465472
466- fflush (stdout );
473+ if (should_output_debug ) {
474+ fflush (stdout );
475+ }
467476}
468477
469478/* Returns text string which can be used to display type of data
0 commit comments