#include "Led.h"
//
CLed::CLed(int pin, EStateLed initstate, bool inverted)
{
    FPin = pin;
    pinMode(FPin, INPUT);
    FInverted = inverted;
    FState = initstate;
}
void CLed::Open(EStateLed initstate)
{
    FState = initstate;
    pinMode(FPin, OUTPUT);
    SetState(FState);
}
void CLed::Close(void)
{
    pinMode(FPin, INPUT);
}
//
EStateLed CLed::GetState(void)
{
    return FState;
}
void CLed::SetState(EStateLed state)
{
    switch (state)
    {
        case sldOff:
            SetOff();
            break;
        case sldOn:
            SetOn();
            break;
        default:
            SetOff();
            break;
    }
}
//
void CLed::SetOn(void)
{
    if (FInverted)
    { // Inverted
        digitalWrite(FPin, LOW);        
    }
    else
    { // Normal
        digitalWrite(FPin, HIGH);
    }
    FState = sldOn;
}
void CLed::SetOff(void)
{
    if (FInverted)
    { // Inverted
        digitalWrite(FPin, HIGH);
    }
    else
    { // Normal
        digitalWrite(FPin, LOW);        
    }
    FState = sldOff;
}
void CLed::Toggle(void)
{
    switch (FState)
    {
        case sldOff:
            SetOn();
            break;
        case sldOn:
            SetOff();
            break;
        default:
            SetOff();
            break;
    }
}
//
const char* CLed::GetStateText(void)
{
    switch (FState)
    {
        case sldOn:
            return "On";
        default:
            return "Off";
    }
}
//