From 4e1089258ccdb2015bac2afd27a6ca08ce07df8f Mon Sep 17 00:00:00 2001 From: Gerardo Marx Date: Mon, 26 Apr 2021 18:39:29 +0000 Subject: [PATCH] On and Off ok --- main.c | 44 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/main.c b/main.c index c549442..1c57dff 100644 --- a/main.c +++ b/main.c @@ -1,27 +1,53 @@ // LED application in C by -// Gerado Marx Chavez Campos -// 26/04/2021 -// -// - - +// Gerado Marx Chavez Campos, 26/04/2021 #include #include #include #define LED3PATH "/sys/class/leds/beaglebone:green:usr3" +#define bon "/brightness" +#define trg "/trigger" //Function prototypes void WriteLED(char fileName[], char value[]); void RemoveTrigger(); //main -int main(int argc, char* argvp[]){ +int main(int argc, char* argv[]){ 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; } -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; } +//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"); +} +