diff --git a/MLed.cpp b/MLed.cpp deleted file mode 100644 index 644866b..0000000 --- a/MLed.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/*OOP in C++ example for LEDs */ -#include -#include -#include -#include -using namespace std; - -#define LED_PATH "/sys/class/leds/beaglebone:green:usr" - -class LED{ -private: - string path; - int number; - virtual void writeLED(string filename, string value); - virtual void removeTrigger(); -public: - LED(int number); - virtual void turnOn(); - virtual void turnOff(); - virtual void flash(string delayms); - virtual void outputState(); - virtual ~LED(); -}; - -LED::LED(int number){ - this->number = number; - ostringstream s; - s << LED_PATH << number; // LED number to the Path - path = string(s.str()); // convert to string -} - -void LED::writeLED(string filename, string value){ - ofstream fs; - fs.open((path + filename).c_str()); - fs << value; - fs.close(); -} - -void LED::removeTrigger(){ - writeLED("/trigger", "none"); -} - -void LED::turnOn(){ - cout << "Turning LED" << number << "on" << endl; - removeTrigger(); - writeLED("/brightness", "1"); -} - -void LED::turnOff(){ - cout << "Turning LED" << number << "off" << endl; - removeTrigger(); - writeLED("/brightness", "0"); -} - -void LED::flash(string delayms ="50"){ - cout << "Making LED" << number << "flash" << endl; - writeLED("/trigger", "timer"); - writeLED("/delay_on", delayms); - writeLED("/delay_off", delayms); -} - -void LED::outputState(){ - ifstream fs; - fs.open((path + "/trigger").c_str()); - string line; - while(getline(fs,line)) cout << line <" << endl; - cout << " is on, off flash or status" << endl; - cout << "e.g. main on" << endl; - } - cout << "Starting program ..." << endl; - string cmd(argv[1]); - LED leds[4] = {LED(0), LED(1), LED(2), LED(3)}; - for(int i=0; i<=3; i++){ - if(cmd=="on") - leds[i].turnOn(); - else if(cmd=="off") - leds[i].turnOff(); - else if(cmd=="flash") - leds[i].flash("100"); - else if(cmd=="status") - leds[i].outputState(); - else - cout << "invalid command, please type main" << endl; - } - cout << "Program done, Thanks." << endl; - return 0; -} diff --git a/LED.cpp b/led.cpp similarity index 98% rename from LED.cpp rename to led.cpp index 3d3078f..faf8301 100644 --- a/LED.cpp +++ b/led.cpp @@ -1,5 +1,5 @@ /*led.cpp*/ -#include"LED.h" +#include"led.h" #include #include #include diff --git a/LED.h b/led.h similarity index 100% rename from LED.h rename to led.h diff --git a/main.cpp b/main.cpp index 1446e57..1a7f264 100644 --- a/main.cpp +++ b/main.cpp @@ -2,14 +2,14 @@ Gerardo Marx April/20/2020 g++ main.cpp -o main LED.cpp*/ #include -#include"LED.h" +#include"led.h" using namespace std; int main(int argc, char* argv[]){ if(argc!=2){ - cout << "The usage is main " << endl; - cout << " is on, off flash or status" << endl; + cout << "The usage is main mkLed" << endl; + cout << "mkLed is on, off flash or status" << endl; cout << "e.g. main on" << endl; return 2; }