-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmotrr.js
115 lines (98 loc) · 2.82 KB
/
motrr.js
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
var AirBeamMotrr = function () {
var self = {
ipAddress: "",
port: 80,
torch: false,
videoInterval: null
};
self.discovered = function() {
// Flash the LED of the iPhone when detected...
self.torchOff();
self.torchToggle();
setTimeout(function() {
self.torchToggle();
}, 100);
setTimeout(function() {
self.torchToggle();
}, 200);
setTimeout(function() {
self.torchToggle();
}, 300);
setTimeout(function() {
self.torchToggle();
}, 400);
setTimeout(function() {
self.torchToggle();
}, 500);
// Start the video playback
self.startVideo();
}
self.panBy = function (amount) {
amount = (amount === null) ? 0 : amount;
self.request("setPosition?pan=" + amount);
};
self.tiltBy = function (amount) {
amount = (amount === null) ? 0 : amount;
self.request("setPosition?tilt=" + amount);
};
self.startPan = function (velocity) {
velocity = (velocity === null) ? 0 : velocity;
self.request("setVelocity?pan=" + velocity);
};
self.adjustPan = function (velocity) {
velocity = (velocity === null) ? 0 : velocity;
self.request("incrementVelocity?pan=" + velocity);
};
self.startTilt = function (velocity) {
velocity = (velocity === null) ? 0 : velocity;
self.request("setVelocity?tilt=" + velocity);
};
self.adjustTilt = function (velocity) {
velocity = (velocity === null) ? 0 : velocity;
self.request("incrementVelocity?tilt=" + velocity);
};
self.stop = function () {
self.request("setVelocity?pan=0&tilt=0");
};
self.torchOn = function () {
self.torch = true;
self.request("torchon");
// Update button tagged 'torch' to active state
CF.setJoin("torch", 1);
};
self.torchOff = function () {
self.torch = false;
self.request("torchoff");
// Update button tagged 'torch' to inactive state
CF.setJoin("torch", 0);
};
self.torchToggle = function () {
if (self.torch) {
self.torchOff();
} else {
self.torchOn();
}
};
self.spin = function () {
// Pan and Tilt at a high speed for fun...
self.request("setVelocity?pan=40&tilt=40");
};
self.startVideo = function() {
// Start showing video on the image object tagged 'video' in the GUI.
self.videoInterval = setInterval(function() {
CF.setJoin("video", "http://" + self.ipAddress + ":" + self.port + "/image.jpg?" + new Date().getTime());
}, 100);
}
self.stopVideo = function() {
clearInterval(self.videoInterval);
}
self.request = function (url) {
if (self.ipAddress == "") {
CF.log("This AirBeamMotrr instance has not been given an IP Address yet...");
return;
}
CF.log("AirBeam Motrr Request: " + "http://" + self.ipAddress + ":" + self.port + "/" + url);
CF.request("http://" + self.ipAddress + ":" + self.port + "/" + url, function(){});
}
return self;
};