-
Notifications
You must be signed in to change notification settings - Fork 1
/
ELED.cpp
86 lines (77 loc) · 1.72 KB
/
ELED.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
//==================================== class ELED =========================
#include "ELED.h"
#ifdef DEBUG_ELED
#define DBG_PRINTLN(a) Serial.println(a)
#define DBG_PRINT(a) Serial.print(a)
#else
#define DBG_PRINTLN(a)
#define DBG_PRINT(a)
#endif
ELED::ELED() : EOutputDevice()
{
this->isOn=false;
};
oid_t ELED::init( const port_t ledPort, const bool reverse )
{
return EOutputDevice::init( ledPort, reverse );
};
void ELED::getName( char* result ) const
{
sprintf( result, "ELED: ID=%d port=%d ", getID(), this->port );
};
int ELED::handleEvent( Event& tmpEvent )
{
#ifdef DEBUG_ELED
DBG_PRINT( "ELED::handleEvent() ID:" );
DBG_PRINT( getID() );
DBG_PRINT( " got eventType=" );
DBG_PRINTLN( tmpEvent.eventType );
#endif
if ( eventForMe( tmpEvent ) ) {
#ifdef DEBUG_ELED
DBG_PRINT( "ELED::handleEvent() ID:" );
DBG_PRINT( getID() );
DBG_PRINT( " got for me eventType=" );
DBG_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;
};
void ELED::on( void ) {
#ifdef DEBUG_ELED
DBG_PRINT( "ELED::on():ON ID=" );
int port = getID();
DBG_PRINTLN(port);
#endif
EOutputDevice::on();
};
void ELED::off( void ) {
#ifdef DEBUG_ELED
DBG_PRINT( "ELED::off():OFF ID=" );
int port = getID();
DBG_PRINTLN( port );
#endif
EOutputDevice::off();
};
void ELED::toggle( void ){
isOn ? off() : on();
};
#ifdef DEBUG_ELED
#undef DBG_PRINTLN(a)
#undef DBG_PRINT(a)
#endif