You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
1.7 KiB

//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 \n");
if(argc!=2){
printf("Incorrect number of arguments");
return 2;
}
if(strcmp(argv[1], "on")==0){
printf("LED on \n");
removeTrigger();
writeLED(bled, "1");
printf("Done");
}
else if (strcmp(argv[1], "off")==0){
printf("LED off \n");
removeTrigger();
writeLED(bled, "0");
printf("Done");
}
else if (strcmp(argv[1], "blink")==0){
printf("LED blinking \n");
writeLED(tled, "timer");
writeLED("/delay_on", "500");
writeLED("/delay_off", "500");
}
else if (strcmp(argv[1], "help")==0){
printf("This is an application to control User LED 3");
printf("List of commands: ");
printf("on - Powers on the LED");
printf("off - Powers off the LED");
printf("blink - Makes the LED blink");
}
else
printf("Error: This is not a command for this application");
printf("These are the commands you can use: ");
printf("on - Powers on the LED");
printf("off - Powers off the LED");
printf("blink - Makes the LED blink");
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");
}