Hi!

Here's a small patch against 2.4.18pre3 that

* Changes the type of unit_exponent to be signed in a few places
  (Including possibly userspace-visible header files. 
  (hiddev.hi, hid.h)
  
* Adds prettyprinting of Unit Items in reports.

  This means that instead of 

    Jan 13 17:26:26 localhost kernel:       Unit Exponent(254)
    Jan 13 17:26:26 localhost kernel:       Unit(20)
    ...
    Jan 13 17:26:26 localhost kernel:       Unit Exponent(253)
    Jan 13 17:26:26 localhost kernel:       Unit(4099)

  We get

    Jan 14 21:25:52 localhost kernel:       Unit Exponent(-2)
    Jan 14 21:25:52 localhost kernel:       Unit(English Rotation : Degrees)
    ...
    Jan 14 21:25:52 localhost kernel:       Unit Exponent(-3)
    Jan 14 21:25:52 localhost kernel:       Unit(English Linear : Seconds)

* Adds Usages/Usage Pages that are used in my joystick to the debug
  tables. (Ordinal Page, usages in PID)


There's a problem though, the joystick has _a_lot_ of reports, with lots
of fields in them, and that overflows the kmsg ring buffer, and I lose
part of the output of hid_dump_device().
I tried adding some calls to schedule() in there, and that changed the
output a bit, but it still loses data.

The guys on #kernelnewbie thought I was nuts for trying to printk that
much data, and suggested using a /proc file instead. What do I do?

/August.
-- 
Wrong on most accounts.  const Foo *foo; and Foo const *foo; mean the same: foo
being a pointer to const Foo.  const Foo const *foo; would mean the same but is
illegal (double const).  You are confusing this with Foo * const foo; and const
Foo * const foo; respectively. -David Kastrup, comp.os.linux.development.system
diff -urN /usr/usrtmp/linux/drivers/usb/hid-core.c ./drivers/usb/hid-core.c
--- /usr/usrtmp/linux/drivers/usb/hid-core.c    Fri Dec 21 18:41:55 2001
+++ ./drivers/usb/hid-core.c    Mon Jan 14 22:42:06 2002
@@ -322,7 +322,7 @@
                        return 0;
 
                case HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT:
-                       parser->global.unit_exponent = item_udata(item);
+                       parser->global.unit_exponent = item_sdata(item);
                        return 0;
 
                case HID_GLOBAL_ITEM_TAG_UNIT:
diff -urN /usr/usrtmp/linux/drivers/usb/hid-debug.h ./drivers/usb/hid-debug.h
--- /usr/usrtmp/linux/drivers/usb/hid-debug.h   Thu Sep 13 00:34:06 2001
+++ ./drivers/usb/hid-debug.h   Mon Jan 14 23:39:37 2002
@@ -87,6 +87,7 @@
   {  7, 0, "Keyboard" },
   {  8, 0, "LED" },
   {  9, 0, "Button" },
+  { 10, 0, "Ordinal" },
   { 12, 0, "Hotkey" },
   { 13, 0, "Digitizers" },
     {0, 0x01, "Digitizer"},
@@ -112,6 +113,112 @@
     {0, 0x45, "Eraser"},
     {0, 0x46, "TabletPick"},
   { 15, 0, "PhysicalInterfaceDevice" },
+    {0, 0x00, "Undefined"},
+    {0, 0x01, "Physical_Interface_Device"},
+    {0, 0x20, "Normal"},
+    {0, 0x21, "Set_Effect_Report"},
+    {0, 0x22, "Effect_Block_Index"},
+    {0, 0x23, "Parameter_Block_Offset"},
+    {0, 0x24, "ROM_Flag"},
+    {0, 0x25, "Effect_Type"},
+    {0, 0x26, "ET_Constant_Force"},
+    {0, 0x27, "ET_Ramp"},
+    {0, 0x28, "ET_Custom_Force_Data"},
+    {0, 0x30, "ET_Square"},
+    {0, 0x31, "ET_Sine"},
+    {0, 0x32, "ET_Triangle"},
+    {0, 0x33, "ET_Sawtooth_Up"},
+    {0, 0x34, "ET_Sawtooth_Down"},
+    {0, 0x40, "ET_Spring"},
+    {0, 0x41, "ET_Damper"},
+    {0, 0x42, "ET_Inertia"},
+    {0, 0x43, "ET_Friction"},
+    {0, 0x50, "Duration"},
+    {0, 0x51, "Sample_Period"},
+    {0, 0x52, "Gain"},
+    {0, 0x53, "Trigger_Button"},
+    {0, 0x54, "Trigger_Repeat_Interval"},
+    {0, 0x55, "Axes_Enable"},
+    {0, 0x56, "Direction_Enable"},
+    {0, 0x57, "Direction"},
+    {0, 0x58, "Type_Specific_Block_Offset"},
+    {0, 0x59, "Block_Type"},
+    {0, 0x5A, "Set_Envelope_Report"},
+    {0, 0x5B, "Attack_Level"},
+    {0, 0x5C, "Attack_Time"},
+    {0, 0x5D, "Fade_Level"},
+    {0, 0x5E, "Fade_Time"},
+    {0, 0x5F, "Set_Condition_Report"},
+    {0, 0x60, "CP_Offset"},
+    {0, 0x61, "Positive_Coefficient"},
+    {0, 0x62, "Negative_Coefficient"},
+    {0, 0x63, "Positive_Saturation"},
+    {0, 0x64, "Negative_Saturation"},
+    {0, 0x65, "Dead_Band"},
+    {0, 0x66, "Download_Force_Sample"},
+    {0, 0x67, "Isoch_Custom_Force_Enable"},
+    {0, 0x68, "Custom_Force_Data_Report"},
+    {0, 0x69, "Custom_Force_Data"},
+    {0, 0x6A, "Custom_Force_Vendor_Defined_Data"},
+    {0, 0x6B, "Set_Custom_Force_Report"},
+    {0, 0x6C, "Custom_Force_Data_Offset"},
+    {0, 0x6D, "Sample_Count"},
+    {0, 0x6E, "Set_Periodic_Report"},
+    {0, 0x6F, "Offset"},
+    {0, 0x70, "Magnitude"},
+    {0, 0x71, "Phase"},
+    {0, 0x72, "Period"},
+    {0, 0x73, "Set_Constant_Force_Report"},
+    {0, 0x74, "Set_Ramp_Force_Report"},
+    {0, 0x75, "Ramp_Start"},
+    {0, 0x76, "Ramp_End"},
+    {0, 0x77, "Effect_Operation_Report"},
+    {0, 0x78, "Effect_Operation"},
+    {0, 0x79, "Op_Effect_Start"},
+    {0, 0x7A, "Op_Effect_Start_Solo"},
+    {0, 0x7B, "Op_Effect_Stop"},
+    {0, 0x7C, "Loop_Count"},
+    {0, 0x7D, "Device_Gain_Report"},
+    {0, 0x7E, "Device_Gain"},
+    {0, 0x7F, "PID_Pool_Report"},
+    {0, 0x80, "RAM_Pool_Size"},
+    {0, 0x81, "ROM_Pool_Size"},
+    {0, 0x82, "ROM_Effect_Block_Count"},
+    {0, 0x83, "Simultaneous_Effects_Max"},
+    {0, 0x84, "Pool_Alignment"},
+    {0, 0x85, "PID_Pool_Move_Report"},
+    {0, 0x86, "Move_Source"},
+    {0, 0x87, "Move_Destination"},
+    {0, 0x88, "Move_Length"},
+    {0, 0x89, "PID_Block_Load_Report"},
+    {0, 0x8B, "Block_Load_Status"},
+    {0, 0x8C, "Block_Load_Success"},
+    {0, 0x8D, "Block_Load_Full"},
+    {0, 0x8E, "Block_Load_Error"},
+    {0, 0x8F, "Block_Handle"},
+    {0, 0x90, "PID_Block_Free_Report"},
+    {0, 0x91, "Type_Specific_Block_Handle"},
+    {0, 0x92, "PID_State_Report"},
+    {0, 0x94, "Effect_Playing"},
+    {0, 0x95, "PID_Device_Control_Report"},
+    {0, 0x96, "PID_Device_Control"},
+    {0, 0x97, "DC_Enable_Actuators"},
+    {0, 0x98, "DC_Disable_Actuators"},
+    {0, 0x99, "DC_Stop_All_Effects"},
+    {0, 0x9A, "DC_Device_Reset"},
+    {0, 0x9B, "DC_Device_Pause"},
+    {0, 0x9C, "DC_Device_Continue"},
+    {0, 0x9F, "Device_Paused"},
+    {0, 0xA0, "Actuators_Enabled"},
+    {0, 0xA4, "Safety_Switch"},
+    {0, 0xA5, "Actuator_Override_Switch"},
+    {0, 0xA6, "Actuator_Power"},
+    {0, 0xA7, "Start_Delay"},
+    {0, 0xA8, "Parameter_Block_Size"},
+    {0, 0xA9, "Device_Managed_Pool"},
+    {0, 0xAA, "Shared_Parameter_Blocks"},
+    {0, 0xAB, "Create_New_Effect_Report"},
+    {0, 0xAC, "RAM_Pool_Available"},
   { 0, 0, NULL }
 };
 
@@ -176,7 +283,50 @@
                tab(n); printk("Unit Exponent(%d)\n", field->unit_exponent);
        }
        if (field->unit) {
-               tab(n); printk("Unit(%u)\n", field->unit);
+               char *systems[5] = { "None", "SI Linear", "SI Rotation", "English 
+Linear", "English Rotation" };
+               char *units[5][8] = {
+                       { "None", "None", "None", "None", "None", "None", "None", 
+"None" },
+                       { "None", "Centimeter", "Gram", "Seconds", "Kelvin",     
+"Ampere", "Candela", "None" },
+                       { "None", "Radians",    "Gram", "Seconds", "Kelvin",     
+"Ampere", "Candela", "None" },
+                       { "None", "Inch",       "Slug", "Seconds", "Fahrenheit", 
+"Ampere", "Candela", "None" },
+                       { "None", "Degrees",    "Slug", "Seconds", "Fahrenheit", 
+"Ampere", "Candela", "None" }
+               };
+
+               int i;
+               int sys;
+                __u32 data = field->unit;
+
+               /* First nibble tells us which system we're in. */
+               sys = data & 0xf;
+               data >>= 4;
+
+               if(sys > 4) {
+                       tab(n); printk("Unit(Invalid)\n");
+               }
+               else {
+                       int earlier_unit = 0;
+
+                       tab(n); printk("Unit(%s : ", systems[sys]);
+
+                       for (i=1 ; i<sizeof(__u32)*2 ; i++) {
+                               char nibble = data & 0xf;
+                               data >>= 4;
+                               if (nibble != 0) {
+                                       if(earlier_unit++ > 0)
+                                               printk("*");
+                                       printk("%s", units[sys][i]);
+                                       if(nibble != 1) {
+                                               /* This is a _signed_ nibble(!) */
+       
+                                               int val = nibble & 0x7;
+                                               if(nibble & 0x08)
+                                                       val = -((0x7 & ~val) +1);
+                                               printk("^%d", val);
+                                       }
+                               }
+                       }
+                       printk(")\n");
+               }
        }
        tab(n); printk("Report Size(%u)\n", field->report_size);
        tab(n); printk("Report Count(%u)\n", field->report_count);
diff -urN /usr/usrtmp/linux/drivers/usb/hid.h ./drivers/usb/hid.h
--- /usr/usrtmp/linux/drivers/usb/hid.h Wed Nov 14 02:45:27 2001
+++ ./drivers/usb/hid.h Mon Jan 14 21:38:15 2002
@@ -197,7 +197,7 @@
        __s32    logical_maximum;
        __s32    physical_minimum;
        __s32    physical_maximum;
-       unsigned unit_exponent;
+       __s32    unit_exponent;
        unsigned unit;
        unsigned report_id;
        unsigned report_size;
@@ -254,7 +254,7 @@
        __s32     logical_maximum;
        __s32     physical_minimum;
        __s32     physical_maximum;
-       unsigned  unit_exponent;
+       __s32     unit_exponent;
        unsigned  unit;
        struct hid_report *report;      /* associated report */
 };
Binary files /usr/usrtmp/linux/include/linux/.input.h.swp and 
./include/linux/.input.h.swp differ
diff -urN /usr/usrtmp/linux/include/linux/hiddev.h ./include/linux/hiddev.h
--- /usr/usrtmp/linux/include/linux/hiddev.h    Thu Sep 13 00:34:06 2001
+++ ./include/linux/hiddev.h    Mon Jan 14 20:33:41 2002
@@ -93,7 +93,7 @@
        __s32 logical_maximum;
        __s32 physical_minimum;
        __s32 physical_maximum;
-       unsigned unit_exponent;
+       __s32 unit_exponent;
        unsigned unit;
 };
 

Reply via email to