Modified for compatibility with Rev.E. hardware
Fork of AkmSensor by
akmsensor.h@49:c8f8946129b6, 2018-05-01 (annotated)
- Committer:
- tkstreet
- Date:
- Tue May 01 21:31:15 2018 +0000
- Revision:
- 49:c8f8946129b6
- Parent:
- 46:5938ad2039b0
Modified for Rev.E. compatibility.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
masahikofukasawa | 0:7a00359e701e | 1 | #ifndef AKMSENSOR_H |
masahikofukasawa | 0:7a00359e701e | 2 | #define AKMSENSOR_H |
masahikofukasawa | 0:7a00359e701e | 3 | |
tkstreet | 43:45225713cd58 | 4 | #include "akdphwinfo.h" |
masahikofukasawa | 0:7a00359e701e | 5 | #include "mbed.h" |
masahikofukasawa | 0:7a00359e701e | 6 | #include "Message.h" |
tkstreet | 43:45225713cd58 | 7 | #include "akdp_debug.h" |
masahikofukasawa | 0:7a00359e701e | 8 | |
tkstreet | 23:50c98b286e41 | 9 | // Sampling rate for ADC |
tkstreet | 43:45225713cd58 | 10 | #define SENSOR_SAMPLING_RATE 0.1 // 10Hz |
tkstreet | 49:c8f8946129b6 | 11 | //#define SENSOR_SAMPLING_RATE 0.025 // 40Hz |
masahikofukasawa | 0:7a00359e701e | 12 | |
tkstreet | 22:f44f1018081e | 13 | /** |
tkstreet | 22:f44f1018081e | 14 | * Abstract base class for general AKM sensors. |
tkstreet | 22:f44f1018081e | 15 | */ |
masahikofukasawa | 0:7a00359e701e | 16 | class AkmSensor |
masahikofukasawa | 0:7a00359e701e | 17 | { |
masahikofukasawa | 0:7a00359e701e | 18 | |
masahikofukasawa | 0:7a00359e701e | 19 | public: |
tkstreet | 23:50c98b286e41 | 20 | /** |
tkstreet | 23:50c98b286e41 | 21 | * Error type for debugging purposes. |
tkstreet | 23:50c98b286e41 | 22 | */ |
masahikofukasawa | 0:7a00359e701e | 23 | typedef enum { |
tkstreet | 34:1ea3357c8d9a | 24 | |
tkstreet | 23:50c98b286e41 | 25 | SUCCESS = 0, /**< Successful termination (0) */ |
tkstreet | 23:50c98b286e41 | 26 | ERROR, /**< Error during execution (1) */ |
masahikofukasawa | 0:7a00359e701e | 27 | } Status; |
masahikofukasawa | 0:7a00359e701e | 28 | |
tkstreet | 23:50c98b286e41 | 29 | /** |
tkstreet | 23:50c98b286e41 | 30 | * Primary IDs for the major categories of sensors. |
tkstreet | 23:50c98b286e41 | 31 | */ |
masahikofukasawa | 0:7a00359e701e | 32 | typedef enum { |
tkstreet | 23:50c98b286e41 | 33 | AKM_PRIMARY_ID_AKD_SPI = 0x0, /**< AKD SPI Devices */ |
tkstreet | 23:50c98b286e41 | 34 | AKM_PRIMARY_ID_UNIPOLAR = 0x1, /**< Unipolar Switches */ |
tkstreet | 23:50c98b286e41 | 35 | AKM_PRIMARY_ID_OMNIPOLAR = 0x2, /**< Omnipolar Switches */ |
tkstreet | 23:50c98b286e41 | 36 | AKM_PRIMARY_ID_LATCH = 0x3, /**< Bipolar Latches */ |
tkstreet | 23:50c98b286e41 | 37 | AKM_PRIMARY_ID_DUAL_OUTPUT = 0x4, /**< Dual Output Switches */ |
tkstreet | 23:50c98b286e41 | 38 | AKM_PRIMARY_ID_ONECHIP_ENCODER = 0x5, /**< One-Chip Encoders */ |
tkstreet | 23:50c98b286e41 | 39 | AKM_PRIMARY_ID_TBD1 = 0x6, /**< Undefined */ |
masahikofukasawa | 37:c76d2edf3426 | 40 | AKM_PRIMARY_ID_CURRENT_SENSOR_3V = 0x7, /**< Current Sensor 3V Output */ |
tkstreet | 34:1ea3357c8d9a | 41 | AKM_PRIMARY_ID_DEMO = 0x8, /**< Demo Sensors */ |
masahikofukasawa | 37:c76d2edf3426 | 42 | AKM_PRIMARY_ID_CURRENT_SENSOR_5V = 0x9, /**< Current Sensors 5V Output */ |
tkstreet | 23:50c98b286e41 | 43 | AKM_PRIMARY_ID_MISC_ANALOG = 0xA, /**< Analog Devices */ |
tkstreet | 23:50c98b286e41 | 44 | AKM_PRIMARY_ID_LINEAR_SENSOR = 0xB, /**< Linear Sensors */ |
tkstreet | 23:50c98b286e41 | 45 | AKM_PRIMARY_ID_MOTOR_DRIVER = 0xC, /**< Motor Drivers */ |
tkstreet | 23:50c98b286e41 | 46 | AKM_PRIMARY_ID_IR_SENSOR = 0xD, /**< IR Sensors */ |
tkstreet | 23:50c98b286e41 | 47 | AKM_PRIMARY_ID_ANGLE_SENSOR = 0xE, /**< Angle Sensors */ |
tkstreet | 23:50c98b286e41 | 48 | AKM_PRIMARY_ID_AKD_I2C = 0xF, /**< AKD I2C Devices */ |
masahikofukasawa | 0:7a00359e701e | 49 | } SensorPrimaryId; |
masahikofukasawa | 0:7a00359e701e | 50 | |
tkstreet | 34:1ea3357c8d9a | 51 | |
masahikofukasawa | 27:41aa9fb23a2f | 52 | virtual ~AkmSensor(){}; |
tkstreet | 23:50c98b286e41 | 53 | |
tkstreet | 23:50c98b286e41 | 54 | /** |
tkstreet | 23:50c98b286e41 | 55 | * Process for intializing the selected sensor. |
tkstreet | 23:50c98b286e41 | 56 | * |
tkstreet | 23:50c98b286e41 | 57 | * @return Termination status type for debugging purposes. |
tkstreet | 23:50c98b286e41 | 58 | */ |
masahikofukasawa | 0:7a00359e701e | 59 | virtual Status init(const uint8_t id, const uint8_t subid) = 0; |
tkstreet | 23:50c98b286e41 | 60 | |
tkstreet | 23:50c98b286e41 | 61 | /** |
tkstreet | 23:50c98b286e41 | 62 | * Process abstraction for starting sensor operation. |
tkstreet | 23:50c98b286e41 | 63 | * |
tkstreet | 23:50c98b286e41 | 64 | * @return Termination status type for debugging purposes. |
tkstreet | 23:50c98b286e41 | 65 | */ |
masahikofukasawa | 0:7a00359e701e | 66 | virtual Status startSensor() = 0; |
tkstreet | 23:50c98b286e41 | 67 | |
tkstreet | 23:50c98b286e41 | 68 | /** |
tkstreet | 23:50c98b286e41 | 69 | * Process abstraction for starting sensor operation. |
tkstreet | 23:50c98b286e41 | 70 | * |
tkstreet | 23:50c98b286e41 | 71 | * @param sec Number of seconds of operation. |
tkstreet | 23:50c98b286e41 | 72 | * @return Termination status type for debugging purposes. |
tkstreet | 23:50c98b286e41 | 73 | */ |
masahikofukasawa | 0:7a00359e701e | 74 | virtual Status startSensor(const float sec) = 0; |
tkstreet | 23:50c98b286e41 | 75 | |
tkstreet | 23:50c98b286e41 | 76 | /** |
tkstreet | 23:50c98b286e41 | 77 | * Process abstraction for stopping sensor operation. |
tkstreet | 23:50c98b286e41 | 78 | * |
tkstreet | 23:50c98b286e41 | 79 | * @return Termination status type for debugging purposes. |
tkstreet | 23:50c98b286e41 | 80 | */ |
masahikofukasawa | 0:7a00359e701e | 81 | virtual Status stopSensor() = 0; |
tkstreet | 23:50c98b286e41 | 82 | |
tkstreet | 23:50c98b286e41 | 83 | /** |
tkstreet | 23:50c98b286e41 | 84 | * Process abstraction for reading data from the sensor. |
tkstreet | 23:50c98b286e41 | 85 | * |
tkstreet | 23:50c98b286e41 | 86 | * @param msg Message object that will hold the sensor data. |
tkstreet | 23:50c98b286e41 | 87 | * @return Termination status type for debugging purposes. |
tkstreet | 23:50c98b286e41 | 88 | */ |
masahikofukasawa | 0:7a00359e701e | 89 | virtual Status readSensorData(Message* msg) = 0; |
tkstreet | 23:50c98b286e41 | 90 | |
tkstreet | 23:50c98b286e41 | 91 | /** |
tkstreet | 23:50c98b286e41 | 92 | * Primary process for interfacing a sensor with the AKDP. When implemented |
tkstreet | 49:c8f8946129b6 | 93 | * in sensor class, it will transfer commands between the sensor control |
tkstreet | 23:50c98b286e41 | 94 | * class and AkmSensorManager. |
tkstreet | 23:50c98b286e41 | 95 | * |
tkstreet | 23:50c98b286e41 | 96 | * @param in Command message to be processed by sensor. |
tkstreet | 23:50c98b286e41 | 97 | * @param out Message returned from sensor. |
tkstreet | 23:50c98b286e41 | 98 | * @return Termination status type for debugging purposes. |
tkstreet | 23:50c98b286e41 | 99 | */ |
masahikofukasawa | 0:7a00359e701e | 100 | virtual Status requestCommand(Message* in, Message* out) = 0; |
tkstreet | 23:50c98b286e41 | 101 | |
tkstreet | 23:50c98b286e41 | 102 | /** |
tkstreet | 34:1ea3357c8d9a | 103 | * Set event flag. |
tkstreet | 34:1ea3357c8d9a | 104 | */ |
masahikofukasawa | 29:b488d2c89fba | 105 | virtual void setEvent(){ |
tkstreet | 45:6af8fdde0ef3 | 106 | VERBOSE("#setEvent called.\r\n"); |
masahikofukasawa | 29:b488d2c89fba | 107 | event = true; |
masahikofukasawa | 29:b488d2c89fba | 108 | } |
masahikofukasawa | 29:b488d2c89fba | 109 | |
tkstreet | 34:1ea3357c8d9a | 110 | /** |
tkstreet | 34:1ea3357c8d9a | 111 | * Clear event flag. |
tkstreet | 34:1ea3357c8d9a | 112 | */ |
masahikofukasawa | 29:b488d2c89fba | 113 | void clearEvent(){ |
tkstreet | 45:6af8fdde0ef3 | 114 | VERBOSE("#clearEvent called.\r\n"); |
masahikofukasawa | 29:b488d2c89fba | 115 | event = false; |
masahikofukasawa | 29:b488d2c89fba | 116 | } |
masahikofukasawa | 29:b488d2c89fba | 117 | |
tkstreet | 34:1ea3357c8d9a | 118 | /** |
tkstreet | 34:1ea3357c8d9a | 119 | * Checks if an event has occurred. |
tkstreet | 23:50c98b286e41 | 120 | * |
tkstreet | 34:1ea3357c8d9a | 121 | * @return TRUE if event has occurred, FALSE otherwise. |
tkstreet | 34:1ea3357c8d9a | 122 | */ |
masahikofukasawa | 27:41aa9fb23a2f | 123 | bool isEvent(){ |
masahikofukasawa | 27:41aa9fb23a2f | 124 | return event; |
masahikofukasawa | 27:41aa9fb23a2f | 125 | } |
masahikofukasawa | 27:41aa9fb23a2f | 126 | |
tkstreet | 34:1ea3357c8d9a | 127 | /** |
tkstreet | 34:1ea3357c8d9a | 128 | * Retrieve the name of the sensor. |
tkstreet | 34:1ea3357c8d9a | 129 | * |
tkstreet | 34:1ea3357c8d9a | 130 | * @return Name of sensor as a character array. |
tkstreet | 23:50c98b286e41 | 131 | */ |
masahikofukasawa | 46:5938ad2039b0 | 132 | const char* getSensorName(){ |
masahikofukasawa | 27:41aa9fb23a2f | 133 | return sensorName; |
masahikofukasawa | 27:41aa9fb23a2f | 134 | }; |
masahikofukasawa | 27:41aa9fb23a2f | 135 | |
tkstreet | 34:1ea3357c8d9a | 136 | /** |
tkstreet | 34:1ea3357c8d9a | 137 | * Retrieve the primary ID of the sensor. |
tkstreet | 34:1ea3357c8d9a | 138 | * |
tkstreet | 34:1ea3357c8d9a | 139 | * @return Primary ID as an integer. |
tkstreet | 34:1ea3357c8d9a | 140 | */ |
masahikofukasawa | 27:41aa9fb23a2f | 141 | int getPrimaryId(){ |
masahikofukasawa | 27:41aa9fb23a2f | 142 | return primaryId; |
masahikofukasawa | 27:41aa9fb23a2f | 143 | }; |
masahikofukasawa | 27:41aa9fb23a2f | 144 | |
tkstreet | 34:1ea3357c8d9a | 145 | /** |
tkstreet | 34:1ea3357c8d9a | 146 | * Retrieve the Sub-ID of the sensor. |
tkstreet | 34:1ea3357c8d9a | 147 | * |
tkstreet | 34:1ea3357c8d9a | 148 | * @return Sub-ID as an integer. |
tkstreet | 34:1ea3357c8d9a | 149 | */ |
masahikofukasawa | 27:41aa9fb23a2f | 150 | int getSecondaryId(){ |
masahikofukasawa | 27:41aa9fb23a2f | 151 | return subId; |
masahikofukasawa | 27:41aa9fb23a2f | 152 | }; |
masahikofukasawa | 0:7a00359e701e | 153 | |
masahikofukasawa | 0:7a00359e701e | 154 | private: |
masahikofukasawa | 29:b488d2c89fba | 155 | bool event; |
masahikofukasawa | 0:7a00359e701e | 156 | |
masahikofukasawa | 27:41aa9fb23a2f | 157 | protected: |
masahikofukasawa | 27:41aa9fb23a2f | 158 | uint8_t primaryId; |
masahikofukasawa | 27:41aa9fb23a2f | 159 | uint8_t subId; |
masahikofukasawa | 46:5938ad2039b0 | 160 | const char* sensorName; |
masahikofukasawa | 27:41aa9fb23a2f | 161 | |
masahikofukasawa | 27:41aa9fb23a2f | 162 | AkmSensor(){ |
masahikofukasawa | 27:41aa9fb23a2f | 163 | event = false; |
masahikofukasawa | 27:41aa9fb23a2f | 164 | primaryId = 0; |
masahikofukasawa | 27:41aa9fb23a2f | 165 | subId = 0; |
masahikofukasawa | 27:41aa9fb23a2f | 166 | sensorName = ""; |
masahikofukasawa | 27:41aa9fb23a2f | 167 | }; |
masahikofukasawa | 0:7a00359e701e | 168 | }; |
masahikofukasawa | 0:7a00359e701e | 169 | |
masahikofukasawa | 0:7a00359e701e | 170 | #endif |