summaryrefslogtreecommitdiffstats
path: root/virtual-programs/camera.folk
blob: f997d4199c89ee56d6e2f306cf126e0cbe701370 (plain)
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
if {$::isLaptop} return

if {$::thisNode eq "folk-interact"} {
    namespace eval ::Camera {
        variable WIDTH 1920
        variable HEIGHT 1080
    }
} else {
    namespace eval ::Camera {
        variable WIDTH 1280
        variable HEIGHT 720
    }
}
set width $::Camera::WIDTH
set height $::Camera::HEIGHT

Start process "camera" {
    Wish $::thisProcess shares statements like \
        [list /someone/ claims the camera /...anything/]

    source pi/Camera.tcl

    Camera::init $width $height

    puts "Camera tid: [getTid] booted at [clock milliseconds]"

    set ::oldFrames [list]
    When $::thisProcess has step count /c/ {
        set frame [Camera::grayFrame]
        Commit {
            Claim the camera time is $::stepTime
            Claim the camera frame is $frame at [clock milliseconds]
        }
        lappend ::oldFrames $frame
        if {[llength $::oldFrames] >= 10} {
            set ::oldFrames [lassign $::oldFrames oldestFrame]
            Camera::freeImage $oldestFrame
        }
    }
}

set ::cameraTime none
When the camera time is /cameraTime/ {
    set ::cameraTime $cameraTime
}
# For backward compatibility.
When the camera frame is /grayFrame/ at /timestamp/ {
    Claim the camera frame is $grayFrame
}