-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakeLED.c
More file actions
74 lines (60 loc) · 2.03 KB
/
makeLED.c
File metadata and controls
74 lines (60 loc) · 2.03 KB
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
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define LED3_PATH "/sys/class/leds/beaglebone:green:usr3"
void writeLED(char filename[], char value[]); //function prototypes
void removeTrigger();
int main(int argc, char* argv[]){
if(argc!=2){
printf("Usage is makeLEDC and one of:\n");
printf(" on, off, flash or status\n");
printf(" e.g. makeLED flash\n");
return 2;
}
printf("Starting the makeLED program\n");
printf("The current LED Path is: " LED3_PATH "\n");
// select whether command is on, off, flash or status
if(strcmp(argv[1],"on")==0){
printf("Turning the LED on\n");
removeTrigger();
writeLED("/brightness", "1");
}
else if (strcmp(argv[1],"off")==0){
printf("Turning the LED off\n");
removeTrigger();
writeLED("/brightness", "0");
}
else if (strcmp(argv[1],"flash")==0){
printf("Flashing the LED\n");
writeLED("/trigger", "timer");
writeLED("/delay_on", "50");
writeLED("/delay_off", "50");
}
else if (strcmp(argv[1],"status")==0){
FILE* fp; // see writeLED function below for description
char fullFileName[100];
char line[80];
sprintf(fullFileName, LED3_PATH "/trigger");
fp = fopen(fullFileName, "rt"); //reading text this time
while (fgets(line, 80, fp) != NULL){
printf("%s", line);
}
fclose(fp);
}
else{
printf("Invalid command!\n");
}
printf("Finished the makeLED Program\n");
return 0;
}
void writeLED(char filename[], char value[]){
FILE* fp; // create a file pointer fp
char fullFileName[100]; // to store the path and filename
sprintf(fullFileName, LED3_PATH "%s", filename); // write path/name
fp = fopen(fullFileName, "w+"); // open file for writing
fprintf(fp, "%s", value); // send the value to the file
fclose(fp); // close the file using the file pointer
}
void removeTrigger(){
writeLED("/trigger", "none");
}