#include "LedsExample.h"
#include <OPENR/ODataFormats.h>
#include <OPENR/OPENRAPI.h>
#include <OPENR/OSyslog.h>
#include <OPENR/core_macro.h>
LedsExample::LedsExample() : State(SYSTEM_IDLE)
{
OSYSDEBUG(("LedsExample()\n"));
};
OStatus LedsExample::DoInit(const OSystemEvent& event)
{
OSYSDEBUG(("LedsExample::DoInit() \n"));
NEW_ALL_SUBJECT_AND_OBSERVER;
REGISTER_ALL_ENTRY;
SET_ALL_READY_AND_NOTIFY_ENTRY;
Leds.OpenPrimitives();
Leds.NewCommandVectorData();
Leds.NewCommandVectorData();
InitLedVectors();
if(!MotorPowerOn())
OSYSPRINT(("LedsExample::DoInit(...) MotorPowerOn failed!\n"));
return oSUCCESS;
};
OStatus LedsExample::DoStart(const OSystemEvent& event)
{
subject[sbjLEDTEST]->SetData( Leds.GetRegion(0));
subject[sbjLEDTEST]->SetData( Leds.GetRegion(1));
subject[sbjLEDTEST]->NotifyObservers();
State = SYSTEM_START;
ENABLE_ALL_SUBJECT;
ASSERT_READY_TO_ALL_OBSERVER;
return oSUCCESS;
};
OStatus LedsExample::DoStop(const OSystemEvent& event)
{
OSYSDEBUG(("LedsExample::DoStop()\n"));
State = SYSTEM_IDLE;
DISABLE_ALL_SUBJECT;
DEASSERT_READY_TO_ALL_OBSERVER;
return oSUCCESS;
};
OStatus LedsExample::DoDestroy(const OSystemEvent& event)
{
OSYSDEBUG(("LedsExample::DoDestroy()\n"));
DELETE_ALL_SUBJECT_AND_OBSERVER;
return oSUCCESS;
};
void LedsExample::NotifyLeds(const OReadyEvent& event)
{
OSYSDEBUG(("LedsExample::NotifyLeds()\n"));
static bool toggle = true;
if(State == SYSTEM_START){
if(toggle){
subject[sbjLEDTEST]->SetData(Leds.GetRegion(0));
OSYSDEBUG(("---Next: Led's on \n"));
}
else{
subject[sbjLEDTEST]->SetData(Leds.GetRegion(1));
OSYSDEBUG(("---Next: Led's off \n"));
}
subject[sbjLEDTEST]->NotifyObservers();
toggle = (toggle) ? false : true;
}
};
void LedsExample::InitLedVectors()
{
OSYSDEBUG(("LedsExample::InitLedvectors()\n"));
for(int i= NUM_LEDS-1; i >= 0; i--){
if(i == LED(HL))
Leds.SetLed(LED(i), 375, false, 0);
else
Leds.SetLed(LED(i), 375);
Leds.SetLed(LED(i), 375, false, 1);
}
};