Skip to content

Commit

Permalink
[plotter] open new plotter with parent settings
Browse files Browse the repository at this point in the history
  • Loading branch information
gautierhattenberger committed Nov 13, 2013
1 parent a0fcc68 commit 0d7f4f5
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions sw/logalizer/plotter.ml
Expand Up @@ -76,7 +76,7 @@ type status =
| Suspend (* Display is freezed, data are updated *)
| Stop (* Display is active, data are not updated *)

class plot = fun ~size ~width ~height ~packing () ->
class plot = fun ~size ~update_time ~width ~height ~packing () ->
let curves = Hashtbl.create 3 in
let bindings = Hashtbl.create 3 in
object (self)
Expand All @@ -85,14 +85,16 @@ class plot = fun ~size ~width ~height ~packing () ->
val mutable min = max_float
val mutable max = -. max_float
val mutable size = size
val mutable dt = 0.5
val mutable dt = update_time
val mutable color_index = 0
val mutable timer = None
val mutable csts = ([] : float list)
val mutable status = Run
val mutable auto_scale = true
method auto_scale = auto_scale
method set_auto_scale = fun x -> auto_scale <- x
method get_size = size
method get_dt = dt
method min = min
method set_min = fun x -> min <- x
method max = max
Expand Down Expand Up @@ -320,9 +322,9 @@ class plot = fun ~size ~width ~height ~packing () ->
let update_time = ref 0.5
let size = ref 500

type window = { title : string; geometry : string; curves : string list }
type window = { title : string; geometry : string; update : float; size : int; curves : string list }

let default_window = {title="Plotter"; geometry=""; curves=[]}
let default_window = {title="Plotter"; geometry=""; update= !update_time; size= !size; curves=[]; }


(** [index_of_fields s] Returns i if s matches x[i] else 0. *)
Expand Down Expand Up @@ -359,7 +361,7 @@ let rec plot_window = fun window ->
let tooltips = GData.tooltips () in

let width = 900 and height = 200 in
let plot = new plot ~size: !size ~width ~height ~packing:(vbox#pack ~expand:true) () in
let plot = new plot ~size:window.size ~update_time:window.update ~width ~height ~packing:(vbox#pack ~expand:true) () in

let quit = fun () -> GMain.Main.quit (); exit 0 in

Expand All @@ -370,7 +372,7 @@ let rec plot_window = fun window ->
if Hashtbl.length windows = 0 then
quit () in

ignore (file_menu_fact#add_item "New" ~key:GdkKeysyms._N ~callback:(fun () -> plot_window {window with curves=[]}));
ignore (file_menu_fact#add_item "New" ~key:GdkKeysyms._N ~callback:(fun () -> plot_window {window with curves=[]; size=plot#get_size; update=plot#get_dt}));

let reset_item = file_menu_fact#add_item "Reset" ~key:GdkKeysyms._L in
let suspend_item = file_menu_fact#add_item "Suspend" ~key:GdkKeysyms._S in
Expand Down Expand Up @@ -400,14 +402,14 @@ let rec plot_window = fun window ->
ignore (max_entry#connect#activate ~callback:(fun () -> if not plot#auto_scale then plot#set_max (float_of_string max_entry#text)));

(* Update time slider *)
let adj = GData.adjustment ~lower:0.05 ~value: !update_time ~step_incr:0.1 ~upper:11.0 () in
let adj = GData.adjustment ~lower:0.05 ~value:plot#get_dt ~step_incr:0.1 ~upper:11.0 () in
let scale = GRange.scale `HORIZONTAL ~digits:2 ~adjustment:adj ~packing:h#add () in
ignore (adj#connect#value_changed ~callback:(fun () -> plot#set_update_time adj#value));
plot#set_update_time adj#value;
tooltips#set_tip scale#coerce ~text:"Update time (s)";

(* Size slider *)
let adj = GData.adjustment ~lower:10. ~value:(float !size) ~step_incr:10. ~upper:1010. () in
let adj = GData.adjustment ~lower:10. ~value:(float plot#get_size) ~step_incr:10. ~upper:1010. () in
let scale = GRange.scale `HORIZONTAL ~digits:0 ~adjustment:adj ~packing:h#add () in
ignore (adj#connect#value_changed ~callback:(fun () -> plot#set_size (truncate adj#value)));
tooltips#set_tip scale#coerce ~text:"Memory size";
Expand Down Expand Up @@ -562,6 +564,9 @@ let _ =
(fun x -> prerr_endline ("WARNING: don't do anything with "^x))
"Usage: ";

(** reset initial size and update time in case they are passed as argument of the plotter *)
init := List.map (fun w -> {w with size= !size; update= !update_time}) !init;

(** Connect to the Ivy bus *)
Ivy.init "Paparazzi plotter" "READY" (fun _ _ -> ());
Ivy.start !ivy_bus;
Expand Down

0 comments on commit 0d7f4f5

Please sign in to comment.