-
Notifications
You must be signed in to change notification settings - Fork 0
/
LED.cpp
63 lines (51 loc) · 1.4 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
60
61
62
63
#include"LED.h"
#include<iostream>
#include<fstream>
#include<string>
#include<sstream>
#include<unistd.h>
using namespace std;
namespace exploringBB {
LED::LED(int number){
this->number = number;
// much easier with C++11 using to_string(number)
ostringstream s; // using a stream to contruct the path
s << LED_PATH << number; //append LED number to LED_PATH
path = string(s.str()); //convert back from stream to string
}
void LED::writeLED(string filename, string value){
ofstream fs;
fs.open((path + filename).c_str());
fs << value;
fs.close();
}
void LED::removeTrigger(){
writeLED("/trigger", "none");
}
void LED::turnOn(){
// cout << "Turning LED" << number << " on." << endl;
removeTrigger();
writeLED("/brightness", "1");
}
void LED::turnOff(){
// cout << "Turning LED" << number << " off." << endl;
removeTrigger();
writeLED("/brightness", "0");
}
void LED::flash(string delayms = "50"){
// cout << "Making LED" << number << " flash." << endl;
writeLED("/trigger", "timer");
writeLED("/delay_on", delayms);
writeLED("/delay_off", delayms);
}
void LED::outputState(){
ifstream fs;
fs.open( (path + "/trigger").c_str());
string line;
while(getline(fs,line)) cout << line << endl;
fs.close();
}
LED::~LED(){
cout << "destroying the LED with path: " << path << endl;
}
}