diff --git a/sw/ground_segment/cockpit/live.ml b/sw/ground_segment/cockpit/live.ml index bcbc9b61de..540a5500a0 100644 --- a/sw/ground_segment/cockpit/live.ml +++ b/sw/ground_segment/cockpit/live.ml @@ -910,14 +910,12 @@ let listen_dl_value = fun () -> match ac.dl_settings_page with Some settings -> let csv = Pprz.string_assoc "values" vs in - let float_of_string_value = fun v -> match v with "?" -> None | _ -> Some v in - let values = Array.map float_of_string_value (Array.of_list (Str.split list_separator csv)) in + let string_value = fun v -> match v with "?" -> None | _ -> Some v in + let values = Array.map string_value (Array.of_list (Str.split list_separator csv)) in ac.dl_values <- values; - let float_of_value = fun v -> match v with None -> raise Not_found | Some x -> x in for i = 0 to min (Array.length values) settings#length - 1 do try - let v = float_of_value values.(i) in - settings#set i (try float_of_string v with _ -> failwith (sprintf "values.(%d)" i)) + settings#set i values.(i) with _ -> () done | None -> () in diff --git a/sw/ground_segment/cockpit/page_settings.ml b/sw/ground_segment/cockpit/page_settings.ml index 8e99856003..0dd1b0ef3f 100644 --- a/sw/ground_segment/cockpit/page_settings.ml +++ b/sw/ground_segment/cockpit/page_settings.ml @@ -31,6 +31,9 @@ class setting = fun (i:int) (xml:Xml.xml) (current_value:GMisc.label) set_defaul object method index = i method xml = xml + val mutable last_known_value = None + method last_known_value = + match last_known_value with None -> raise Not_found | Some v -> v method current_value = let auc = Pprz.alt_unit_coef_of_xml xml in let (alt_a, alt_b) = Ocaml_tools.affine_transform auc in @@ -42,7 +45,11 @@ object else if current_value#text <> s then begin current_value#set_text s; - try set_default (float_of_string s) with Failure "float_of_string" -> () + try + let v = float_of_string s in + last_known_value <- Some v; + set_default v + with Failure "float_of_string" -> () end end @@ -317,26 +324,31 @@ object (self) method widget = sw#coerce method length = length method keys = !keys - method set = fun i v -> + method set = fun i value -> if visible self#widget then let setting = variables.(i) in - let auc = Pprz.alt_unit_coef_of_xml setting#xml in - let (alt_a, alt_b) = Ocaml_tools.affine_transform auc in - let v = alt_a *. v +. alt_b in - let s = string_of_float v in + let s, v = match value with + | None -> "?", -1 + | Some x -> + let v = try float_of_string x with _ -> failwith (sprintf "Pages.settings#set:wrong values.(%d) = %s" i x) in + let auc = Pprz.alt_unit_coef_of_xml setting#xml in + let (alt_a, alt_b) = Ocaml_tools.affine_transform auc in + let v = alt_a *. v +. alt_b in + string_of_float v, truncate v + in if i < 0 || i >= Array.length variables then failwith (sprintf "Pages.settings#set: %d out of bounnds (length=%d)" i (Array.length variables)); let s = let values = values_of_dl_setting setting#xml in try let lower = int_of_string (ExtXml.attrib setting#xml "min") in - values.(truncate v - lower) + values.(v - lower) with _ -> s in setting#update s method assoc var = List.assoc var assocs method save = fun airframe_filename -> - let settings = Array.fold_right (fun setting r -> try (setting#index, setting#xml, setting#current_value)::r with _ -> r) variables [] in + let settings = Array.fold_right (fun setting r -> try (setting#index, setting#xml, setting#last_known_value)::r with _ -> r) variables [] in SaveSettings.popup airframe_filename (Array.of_list settings) do_change end diff --git a/sw/ground_segment/cockpit/page_settings.mli b/sw/ground_segment/cockpit/page_settings.mli index 52691f6a67..73b1600ba5 100644 --- a/sw/ground_segment/cockpit/page_settings.mli +++ b/sw/ground_segment/cockpit/page_settings.mli @@ -26,7 +26,7 @@ class settings : ?visible:(GObj.widget -> bool) -> Xml.xml list -> (int -> float -> unit) -> (string -> GObj.widget -> unit) -> object method length : int (** Total number of settings *) - method set : int -> float -> unit (** Set the current value *) + method set : int -> string option -> unit (** Set the current value *) method assoc : string -> int method widget : GObj.widget method save : string -> unit diff --git a/sw/ground_segment/tmtc/settings.ml b/sw/ground_segment/tmtc/settings.ml index e8ae766efd..0569ccc69c 100644 --- a/sw/ground_segment/tmtc/settings.ml +++ b/sw/ground_segment/tmtc/settings.ml @@ -59,7 +59,7 @@ let one_ac = fun (notebook:GPack.notebook) ac_name -> (* Bind to values updates *) let get_dl_value = fun _sender vs -> - settings#set (Pprz.int_assoc "index" vs) (Pprz.float_assoc "value" vs) + settings#set (Pprz.int_assoc "index" vs) (Some (string_of_float (Pprz.float_assoc "value" vs))) in ignore (Tele_Pprz.message_bind "DL_VALUE" get_dl_value);