Skip to content

Commit e6540c1

Browse files
committed
Update ipcam2 example
1 parent 8a66458 commit e6540c1

File tree

6 files changed

+329
-5
lines changed

6 files changed

+329
-5
lines changed

examples/ipcam2/code.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
from adafruit_httpserver import (BAD_REQUEST_400, GET, NOT_FOUND_404, POST, FileResponse,
1717
JSONResponse, Request, Response, Server)
1818

19+
# Disable autoreload. this is very handy while editing the js & html files
20+
# as you want to just reload the web browser, not the CircutPython program!
21+
import supervisor
22+
supervisor.runtime.autoreload = False
23+
1924
pycam = adafruit_pycamera.PyCamera()
2025
pycam.autofocus_init()
2126

@@ -34,7 +39,7 @@
3439

3540
@server.route("/metadata.json", [GET])
3641
def property(request: Request) -> Response:
37-
return FileResponse(request, "/metadata.json")
42+
return FileResponse(request, "/metadata.js")
3843

3944
@server.route("/", [GET])
4045
def property(request: Request) -> Response:

examples/ipcam2/htdocs/index.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<template id="control">
5+
<tr>
6+
<td>Contents</td>
7+
</tr>
8+
</template>
9+
<body>
10+
<div id="image">
11+
<img src="/jpeg" id="jpeg">
12+
</div>
13+
<div id="controls">
14+
</div>
15+
<script src="/metadata.js"></script>
16+
<script src="/index.js"></script>
17+
</body>
18+
</html>

examples/ipcam2/htdocs/index.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
const html = (strings, ...values) => String.raw({ raw: strings }, ...values);
2+
3+
var ii = 0;
4+
5+
function option_change(k1, k2) {
6+
var id_ = k1 + "-" + k2;
7+
var el = document.getElementById(id_)
8+
9+
url = `/${k1}?k=${k2}&v=${el.value}`
10+
console.log(url)
11+
var req = new XMLHttpRequest();
12+
req.open("GET", url, false)
13+
req.send();
14+
15+
document.getElementById("jpeg").src = `/jpeg?${ii++}`
16+
}
17+
18+
function make_controls(k1, t) {
19+
console.log(t);
20+
for(var k2 in t) {
21+
var id_ = k1 + "-" + k2;
22+
var options = ""
23+
for(var v in t[k2]) {
24+
options += html`
25+
<option value="${v}">${v}</option>
26+
`
27+
}
28+
var ht = html`
29+
<form >
30+
<label for="${id_}">${k2}:</label>
31+
<select id="${id_}" onchange="option_change('${k1}', '${k2}')">
32+
${options}
33+
</select>
34+
</form>
35+
`
36+
console.log(ht);
37+
38+
var el = document.getElementById("controls")
39+
el.insertAdjacentHTML("beforeend", ht)
40+
}
41+
}
42+
43+
for(var k in tunables) {
44+
console.log(k)
45+
make_controls(k, tunables[k]);
46+
}

examples/ipcam2/htdocs/metadata.js

