RSeries astromech firmware
MagicPanelI2C.h
Go to the documentation of this file.
1 #ifndef MagicPanelI2C_h
2 #define MagicPanelI2C_h
3 
4 #include "core/CommandEvent.h"
5 #include <Wire.h>
6 
17 {
18 public:
19  MagicPanelI2C(const byte i2cAddress = I2C_MAGIC_PANEL) :
20  fI2CAddress(i2cAddress)
21  {
22  }
23 
27  virtual void handleCommand(const char* cmd) override
28  {
29  if (cmd[0] == 'M' && cmd[1] == 'P')
30  {
31  DEBUG_PRINT("SEND: "); DEBUG_PRINTLN(cmd);
32  Wire.beginTransmission(fI2CAddress);
33  for (size_t len = strlen(cmd); len-- > 0; cmd++)
34  Wire.write(*cmd);
35  Wire.endTransmission();
36  }
37  }
38 
39 private:
40  byte fI2CAddress;
41 };
42 
43 
54 {
55 public:
56  MagicPanelClassicI2C(const byte i2cAddress = 0x14) :
57  fI2CAddress(i2cAddress)
58  {
59  }
60 
61  void on(byte numSeconds = 0)
62  {
63  switch (numSeconds)
64  {
65  case 0:
66  sendCommand(kPanelOn);
67  break;
68  case 2:
69  sendCommand(kPanelOn2S);
70  break;
71  case 5:
72  sendCommand(kPanelOn5S);
73  break;
74  case 10:
75  sendCommand(kPanelOn10S);
76  break;
77  }
78  }
79 
80  void off()
81  {
82  sendCommand(kPanelOff);
83  }
84 
85  void random()
86  {
87  sendCommand(kPanelRandom6S);
88  }
89 
90 private:
91  enum
92  {
93  kPanelOff = 0,
94  kPanelOn = 1,
95  kPanelOn2S = 2,
96  kPanelOn5S = 3,
97  kPanelOn10S = 4,
98  kPanelToggle = 5,
99  kPanelAlert4S = 6,
100  kPanelAlert10S = 7,
101  kPanelTraceUpType1 = 8,
102  kPanelTraceUpType2 = 9,
103  kPanelTraceDownType1 = 10,
104  kPanelTraceDownType2 = 11,
105  kPanelTraceRightType1 = 12,
106  kPanelTraceRightType2 = 13,
107  kPanelTraceLeftType1 = 14,
108  kPanelTraceLeftType2 = 15,
109  kPanelExpandType1 = 16,
110  kPanelExpandType2 = 17,
111  kPanelCompressType1 = 18,
112  kPanelCompressType2 = 19,
113  kPanelCross3S = 20,
114  kPanelCyclonColumn = 21,
115  kPanelCyclonRow = 22,
116  kPanelEyeScan = 23,
117  kPanelFadeOuIn = 24,
118  kPanelFaceOut = 25,
119  kPanelFlash5S = 26,
120  kPanelFlashV = 27,
121  kPanelFlashQ = 28,
122  kPanelTwoLoop = 29,
123  kPanelOneLoop = 30,
124  kPanelTestSequenceType1 = 31,
125  kPanelTestSequenceType2 = 32,
126  kPanelAILogo = 33,
127  kPanel2GWDLogo = 34,
128  kPanelQuadrantType1 = 35,
129  kPanelQuadrantType2 = 36,
130  kPanelQuadrantType3 = 37,
131  kPanelQuadrantType4 = 38,
132  kPanelRandom6S = 39
133  };
134 
135  void sendCommand(int cmd)
136  {
137  Wire.beginTransmission(fI2CAddress);
138  Wire.write(cmd);
139  Wire.endTransmission();
140  }
141 
142  byte fI2CAddress;
143 };
144 
145 #endif
MagicPanelClassicI2C::off
void off()
Definition: MagicPanelI2C.h:80
CommandEvent
Base class for all command enabled devices. CommandEvent::handleCommand() is called for each device e...
Definition: CommandEvent.h:17
MagicPanelClassicI2C::on
void on(byte numSeconds=0)
Definition: MagicPanelI2C.h:61
DEBUG_PRINT
#define DEBUG_PRINT(s)
Definition: ReelTwo.h:189
I2C_MAGIC_PANEL
#define I2C_MAGIC_PANEL
Definition: ReelTwo.h:20
DEBUG_PRINTLN
#define DEBUG_PRINTLN(s)
Definition: ReelTwo.h:188
MagicPanelI2C
Forwards any 'MP' CommandEvent over i2c to a ia-parts magic panel that has been flashed with Reeltwo.
Definition: MagicPanelI2C.h:16
MagicPanelI2C::MagicPanelI2C
MagicPanelI2C(const byte i2cAddress=I2C_MAGIC_PANEL)
Definition: MagicPanelI2C.h:19
MagicPanelClassicI2C::MagicPanelClassicI2C
MagicPanelClassicI2C(const byte i2cAddress=0x14)
Definition: MagicPanelI2C.h:56
MagicPanelClassicI2C
Encapsulates the available i2c commands that can be sent to the ia-parts.com magic panel.
Definition: MagicPanelI2C.h:53
CommandEvent.h
MagicPanelI2C::handleCommand
virtual void handleCommand(const char *cmd) override
Magic Panel Commands start with 'MP'.
Definition: MagicPanelI2C.h:27
MagicPanelClassicI2C::random
void random()
Definition: MagicPanelI2C.h:85