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