-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
64 lines (59 loc) · 1.54 KB
/
main.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
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
#define LED0_PATH "/sys/class/leds/beaglebone:green:usr0"
void removeTrigger(){
// remove the trigger from the LED
std::fstream fs;
fs.open( LED0_PATH "/trigger", std::fstream::out);
fs << "none";
fs.close();
}
int main(int argc, char* argv[]){
if(argc!=2){
cout << "Usage is makeLED and one of: on, off, flash or status"
<< endl;
cout << "e.g. makeLED flash" << endl;
}
string cmd(argv[1]);
std::fstream fs;
cout << "Starting the LED flash program" << endl;
cout << "The LED Path is: " << LED0_PATH << endl;
// select whether it is on, off or flash
if(cmd=="on"){
removeTrigger();
fs.open (LED0_PATH "/brightness", std::fstream::out);
fs << "1";
fs.close();
}
else if (cmd=="off"){
removeTrigger();
fs.open (LED0_PATH "/brightness", std::fstream::out);
fs << "0";
fs.close();
}
else if (cmd=="flash"){
fs.open (LED0_PATH "/trigger", std::fstream::out);
fs << "timer";
fs.close();
fs.open (LED0_PATH "/delay_on", std::fstream::out);
fs << "50";
fs.close();
fs.open (LED0_PATH "/delay_off", std::fstream::out);
fs << "50";
fs.close();
}
else if (cmd=="status"){
// display the current trigger details
fs.open( LED0_PATH "/trigger", std::fstream::in);
string line;
while(getline(fs,line)) cout << line;
fs.close();
}
else{
cout << "Invalid command" << endl;
}
cout << "Finished the LED flash program" << endl;
return 0;
}