Created
July 16, 2018 12:05
-
-
Save a1ea321/e2575745870bffbeb8dad11d0f81b47e to your computer and use it in GitHub Desktop.
footbased mouse
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sensor import Sensor | |
from pymouse import PyMouse | |
s = Sensor() | |
m = PyMouse() | |
# init sensor | |
while not s.get_single_sample(): pass | |
m.move(10000, 10000) | |
x, y = m.position() | |
m.move(x / 2, y / 2) | |
X_THRESHOLD = 2. | |
Y_THRESHOLD = 6. | |
def convert(raw_value, threshold): | |
PARAM = 1.5 | |
PARAM2 = 1.5 | |
if threshold < val < 2 * threshold: | |
return val - threshold | |
return val | |
while True: | |
sample = s.get_single_sample()[1] | |
#y = y * 0.96 + 0.04 * (sample[0] - 1.0) * (1079 / 4.0) | |
x = m.position()[0] | |
val = sample[8] | |
if abs(val) > X_THRESHOLD: | |
x -= convert(val, X_THRESHOLD) | |
if str(x) == 'nan': continue | |
y = m.position()[1] | |
val = sample[7] | |
if abs(val) > Y_THRESHOLD: | |
y -= convert(val, Y_THRESHOLD) | |
if str(y) == 'nan': continue | |
m.move(x, y) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment