-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtester.html
executable file
·91 lines (84 loc) · 2.42 KB
/
tester.html
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
<html>
<head>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<style>
.controls {
opacity: 0.5;
}
.controls.connected {
opacity: 1;
}
</style>
</head>
<body>
<div class="triggers">
<label>Servo</label>
<input type="number" value="0" id="servoNumber"/>
<label>Position</label>
<input type="number" value="580" id="servoPosition"/>
<button id="setServo" class="trigger-button">Set</button>
</div>
<div class="detachments">
<label>Servo</label>
<input type="number" value="0" id="detachServoNumber"/>
<button id="detachServo" class="trigger-button">Detach</button>
</div>
<div class="position">
<label>X</label>
<input type="number" value="0" id="x"/>
<label>Y</label>
<input type="number" value="0" id="y"/>
<label>Z</label>
<input type="number" value="0" id="z"/>
<label>Gripper</label>
<input type="number" value="0" id="gripper"/>
<button id="positionServo" class="trigger-button">Set</button>
</div>
<script>
var deviceId = '<ADD YOUR DEVICE ID HERE>',
accessToken = '<ADD YOUR ACCESS TOKEN HERE>';
var baseUrl = 'https://api.spark.io/v1/devices/' + deviceId + '/';
$('#setServo').on('click', function(ev) {
var servoNumber = parseInt($('#servoNumber').val(),10),
servoPosition = parseInt($('#servoPosition').val(),10);
$.ajax({
type: 'POST',
url: baseUrl + 'setServo',
data: {
access_token: accessToken,
args: servoNumber + "," + servoPosition
}
});
});
$('#detachServo').on('click', function(ev) {
var servoNumber = parseInt($('#detachServoNumber').val(),10);
$.ajax({
type: 'POST',
url: baseUrl + 'detachServo',
data: {
access_token: accessToken,
args: servoNumber
}
});
});
$('#positionServo').on('click', function(ev) {
var x = parseInt($('#x').val(),10),
y = parseInt($('#y').val(),10),
z = parseInt($('#z').val(),10),
g = parseInt($('#gripper').val(),10);
$.ajax({
type: 'POST',
url: baseUrl + 'setPosition',
data: {
access_token: accessToken,
args: x + "," + y + "," + z + "," + g
},
success: function(ev) {
console.log(JSON.stringify(ev));
}
});
});
</script>
</body>
</html>