Lines changed: 254 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,254 @@
1+
tunables = {
2+
"property": {
3+
"effect": [
4+
"Normal",
5+
"Invert",
6+
"B&W",
7+
"Reddish",
8+
"Greenish",
9+
"Bluish",
10+
"Sepia",
11+
"Solarize"
12+
],
13+
"resolution": [
14+
"240x240",
15+
"320x240",
16+
"640x480",
17+
"800x600",
18+
"1024x768",
19+
"1280x720",
20+
"1280x1024",
21+
"1600x1200",
22+
"1920x1080",
23+
"2048x1536",
24+
"2560x1440",
25+
"2560x1600",
26+
"2560x1920"
27+
],
28+
"led_level": [
29+
0,
30+
1,
31+
2,
32+
3,
33+
4
34+
],
35+
"led_color": [
36+
0,
37+
1,
38+
2,
39+
3,
40+
4,
41+
5,
42+
6,
43+
7
44+
]
45+
},
46+
"property2": {
47+
"contrast": [
48+
-2,
49+
-1,
50+
0,
51+
1,
52+
2
53+
],
54+
"brightness": [
55+
-2,
56+
-1,
57+
0,
58+
1,
59+
2
60+
],
61+
"saturation": [
62+
-2,
63+
-1,
64+
0,
65+
1,
66+
2
67+
],
68+
"sharpness": [
69+
-2,
70+
-1,
71+
0,
72+
1,
73+
2
74+
],
75+
"ae_level": [
76+
-2,
77+
-1,
78+
0,
79+
1,
80+
2
81+
],
82+
"denoise": [
83+
0,
84+
1,
85+
2,
86+
3,
87+
4,
88+
5,
89+
6,
90+
7,
91+
8,
92+
9
93+
],
94+
"gain_ceiling": [
95+
0,
96+
1,
97+
2,
98+
3,
99+
4,
100+
5,
101+
6,
102+
7,
103+
8,
104+
9
105+
],
106+
"quality": [
107+
8,
108+
9,
109+
10,
110+
11,
111+
12,
112+
13,
113+
14,
114+
15,
115+
16,
116+
17,
117+
18,
118+
19,
119+
20,
120+
21,
121+
22,
122+
23,
123+
24,
124+
25,
125+
26,
126+
27,
127+
28,
128+
29,
129+
30,
130+
31,
131+
32,
132+
33,
133+
34,
134+
35
135+
],
136+
"colorbar": [
137+
false,
138+
true
139+
],
140+
"whitebal": [
141+
false,
142+
true
143+
],
144+
"gain_ctrl": [
145+
false,
146+
true
147+
],
148+
"exposure_ctrl": [
149+
false,
150+
true
151+
],
152+
"hmirror": [
153+
false,
154+
true
155+
],
156+
"vflip": [
157+
false,
158+
true
159+
],
160+
"aec2": [
161+
false,
162+
true
163+
],
164+
"awb_gain": [
165+
false,
166+
true
167+
],
168+
"dcw": [
169+
false,
170+
true
171+
],
172+
"bpc": [
173+
false,
174+
true
175+
],
176+
"wpc": [
177+
false,
178+
true
179+
],
180+
"raw_gma": [
181+
false,
182+
true
183+
],
184+
"lenc": [
185+
false,
186+
true
187+
],
188+
"aec_gain": [
189+
0,
190+
1,
191+
2,
192+
3,
193+
4,
194+
5,
195+
6,
196+
7,
197+
8,
198+
9,
199+
10,
200+
11,
201+
12,
202+
13,
203+
14,
204+
15,
205+
16,
206+
17,
207+
18,
208+
19,
209+
20,
210+
21,
211+
22,
212+
23,
213+
24,
214+
25,
215+
26,
216+
27,
217+
28,
218+
29
219+
],
220+
"aec_value": [
221+
0,
222+
50,
223+
100,
224+
150,
225+
200,
226+
250,
227+
300,
228+
350,
229+
400,
230+
450,
231+
500,
232+
550,
233+
600,
234+
650,
235+
700,
236+
750,
237+
800,
238+
850,
239+
900,
240+
950,
241+
1000,
242+
1050,
243+
1100,
244+
1150
245+
],
246+
"wb_mode": [
247+
0,
248+
1,
249+
2,
250+
3,
251+
4
252+
]
253+
}
254+
};

examples/ipcam2/htdocs/metadata.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

examples/ipcam2/make_web_metadata.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def list_range(*args): return list(range(*args))
3333
"led_color": list_range(8),
3434
},
3535
"property2": {
36-
"sensor_name": None,
36+
#"sensor_name": None,
3737
"contrast": list_range(-2, 3),
3838
"brightness": list_range(-2, 3),
3939
"saturation": list_range(-2, 3),
@@ -61,5 +61,7 @@ def list_range(*args): return list(range(*args))
6161
},
6262
}
6363

64-
with open("metadata.json", "w", encoding="utf-8") as f:
65-
json.dump(metadata, f)
64+
with open("htdocs/metadata.js", "w", encoding="utf-8") as f:
65+
print(end="tunables = ", file=f)
66+
json.dump(metadata, f, indent=4)
67+
print(";", file=f)

0 commit comments

Comments
 (0)