#include "SensorsExample.h"
#include <OPENR/ODataFormats.h>
#include <OPENR/OPENRAPI.h>
#include <OPENR/OSyslog.h>
#include <OPENR/core_macro.h>
SensorsExample::SensorsExample() : State(SYSTEM_IDLE)
{
};
OStatus SensorsExample::DoInit(const OSystemEvent& event)
{
OSYSDEBUG(("SensorsExample::DoInit() \n"));
NEW_ALL_SUBJECT_AND_OBSERVER;
REGISTER_ALL_ENTRY;
SET_ALL_READY_AND_NOTIFY_ENTRY;
return oSUCCESS;
};
OStatus SensorsExample::DoStart(const OSystemEvent& event)
{
OSYSDEBUG(("SensorsExample::DoStart()\n"));
State = SYSTEM_START;
ENABLE_ALL_SUBJECT;
ASSERT_READY_TO_ALL_OBSERVER;
return oSUCCESS;
};
OStatus SensorsExample::DoStop(const OSystemEvent& event)
{
OSYSDEBUG(("SensorsExample::DoStop()\n"));
State = SYSTEM_IDLE;
DISABLE_ALL_SUBJECT;
DEASSERT_READY_TO_ALL_OBSERVER;
return oSUCCESS;
};
OStatus SensorsExample::DoDestroy(const OSystemEvent& event)
{
OSYSDEBUG(("SensorsExample::DoDestroy()\n"));
DELETE_ALL_SUBJECT_AND_OBSERVER;
return oSUCCESS;
};
void SensorsExample::NotifySensors(const ONotifyEvent& event)
{
OSYSDEBUG(("SensorsExample::NotifySensors()\n"));
OSensorFrameVectorData* sensorVec = (OSensorFrameVectorData*)event.Data(0);
if (!Sensors.Initialized()) {
Sensors.InitSensorIndex(sensorVec);
}
OSYSPRINT(("\n ERS-220 numData %d frameNumber %d\n",
sensorVec->vectorInfo.numData, sensorVec->info[0].frameNumber));
OSYSPRINT(("-------------------MYSENSORDATA----------------------\n"));
myPrint(sensorVec);
observer[event.ObsIndex()]->AssertReady();
};
void SensorsExample::myPrint(OSensorFrameVectorData* sensorVec)
{
OSYSPRINT(("Distance: %f \n", Sensors.GetDistance(sensorVec)));
OSYSPRINT(("Mean Distance: %f \n", Sensors.GetMeanDistance(sensorVec,4)));
OSYSPRINT(("Temperature: %f \n", Sensors.GetTemp(sensorVec)));
if( Sensors.IsPressed(sensorVec,S_TIN_SW))
OSYSPRINT(("TIN_SW: pressed \n"));
else
OSYSPRINT(("TIN_SW: not pressed \n"));
if( Sensors.IsPressed(sensorVec,S_BACK_SW))
OSYSPRINT(("BACK_SW: pressed \n"));
else
OSYSPRINT(("BACK_SW: not pressed \n"));
OSYSPRINT(("Head_tilt: %f \n\n", Sensors.GetJointValue(sensorVec,J_HEAD_TILT)));
};