Modified for compatibility with Rev.E. hardware
Fork of AkmSensor by
Diff: akmhallswitch.cpp
- Revision:
- 0:7a00359e701e
- Child:
- 10:5c69b067d88a
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/akmhallswitch.cpp Thu Apr 28 21:12:04 2016 +0000 @@ -0,0 +1,119 @@ +#include "akmhallswitch.h" +#include "debug.h" + +/////////////////////////////////////////////////////////////////////////////////// +// Interface implementation +/////////////////////////////////////////////////////////////////////////////////// +/** + * Constructor. + * + */ +AkmHallSwitch::AkmHallSwitch(){ + event = false; + sw0 = NULL; + sw1 = NULL; + d0 = DigitalIn(DIGITAL_D0); + d1 = DigitalIn(DIGITAL_D1); +} + +/** + * Destructor. + * + */ +AkmHallSwitch::~AkmHallSwitch(){ + sw1->rise(0); + sw1->fall(0); + sw0->rise(0); + sw0->fall(0); + + if(sw0) delete sw0; + if(sw1) delete sw1; +} + +AkmSensor::Status AkmHallSwitch::init(const uint8_t id, const uint8_t subid){ + primaryId = id; + subId = subid; + + sw0 = new InterruptIn(DIGITAL_D0); + sw1 = new InterruptIn(DIGITAL_D1); + + sw1->rise(0); + sw1->fall(0); + sw0->rise(0); + sw0->fall(0); + + return AkmSensor::SUCCESS; +} + +void AkmHallSwitch::riseEventD0(){ + d0 = 1; + event = true; +} +void AkmHallSwitch::fallEventD0(){ + d0 = 0; + event = true; +} +void AkmHallSwitch::riseEventD1(){ + d1 = 1; + event = true; +} + +void AkmHallSwitch::fallEventD1(){ + d1 = 0; + event = true; +} + +bool AkmHallSwitch::isEvent(){ + return event; +} + +AkmSensor::Status AkmHallSwitch::startSensor(){ + sw1->rise(this, &AkmHallSwitch::riseEventD1); + sw1->fall(this, &AkmHallSwitch::fallEventD1); + if(primaryId == AkmSensor::AKM_PRIMARY_ID_DUAL_OUTPUT || primaryId == AkmSensor::AKM_PRIMARY_ID_ONECHIP_ENCODER) + { + sw0->rise(this, &AkmHallSwitch::riseEventD0); + sw0->fall(this, &AkmHallSwitch::fallEventD0); + } + return AkmSensor::SUCCESS; +} + +AkmSensor::Status AkmHallSwitch::startSensor(const float sec){ + return AkmSensor::ERROR_DOESNT_SUPPORT; +} + +AkmSensor::Status AkmHallSwitch::stopSensor(){ + sw1->rise(0); + sw1->fall(0); + sw0->rise(0); + sw0->fall(0); + return AkmSensor::SUCCESS; +} + +AkmSensor::Status AkmHallSwitch::readSensorData(Message* msg){ + event = false; + + msg->setCommand(Message::CMD_START_MEASUREMENT); + msg->setArgument( 0, d1 ? 1 : 0 ); + if(primaryId == AkmSensor::AKM_PRIMARY_ID_DUAL_OUTPUT || primaryId == AkmSensor::AKM_PRIMARY_ID_ONECHIP_ENCODER) + { + msg->setArgument( 1, d0 ? 1 : 0 ); + } + +/* + if(primaryId == AkmSensor::AKM_PRIMARY_ID_DUAL_OUTPUT || primaryId == AkmSensor::AKM_PRIMARY_ID_ONECHIP_ENCODER) + { + sprintf(str, "$B%X0%d0%d\r\n",primaryId,d1,d0); + } + else + { + sprintf(str, "$B%X0%d\r\n",primaryId,d1); + } +*/ + return AkmSensor::SUCCESS; +} + +AkmSensor::Status AkmHallSwitch::requestCommand(Message* in, Message* out){ + return AkmSensor::SUCCESS; +} +