summaryrefslogtreecommitdiffstats
path: root/led.cpp
blob: 4888d84fb72295b78552b518347e9345f32b98c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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); // output
}


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::is_set() const
{
    return _pin->is_set();
}

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 += (is_set()) ? "on" : "off";

    return str;
}