summaryrefslogtreecommitdiffstats
path: root/virtual-programs
diff options
context:
space:
mode:
authorAndrés Cuervo <andrescuervor@gmail.com>2023-07-06 18:36:54 +0000
committerAndrés Cuervo <andrescuervor@gmail.com>2023-07-06 18:36:54 +0000
commitc76f4d0876a4bc356d3b7d0242aee04431aafebf (patch)
treef0c09507ee9b98a22cf7616def3371acafd5b270 /virtual-programs
parentWIP: libdrm rendering. standalone pi/Display.tcl works but not Folk (diff)
parentBring back WS send-back? It makes it faster?? (diff)
downloadfolk-c76f4d0876a4bc356d3b7d0242aee04431aafebf.tar.gz
folk-c76f4d0876a4bc356d3b7d0242aee04431aafebf.zip
Merge & fix text call
Diffstat (limited to 'virtual-programs')
-rw-r--r--virtual-programs/archive/metrics.folk17
-rw-r--r--virtual-programs/camera.folk37
-rw-r--r--virtual-programs/music.folk17
-rw-r--r--virtual-programs/new-program-web-editor.folk9
-rw-r--r--virtual-programs/regions.folk3
-rw-r--r--virtual-programs/tags-and-calibration.folk5
-rw-r--r--virtual-programs/web-editor.folk188
7 files changed, 164 insertions, 112 deletions
diff --git a/virtual-programs/archive/metrics.folk b/virtual-programs/archive/metrics.folk
index b4f76fa0..fe6baebd 100644
--- a/virtual-programs/archive/metrics.folk
+++ b/virtual-programs/archive/metrics.folk
@@ -1,11 +1,14 @@
-When $::nodename has step count /c/ {
- Wish $this is labelled [string trim "
+When $::thisNode has step count /c/ & the camera time is /cameraTime/ & the AprilTag time is /aprilTime/ {
+ Wish $this is labelled [string trim "
+
+Metrics
+----
step count: $c
step time: $::stepTime
-camera time: [expr {[namespace exists ::Camera] ? [lindex $::Camera::statements 0 end] : {none}}]
+camera time: $cameraTime
+AprilTag time: $aprilTime
display time: $::Display::displayTime
-statement count: [Statements::size]
-logsize: $::logsize
- "]
+
+"]
}
-Wish $this is outlined green \ No newline at end of file
+Wish $this is outlined skyblue
diff --git a/virtual-programs/camera.folk b/virtual-programs/camera.folk
new file mode 100644
index 00000000..b865392e
--- /dev/null
+++ b/virtual-programs/camera.folk
@@ -0,0 +1,37 @@
+if {$::isLaptop} return
+
+namespace eval ::Camera {
+ variable WIDTH 1280
+ variable HEIGHT 720
+}
+
+On process {
+ source pi/Camera.tcl
+ source pi/AprilTags.tcl
+ Camera::init 1280 720
+ AprilTags::init
+
+ puts "Camera tid: [getTid]"
+
+ while true {
+ set cameraTime [time {
+ set grayFrame [Camera::grayFrame]
+ }]
+ set aprilTime [time {
+ set tags [AprilTags::detect $grayFrame]
+ }]
+
+ Commit {
+ Claim the camera frame is $grayFrame
+
+ Claim the camera time is $cameraTime
+ Claim the AprilTag time is $aprilTime
+
+ foreach tag $tags {
+ Claim tag [dict get $tag id] has center [dict get $tag center] size [dict get $tag size]
+ Claim tag [dict get $tag id] has corners [dict get $tag corners]
+ }
+ }
+ Step
+ }
+}
diff --git a/virtual-programs/music.folk b/virtual-programs/music.folk
index d2c979b6..1f48c9a8 100644
--- a/virtual-programs/music.folk
+++ b/virtual-programs/music.folk
@@ -114,15 +114,18 @@ proc ::Music::finishSetup {} {
exec jack_control dps nperiods 2
exec jack_control dps period 64
+ catch {exec pkill ghci}
catch {exec pkill sclang}
- exec -ignorestderr xvfb-run --auto-servernum sclang $musicDir/startup.sc &
+ after 500 {
+ exec -ignorestderr xvfb-run --auto-servernum sclang $::Music::musicDir/startup.sc &
- set fifo $musicDir/tidal-input
- exec rm -f $fifo
- exec mkfifo $fifo
- exec -ignorestderr sh -c "ghci < $fifo" &
- set fifoId [open $fifo w]
- ::exec cat $musicDir/BootTidal.hs > $fifo
+ set fifo $::Music::musicDir/tidal-input
+ exec rm -f $fifo
+ exec mkfifo $fifo
+ exec -ignorestderr sh -c "ghci < $fifo" &
+ set fifoId [open $fifo w]
+ ::exec cat $::Music::musicDir/BootTidal.hs > $fifo
+ }
}
proc ::Music::waitForDbus {} {
diff --git a/virtual-programs/new-program-web-editor.folk b/virtual-programs/new-program-web-editor.folk
index 692b00e0..5797365b 100644
--- a/virtual-programs/new-program-web-editor.folk
+++ b/virtual-programs/new-program-web-editor.folk
@@ -113,9 +113,9 @@ Wish the web server handles route "/new" with handler {
ws.close();
}
ws.onmessage = (msg) => {
- if (msg.data.startsWith("ERROR:")) {
+ if (msg.data.startsWith("Error:")) {
const errorEl = document.getElementById("error");
- if (msg.data == "ERROR: {}") {
+ if (msg.data === "Error:") {
errorEl.style.backgroundColor = "";
errorEl.innerText = "";
} else {
@@ -153,7 +153,10 @@ Wish the web server handles route "/new" with handler {
if {$::isLaptop} { Step }
`);
setTimeout(() => {
- send(`list ERROR: [Statements::findMatches [list {${program}} has error /err/ with info /errorInfo/]]`);
+ send(`
+set errors [Statements::findMatches [list {${program}} has error /err/ with info /errorInfo/]]
+join [list "Error:" {*}[lmap e $errors {dict get $e errorInfo}]] "\n"
+`);
}, 500);
}
let jobid;
diff --git a/virtual-programs/regions.folk b/virtual-programs/regions.folk
index 1702bbfa..8f320b42 100644
--- a/virtual-programs/regions.folk
+++ b/virtual-programs/regions.folk
@@ -1,5 +1,4 @@
namespace eval ::vec2 {
- namespace import ::tcl::mathop::+ ::tcl::mathop::- ::tcl::mathop::*
proc add {a b} {
list [+ [lindex $a 0] [lindex $b 0]] [+ [lindex $a 1] [lindex $b 1]]
}
@@ -21,8 +20,6 @@ namespace eval ::vec2 {
proc dot {a b} {
expr {[lindex $a 0]*[lindex $b 0] + [lindex $a 1]*[lindex $b 1]}
}
- namespace import ::tcl::mathfunc::max ::tcl::mathfunc::min
- namespace import ::tcl::mathop::/
proc distanceToLineSegment {a v w} {
set l2 [vec2 distance $v $w]
if {$l2 == 0.0} {
diff --git a/virtual-programs/tags-and-calibration.folk b/virtual-programs/tags-and-calibration.folk
index f3155612..cf252de6 100644
--- a/virtual-programs/tags-and-calibration.folk
+++ b/virtual-programs/tags-and-calibration.folk
@@ -1,5 +1,10 @@
if {$::isLaptop} { return }
+namespace eval ::Camera {
+ variable WIDTH 1280
+ variable HEIGHT 720
+}
+
package require math::linearalgebra
namespace import ::math::linearalgebra::add \
::math::linearalgebra::sub \
diff --git a/virtual-programs/web-editor.folk b/virtual-programs/web-editor.folk
index 6669d9fa..ae14f9b4 100644
--- a/virtual-programs/web-editor.folk
+++ b/virtual-programs/web-editor.folk
@@ -1,117 +1,121 @@
Wish the web server handles route {/page/(.*)$} with handler {
if {[regexp -all {/page/(\d*)$} $path whole_match program_id]} {
- set filename "../folk-printed-programs/$program_id.folk"
+ set filename "../folk-printed-programs/$program_id.folk"
set fp [open $filename r]
set file_data [read $fp]
close $fp
} elseif {[regexp -all {/page/(.*)$} $path whole_match program_id]} {
- set filename "virtual-programs/$program_id.folk"
+ set filename "virtual-programs/$program_id.folk"
set fp [open $filename r]
set file_data [read $fp]
close $fp
}
html [string map [list file_data [htmlEscape $file_data] program_id $program_id file_name $filename] {
- <html>
- <body>
- <div>
- <span id="status">Status</span>
- <button onclick="handleSave()">Save</button>
- <button id="print" onclick="handlePrint()">Print</button>
- </div>
- <textarea id="code" style="width: 100%;height: 95vh;">file_data</textarea>
- <pre id="error"></pre>
- <script>
- const isVirtualProgram = 'file_name'.includes('virtual-programs');
+ <html>
+ <body>
+ <div>
+ <span id="status">Status</span>
+ <button onclick="handleSave()">Save</button>
+ <button id="print" onclick="handlePrint()">Print</button>
+ </div>
+ <textarea id="code" style="width: 100%;height: 95vh;">file_data</textarea>
+ <pre id="error"></pre>
+ <script>
+ const isVirtualProgram = 'file_name'.includes('virtual-programs');
- if (isVirtualProgram) {
- document.getElementById("print").disabled = true;
- }
+ if (isVirtualProgram) {
+ document.getElementById("print").disabled = true;
+ }
- const codeEle = document.getElementById("code");
- function uuidv4() {
- return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c =>
- (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
- );
- }
+ const codeEle = document.getElementById("code");
+ function uuidv4() {
+ return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c =>
+ (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
+ );
+ }
- // Cmd + S || Ctrl + S => Save
- document.addEventListener('keydown', function(e) {
- if ((window.navigator.platform.match('Mac') ? e.metaKey : e.ctrlKey) && e.keyCode == 83) {
- e.preventDefault();
- handleSave();
- }
- }, false);
- // Cmd + P || Ctrl + P => Print
- document.addEventListener('keydown', function(e) {
- if ((window.navigator.platform.match('Mac') ? e.metaKey : e.ctrlKey) && e.keyCode == 80) {
- e.preventDefault();
- handlePrint();
- }
- }, false);
+ // Cmd + S || Ctrl + S => Save
+ document.addEventListener('keydown', function(e) {
+ if ((window.navigator.platform.match('Mac') ? e.metaKey : e.ctrlKey) && e.keyCode == 83) {
+ e.preventDefault();
+ handleSave();
+ }
+ }, false);
+ // Cmd + P || Ctrl + P => Print
+ document.addEventListener('keydown', function(e) {
+ if ((window.navigator.platform.match('Mac') ? e.metaKey : e.ctrlKey) && e.keyCode == 80) {
+ e.preventDefault();
+ handlePrint();
+ }
+ }, false);
- let ws;
- let send;
- function wsConnect() {
- ws = new WebSocket(window.location.origin.replace("http", "ws") + "/ws");
- send = function(s) { ws.send(s); }
+ let ws;
+ let send;
+ function wsConnect() {
+ ws = new WebSocket(window.location.origin.replace("http", "ws") + "/ws");
+ send = function(s) { ws.send(s); }
- ws.onopen = () => {
- document.getElementById('status').innerHTML = "<span style=background-color:seagreen;color:white;>Connnected</span>";
- };
- ws.onclose = window.onbeforeunload = () => {
- document.getElementById('status').innerHTML = "<span style=background-color:red;color:white;>Disconnnected</span>";
- setTimeout(() => { wsConnect(); }, 1000);
- };
- ws.onerror = (err) => {
- document.getElementById('status').innerText = "Error";
- console.error('Socket encountered error: ', err.message, 'Closing socket');
- ws.close();
- }
- ws.onmessage = (msg) => {
- if (msg.data.startsWith("ERROR:")) {
- const errorEl = document.getElementById("error");
- if (msg.data == "ERROR: {}") {
- errorEl.style.backgroundColor = "";
- errorEl.innerText = "";
- } else {
- errorEl.style.backgroundColor = "#f55";
- errorEl.innerText = msg.data;
- }
- }
- }
- };
- wsConnect();
+ ws.onopen = () => {
+ document.getElementById('status').innerHTML = "<span style=background-color:seagreen;color:white;>Connnected</span>";
+ };
+ ws.onclose = window.onbeforeunload = () => {
+ document.getElementById('status').innerHTML = "<span style=background-color:red;color:white;>Disconnnected</span>";
+ setTimeout(() => { wsConnect(); }, 1000);
+ };
+ ws.onerror = (err) => {
+ document.getElementById('status').innerText = "Error";
+ console.error('Socket encountered error: ', err.message, 'Closing socket');
+ ws.close();
+ }
+ ws.onmessage = (msg) => {
+ if (msg.data.startsWith("Error:")) {
+ const errorEl = document.getElementById("error");
+ if (msg.data === "Error:") {
+ errorEl.style.backgroundColor = "";
+ errorEl.innerText = "";
+ } else {
+ errorEl.style.backgroundColor = "#f55";
+ errorEl.innerText = msg.data;
+ }
+ }
+ }
+ };
+ wsConnect();
- function handleSave() {
- const code = document.getElementById("code").value;
- send(`
- set fp [open file_name w]
- puts -nonewline $fp {${code}}
- close $fp
- puts "Saved program_id.folk"
- `);
+ function handleSave() {
+ const code = document.getElementById("code").value;
+ send(`
+ set fp [open file_name w]
+ puts -nonewline $fp {${code}}
+ close $fp
+ puts "Saved program_id.folk"
+ `);
if (isVirtualProgram) {
send(`EditVirtualProgram file_name {${code}}`)
- }
+ }
- setTimeout(() => {
- send(`list ERROR: [Statements::findMatches [list program_id has error /err/ with info /errorInfo/]]`);
- }, 500);
- }
- let jobid;
- function handlePrint() {
- const code = document.getElementById("code").value;
- jobid = String(Math.random());
- send(`Assert web wishes to print program program_id with code {${code}} with job id {${jobid}}`);
- setTimeout(500, () => {
- send(`Retract web wishes to print program program_id with code {${code}} with job id {${jobid}}`);
- });
- }
- </script>
- </body>
- </html>
+ setTimeout(() => {
+ send(`
+set errors [Statements::findMatches [list program_id has error /err/ with info /errorInfo/]]
+join [list "Error:" {*}[lmap e $errors {dict get $e errorInfo}]] "\n"
+`);
+ }, 500);
+ }
+
+ let jobid;
+ function handlePrint() {
+ const code = document.getElementById("code").value;
+ jobid = String(Math.random());
+ send(`Assert web wishes to print program program_id with code {${code}} with job id {${jobid}}`);
+ setTimeout(500, () => {
+ send(`Retract web wishes to print program program_id with code {${code}} with job id {${jobid}}`);
+ });
+ }
+ </script>
+ </body>
+ </html>
}]
}