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

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. //This project turns on, off or toggle an LED
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4. #include<string.h>
  5. #define LED3_PATH "/sys/class/leds/beaglebone:green:usr3"
  6. #define bled "/brightness"
  7. #define tled "/trigger"
  8. //Protypes:
  9. void writeLED(char fileName[], char value[]);
  10. void removeTrigger();
  11. //main:
  12. ////////////////////////////////////////////////////////
  13. int main(int argc, char* argv[]){
  14. printf("Starting app \n");
  15. if(argc!=2){
  16. printf("Incorrect number of arguments");
  17. return 2;
  18. }
  19. if(strcmp(argv[1], "on")==0){
  20. printf("LED on \n");
  21. removeTrigger();
  22. writeLED(bled, "1");
  23. printf("Done");
  24. }
  25. else if (strcmp(argv[1], "off")==0){
  26. printf("LED off \n");
  27. removeTrigger();
  28. writeLED(bled, "0");
  29. printf("Done");
  30. }
  31. else if (strcmp(argv[1], "blink")==0){
  32. printf("LED blinking \n");
  33. writeLED(tled, "timer");
  34. writeLED("/delay_on", "500");
  35. writeLED("/delay_off", "500");
  36. }
  37. else if (strcmp(argv[1], "help")==0){
  38. printf("This is an application to control User LED 3");
  39. printf("List of commands: ");
  40. printf("on - Powers on the LED");
  41. printf("off - Powers off the LED");
  42. printf("blink - Makes the LED blink");
  43. }
  44. else
  45. printf("Error: This is not a command for this application");
  46. printf("These are the commands you can use: ");
  47. printf("on - Powers on the LED");
  48. printf("off - Powers off the LED");
  49. printf("blink - Makes the LED blink");
  50. return 0;
  51. }
  52. ////////////////////////////////////////////////////////
  53. void writeLED(char fileName[], char value[]){
  54. FILE* fp;
  55. char fullName[150];
  56. sprintf(fullName, LED3_PATH "%s", fileName);
  57. fp = fopen(fullName, "w+");
  58. fprintf(fp, "%s", value);
  59. fclose(fp);
  60. }
  61. void removeTrigger(){
  62. writeLED(tled, "none");
  63. }