From 2e64fddd80439b7f5aad6e73251fd0cf07a2bbb1 Mon Sep 17 00:00:00 2001 From: matthias wenzel Date: Tue, 30 Apr 2024 09:39:51 +0200 Subject: [PATCH 1/2] add percent() to Rotary Signed-off-by: matthias wenzel --- rotary.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rotary.py b/rotary.py index b599e74..96b80ab 100644 --- a/rotary.py +++ b/rotary.py @@ -112,6 +112,9 @@ def set(self, value=None, min_val=None, incr=None, def value(self): return self._value + def percent(self, scale=100.0): + return scale * (self._value - self._min_val) / (self._max_val - self._min_val) + def reset(self): self._value = 0 From 5d878a3de9229a73ca707125eb9fa49bb81fb64e Mon Sep 17 00:00:00 2001 From: matthias wenzel Date: Tue, 30 Apr 2024 09:44:52 +0200 Subject: [PATCH 2/2] document percent() Signed-off-by: matthias wenzel --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index fd047e2..1cae108 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,12 @@ Examples: * `set(min_val=0, max_val=59)` change encoder bounds - useful to set minutes on a clock display * `set(value=6)` change encoder value to `6`. calling `value()` will now return `6` *** +`percent(scale=100.0)` Return the encoder value in percent + +Examples: +* `percent()` Return the encoder value in percent (0.0 through 100.0) +* `percent(scale=1.0)` Return the encoder value in the range 0.0 through 1.0 +*** `reset()` set encoder value to `min_val`. Redundant with the addition of the `set()` method. Retained for backwards compatibility) *** `add_listener(function)` add a callback function that will be called on each change of encoder count