RSeries astromech firmware
BadMotivator.h
Go to the documentation of this file.
1 #ifndef BadMotivator_h
2 #define BadMotivator_h
3 
4 #include "core/RelaySwitch.h"
5 #include "core/CommandEvent.h"
6 
52 class BadMotivator :
53  public CommandEvent, protected RelaySwitch
54 {
55 public:
59  BadMotivator(byte smokeRelayPin) :
60  RelaySwitch(smokeRelayPin, PAUSE_TIME)
61  {
62  }
63 
68  void smokeOn()
69  {
70  relayOn(MAXIMUM_TIME);
71  }
72 
76  void smokeOff()
77  {
78  relayOff();
79  }
80 
84  virtual void handleCommand(const char* cmd) override
85  {
86  if (*cmd++ == 'B' && *cmd++ == 'M')
87  {
88  if (cmd[0] == 'O' && cmd[1] == 'N' && cmd[2] == '\0')
89  {
90  smokeOn();
91  }
92  else if (cmd[0] == 'O' && cmd[1] == 'F' && cmd[2] == 'F' && cmd[3] == '\0')
93  {
94  smokeOff();
95  }
96  }
97  }
98 
99 private:
100  static const uint32_t MAXIMUM_TIME = 6500L; /* 6.5 seconds */
101  static const uint32_t PAUSE_TIME = 1*60*1000L; /* 1 minute */
102 };
103 
105 
106 #endif
CommandEvent
Base class for all command enabled devices. CommandEvent::handleCommand() is called for each device e...
Definition: CommandEvent.h:17
RelaySwitch.h
BadMotivator::handleCommand
virtual void handleCommand(const char *cmd) override
BadMotivator Commands start with 'BM'.
Definition: BadMotivator.h:84
BadMotivator
Controls a relay to a smoke machine and some LEDs.
Definition: BadMotivator.h:52
RelaySwitch
Controls a relay.
Definition: RelaySwitch.h:18
BadMotivator::BadMotivator
BadMotivator(byte smokeRelayPin)
Constructor.
Definition: BadMotivator.h:59
RelaySwitch::relayOn
void relayOn(uint32_t switchOffMS=0)
Turn on the smoke machine.
Definition: RelaySwitch.h:40
RelaySwitch::relayOff
void relayOff()
Turn off the smoke machine.
Definition: RelaySwitch.h:58
BadMotivator::smokeOn
void smokeOn()
Turn on the smoke machine.
Definition: BadMotivator.h:68
CommandEvent.h
BadMotivator::smokeOff
void smokeOff()
Turn off the smoke machine.
Definition: BadMotivator.h:76