Linux Input/HID development
 help / color / mirror / Atom feed
* [PATCH 1/2] hid-ntrig: sysfs nodes for modes
@ 2011-03-11  7:37 Rafi Rubin
  2011-03-11  7:37 ` [PATCH 2/2] hid-ntrig: calibration Rafi Rubin
  2011-03-11  8:18 ` [PATCH 1/2] hid-ntrig: sysfs nodes for modes Dmitry Torokhov
  0 siblings, 2 replies; 13+ messages in thread
From: Rafi Rubin @ 2011-03-11  7:37 UTC (permalink / raw)
  To: jkosina, linux-input
  Cc: linux-kernel, micki, rydberg, chatty, dmitry.torokhov, Rafi Rubin

Signed-off-by: Rafi Rubin <rafi@seas.upenn.edu>

---

If the code is there, might as well expose a friendly interface to the
user.
---
 drivers/hid/hid-ntrig.c |   61 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 61 insertions(+), 0 deletions(-)

diff --git a/drivers/hid/hid-ntrig.c b/drivers/hid/hid-ntrig.c
index fa862c5..24ab6a5 100644
--- a/drivers/hid/hid-ntrig.c
+++ b/drivers/hid/hid-ntrig.c
@@ -24,6 +24,8 @@
 
 #define NTRIG_DUPLICATE_USAGES	0x001
 
+static const char *ntrig_modes[4] = { "pen", "touch", "auto", "dual" };
+
 static unsigned int min_width;
 module_param(min_width, uint, 0644);
 MODULE_PARM_DESC(min_width, "Minimum touch contact width to accept.");
@@ -430,6 +432,64 @@ static ssize_t set_deactivate_slack(struct device *dev,
 static DEVICE_ATTR(deactivate_slack, S_IWUSR | S_IRUGO, show_deactivate_slack,
 		   set_deactivate_slack);
 
+
+static ssize_t show_mode(struct device *dev,
+			struct device_attribute *attr,
+			char *buf)
+{
+	int mode = ntrig_get_mode(container_of(dev, struct hid_device, dev));
+	int i, ret;
+	char *s = buf;
+
+	if (mode < 0)
+		return mode;
+
+
+	for (i = 0; i < 4; i++)
+		s += sprintf(s, "%s%s%s ", (i == mode) ? "[" : "",
+			     ntrig_modes[i], (i == mode) ? "]" : "");
+
+	if (mode >= 4)
+		s += sprintf(s, "[%d]\n", mode);
+	else
+		*(s - 1) = '\n';
+
+	ret = s - buf;
+
+	return ret;
+}
+
+static ssize_t store_mode(struct device *dev,
+			       struct device_attribute *attr,
+			       const char *buf, size_t count)
+{
+	int len;
+	int i;
+	int mode = -EINVAL;
+	char *p;
+
+	p = memchr(buf, '\n', count);
+	len = p ? p - buf : count;
+
+	if (len == 1 && buf[0] >= '0' && buf[0] <= '4') {
+		mode = buf[0] - '0';
+	} else
+		for (i = 0; i < 4; i++)
+			if (len == strlen(ntrig_modes[i]) &&
+			    !strncmp(buf, ntrig_modes[i], len)) {
+				mode = i;
+				break;
+			}
+
+	if (mode < 0)
+		return mode;
+
+	ntrig_set_mode(container_of(dev, struct hid_device, dev), mode);
+
+	return count;
+}
+static DEVICE_ATTR(mode, S_IWUSR | S_IRUGO, show_mode, store_mode);
+
 static struct attribute *sysfs_attrs[] = {
 	&dev_attr_sensor_physical_width.attr,
 	&dev_attr_sensor_physical_height.attr,
@@ -441,6 +501,7 @@ static struct attribute *sysfs_attrs[] = {
 	&dev_attr_activation_width.attr,
 	&dev_attr_activation_height.attr,
 	&dev_attr_deactivate_slack.attr,
+	&dev_attr_mode.attr,
 	NULL
 };
 
-- 
1.7.2.3


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2011-03-24 16:52 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-11  7:37 [PATCH 1/2] hid-ntrig: sysfs nodes for modes Rafi Rubin
2011-03-11  7:37 ` [PATCH 2/2] hid-ntrig: calibration Rafi Rubin
2011-03-11  7:48   ` Rafi Rubin
2011-03-15 15:47     ` Jiri Kosina
2011-03-15 20:05       ` Rafi Rubin
2011-03-21 17:15   ` Henrik Rydberg
2011-03-21 18:25     ` Rafi Rubin
2011-03-24 14:32     ` Jiri Kosina
2011-03-24 16:52       ` Rafi Rubin
2011-03-11  8:18 ` [PATCH 1/2] hid-ntrig: sysfs nodes for modes Dmitry Torokhov
2011-03-11  9:56   ` Rafi Rubin
2011-03-13  6:27     ` Dmitry Torokhov
2011-03-15  4:30       ` Rafi Rubin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox