Modified for compatibility with Rev.E. hardware
Fork of AkmSensor by
akmhallswitch.cpp@16:d85be9bafb80, 2017-01-04 (annotated)
- Committer:
- masahikofukasawa
- Date:
- Wed Jan 04 00:52:30 2017 +0000
- Revision:
- 16:d85be9bafb80
- Parent:
- 15:1238993fd75f
- Child:
- 27:41aa9fb23a2f
Rev012. Modified for using the latest BLE_API, nRF51822 and mbed libs.
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 | 13:d008249f0359 | 17 | sensorName = ""; |
masahikofukasawa | 0:7a00359e701e | 18 | } |
masahikofukasawa | 0:7a00359e701e | 19 | |
masahikofukasawa | 0:7a00359e701e | 20 | /** |
masahikofukasawa | 0:7a00359e701e | 21 | * Destructor. |
masahikofukasawa | 0:7a00359e701e | 22 | * |
masahikofukasawa | 0:7a00359e701e | 23 | */ |
masahikofukasawa | 0:7a00359e701e | 24 | AkmHallSwitch::~AkmHallSwitch(){ |
masahikofukasawa | 0:7a00359e701e | 25 | sw1->rise(0); |
masahikofukasawa | 0:7a00359e701e | 26 | sw1->fall(0); |
masahikofukasawa | 0:7a00359e701e | 27 | sw0->rise(0); |
masahikofukasawa | 0:7a00359e701e | 28 | sw0->fall(0); |
masahikofukasawa | 0:7a00359e701e | 29 | |
masahikofukasawa | 0:7a00359e701e | 30 | if(sw0) delete sw0; |
masahikofukasawa | 0:7a00359e701e | 31 | if(sw1) delete sw1; |
masahikofukasawa | 0:7a00359e701e | 32 | } |
masahikofukasawa | 0:7a00359e701e | 33 | |
masahikofukasawa | 0:7a00359e701e | 34 | AkmSensor::Status AkmHallSwitch::init(const uint8_t id, const uint8_t subid){ |
masahikofukasawa | 0:7a00359e701e | 35 | primaryId = id; |
masahikofukasawa | 0:7a00359e701e | 36 | subId = subid; |
masahikofukasawa | 0:7a00359e701e | 37 | |
masahikofukasawa | 13:d008249f0359 | 38 | |
masahikofukasawa | 13:d008249f0359 | 39 | if(primaryId == AKM_PRIMARY_ID_UNIPOLAR && subId == AkmHallSwitch::SUB_ID_EM1771) sensorName = "EM-1771"; |
masahikofukasawa | 13:d008249f0359 | 40 | else if(primaryId == AKM_PRIMARY_ID_UNIPOLAR && subId == AkmHallSwitch::SUB_ID_EW453) sensorName = "EW-453"; |
masahikofukasawa | 13:d008249f0359 | 41 | else if(primaryId == AKM_PRIMARY_ID_UNIPOLAR && subId == AkmHallSwitch::SUB_ID_EW652B) sensorName = "EW-652B"; |
masahikofukasawa | 13:d008249f0359 | 42 | else if(primaryId == AKM_PRIMARY_ID_UNIPOLAR && subId == AkmHallSwitch::SUB_ID_EW6672) sensorName = "EW-6672"; |
masahikofukasawa | 13:d008249f0359 | 43 | else if(primaryId == AKM_PRIMARY_ID_OMNIPOLAR && subId == AkmHallSwitch::SUB_ID_EM1781) sensorName = "EM-1781"; |
masahikofukasawa | 13:d008249f0359 | 44 | else if(primaryId == AKM_PRIMARY_ID_OMNIPOLAR && subId == AkmHallSwitch::SUB_ID_AK8788A) sensorName = "AK8788A"; |
masahikofukasawa | 13:d008249f0359 | 45 | else if(primaryId == AKM_PRIMARY_ID_OMNIPOLAR && subId == AkmHallSwitch::SUB_ID_EM6781) sensorName = "EM-6781"; |
masahikofukasawa | 13:d008249f0359 | 46 | else if(primaryId == AKM_PRIMARY_ID_LATCH && subId == AkmHallSwitch::SUB_ID_AK8771) sensorName = "AK8771"; |
masahikofukasawa | 13:d008249f0359 | 47 | else if(primaryId == AKM_PRIMARY_ID_LATCH && subId == AkmHallSwitch::SUB_ID_EW432) sensorName = "EW-432"; |
masahikofukasawa | 13:d008249f0359 | 48 | else if(primaryId == AKM_PRIMARY_ID_LATCH && subId == AkmHallSwitch::SUB_ID_EZ470) sensorName = "EZ-470"; |
masahikofukasawa | 13:d008249f0359 | 49 | else if(primaryId == AKM_PRIMARY_ID_LATCH && subId == AkmHallSwitch::SUB_ID_EZ471) sensorName = "EZ-471"; |
masahikofukasawa | 13:d008249f0359 | 50 | else if(primaryId == AKM_PRIMARY_ID_LATCH && subId == AkmHallSwitch::SUB_ID_EW612B) sensorName = "EW-612B"; |
masahikofukasawa | 13:d008249f0359 | 51 | else if(primaryId == AKM_PRIMARY_ID_LATCH && subId == AkmHallSwitch::SUB_ID_EW632) sensorName = "EW-632"; |
masahikofukasawa | 13:d008249f0359 | 52 | else if(primaryId == AKM_PRIMARY_ID_DUAL_OUTPUT && subId == AkmHallSwitch::SUB_ID_EM1791) sensorName = "EM-1791"; |
masahikofukasawa | 13:d008249f0359 | 53 | else if(primaryId == AKM_PRIMARY_ID_DUAL_OUTPUT && subId == AkmHallSwitch::SUB_ID_AK8789) sensorName = "AK8789"; |
masahikofukasawa | 13:d008249f0359 | 54 | else if(primaryId == AKM_PRIMARY_ID_ONECHIP_ENCODER && subId == AkmHallSwitch::SUB_ID_AK8775) sensorName = "AK8775"; |
masahikofukasawa | 13:d008249f0359 | 55 | else if(primaryId == AKM_PRIMARY_ID_ONECHIP_ENCODER && subId == AkmHallSwitch::SUB_ID_AK8776) sensorName = "AK8776"; |
masahikofukasawa | 13:d008249f0359 | 56 | else if(primaryId == AKM_PRIMARY_ID_ONECHIP_ENCODER && subId == AkmHallSwitch::SUB_ID_AK8779A) sensorName = "AK8779A"; |
masahikofukasawa | 13:d008249f0359 | 57 | else if(primaryId == AKM_PRIMARY_ID_ONECHIP_ENCODER && subId == AkmHallSwitch::SUB_ID_AK8779B) sensorName = "AK8779B"; |
masahikofukasawa | 13:d008249f0359 | 58 | |
masahikofukasawa | 0:7a00359e701e | 59 | sw0 = new InterruptIn(DIGITAL_D0); |
masahikofukasawa | 0:7a00359e701e | 60 | sw1 = new InterruptIn(DIGITAL_D1); |
masahikofukasawa | 0:7a00359e701e | 61 | |
masahikofukasawa | 0:7a00359e701e | 62 | sw1->rise(0); |
masahikofukasawa | 0:7a00359e701e | 63 | sw1->fall(0); |
masahikofukasawa | 0:7a00359e701e | 64 | sw0->rise(0); |
masahikofukasawa | 0:7a00359e701e | 65 | sw0->fall(0); |
masahikofukasawa | 0:7a00359e701e | 66 | |
masahikofukasawa | 0:7a00359e701e | 67 | return AkmSensor::SUCCESS; |
masahikofukasawa | 0:7a00359e701e | 68 | } |
masahikofukasawa | 0:7a00359e701e | 69 | |
masahikofukasawa | 0:7a00359e701e | 70 | void AkmHallSwitch::riseEventD0(){ |
masahikofukasawa | 0:7a00359e701e | 71 | d0 = 1; |
masahikofukasawa | 0:7a00359e701e | 72 | event = true; |
masahikofukasawa | 0:7a00359e701e | 73 | } |
masahikofukasawa | 0:7a00359e701e | 74 | void AkmHallSwitch::fallEventD0(){ |
masahikofukasawa | 0:7a00359e701e | 75 | d0 = 0; |
masahikofukasawa | 0:7a00359e701e | 76 | event = true; |
masahikofukasawa | 0:7a00359e701e | 77 | } |
masahikofukasawa | 0:7a00359e701e | 78 | void AkmHallSwitch::riseEventD1(){ |
masahikofukasawa | 0:7a00359e701e | 79 | d1 = 1; |
masahikofukasawa | 0:7a00359e701e | 80 | event = true; |
masahikofukasawa | 0:7a00359e701e | 81 | } |
masahikofukasawa | 0:7a00359e701e | 82 | |
masahikofukasawa | 0:7a00359e701e | 83 | void AkmHallSwitch::fallEventD1(){ |
masahikofukasawa | 0:7a00359e701e | 84 | d1 = 0; |
masahikofukasawa | 0:7a00359e701e | 85 | event = true; |
masahikofukasawa | 0:7a00359e701e | 86 | } |
masahikofukasawa | 0:7a00359e701e | 87 | |
masahikofukasawa | 0:7a00359e701e | 88 | bool AkmHallSwitch::isEvent(){ |
masahikofukasawa | 0:7a00359e701e | 89 | return event; |
masahikofukasawa | 0:7a00359e701e | 90 | } |
masahikofukasawa | 0:7a00359e701e | 91 | |
masahikofukasawa | 0:7a00359e701e | 92 | AkmSensor::Status AkmHallSwitch::startSensor(){ |
masahikofukasawa | 16:d85be9bafb80 | 93 | sw1->rise(callback(this, &AkmHallSwitch::riseEventD1)); |
masahikofukasawa | 16:d85be9bafb80 | 94 | sw1->fall(callback(this, &AkmHallSwitch::fallEventD1)); |
masahikofukasawa | 0:7a00359e701e | 95 | if(primaryId == AkmSensor::AKM_PRIMARY_ID_DUAL_OUTPUT || primaryId == AkmSensor::AKM_PRIMARY_ID_ONECHIP_ENCODER) |
masahikofukasawa | 0:7a00359e701e | 96 | { |
masahikofukasawa | 16:d85be9bafb80 | 97 | sw0->rise(callback(this, &AkmHallSwitch::riseEventD0)); |
masahikofukasawa | 16:d85be9bafb80 | 98 | sw0->fall(callback(this, &AkmHallSwitch::fallEventD0)); |
masahikofukasawa | 0:7a00359e701e | 99 | } |
masahikofukasawa | 0:7a00359e701e | 100 | return AkmSensor::SUCCESS; |
masahikofukasawa | 0:7a00359e701e | 101 | } |
masahikofukasawa | 0:7a00359e701e | 102 | |
masahikofukasawa | 0:7a00359e701e | 103 | AkmSensor::Status AkmHallSwitch::startSensor(const float sec){ |
masahikofukasawa | 11:cef8dc1cf010 | 104 | return AkmSensor::ERROR; |
masahikofukasawa | 0:7a00359e701e | 105 | } |
masahikofukasawa | 0:7a00359e701e | 106 | |
masahikofukasawa | 0:7a00359e701e | 107 | AkmSensor::Status AkmHallSwitch::stopSensor(){ |
masahikofukasawa | 0:7a00359e701e | 108 | sw1->rise(0); |
masahikofukasawa | 0:7a00359e701e | 109 | sw1->fall(0); |
masahikofukasawa | 0:7a00359e701e | 110 | sw0->rise(0); |
masahikofukasawa | 0:7a00359e701e | 111 | sw0->fall(0); |
masahikofukasawa | 0:7a00359e701e | 112 | return AkmSensor::SUCCESS; |
masahikofukasawa | 0:7a00359e701e | 113 | } |
masahikofukasawa | 0:7a00359e701e | 114 | |
masahikofukasawa | 0:7a00359e701e | 115 | AkmSensor::Status AkmHallSwitch::readSensorData(Message* msg){ |
masahikofukasawa | 0:7a00359e701e | 116 | event = false; |
masahikofukasawa | 0:7a00359e701e | 117 | |
masahikofukasawa | 0:7a00359e701e | 118 | msg->setCommand(Message::CMD_START_MEASUREMENT); |
masahikofukasawa | 0:7a00359e701e | 119 | msg->setArgument( 0, d1 ? 1 : 0 ); |
masahikofukasawa | 0:7a00359e701e | 120 | if(primaryId == AkmSensor::AKM_PRIMARY_ID_DUAL_OUTPUT || primaryId == AkmSensor::AKM_PRIMARY_ID_ONECHIP_ENCODER) |
masahikofukasawa | 0:7a00359e701e | 121 | { |
masahikofukasawa | 0:7a00359e701e | 122 | msg->setArgument( 1, d0 ? 1 : 0 ); |
masahikofukasawa | 0:7a00359e701e | 123 | } |
masahikofukasawa | 0:7a00359e701e | 124 | return AkmSensor::SUCCESS; |
masahikofukasawa | 0:7a00359e701e | 125 | } |
masahikofukasawa | 0:7a00359e701e | 126 | |
masahikofukasawa | 0:7a00359e701e | 127 | AkmSensor::Status AkmHallSwitch::requestCommand(Message* in, Message* out){ |
masahikofukasawa | 15:1238993fd75f | 128 | return AkmSensor::ERROR; |
masahikofukasawa | 0:7a00359e701e | 129 | } |
masahikofukasawa | 13:d008249f0359 | 130 | char* AkmHallSwitch::getSensorName(){ |
masahikofukasawa | 13:d008249f0359 | 131 | return sensorName; |
masahikofukasawa | 13:d008249f0359 | 132 | } |