23 #include <boost/msm/back/state_machine.hpp>
24 #include <boost/msm/front/functor_row.hpp>
25 #include <boost/msm/front/state_machine_def.hpp>
92 namespace msmf = boost::msm::front;
108 template <
class Event,
class Fsm>
111 DEBUG(
"Idle::on_entry()");
112 fsm.next_update_time_ = std::chrono::system_clock::time_point::max();
116 template <
class Event,
class Fsm>
119 DEBUG(
"Idle::on_exit()");
127 template <
class Event,
class Fsm>
130 ERROR(
"Bad event when entering PlayingPattern");
144 std::cout <<
"PlayingPattern::on_entry()" << std::endl;
145 fsm.next_update_time_ = std::chrono::system_clock::now();
146 fsm.playing_pattern_ =
true;
151 template <
class Event,
class Fsm>
154 std::cout <<
"PlayingPattern::on_exit()" << std::endl;
158 if (std::is_same<Event, EventPlayingPatternStop>::value)
159 fsm.playing_pattern_ =
false;
168 template <
class Event,
class Fsm>
171 ERROR(
"Bad event when entering StateBlinking");
178 DEBUG(
"StateBlinking::on_entry(). Duration = "
180 fsm.next_update_time_ = std::chrono::system_clock::now();
183 fsm.led_state_.duration = e.
duration;
184 fsm.led_state_.speed = e.
speed;
189 template <
class Event,
class Fsm>
192 std::cout <<
"StateBlinking::on_exit()" << std::endl;
207 template <
class Event,
class Fsm,
class SourceState,
class TargetState>
208 void operator()(Event
const &, Fsm &, SourceState &, TargetState &)
const
210 ERROR(
"Bad transition");
219 template <
class Event,
class Fsm,
class TargetState>
228 std::pair<int, int> current_pattern = ss.
pattern_.back();
234 b.
speed = current_pattern.second;
235 fsm.process_event(b);
241 template <
class Event,
class Fsm,
class TargetState>
246 fsm.next_update_time_ = std::chrono::system_clock::now() +
247 std::chrono::milliseconds(ss.
speed_);
263 template <
class Fsm,
class SourceState,
class TargetState>
267 if (std::is_same<TargetState, PlayingPattern>::value)
269 return fsm.playing_pattern_;
273 return !fsm.playing_pattern_;
280 : boost::mpl::vector<
282 msmf::Row<Idle, EventBlink, StateBlinking, msmf::none, msmf::none>,
283 msmf::Row<StateBlinking, EventBlinkStop, Idle, msmf::none,
285 msmf::Row<StateBlinking, EventBlinkStop, PlayingPattern, msmf::none,
287 msmf::Row<StateBlinking, EventUpdate, msmf::none, UpdateAction,
289 msmf::Row<Idle, EventPlayingPattern, PlayingPattern, msmf::none,
291 msmf::Row<PlayingPattern, EventUpdate, msmf::none, UpdateAction,
293 msmf::Row<PlayingPattern, EventBlink, StateBlinking, msmf::none,
295 msmf::Row<PlayingPattern, EventPlayingPatternStop, Idle, msmf::none,
331 typedef boost::msm::back::state_machine<SM::LedBuzzerSM_>
LedBuzzerSM;