mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-06-05 23:49:00 +08:00
[settings] handle update from other agents than GCS and save based on last known value
This commit is contained in:
@@ -910,14 +910,12 @@ let listen_dl_value = fun () ->
|
|||||||
match ac.dl_settings_page with
|
match ac.dl_settings_page with
|
||||||
Some settings ->
|
Some settings ->
|
||||||
let csv = Pprz.string_assoc "values" vs in
|
let csv = Pprz.string_assoc "values" vs in
|
||||||
let float_of_string_value = fun v -> match v with "?" -> None | _ -> Some v in
|
let 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 values = Array.map string_value (Array.of_list (Str.split list_separator csv)) in
|
||||||
ac.dl_values <- values;
|
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
|
for i = 0 to min (Array.length values) settings#length - 1 do
|
||||||
try
|
try
|
||||||
let v = float_of_value values.(i) in
|
settings#set i values.(i)
|
||||||
settings#set i (try float_of_string v with _ -> failwith (sprintf "values.(%d)" i))
|
|
||||||
with _ -> ()
|
with _ -> ()
|
||||||
done
|
done
|
||||||
| None -> () in
|
| None -> () in
|
||||||
|
|||||||
@@ -31,6 +31,9 @@ class setting = fun (i:int) (xml:Xml.xml) (current_value:GMisc.label) set_defaul
|
|||||||
object
|
object
|
||||||
method index = i
|
method index = i
|
||||||
method xml = xml
|
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 =
|
method current_value =
|
||||||
let auc = Pprz.alt_unit_coef_of_xml xml in
|
let auc = Pprz.alt_unit_coef_of_xml xml in
|
||||||
let (alt_a, alt_b) = Ocaml_tools.affine_transform auc in
|
let (alt_a, alt_b) = Ocaml_tools.affine_transform auc in
|
||||||
@@ -42,7 +45,11 @@ object
|
|||||||
else
|
else
|
||||||
if current_value#text <> s then begin
|
if current_value#text <> s then begin
|
||||||
current_value#set_text s;
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -317,26 +324,31 @@ object (self)
|
|||||||
method widget = sw#coerce
|
method widget = sw#coerce
|
||||||
method length = length
|
method length = length
|
||||||
method keys = !keys
|
method keys = !keys
|
||||||
method set = fun i v ->
|
method set = fun i value ->
|
||||||
if visible self#widget then
|
if visible self#widget then
|
||||||
let setting = variables.(i) in
|
let setting = variables.(i) in
|
||||||
let auc = Pprz.alt_unit_coef_of_xml setting#xml in
|
let s, v = match value with
|
||||||
let (alt_a, alt_b) = Ocaml_tools.affine_transform auc in
|
| None -> "?", -1
|
||||||
let v = alt_a *. v +. alt_b in
|
| Some x ->
|
||||||
let s = string_of_float v in
|
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
|
if i < 0 || i >= Array.length variables then
|
||||||
failwith (sprintf "Pages.settings#set: %d out of bounnds (length=%d)" i (Array.length variables));
|
failwith (sprintf "Pages.settings#set: %d out of bounnds (length=%d)" i (Array.length variables));
|
||||||
let s =
|
let s =
|
||||||
let values = values_of_dl_setting setting#xml in
|
let values = values_of_dl_setting setting#xml in
|
||||||
try
|
try
|
||||||
let lower = int_of_string (ExtXml.attrib setting#xml "min") in
|
let lower = int_of_string (ExtXml.attrib setting#xml "min") in
|
||||||
values.(truncate v - lower)
|
values.(v - lower)
|
||||||
with
|
with
|
||||||
_ -> s in
|
_ -> s in
|
||||||
setting#update s
|
setting#update s
|
||||||
method assoc var = List.assoc var assocs
|
method assoc var = List.assoc var assocs
|
||||||
method save = fun airframe_filename ->
|
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
|
SaveSettings.popup airframe_filename (Array.of_list settings) do_change
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
class settings : ?visible:(GObj.widget -> bool) -> Xml.xml list -> (int -> float -> unit) -> (string -> GObj.widget -> unit) ->
|
class settings : ?visible:(GObj.widget -> bool) -> Xml.xml list -> (int -> float -> unit) -> (string -> GObj.widget -> unit) ->
|
||||||
object
|
object
|
||||||
method length : int (** Total number of settings *)
|
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 assoc : string -> int
|
||||||
method widget : GObj.widget
|
method widget : GObj.widget
|
||||||
method save : string -> unit
|
method save : string -> unit
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ let one_ac = fun (notebook:GPack.notebook) ac_name ->
|
|||||||
|
|
||||||
(* Bind to values updates *)
|
(* Bind to values updates *)
|
||||||
let get_dl_value = fun _sender vs ->
|
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
|
in
|
||||||
ignore (Tele_Pprz.message_bind "DL_VALUE" get_dl_value);
|
ignore (Tele_Pprz.message_bind "DL_VALUE" get_dl_value);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user