summaryrefslogtreecommitdiffstats
path: root/led.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--led.cpp80
1 files changed, 80 insertions, 0 deletions
diff --git a/led.cpp b/led.cpp
new file mode 100644
index 0000000..1d10e24
--- /dev/null
+++ b/led.cpp
@@ -0,0 +1,80 @@
+/*
+ * File: led.cpp
+ * Author: naopross
+ *
+ * Created on May 5, 2018, 2:33 PM
+ */
+
+#include "led.hpp"
+
+led::led(gpio *pin, led::color color) : _pin(pin), _color(color)
+{
+ _pin->set_mode(0);
+}
+
+
+led::~led()
+{
+
+}
+
+void led::pin(gpio *pin)
+{
+ if (pin) {
+ _pin = pin;
+ }
+}
+
+gpio * led::pin() const
+{
+ return _pin;
+}
+
+void led::get_color(led::color color)
+{
+ _color = color;
+}
+
+led::color led::set_color() const
+{
+ return _color;
+}
+
+void led::set(unsigned s)
+{
+ _pin->set(s);
+}
+
+unsigned led::read() const
+{
+ return _pin->read();
+}
+
+void led::toggle()
+{
+ _pin->toggle();
+}
+
+std::string led::to_string()
+{
+ std::string str = "led (";
+
+ switch (_color) {
+ case color::RED:
+ str += "red";
+ break;
+
+ case color::GREEN:
+ str += "green";
+ break;
+
+ case color::YELLOW:
+ str += "yellow";
+ break;
+ }
+
+ str += ") is ";
+ str += (read()) ? "on" : "off";
+
+ return str;
+}