diff mbox series

[11/18] HID: input: calculate resolution for pressure

Message ID 20211221191743.1893185-12-acz@semihalf.com (mailing list archive)
State Superseded
Delegated to: Jiri Kosina
Headers show
Series *** Implement simple haptic HID support *** | expand

Commit Message

Angela Czubak Dec. 21, 2021, 7:17 p.m. UTC
Assume that if the pressure is given in newtons it should be normalized
to grams. If the pressure has no unit do not calculate resolution.

Signed-off-by: Angela Czubak <acz@semihalf.com>
---
 drivers/hid/hid-input.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

Comments

Dmitry Torokhov Jan. 7, 2022, 10:23 p.m. UTC | #1
On Tue, Dec 21, 2021 at 07:17:36PM +0000, Angela Czubak wrote:
> Assume that if the pressure is given in newtons it should be normalized
> to grams. If the pressure has no unit do not calculate resolution.
> 
> Signed-off-by: Angela Czubak <acz@semihalf.com>
> ---
>  drivers/hid/hid-input.c | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
> 
> diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c
> index 81eb277dee91..b680641a30c0 100644
> --- a/drivers/hid/hid-input.c
> +++ b/drivers/hid/hid-input.c
> @@ -257,6 +257,19 @@ __s32 hidinput_calc_abs_res(const struct hid_field *field, __u16 code)
>  		}
>  		break;
>  
> +	case ABS_PRESSURE:
> +	case ABS_MT_PRESSURE:
> +		if (field->unit == 0xe111) {		/* If newtons */

Using a named constant would be great.

> +			/* Convert to grams */

If you could add to the comment that 1 newton is 101.97 grams that would
be great.

> +			prev = physical_extents;
> +			physical_extents *= 10197;
> +			if (physical_extents < prev)
> +				return 0;
> +			unit_exponent -= 2;
> +		} else if (field->unit != 0x101) {	/* If not grams */
> +			return 0;
> +		}
> +		break;
>  	default:
>  		return 0;
>  	}
> -- 
> 2.34.1.307.g9b7440fafd-goog
> 

Thanks.
diff mbox series

Patch

diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c
index 81eb277dee91..b680641a30c0 100644
--- a/drivers/hid/hid-input.c
+++ b/drivers/hid/hid-input.c
@@ -257,6 +257,19 @@  __s32 hidinput_calc_abs_res(const struct hid_field *field, __u16 code)
 		}
 		break;
 
+	case ABS_PRESSURE:
+	case ABS_MT_PRESSURE:
+		if (field->unit == 0xe111) {		/* If newtons */
+			/* Convert to grams */
+			prev = physical_extents;
+			physical_extents *= 10197;
+			if (physical_extents < prev)
+				return 0;
+			unit_exponent -= 2;
+		} else if (field->unit != 0x101) {	/* If not grams */
+			return 0;
+		}
+		break;
 	default:
 		return 0;
 	}