|
|
@ -0,0 +1,75 @@ |
|
|
|
/* led.cpp */ |
|
|
|
#include"led.h"
|
|
|
|
#include<iostream>
|
|
|
|
#include<fstream>
|
|
|
|
#include<string>
|
|
|
|
#include<sstream>
|
|
|
|
|
|
|
|
#define LED_PATH "/sys/class/leds/beaglebone:green:usr"
|
|
|
|
|
|
|
|
CLED::CLED(int ledNumber){ |
|
|
|
this->ledNumber = ledNumber; //Solo para argumentos que sean numeros
|
|
|
|
std::ostringstream s; |
|
|
|
s << LED_PATH << ledNumber; |
|
|
|
path =std::string(s.str()); //convert to string
|
|
|
|
} |
|
|
|
|
|
|
|
void CLED::WriteLED(std::string filename, std::string value){ |
|
|
|
std::ofstream fs; |
|
|
|
fs.open((path+filename).c_str()); |
|
|
|
fs << value; |
|
|
|
fs.close(); |
|
|
|
} |
|
|
|
|
|
|
|
void CLED::RemoveTrigger(){ |
|
|
|
WriteLED("/trigger", "none"); |
|
|
|
} |
|
|
|
|
|
|
|
void CLED::TurnOn(){ |
|
|
|
std::cout << "LED" << ledNumber << "on" << std::endl; |
|
|
|
RemoveTrigger(); |
|
|
|
WriteLED("/brightness", "1"); |
|
|
|
} |
|
|
|
|
|
|
|
void CLED::TurnOff(){ |
|
|
|
std::cout << "LED" << ledNumber << "off" << std::endl; |
|
|
|
RemoveTrigger(); |
|
|
|
WriteLED("/brightness","0"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void CLED::blink(){ |
|
|
|
std::cout << "LED" << ledNumber << "blinking" << std::endl; |
|
|
|
WriteLED("/trigger", "timer"); |
|
|
|
WriteLED("/delay_on", "50"); |
|
|
|
WriteLED("/delay_off", "50"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
CLED::~CLED(){ |
|
|
|
std::cout << "destroying LED " << path << std::endl; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char* argv[]){ |
|
|
|
if(argc!=2){ |
|
|
|
std::cout << "Para usarse es: makeLEDS <comand>" << std::endl; |
|
|
|
std::cout << "los comandos son on, off y blink" << std::endl; |
|
|
|
} |
|
|
|
std::cout << "Starting app" << std::endl; |
|
|
|
std::string cmd(argv[1]); |
|
|
|
|
|
|
|
// se crean 4 objetos de LED y se ponen en el array para controlar todos los LEDS.
|
|
|
|
CLED leds[4]= {CLED(0), CLED(1), CLED(2), CLED(3) }; |
|
|
|
|
|
|
|
for(int i=0; i<=3; i++){ |
|
|
|
if(cmd=="on")leds[i].TurnOn(); |
|
|
|
else if(cmd=="off")leds[i].TurnOff(); |
|
|
|
else if(cmd=="blink")leds[i].blink(); |
|
|
|
else{std::cout << "comando invalido" << std::endl;} |
|
|
|
} |
|
|
|
std::cout << "programa terminado" << std::endl; |
|
|
|
return 0; |
|
|
|
|
|
|
|
} |