|
From: Jérémie D. <Ba...@us...> - 2010-02-02 14:52:29
|
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 317345f5f4277633b9600b366d2150d59cfcdfca (commit)
from 8370857c4bdbf0534e57609729a5b5ebcbceff17 (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 317345f5f4277633b9600b366d2150d59cfcdfca
Author: Jérémie Dimino <je...@di...>
Date: Tue Feb 2 15:51:57 2010 +0100
implement controls in the monitor
-----------------------------------------------------------------------
Changes:
diff --git a/PC_Mainboard/clients/tools/monitor.ml b/PC_Mainboard/clients/tools/monitor.ml
index 01796f0..0cf506b 100644
--- a/PC_Mainboard/clients/tools/monitor.ml
+++ b/PC_Mainboard/clients/tools/monitor.ml
@@ -58,7 +58,7 @@ let draw_text clip ?style x y txt =
let drawer_mutex = Lwt_mutex.create ()
(* Draw the whole screen *)
-let rec draw size (compass, logic_sensors, range_finders, team, jack) (engine_state, box) (state_interface, state_sensor, state_motor) =
+let rec draw size (compass, logic_sensors, range_finders, team, jack) (engine_state, box, logs) (state_interface, state_sensor, state_motor) =
Lwt_mutex.with_lock drawer_mutex begin fun () ->
if Lwt_mutex.is_empty drawer_mutex then begin
(* Redraw the screen only if there is no other thread waiting to
@@ -119,6 +119,22 @@ let rec draw size (compass, logic_sensors, range_finders, team, jack) (engine_st
Draw.textf zone x 4 "sensor card is %s" (string_of_state state_sensor);
Draw.textf zone x 5 "motor card is %s" (string_of_state state_motor);
+ (* ===== History ===== *)
+
+ let zone = Zone.sub ~zone:screen ~x:1 ~y:10 ~width:(Zone.width screen - 2) ~height:(Zone.height screen - 15) in
+ let rec loop y = function
+ | [] ->
+ ()
+ | line :: rest ->
+ if y < 0 then
+ ()
+ else begin
+ Draw.text zone 0 y line;
+ loop (y - 1) rest
+ end
+ in
+ loop (Zone.height zone - 1) logs;
+
(* ===== Read-line ===== *)
points.(size.lines - 3).(0) <- { blank with char = "├" };
@@ -204,13 +220,44 @@ let rec draw size (compass, logic_sensors, range_finders, team, jack) (engine_st
end
(* +-----------------------------------------------------------------+
+ | Actions |
+ +-----------------------------------------------------------------+ *)
+
+let handle_action krobot line =
+ match Text.words line with
+ | [] ->
+ return ()
+ | action :: args ->
+ let rec make_args acc = function
+ | [] | [_] ->
+ acc
+ | key :: value :: rest ->
+ make_args ((key, value) :: acc) rest
+ in
+ let args = make_args [] args in
+ let arg key default = try int_of_string (List.assoc key args) with Not_found -> default in
+ match action with
+ | "forward" ->
+ Krobot.move krobot ~dist:(arg "dist" 100) ~speed:(arg "speed" 400) ?acc:(arg "acc" 800)
+ | "backward" ->
+ Krobot.move krobot ~dist:(-(arg "dist" 100)) ~speed:(arg "speed" 400) ?acc:(arg "acc" 800)
+ | "left" ->
+ Krobot.turn krobot ~angle:(arg "dist" 100) ~speed:(arg "speed" 400) ?acc:(arg "acc" 800)
+ | "right" ->
+ Krobot.turn krobot ~angle:(-(arg "dist" 100)) ~speed:(arg "speed" 400) ?acc:(arg "acc" 800)
+ | _ ->
+ return ()
+
+(* +-----------------------------------------------------------------+
| Read-line |
+-----------------------------------------------------------------+ *)
let engine_state, set_engine_state = React.S.create (Engine.init [])
let box, set_box = React.S.create Terminal.Box_empty
-let functions = List.fold_left (fun set x -> TextSet.add x set) TextSet.empty [
+let set_of_list l = List.fold_left (fun set x -> TextSet.add x set) TextSet.empty l
+
+let functions = set_of_list [
"exit";
"forward";
"backward";
@@ -218,10 +265,19 @@ let functions = List.fold_left (fun set x -> TextSet.add x set) TextSet.empty [
"right";
]
+let argument = <:re< alpha+ blank* "=" blank* alnum+ >>
+
let complete before after =
match before with
- | <:re< (space* as before) (["a" - "z"]* as word) eos >> ->
- Lwt_read_line.complete before word after functions
+ | <:re< (blank* as before) (alpha* as word) eos >> ->
+ Lwt_read_line.complete ~suffix:" " before word after functions
+ | <:re< (blank* (alpha+ as action) (blank+ argument)* blank+ as before) (alpha* as arg) eos >> ->
+ Lwt_read_line.complete ~suffix:"=" before arg after
+ (set_of_list
+ (match action with
+ | "forward" | "backward" -> ["dist"; "speed"; "acc"]
+ | "right" | "left" -> ["angle"; "speed"; "acc"]
+ | _ -> []))
| _ ->
{ comp_state = (before, after);
comp_words = TextSet.empty }
@@ -238,7 +294,9 @@ let () =
set_box (Terminal.Box_message "<backward search>"))
(React.S.map (fun state -> state.Engine.mode) engine_state)
-let rec loop history =
+let logs, set_logs = React.S.create []
+
+let rec loop krobot history =
lwt key = read_key () in
if key = key_escape then
return ()
@@ -251,17 +309,19 @@ let rec loop history =
else begin
let history = Lwt_read_line.add_entry line history in
set_engine_state (Engine.init history);
- loop history
+ set_logs (line :: React.S.value logs);
+ ignore (handle_action krobot line);
+ loop krobot history
end
| Command.Complete ->
let engine_state = Engine.reset (React.S.value engine_state) in
let before, after = Engine.edition_state engine_state in
let comp = complete before after in
set_engine_state { engine_state with Engine.mode = Engine.Edition comp.comp_state };
- loop history
+ loop krobot history
| command ->
set_engine_state (Engine.update (React.S.value engine_state) command ());
- loop history
+ loop krobot history
(* +-----------------------------------------------------------------+
| Entry point |
@@ -280,9 +340,10 @@ lwt () =
(Krobot.range_finders krobot)
(Krobot.team krobot)
(Krobot.jack krobot))
- (React.S.l2 (fun a b -> (a, b))
+ (React.S.l3 (fun a b c -> (a, b, c))
engine_state
- box)
+ box
+ logs)
(React.S.l3 (fun a b c -> (a, b, c))
(Krobot.Card.state krobot `Interface)
(Krobot.Card.state krobot `Sensor)
@@ -290,6 +351,6 @@ lwt () =
in
(* Make the compiler happy: *)
ignore signal;
- Lwt_term.with_raw_mode (fun () -> loop [])
+ Lwt_term.with_raw_mode (fun () -> loop krobot [])
finally
show_cursor ()
hooks/post-receive
--
krobot
|