//This project turns on, off or toggle an LED
|
|
#include<stdio.h>
|
|
#include<stdlib.h>
|
|
#include<string.h>
|
|
|
|
#define LED3_PATH "/sys/class/leds/beaglebone:green:usr3"
|
|
#define bled "/brightness"
|
|
#define tled "/trigger"
|
|
|
|
//Protypes:
|
|
void writeLED(char fileName[], char value[]);
|
|
void removeTrigger();
|
|
|
|
//main:
|
|
////////////////////////////////////////////////////////
|
|
int main(int argc, char* argv[]){
|
|
printf("Starting app");
|
|
|
|
if(argc!=2){
|
|
printf("Incorrect number of arguments");
|
|
return 2;
|
|
}
|
|
|
|
if(strcmp(argv[1], "on")==0){
|
|
printf("LED on");
|
|
removeTrigger();
|
|
writeLED(bled, "1");
|
|
printf("Done");
|
|
}
|
|
|
|
else if (strcmp(argv[1], "off")==0){
|
|
printf("LED off");
|
|
removeTrigger();
|
|
writeLED(bled, "0");
|
|
printf("Done");
|
|
}
|
|
|
|
else if (strcmp(argv[1], "blink")==0){
|
|
printf("LED blinking");
|
|
writeLED(tled, "timer");
|
|
writeLED("/delay_on", "50");
|
|
writeLED("/delay_off", "50");
|
|
}
|
|
|
|
else
|
|
printf("Invalid command!\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
////////////////////////////////////////////////////////
|
|
void writeLED(char fileName[], char value[]){
|
|
FILE* fp;
|
|
char fullName[150];
|
|
sprintf(fullName, LED3_PATH "%s", fileName);
|
|
fp = fopen(fullName, "w+");
|
|
fprintf(fp, "%s", value);
|
|
fclose(fp);
|
|
}
|
|
|
|
void removeTrigger(){
|
|
writeLED(tled, "none");
|
|
}
|
|
|