summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2018-01-12 08:29:05 +0100
committerDaniel Friesel <derf@finalrewind.org>2018-01-12 08:29:05 +0100
commit4436c14ab688ca57fc82c1fd68f2f366fa131de1 (patch)
tree3b930d1285fe8255b9adc13cda37ccf190e069a8
parent0d84f5e512c4148bc45dd26eea177e09c0a21b56 (diff)
add mmsimple driver
-rw-r--r--Makefile5
-rw-r--r--include/driver/mmsimple.h34
-rw-r--r--src/driver/mmsimple.cc32
3 files changed, 71 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index 38b6571..b05a7cd 100644
--- a/Makefile
+++ b/Makefile
@@ -14,6 +14,11 @@ ifneq ($(findstring lm75,${drivers}), )
COMMON_FLAGS += -DDRIVER_LM75
endif
+ifneq ($(findstring mmsimple,${drivers}), )
+ TARGETS += src/driver/mmsimple.cc
+ COMMON_FLAGS += -DDRIVER_MMSIMPLE
+endif
+
ifneq ($(findstring sharp96,${drivers}), )
TARGETS += src/driver/sharp96.cc
COMMON_FLAGS += -DDRIVER_SHARP6
diff --git a/include/driver/mmsimple.h b/include/driver/mmsimple.h
new file mode 100644
index 0000000..42b0f5d
--- /dev/null
+++ b/include/driver/mmsimple.h
@@ -0,0 +1,34 @@
+#ifndef MMSIMPLE_H
+#define MMSIMPLE_H
+
+class MicroMoodySimple {
+ private:
+ MicroMoodySimple(const MicroMoodySimple &copy);
+
+ unsigned char const address;
+ unsigned char txbuf[3];
+
+ void sendCmd(unsigned char byte);
+
+ public:
+ MicroMoodySimple(unsigned char const addr) : address(addr) {}
+
+ void off();
+ void red();
+ void redOn();
+ void redOff();
+ void green();
+ void greenOn();
+ void greenOff();
+ void blue();
+ void blueOn();
+ void blueOff();
+ void toggleRed();
+ void toggleGreen();
+ void toggleBlue();
+ void setBrightness(unsigned char red, unsigned char green);
+};
+
+extern MicroMoodySimple moody;
+
+#endif
diff --git a/src/driver/mmsimple.cc b/src/driver/mmsimple.cc
new file mode 100644
index 0000000..d47d10d
--- /dev/null
+++ b/src/driver/mmsimple.cc
@@ -0,0 +1,32 @@
+#include "driver/mmsimple.h"
+#include "driver/i2c.h"
+
+void MicroMoodySimple::sendCmd(unsigned char byte)
+{
+ txbuf[0] = byte;
+ i2c.xmit(address, 3, txbuf, 0, txbuf);
+}
+
+void MicroMoodySimple::setBrightness(unsigned char red, unsigned char green)
+{
+ txbuf[0] = 13;
+ txbuf[1] = green;
+ txbuf[2] = red;
+ i2c.xmit(address, 3, txbuf, 0, txbuf);
+}
+
+void MicroMoodySimple::off() { sendCmd(0); }
+void MicroMoodySimple::redOff() { sendCmd(1); }
+void MicroMoodySimple::greenOff() { sendCmd(2); }
+void MicroMoodySimple::blueOff() { sendCmd(3); }
+void MicroMoodySimple::redOn() { sendCmd(4); }
+void MicroMoodySimple::greenOn() { sendCmd(5); }
+void MicroMoodySimple::blueOn() { sendCmd(6); }
+void MicroMoodySimple::toggleRed() { sendCmd(7); }
+void MicroMoodySimple::toggleGreen() { sendCmd(8); }
+void MicroMoodySimple::toggleBlue() { sendCmd(9); }
+void MicroMoodySimple::red() { sendCmd(10); }
+void MicroMoodySimple::green() { sendCmd(11); }
+void MicroMoodySimple::blue() { sendCmd(12); }
+
+MicroMoodySimple moody(0x11);