From: Jérémie D. <Ba...@us...> - 2011-03-16 23:24:41
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "krobot". The branch, master has been updated via 6ce1124621e474f08558dac8d8f526973716bb9c (commit) from c8e4360b8d33d3ece5eda6020e207d1ffd4cd71f (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 6ce1124621e474f08558dac8d8f526973716bb9c Author: Jérémie Dimino <je...@di...> Date: Thu Mar 17 00:24:02 2011 +0100 [info] draw in a different thread in krobot-plot ----------------------------------------------------------------------- Changes: diff --git a/info/control2011/_oasis b/info/control2011/_oasis index dd67350..660cd97 100644 --- a/info/control2011/_oasis +++ b/info/control2011/_oasis @@ -70,7 +70,7 @@ Executable "krobot-plot" Install: true CompiledObject: best MainIs: krobot_plot.ml - BuildDepends: krobot.can-bus, lwt.syntax, cairo.lablgtk2, lwt.glib + BuildDepends: krobot.can-bus, lwt.syntax, cairo.lablgtk2, lwt.glib, threads # +-------------------------------------------------------------------+ # | Examples | diff --git a/info/control2011/_tags b/info/control2011/_tags index fee2129..84b7177 100644 --- a/info/control2011/_tags +++ b/info/control2011/_tags @@ -2,7 +2,7 @@ <src/interfaces/*.ml>: -syntax_camlp4o # OASIS_START -# DO NOT EDIT (digest: 38a5a55661f6998cf1a3f011ff7ecfd3) +# DO NOT EDIT (digest: 0d12bbe4a1abf7768037e82c428ea4fa) # Library krobot "src/lib": include <src/lib/*.ml{,i}>: pkg_obus @@ -54,6 +54,7 @@ # Executable krobot-plot <tools/krobot_plot.{native,byte}>: use_krobot-can-bus <tools/krobot_plot.{native,byte}>: use_krobot +<tools/krobot_plot.{native,byte}>: pkg_threads <tools/krobot_plot.{native,byte}>: pkg_obus <tools/krobot_plot.{native,byte}>: pkg_lwt.unix <tools/krobot_plot.{native,byte}>: pkg_lwt.syntax @@ -62,6 +63,7 @@ <tools/krobot_plot.{native,byte}>: pkg_cairo.lablgtk2 <tools/*.ml{,i}>: use_krobot-can-bus <tools/*.ml{,i}>: use_krobot +<tools/*.ml{,i}>: pkg_threads <tools/*.ml{,i}>: pkg_obus <tools/*.ml{,i}>: pkg_lwt.unix <tools/*.ml{,i}>: pkg_lwt.syntax diff --git a/info/control2011/setup.ml b/info/control2011/setup.ml index 02aa273..ced1ec2 100644 --- a/info/control2011/setup.ml +++ b/info/control2011/setup.ml @@ -1,7 +1,7 @@ (* setup.ml generated for the first time by OASIS v0.2.0~alpha1 *) (* OASIS_START *) -(* DO NOT EDIT (digest: a60a31dc8dbfa28c3584c2830b23531f) *) +(* DO NOT EDIT (digest: c25983b62a9af39916294c75cf318f50) *) (* Regenerated by OASIS v0.2.0 Visit http://oasis.forge.ocamlcore.org for more information and @@ -5251,7 +5251,8 @@ let setup_t = InternalLibrary "krobot-can-bus"; FindlibPackage ("lwt.syntax", None); FindlibPackage ("cairo.lablgtk2", None); - FindlibPackage ("lwt.glib", None) + FindlibPackage ("lwt.glib", None); + FindlibPackage ("threads", None) ]; bs_build_tools = [ExternalTool "ocamlbuild"]; bs_c_sources = []; diff --git a/info/control2011/tools/krobot_plot.ml b/info/control2011/tools/krobot_plot.ml index 3e8b1f9..e610d8f 100644 --- a/info/control2011/tools/krobot_plot.ml +++ b/info/control2011/tools/krobot_plot.ml @@ -85,6 +85,24 @@ let decode_frame time frame = direction = if get_uint8 data 5 = 0 then Forward else Backward }) (* +-----------------------------------------------------------------+ + | Drawing | + +-----------------------------------------------------------------+ *) + +let draw window graph = + while true do + let { Gtk.width; Gtk.height } = window#misc#allocation in + let surface = Cairo.image_surface_create Cairo.FORMAT_ARGB32 width height in + let ctx = Cairo.create surface in + plot ctx (float width) (float height) graph (Unix.gettimeofday ()); + let ctx = Cairo_lablgtk.create window#misc#window in + Cairo.set_source_surface ctx surface 0. 0.; + Cairo.rectangle ctx 0. 0. (float width) (float height); + Cairo.fill ctx; + Cairo.surface_finish surface; + ignore (Unix.select [] [] [] (1. /. 25.)) + done + +(* +-----------------------------------------------------------------+ | Main-loop | +-----------------------------------------------------------------+ *) @@ -102,38 +120,24 @@ lwt () = let graph = { points = Array.init 4 (fun _ -> Queue.create ()); max = 1 } in + ignore (Thread.create (fun () -> draw window graph) ()); + try_lwt lwt bus = Krobot_can_bus.open_can Sys.argv.(1) in - join [ - (* Data reading. *) - while_lwt true do - (* Read coder positions. *) - lwt coder1, coder2 = Krobot_can_bus.recv bus >|= (fun frame -> decode_frame (Unix.gettimeofday ()) frame) in - lwt coder3, coder4 = Krobot_can_bus.recv bus >|= (fun frame -> decode_frame (Unix.gettimeofday ()) frame) in - (* Compute the new maximum. *) - graph.max <- List.fold_left max graph.max [coder1.position; coder2.position; coder3.position; coder4.position]; - (* Add points to the graph. *) - Queue.push coder1 graph.points.(0); - Queue.push coder2 graph.points.(1); - Queue.push coder3 graph.points.(2); - Queue.push coder4 graph.points.(3); - (* Remove old points. *) - update_graph graph (Unix.gettimeofday ()); - return () - done; - (* Drawing. *) - while_lwt true do - let { Gtk.width; Gtk.height } = window#misc#allocation in - let surface = Cairo.image_surface_create Cairo.FORMAT_ARGB32 width height in - let ctx = Cairo.create surface in - plot ctx (float width) (float height) graph (Unix.gettimeofday ()); - let ctx = Cairo_lablgtk.create window#misc#window in - Cairo.set_source_surface ctx surface 0. 0.; - Cairo.rectangle ctx 0. 0. (float width) (float height); - Cairo.fill ctx; - Cairo.surface_finish surface; - Lwt_unix.sleep 0.05 - done; - ] + while_lwt true do + (* Read coder positions. *) + lwt coder1, coder2 = Krobot_can_bus.recv bus >|= (fun frame -> decode_frame (Unix.gettimeofday ()) frame) in + lwt coder3, coder4 = Krobot_can_bus.recv bus >|= (fun frame -> decode_frame (Unix.gettimeofday ()) frame) in + (* Compute the new maximum. *) + graph.max <- List.fold_left max graph.max [coder1.position; coder2.position; coder3.position; coder4.position]; + (* Add points to the graph. *) + Queue.push coder1 graph.points.(0); + Queue.push coder2 graph.points.(1); + Queue.push coder3 graph.points.(2); + Queue.push coder4 graph.points.(3); + (* Remove old points. *) + update_graph graph (Unix.gettimeofday ()); + return () + done with Unix.Unix_error(error, func, arg) -> Lwt_log.error_f "'%s' failed with: %s" func (Unix.error_message error) hooks/post-receive -- krobot |