Modified for compatibility with Rev.E. hardware
Fork of AkmSensor by
akmhallswitch.cpp@11:cef8dc1cf010, 2016-07-22 (annotated)
- Committer:
- masahikofukasawa
- Date:
- Fri Jul 22 22:54:11 2016 +0000
- Revision:
- 11:cef8dc1cf010
- Parent:
- 10:5c69b067d88a
- Child:
- 13:d008249f0359
RevD7_004
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
masahikofukasawa | 0:7a00359e701e | 1 | #include "akmhallswitch.h" |
masahikofukasawa | 0:7a00359e701e | 2 | #include "debug.h" |
masahikofukasawa | 0:7a00359e701e | 3 | |
masahikofukasawa | 0:7a00359e701e | 4 | /////////////////////////////////////////////////////////////////////////////////// |
masahikofukasawa | 0:7a00359e701e | 5 | // Interface implementation |
masahikofukasawa | 0:7a00359e701e | 6 | /////////////////////////////////////////////////////////////////////////////////// |
masahikofukasawa | 0:7a00359e701e | 7 | /** |
masahikofukasawa | 0:7a00359e701e | 8 | * Constructor. |
masahikofukasawa | 0:7a00359e701e | 9 | * |
masahikofukasawa | 0:7a00359e701e | 10 | */ |
masahikofukasawa | 0:7a00359e701e | 11 | AkmHallSwitch::AkmHallSwitch(){ |
masahikofukasawa | 0:7a00359e701e | 12 | event = false; |
masahikofukasawa | 0:7a00359e701e | 13 | sw0 = NULL; |
masahikofukasawa | 0:7a00359e701e | 14 | sw1 = NULL; |
masahikofukasawa | 0:7a00359e701e | 15 | d0 = DigitalIn(DIGITAL_D0); |
masahikofukasawa | 0:7a00359e701e | 16 | d1 = DigitalIn(DIGITAL_D1); |
masahikofukasawa | 0:7a00359e701e | 17 | } |
masahikofukasawa | 0:7a00359e701e | 18 | |
masahikofukasawa | 0:7a00359e701e | 19 | /** |
masahikofukasawa | 0:7a00359e701e | 20 | * Destructor. |
masahikofukasawa | 0:7a00359e701e | 21 | * |
masahikofukasawa | 0:7a00359e701e | 22 | */ |
masahikofukasawa | 0:7a00359e701e | 23 | AkmHallSwitch::~AkmHallSwitch(){ |
masahikofukasawa | 0:7a00359e701e | 24 | sw1->rise(0); |
masahikofukasawa | 0:7a00359e701e | 25 | sw1->fall(0); |
masahikofukasawa | 0:7a00359e701e | 26 | sw0->rise(0); |
masahikofukasawa | 0:7a00359e701e | 27 | sw0->fall(0); |
masahikofukasawa | 0:7a00359e701e | 28 | |
masahikofukasawa | 0:7a00359e701e | 29 | if(sw0) delete sw0; |
masahikofukasawa | 0:7a00359e701e | 30 | if(sw1) delete sw1; |
masahikofukasawa | 0:7a00359e701e | 31 | } |
masahikofukasawa | 0:7a00359e701e | 32 | |
masahikofukasawa | 0:7a00359e701e | 33 | AkmSensor::Status AkmHallSwitch::init(const uint8_t id, const uint8_t subid){ |
masahikofukasawa | 0:7a00359e701e | 34 | primaryId = id; |
masahikofukasawa | 0:7a00359e701e | 35 | subId = subid; |
masahikofukasawa | 0:7a00359e701e | 36 | |
masahikofukasawa | 0:7a00359e701e | 37 | sw0 = new InterruptIn(DIGITAL_D0); |
masahikofukasawa | 0:7a00359e701e | 38 | sw1 = new InterruptIn(DIGITAL_D1); |
masahikofukasawa | 0:7a00359e701e | 39 | |
masahikofukasawa | 0:7a00359e701e | 40 | sw1->rise(0); |
masahikofukasawa | 0:7a00359e701e | 41 | sw1->fall(0); |
masahikofukasawa | 0:7a00359e701e | 42 | sw0->rise(0); |
masahikofukasawa | 0:7a00359e701e | 43 | sw0->fall(0); |
masahikofukasawa | 0:7a00359e701e | 44 | |
masahikofukasawa | 0:7a00359e701e | 45 | return AkmSensor::SUCCESS; |
masahikofukasawa | 0:7a00359e701e | 46 | } |
masahikofukasawa | 0:7a00359e701e | 47 | |
masahikofukasawa | 0:7a00359e701e | 48 | void AkmHallSwitch::riseEventD0(){ |
masahikofukasawa | 0:7a00359e701e | 49 | d0 = 1; |
masahikofukasawa | 0:7a00359e701e | 50 | event = true; |
masahikofukasawa | 0:7a00359e701e | 51 | } |
masahikofukasawa | 0:7a00359e701e | 52 | void AkmHallSwitch::fallEventD0(){ |
masahikofukasawa | 0:7a00359e701e | 53 | d0 = 0; |
masahikofukasawa | 0:7a00359e701e | 54 | event = true; |
masahikofukasawa | 0:7a00359e701e | 55 | } |
masahikofukasawa | 0:7a00359e701e | 56 | void AkmHallSwitch::riseEventD1(){ |
masahikofukasawa | 0:7a00359e701e | 57 | d1 = 1; |
masahikofukasawa | 0:7a00359e701e | 58 | event = true; |
masahikofukasawa | 0:7a00359e701e | 59 | } |
masahikofukasawa | 0:7a00359e701e | 60 | |
masahikofukasawa | 0:7a00359e701e | 61 | void AkmHallSwitch::fallEventD1(){ |
masahikofukasawa | 0:7a00359e701e | 62 | d1 = 0; |
masahikofukasawa | 0:7a00359e701e | 63 | event = true; |
masahikofukasawa | 0:7a00359e701e | 64 | } |
masahikofukasawa | 0:7a00359e701e | 65 | |
masahikofukasawa | 0:7a00359e701e | 66 | bool AkmHallSwitch::isEvent(){ |
masahikofukasawa | 0:7a00359e701e | 67 | return event; |
masahikofukasawa | 0:7a00359e701e | 68 | } |
masahikofukasawa | 0:7a00359e701e | 69 | |
masahikofukasawa | 0:7a00359e701e | 70 | AkmSensor::Status AkmHallSwitch::startSensor(){ |
masahikofukasawa | 0:7a00359e701e | 71 | sw1->rise(this, &AkmHallSwitch::riseEventD1); |
masahikofukasawa | 0:7a00359e701e | 72 | sw1->fall(this, &AkmHallSwitch::fallEventD1); |
masahikofukasawa | 0:7a00359e701e | 73 | if(primaryId == AkmSensor::AKM_PRIMARY_ID_DUAL_OUTPUT || primaryId == AkmSensor::AKM_PRIMARY_ID_ONECHIP_ENCODER) |
masahikofukasawa | 0:7a00359e701e | 74 | { |
masahikofukasawa | 0:7a00359e701e | 75 | sw0->rise(this, &AkmHallSwitch::riseEventD0); |
masahikofukasawa | 0:7a00359e701e | 76 | sw0->fall(this, &AkmHallSwitch::fallEventD0); |
masahikofukasawa | 0:7a00359e701e | 77 | } |
masahikofukasawa | 0:7a00359e701e | 78 | return AkmSensor::SUCCESS; |
masahikofukasawa | 0:7a00359e701e | 79 | } |
masahikofukasawa | 0:7a00359e701e | 80 | |
masahikofukasawa | 0:7a00359e701e | 81 | AkmSensor::Status AkmHallSwitch::startSensor(const float sec){ |
masahikofukasawa | 11:cef8dc1cf010 | 82 | return AkmSensor::ERROR; |
masahikofukasawa | 0:7a00359e701e | 83 | } |
masahikofukasawa | 0:7a00359e701e | 84 | |
masahikofukasawa | 0:7a00359e701e | 85 | AkmSensor::Status AkmHallSwitch::stopSensor(){ |
masahikofukasawa | 0:7a00359e701e | 86 | sw1->rise(0); |
masahikofukasawa | 0:7a00359e701e | 87 | sw1->fall(0); |
masahikofukasawa | 0:7a00359e701e | 88 | sw0->rise(0); |
masahikofukasawa | 0:7a00359e701e | 89 | sw0->fall(0); |
masahikofukasawa | 0:7a00359e701e | 90 | return AkmSensor::SUCCESS; |
masahikofukasawa | 0:7a00359e701e | 91 | } |
masahikofukasawa | 0:7a00359e701e | 92 | |
masahikofukasawa | 0:7a00359e701e | 93 | AkmSensor::Status AkmHallSwitch::readSensorData(Message* msg){ |
masahikofukasawa | 0:7a00359e701e | 94 | event = false; |
masahikofukasawa | 0:7a00359e701e | 95 | |
masahikofukasawa | 0:7a00359e701e | 96 | msg->setCommand(Message::CMD_START_MEASUREMENT); |
masahikofukasawa | 0:7a00359e701e | 97 | msg->setArgument( 0, d1 ? 1 : 0 ); |
masahikofukasawa | 0:7a00359e701e | 98 | if(primaryId == AkmSensor::AKM_PRIMARY_ID_DUAL_OUTPUT || primaryId == AkmSensor::AKM_PRIMARY_ID_ONECHIP_ENCODER) |
masahikofukasawa | 0:7a00359e701e | 99 | { |
masahikofukasawa | 0:7a00359e701e | 100 | msg->setArgument( 1, d0 ? 1 : 0 ); |
masahikofukasawa | 0:7a00359e701e | 101 | } |
masahikofukasawa | 0:7a00359e701e | 102 | return AkmSensor::SUCCESS; |
masahikofukasawa | 0:7a00359e701e | 103 | } |
masahikofukasawa | 0:7a00359e701e | 104 | |
masahikofukasawa | 0:7a00359e701e | 105 | AkmSensor::Status AkmHallSwitch::requestCommand(Message* in, Message* out){ |
masahikofukasawa | 0:7a00359e701e | 106 | return AkmSensor::SUCCESS; |
masahikofukasawa | 0:7a00359e701e | 107 | } |
masahikofukasawa | 0:7a00359e701e | 108 |