-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathled.cpp
59 lines (52 loc) · 1.12 KB
/
led.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
#include "led.h"
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
void Led::Control(bool on)
{
const char* const von="255";
const char* const voff="0";
if( m_InternalLed > 0 )
{
const char* val = on ? von : voff;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-result"
write(m_InternalLed, val, strlen(val) );
#pragma GCC diagnostic pop
}
}
bool Led::Open(std::string device)
{
const std::string path("/sys/class/leds/");
if( m_InternalLed < 0 )
{
std::string trigger = path + device + "/trigger";
int fd = open(trigger.c_str(), O_WRONLY);
if( fd < 0 )
{
return false;
}
else
{
const char none[] = "none";
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-result"
write(fd, none, sizeof(none));
#pragma GCC diagnostic pop
close(fd);
}
std::string dev = path + device + "/brightness";
m_InternalLed = open(dev.c_str(), O_WRONLY);
}
if( m_InternalLed < 0 )
return false;
return true;
}
void Led::Close()
{
if( m_InternalLed < 0)
{
close(m_InternalLed);
m_InternalLed=-1;
}
}