Add reloading page to camera + change round xlib example.

This commit is contained in:
Brad Nelson
2021-06-12 17:29:56 -07:00
parent 24a4525387
commit cfa5f803e8
2 changed files with 43 additions and 1 deletions

View File

@ -4,6 +4,47 @@ DEFINED? camera [IF]
vocabulary camera-server camera-server definitions
also camera also httpd
r|
<!DOCTYPE html>
<body>
<img id="pic">
<script>
var pic = document.getElementById('pic');
function httpPost(url, callback) {
var r = new XMLHttpRequest();
r.responseType = 'blob';
r.onreadystatechange = function() {
if (this.readyState == XMLHttpRequest.DONE) {
if (this.status === 200) {
callback(this.response);
} else {
callback(null);
}
}
};
r.open('POST', url);
r.send();
}
function Frame() {
httpPost('./image', function(r) {
if (r !== null) {
try {
pic.src = URL.createObjectURL(r);
} catch (e) {
}
}
setTimeout(Frame, 30);
});
}
Frame();
</script>
| constant index-html# constant index-html
: handle-index
s" text/html" ok-response
index-html index-html# send
;
: handle-image
s" image/jpeg" ok-response
esp_camera_fb_get dup dup @ swap cell+ @ send
@ -12,6 +53,7 @@ also camera also httpd
: handle1
handleClient
s" /" path str= if handle-index exit then
s" /image" path str= if handle-image exit then
notfound-response
;

View File

@ -2,7 +2,7 @@ include posix/xlib.fs
also x11
z" :0" XOpenDisplay constant display
0 XOpenDisplay constant display
display XDefaultScreen constant screen
display screen XBlackPixel constant black
display screen XWhitePixel constant white