Use Channel comms helper tools form AlgTools.

Wed, 11 Dec 2019 18:46:02 +0200

author
Tuomo Valkonen <tuomov@iki.fi>
date
Wed, 11 Dec 2019 18:46:02 +0200
changeset 16
9b0cfc67d6cb
parent 15
6ac8641e7cfb
child 17
8ff7da7bc77d

Use Channel comms helper tools form AlgTools.

src/Visualise.jl file | annotate | diff | comparison | revisions
--- a/src/Visualise.jl	Tue Dec 10 15:41:20 2019 +0200
+++ b/src/Visualise.jl	Wed Dec 11 18:46:02 2019 +0200
@@ -15,6 +15,7 @@
 using AlgTools.Util
 using AlgTools.StructTools
 using AlgTools.LinkedLists
+using AlgTools.Comms
 
 ##############
 # Our exports
@@ -64,19 +65,7 @@
 ################
 
 function bg_visualise(rc)
-    while true
-        imgs=take!(rc)
-        # Take only the latest image to visualise
-        while isready(rc)
-            imgs=take!(rc)
-        end
-        # We're done if we were fed an empty image
-        if isnothing(imgs)
-            break
-        end
-        do_visualise(imgs)
-    end
-    return
+    process_channel(do_visualise, rc)
 end
 
 # function do_visualise(imgs)
@@ -89,7 +78,7 @@
     return 0x010101*y + 0xff000000
 end
 
-function do_visualise(imgs)
+function do_visualise(imgs; refresh=true)
     n = length(imgs)
     # Get device dimensions in metres and pixels
     scrw, scrh, pw, ph = GR.inqdspsize()
@@ -116,16 +105,14 @@
         sz = size(im)
         GR.drawimage(i-1, i, 0, 1, sz[1], sz[2], grayGR.(im))
     end
-    GR.updatews()
+    if refresh
+        GR.updatews()
+    end
 end
 
 function visualise(channel_or_toggle, imgs)
     if isa(channel_or_toggle, Channel)
-        rc = channel_or_toggle
-        while isready(rc)
-            take!(rc)
-        end
-        put!(rc, imgs)
+        put_onlylatest!(channel_or_toggle, imgs)
     elseif isa(channel_or_toggle, Bool) && channel_or_toggle
         do_visualise(imgs)
     end

mercurial