-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathIPCamControl.cs
190 lines (153 loc) · 3.17 KB
/
IPCamControl.cs
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
using UnityEngine;
using System.Collections;
public class IPCamControl : MonoBehaviour
{
public string url;
public string username;
public string password;
public Texture2D texture;
public bool streamOnStart = true;
bool streaming = false;
void Start() {
if(streamOnStart)
StartStream();
}
public void Snapshot ()
{
var request = new HTTP.Request ("GET", URL ("/snapshot.cgi"));
request.Send ((obj) => {
texture.LoadImage (obj.Bytes);
});
}
IEnumerator StreamSnapshots() {
while(streaming) {
var request = new HTTP.Request ("GET", URL ("/snapshot.cgi"));
request.Send ();
while(!request.isDone) yield return null;
if(request.response.status == 200) {
texture.LoadImage (request.response.Bytes);
}
}
}
public void StartStream() {
if(!streaming) {
streaming = true;
StartCoroutine(StreamSnapshots());
}
}
public void StopStream() {
streaming = false;
}
public void Up ()
{
Decoder (0);
}
public void StopUp ()
{
Decoder (1);
}
public void Down ()
{
Decoder (2);
}
public void StopDown ()
{
Decoder (3);
}
public void Left ()
{
Decoder (6);
}
public void StopLeft ()
{
Decoder (7);
}
public void Right ()
{
Decoder (4);
}
public void StopRight ()
{
Decoder (5);
}
public void Center ()
{
Decoder (25);
}
public void VerticalPatrol ()
{
Decoder (26);
}
public void StopVerticalPatrol ()
{
Decoder (27);
}
public void HorizonPatrol ()
{
Decoder (28);
}
public void StopHorizonPatrol ()
{
Decoder (29);
}
public void IOOutputHigh ()
{
Decoder (94);
}
public void IOOutputLow ()
{
Decoder (95);
}
public void SetHighResolution() {
CameraControl(0, 32);
}
public void SetLowResolution() {
CameraControl(0, 8);
}
public void SetBrightness(int brightness) {
if(brightness < 0 || brightness > 255) throw new System.ArgumentException("Brightness must be between 0 - 255");
CameraControl(1, brightness);
}
public void SetContrast(int contrast) {
if(contrast < 0 || contrast > 6) throw new System.ArgumentException("Contrast must be between 0 - 6");
CameraControl(2, contrast);
}
public void Set50hzMode() {
CameraControl(3, 0);
}
public void Set60HzMode() {
CameraControl(3, 1);
}
public void SetOutdoorMode() {
CameraControl(3, 2);
}
public void SetFlipAndMirror(int e) {
if(e < 0 || e > 3) throw new System.ArgumentException("e must be 0,1,2 or 3.");
CameraControl(5, e);
}
public void Reboot() {
var request = new HTTP.Request("GET", URL ("reboot.cgi"));
request.Send();
}
void Decoder (int command)
{
var u = URL ("/decoder_control.cgi") + "&command=" + command.ToString ();
Debug.Log(u);
var request = new HTTP.Request ("GET", u);
request.Send ((HTTP.Response obj) => {
Debug.Log (obj.status);
});
}
void CameraControl(int param, int value) {
var u = URL ("/camera_control.cgi") + string.Format("¶m={0}&value={1}", param, value);
Debug.Log(u);
var request = new HTTP.Request ("GET", u);
request.Send ((HTTP.Response obj) => {
Debug.Log (obj.status);
});
}
string URL (string path)
{
return url + path + "?user=" + username + "&pwd=" + password;
}
}