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.

49 lines
1.1 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
  1. /* led.cpp */
  2. #include"led.h"
  3. #include<iostream>
  4. #include<fstream>
  5. #include<string>
  6. #include<sstream>
  7. #define LED_PATH "/sys/class/leds/beaglebone:green:usr"
  8. CLED::CLED(int ledNumber){
  9. this->ledNumber = ledNumber; //Solo para argumentos que sean numeros
  10. std::ostringstream s;
  11. s << LED_PATH << ledNumber;
  12. path =std::string(s.str()); //convert to string
  13. }
  14. void CLED::WriteLED(std::string filename, std::string value){
  15. std::ofstream fs;
  16. fs.open((path+filename).c_str());
  17. fs << value;
  18. fs.close();
  19. }
  20. void CLED::RemoveTrigger(){
  21. WriteLED("/trigger", "none");
  22. }
  23. void CLED::TurnOn(){
  24. std::cout << "LED Turn On: " << ledNumber << " on" << std::endl;
  25. RemoveTrigger();
  26. WriteLED("/brightness", "1");
  27. }
  28. void CLED::TurnOff(){
  29. std::cout << "LED Turn Off: " << ledNumber << " off" << std::endl;
  30. RemoveTrigger();
  31. WriteLED("/brightness", "0");
  32. }
  33. void CLED::BlinkLED(){
  34. std::cout << "LED blinking: " << ledNumber << " blinking" << std::endl;
  35. WriteLED("/trigger", "timer");
  36. WriteLED("/delay_on", "50");
  37. WriteLED("/delay_off", "50");
  38. }
  39. CLED::~CLED(){
  40. std::cout << "destroying LED " << path << std::endl;
  41. }