summaryrefslogtreecommitdiffhomepage
path: root/digital
diff options
context:
space:
mode:
authorNicolas Schodet2013-03-24 00:15:58 +0100
committerNicolas Schodet2013-03-26 21:03:14 +0100
commit9ee19a4d7c2abfcf73001c391687250961597337 (patch)
treeb4528383746b4f8fd108ec54fa186ea20895b860 /digital
parentf351f14ce40700e8a47c7322853b6c28da60d7d0 (diff)
digital/io-hub/src/apbirthday: add FSM debug
Diffstat (limited to 'digital')
-rw-r--r--digital/io-hub/src/apbirthday/robot.cc13
-rw-r--r--digital/io-hub/src/apbirthday/robot.hh11
2 files changed, 22 insertions, 2 deletions
diff --git a/digital/io-hub/src/apbirthday/robot.cc b/digital/io-hub/src/apbirthday/robot.cc
index 25ea7059..2dc3de95 100644
--- a/digital/io-hub/src/apbirthday/robot.cc
+++ b/digital/io-hub/src/apbirthday/robot.cc
@@ -37,6 +37,7 @@ Robot::Robot ()
zb_proto (*this, hardware.zb_uart),
usb_proto (*this, hardware.usb),
chrono (90000 - 1000),
+ fsm_debug_state_ (FSM_DEBUG_RUN),
outputs_set_ (outputs_, lengthof (outputs_)),
stats_proto_ (0),
stats_chrono_ (false), stats_chrono_last_s_ (-1),
@@ -92,8 +93,12 @@ Robot::main_loop ()
// Handle communications.
bool sync = main_i2c_queue_.sync ();
// Handle events if synchronised.
- if (sync)
- fsm_gen_event ();
+ if (sync && fsm_debug_state_ != FSM_DEBUG_STOP)
+ {
+ if (fsm_gen_event ()
+ && fsm_debug_state_ == FSM_DEBUG_STEP)
+ fsm_debug_state_ = FSM_DEBUG_STOP;
+ }
// Handle commands.
dev_proto.accept ();
zb_proto.accept ();
@@ -147,6 +152,10 @@ Robot::proto_handle (ucoo::Proto &proto, char cmd, const uint8_t *args, int size
// Reset.
ucoo::arch_reset ();
break;
+ case c ('f', 0):
+ // Enter FSM debug mode, then step once.
+ fsm_debug_state_ = FSM_DEBUG_STEP;
+ break;
case c ('m', 5):
// Go to position.
// 2H: x, y.
diff --git a/digital/io-hub/src/apbirthday/robot.hh b/digital/io-hub/src/apbirthday/robot.hh
index f7d5e57a..99997fd0 100644
--- a/digital/io-hub/src/apbirthday/robot.hh
+++ b/digital/io-hub/src/apbirthday/robot.hh
@@ -63,6 +63,17 @@ class Robot : public ucoo::Proto::Handler
/// Public access to chrono.
Chrono chrono;
private:
+ /// FSM debug mode.
+ enum FsmDebugState
+ {
+ /// Not debugging, running.
+ FSM_DEBUG_RUN,
+ /// Will stop after next transition.
+ FSM_DEBUG_STEP,
+ /// Stopped, waiting for orders.
+ FSM_DEBUG_STOP,
+ };
+ FsmDebugState fsm_debug_state_;
/// All inputs.
ucoo::Io *inputs_[Hardware::inputs_nb];
/// All outputs.