RSeries astromech firmware
StealthBoardI2C.h
Go to the documentation of this file.
1 #ifndef StealthBoardI2C_h
2 #define StealthBoardI2C_h
3 
4 #include "core/CommandEvent.h"
5 #include <Wire.h>
6 
17 {
18 public:
23  StealthBoardI2C(const byte i2cAddress = 0) :
24  fI2CAddress(i2cAddress)
25  {
26  }
27 
31  virtual void handleCommand(const char* cmd) override
32  {
33  if (*cmd++ == 'S' && *cmd++ == 'T')
34  {
35  byte sum = 0;
36  Wire.beginTransmission(fI2CAddress);
37  for (size_t len = strlen(cmd); len-- > 0; cmd++)
38  {
39  Wire.write(*cmd);
40  sum += byte(*cmd);
41  }
42  Wire.write(sum);
43  Wire.endTransmission();
44  }
45  }
46 
47 private:
48  byte fI2CAddress;
49 };
50 
51 #endif
CommandEvent
Base class for all command enabled devices. CommandEvent::handleCommand() is called for each device e...
Definition: CommandEvent.h:17
StealthBoardI2C::StealthBoardI2C
StealthBoardI2C(const byte i2cAddress=0)
Default Constructor.
Definition: StealthBoardI2C.h:23
StealthBoardI2C::handleCommand
virtual void handleCommand(const char *cmd) override
Stealth Commands start with 'ST'.
Definition: StealthBoardI2C.h:31
StealthBoardI2C
Encapsulates the available i2c commands that can be sent to the ia-parts.com magic panel.
Definition: StealthBoardI2C.h:16
CommandEvent.h