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;
99 : playing_pattern_(false)
101 , next_update_time_(
std::chrono::system_clock::time_point::max())
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,
302 return next_update_time_;
331 typedef boost::msm::back::state_machine<SM::LedBuzzerSM_>
LedBuzzerSM;
std::chrono::system_clock::time_point next_update() const
Fired when playing pattern has terminated.
void operator()(Event const &, Fsm &, SourceState &, TargetState &) const
void on_entry(Event const &, Fsm &)
void operator()(Event const &, Fsm &fsm, PlayingPattern &ss, TargetState &) const
Updating PlayingPattern.
A Facade to a GPIO object.
void on_entry(Event const &, Fsm &fsm)
This is the header file for a generated source file, GitSHA1.cpp.
bool playing_pattern_
If we are currently blinking in pattern, this will be true.
This event is fired when we want to start blinking.
Hardware::FLED::State led_state_
The state of the LED.
std::vector< std::pair< int, int > > pattern_
Fired when we update the state machine.
void on_entry(EventBlinkStop const &, Fsm &)
void on_exit(Event const &, Fsm &fsm)
bool operator()(const EventBlinkStop &, Fsm &fsm, SourceState &, TargetState &)
Fired when we are done blinking.
boost::msm::back::state_machine< SM::LedBuzzerSM_ > LedBuzzerSM
void on_entry(EventPlayingPattern const &e, Fsm &fsm)
A transition guard that check EventBlinkStop.
int64_t speed
Period for before blinking (ie switch state every N ms)
void on_entry(EventBlink const &e, Fsm &fsm)
void operator()(Event const &, Fsm &fsm, StateBlinking &ss, TargetState &) const
Blink by toggling the GPIO, or return to Idle state.
void on_entry(Event const &, Fsm &)
int64_t duration
Requested duration (in ms) of the blink.
Hardware::FGPIO & gpio_
Facade to the underlying gpio.
Fired when we want to "play" a pattern.
std::chrono::system_clock::time_point next_update_time_
Next time_point we want to be updated.
void on_exit(Event const &, Fsm &)
void on_exit(Event const &, Fsm &fsm)
std::vector< std::pair< int, int > > pattern
A vector of <duration, speed> that represents our blinking pattern.
LedBuzzerSM_(Hardware::FGPIO &h)