-
Notifications
You must be signed in to change notification settings - Fork 3
/
Flick.py
123 lines (102 loc) · 2.59 KB
/
Flick.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/env python
# -*- coding: <utf-8> -*-
#Author: Callum Pritchard, Joachim Hummel
#Project Name: Flick 3D Gesture
#Project Description: Sending Flick 3D Gesture sensor data to mqtt
#Version Number: 0.1
#Date: 15/6/17
#Release State: Alpha testing
#Changes: Created
#needed commands
# pip install paho-mqtt
# Run this line and Flick will be setup and installed
# curl -sSL https://pisupp.ly/flickcode | sudo bash
import signal
import flicklib
import time
import paho.mqtt.client as mqtt
from curses import wrapper
some_value = 5000
def message(publisher, value):
client = mqtt.Client()
client.connect("mqtt.unixweb.de",1883,60)
client.publish(publisher, value)
client.disconnect()
@flicklib.move()
def move(x, y, z):
global xyztxt
xyztxt = '{:5.3f} {:5.3f} {:5.3f}'.format(x,y,z)
@flicklib.flick()
def flick(start,finish):
global flicktxt
flicktxt = 'FLICK-' + start[0].upper() + finish[0].upper()
message('flick',flicktxt)
@flicklib.airwheel()
def spinny(delta):
global some_value
global airwheeltxt
some_value += delta
if some_value < 0:
some_value = 0
if some_value > 10000:
some_value = 10000
airwheeltxt = str(some_value/100)
@flicklib.double_tap()
def doubletap(position):
global doubletaptxt
doubletaptxt = position
@flicklib.tap()
def tap(position):
global taptxt
taptxt = position
@flicklib.touch()
def touch(position):
global touchtxt
touchtxt = position
def main():
global xyztxt
global flicktxt
global airwheeltxt
global touchtxt
global taptxt
global doubletaptxt
xyztxt = ''
flicktxt = ''
flickcount = 0
airwheeltxt = ''
airwheelcount = 0
touchtxt = ''
touchcount = 0
taptxt = ''
tapcount = 0
doubletaptxt = ''
doubletapcount = 0
while True:
xyztxt = ''
if len(flicktxt) > 0 and flickcount < 5:
flickcount += 1
else:
flicktxt = ''
flickcount = 0
if len(airwheeltxt) > 0 and airwheelcount < 5:
airwheelcount += 1
else:
airwheeltxt = ''
airwheelcount = 0
if len(touchtxt) > 0 and touchcount < 5:
touchcount += 1
else:
touchtxt = ''
touchcount = 0
if len(taptxt) > 0 and tapcount < 5:
tapcount += 1
else:
taptxt = ''
tapcount = 0
if len(doubletaptxt) > 0 and doubletapcount < 5:
doubletapcount += 1
else:
doubletaptxt = ''
doubletapcount = 0
time.sleep(0.1)
main()