Signed-off-by: Peter Hutterer <peter.hutte...@who-t.net>
---
 libwacom/libwacom.c    |  112 ++++++++++++++++++++++++++++++++++++++++++++++++
 libwacom/libwacom.h    |   10 +++++
 libwacom/libwacomint.h |    3 +-
 3 files changed, 124 insertions(+), 1 deletion(-)

diff --git a/libwacom/libwacom.c b/libwacom/libwacom.c
index 29ce625..eaf5e2c 100644
--- a/libwacom/libwacom.c
+++ b/libwacom/libwacom.c
@@ -351,6 +351,118 @@ libwacom_new_from_name(WacomDeviceDatabase *db, const 
char *name, WacomError *er
        return NULL;
 }
 
+static void print_styli_for_device (FILE *file, WacomDevice *device)
+{
+       int nstyli, *styli;
+       int i;
+
+       if (!libwacom_has_stylus(device))
+               return;
+
+       styli = libwacom_get_supported_styli(device, &nstyli);
+
+       fprintf(file, "Styli=");
+       for (i = 0; i < nstyli; i++)
+               fprintf(file, "%#x;", styli[i]);
+       fprintf(file, "\n");
+}
+
+static void print_button_flag_if(FILE *file, WacomDevice *device, const char 
*label, int flag)
+{
+       int nbuttons = libwacom_get_num_buttons(device);
+       char b;
+       fprintf(file, "%s=", label);
+       for (b = 'A'; b < 'A' + nbuttons; b++)
+               if (libwacom_get_button_flag(device, b) & flag)
+                       fprintf(file, "%c;", b);
+       fprintf(file, "\n");
+}
+
+static void print_buttons_for_device (FILE *file, WacomDevice *device)
+{
+       int nbuttons = libwacom_get_num_buttons(device);
+
+       if (nbuttons == 0)
+               return;
+
+       fprintf(file, "[Buttons]\n");
+
+       print_button_flag_if(file, device, "Left", WACOM_BUTTON_POSITION_LEFT);
+       print_button_flag_if(file, device, "Right", 
WACOM_BUTTON_POSITION_RIGHT);
+       print_button_flag_if(file, device, "Top", WACOM_BUTTON_POSITION_TOP);
+       print_button_flag_if(file, device, "Bottom", 
WACOM_BUTTON_POSITION_BOTTOM);
+       print_button_flag_if(file, device, "Touchstrip", 
WACOM_BUTTON_TOUCHSTRIP_MODESWITCH);
+       print_button_flag_if(file, device, "Touchstrip2", 
WACOM_BUTTON_TOUCHSTRIP2_MODESWITCH);
+       print_button_flag_if(file, device, "OLEDs", WACOM_BUTTON_OLED);
+       print_button_flag_if(file, device, "Ring", 
WACOM_BUTTON_RING_MODESWITCH);
+       print_button_flag_if(file, device, "Ring2", 
WACOM_BUTTON_RING2_MODESWITCH);
+       fprintf(file, "RingNumModes=%d\n", libwacom_get_ring_num_modes(device));
+       fprintf(file, "Ring2NumModes=%d\n", 
libwacom_get_ring2_num_modes(device));
+       fprintf(file, "StripsNumModes=%d\n", 
libwacom_get_strips_num_modes(device));
+
+       fprintf(file, "\n");
+}
+
+void
+libwacom_print_device_description(FILE *file, WacomDevice *device)
+{
+       int nmatches;
+       WacomClass   class      = libwacom_get_class(device);
+       WacomMatch   **matches  = libwacom_get_matches(device, &nmatches);
+       const char *bus_name, *class_name;
+
+       switch(class) {
+               case WCLASS_UNKNOWN:    class_name = "Unknown"; break;
+               case WCLASS_INTUOS3:    class_name = "Intuos3"; break;
+               case WCLASS_INTUOS4:    class_name = "Intuos4"; break;
+               case WCLASS_INTUOS5:    class_name = "Intuos5"; break;
+               case WCLASS_CINTIQ:     class_name = "Cintiq";  break;
+               case WCLASS_BAMBOO:     class_name = "Bamboo";  break;
+               case WCLASS_GRAPHIRE:   class_name = "Graphire";break;
+               case WCLASS_ISDV4:      class_name = "ISDV4";   break;
+               default:                BUG_WARN(class); break;
+       }
+
+       fprintf(file, "[Device]\n");
+       fprintf(file, "Name=%s\n",              libwacom_get_name(device));
+       fprintf(file, "DeviceMatch=");
+       while (nmatches--) {
+               WacomBusType type       = 
libwacom_match_get_bustype(matches[nmatches]);
+               int          vendor     = 
libwacom_match_get_vendor_id(matches[nmatches]);
+               int          product    = 
libwacom_match_get_product_id(matches[nmatches]);
+
+               switch(type) {
+                       case WBUSTYPE_BLUETOOTH:        bus_name = "bluetooth"; 
break;
+                       case WBUSTYPE_USB:              bus_name = "usb";       
break;
+                       case WBUSTYPE_SERIAL:           bus_name = "serial";    
break;
+                       case WBUSTYPE_UNKNOWN:          bus_name = "unknown";   
break;
+                       default:                        BUG_WARN(type); break;
+               }
+               fprintf(file, "%s:%04x:%04x;", bus_name, vendor, product);
+       }
+       fprintf(file, "\n");
+
+       fprintf(file, "Class=%s\n",             class_name);
+       fprintf(file, "Width=%d\n",             libwacom_get_width(device));
+       fprintf(file, "Height=%d\n",            libwacom_get_height(device));
+       print_styli_for_device(file, device);
+       fprintf(file, "\n");
+
+       fprintf(file, "[Features]\n");
+       fprintf(file, "Reversible=%s\n", libwacom_is_reversible(device) ? 
"true" : "false");
+       fprintf(file, "Stylus=%s\n",     libwacom_has_stylus(device)    ? 
"true" : "false");
+       fprintf(file, "Ring=%s\n",       libwacom_has_ring(device)      ? 
"true" : "false");
+       fprintf(file, "Ring2=%s\n",      libwacom_has_ring2(device)     ? 
"true" : "false");
+       fprintf(file, "BuiltIn=%s\n",    libwacom_is_builtin(device)    ? 
"true" : "false");
+       fprintf(file, "Touch=%s\n",      libwacom_has_touch(device)     ? 
"true" : "false");
+
+       fprintf(file, "NumStrips=%d\n", libwacom_get_num_strips(device));
+       fprintf(file, "Buttons=%d\n",           
libwacom_get_num_buttons(device));
+
+       print_buttons_for_device(file, device);
+}
+
+
 void
 libwacom_destroy(WacomDevice *device)
 {
diff --git a/libwacom/libwacom.h b/libwacom/libwacom.h
index d44eb89..11192a4 100644
--- a/libwacom/libwacom.h
+++ b/libwacom/libwacom.h
@@ -35,6 +35,7 @@
 /** @endcond */
 
 #include <stdint.h>
+#include <stdio.h>
 /**
  @mainpage
 
@@ -273,6 +274,15 @@ WacomDevice* libwacom_new_from_name(WacomDeviceDatabase 
*db, const char *name, W
 WacomDevice** libwacom_list_devices_from_database(WacomDeviceDatabase *db, 
WacomError *error);
 
 /**
+ * Print the description of this device to the given file.
+ *
+ * @param file The stream to print to
+ * @param device The device to print the description for.
+ */
+void libwacom_print_device_description (FILE *file, WacomDevice *device);
+
+
+/**
  * Remove the device and free all memory and references to it.
  *
  * @param device The device to delete
diff --git a/libwacom/libwacomint.h b/libwacom/libwacomint.h
index 6be561b..387bf6f 100644
--- a/libwacom/libwacomint.h
+++ b/libwacom/libwacomint.h
@@ -78,7 +78,8 @@ struct _WacomMatch {
 };
 
 /* WARNING: When adding new members to this struct
- * make sure to update libwacom_copy() ! */
+ * make sure to update libwacom_copy() and
+ * libwacom_print_device_description() ! */
 struct _WacomDevice {
        char *name;
        int width;
-- 
1.7.10


------------------------------------------------------------------------------
Better than sec? Nothing is better than sec when it comes to
monitoring Big Data applications. Try Boundary one-second 
resolution app monitoring today. Free.
http://p.sf.net/sfu/Boundary-dev2dev
_______________________________________________
Linuxwacom-devel mailing list
Linuxwacom-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel

Reply via email to