| @ -1,27 +1,53 @@ | |||||
| // LED application in C by | // LED application in C by | ||||
| // Gerado Marx Chavez Campos | |||||
| // 26/04/2021 | |||||
| // | |||||
| // | |||||
| // Gerado Marx Chavez Campos, 26/04/2021 | |||||
| #include<stdio.h> | #include<stdio.h> | ||||
| #include<stdlib.h> | #include<stdlib.h> | ||||
| #include<string.h> | #include<string.h> | ||||
| #define LED3PATH "/sys/class/leds/beaglebone:green:usr3" | #define LED3PATH "/sys/class/leds/beaglebone:green:usr3" | ||||
| #define bon "/brightness" | |||||
| #define trg "/trigger" | |||||
| //Function prototypes | //Function prototypes | ||||
| void WriteLED(char fileName[], char value[]); | void WriteLED(char fileName[], char value[]); | ||||
| void RemoveTrigger(); | void RemoveTrigger(); | ||||
| //main | //main | ||||
| int main(int argc, char* argvp[]){ | |||||
| int main(int argc, char* argv[]){ | |||||
| if(argc!=2){ | if(argc!=2){ | ||||
| printf("Incorrect use..."); | |||||
| printf("Incorrect use of command...\n"); | |||||
| printf("Please use LEDc with:\n"); | |||||
| printf("on, off, flash or status.\n"); | |||||
| printf("\n"); | |||||
| printf("Example: LEDc on\n"); | |||||
| return 2; | return 2; | ||||
| } | } | ||||
| printf("LED Application Done"); | |||||
| printf("Starting Application...\n"); | |||||
| //checking the command argument: | |||||
| if(strcmp(argv[1], "on")==0){ | |||||
| printf("Turning LED on\n"); | |||||
| RemoveTrigger(); | |||||
| WriteLED(bon,"1"); | |||||
| } | |||||
| else if(strcmp(argv[1], "off")==0){ | |||||
| printf("Turning LED off\n"); | |||||
| RemoveTrigger(); | |||||
| WriteLED(bon,"0"); | |||||
| } | |||||
| printf("LED Application Done\n"); | |||||
| return 0; | return 0; | ||||
| } | } | ||||
| //complete functions here: | |||||
| void WriteLED(char filename[], char value[]){ | |||||
| FILE* fp; //file pointer | |||||
| char fileName[100]; //var to store path and file | |||||
| sprintf(fileName, LED3PATH "%s", filename); | |||||
| fp = fopen(fileName, "w+"); | |||||
| fprintf(fp, "%s", value); | |||||
| fclose(fp); | |||||
| } | |||||
| void RemoveTrigger(){ | |||||
| WriteLED(trg, "none"); | |||||
| } | |||||