-
Notifications
You must be signed in to change notification settings - Fork 1
/
ERGBLED.cpp
91 lines (75 loc) · 1.84 KB
/
ERGBLED.cpp
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
81
82
83
84
85
86
87
88
89
90
91
#include "ERGBLED.h"
//==================================== class ERGBLED =========================
// ????Reverce????
ERGBLED::ERGBLED() : EOutputDevice()
{
};
oid_t ERGBLED::init( const port_t rPort, const port_t gPort, const port_t bPort )
{
//Save initial states
this->isOn = false;
this->port = rPort;
this->portR = rPort;
this->portG = gPort;
this->portB = bPort;
this->currentState = elsOff;
//Set mode for all output ports
pinMode( this->portR, OUTPUT );
pinMode( this->portG, OUTPUT );
pinMode( this->portB, OUTPUT );
digitalWrite( this->portR, LOW );
digitalWrite( this->portG, LOW );
digitalWrite( this->portB, LOW );
return getID();
};
void ERGBLED::getName(char* result)
{
sprintf( result,"ERGBLED: ID=%d ports=%d %d %d ", getID(), portR,
portG, portB );
};
int ERGBLED::handleEvent(Event& tmpEvent)
{
if ( eventForMe( tmpEvent ) ) {
#ifdef DEBUG_ERGBLED
Serial.print("ERGBLED::handleEvent() ID:");
Serial.print(getID());
Serial.print(" got eventType=");
Serial.println(tmpEvent.eventType);
#endif
if ( this->isEnabled ) {
switch ( tmpEvent.eventType) {
case evTurnOn :
this->on();
return getID();
break;
case evTurnOff :
this->off();
return getID();
break;
default:
break;
}
}
return EOutputDevice::handleEvent( tmpEvent );
}
return 0;
};
//Turn the light On according to his mode
void ERGBLED::on(void){
#ifdef DEBUG_ERGBLED
Serial.print("ELED::on():ON ID=");
int port = getID();
Serial.println(port);
#endif
this->isOn=true;
digitalWrite(this->port,HIGH);
};
//Turn the LED off
void ERGBLED::off(void){
this->isOn=false;
digitalWrite(this->port,LOW);
};
//Change LED State
void ERGBLED::toggle(void){
isOn ? off() : on();
};