# HG changeset patch # User Tuomo Valkonen # Date 1576082762 -7200 # Node ID 9b0cfc67d6cb5b37d8743a8b62457a12b0e31bee # Parent 6ac8641e7cfb6dbc3c49d5196b23a9cc994c1664 Use Channel comms helper tools form AlgTools. diff -r 6ac8641e7cfb -r 9b0cfc67d6cb src/Visualise.jl --- 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