Modified for compatibility with Rev.E. hardware
Fork of AkmSensor by
akmsensor.h@23:50c98b286e41, 2017-04-13 (annotated)
- Committer:
- tkstreet
- Date:
- Thu Apr 13 22:15:54 2017 +0000
- Revision:
- 23:50c98b286e41
- Parent:
- 22:f44f1018081e
- Child:
- 34:1ea3357c8d9a
Added documentation for all classes
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 | |
masahikofukasawa | 0:7a00359e701e | 4 | #include "mbed.h" |
masahikofukasawa | 0:7a00359e701e | 5 | #include "Message.h" |
masahikofukasawa | 0:7a00359e701e | 6 | |
tkstreet | 23:50c98b286e41 | 7 | // SPI Pin Number Definitions |
tkstreet | 23:50c98b286e41 | 8 | #define SPI_SCK P0_8 // SPI, SCK |
tkstreet | 23:50c98b286e41 | 9 | #define SPI_MISO P0_9 // SPI, MISO |
masahikofukasawa | 0:7a00359e701e | 10 | #define SPI_MOSI P0_10 //SPI, MOSI |
masahikofukasawa | 4:af13b985c689 | 11 | #define SPI_CS P0_11 //SPI, CS |
masahikofukasawa | 7:e269411568c9 | 12 | #define SPI_DRDY P0_7 //SPI, DRDY |
masahikofukasawa | 0:7a00359e701e | 13 | |
tkstreet | 23:50c98b286e41 | 14 | // I2C Pin Number Definitions |
masahikofukasawa | 0:7a00359e701e | 15 | #define I2C_SCL P0_8 //I2C, SCL |
masahikofukasawa | 0:7a00359e701e | 16 | #define I2C_SDA P0_10 //I2C, SDA |
masahikofukasawa | 0:7a00359e701e | 17 | |
tkstreet | 23:50c98b286e41 | 18 | // Digital Port Pin Number Definitions |
masahikofukasawa | 0:7a00359e701e | 19 | #define DIGITAL_D0 P0_11 |
masahikofukasawa | 0:7a00359e701e | 20 | #define DIGITAL_D1 P0_9 |
masahikofukasawa | 0:7a00359e701e | 21 | |
tkstreet | 23:50c98b286e41 | 22 | // DRDY Port Pin Number Definitions |
masahikofukasawa | 7:e269411568c9 | 23 | #define I2C_DRDY P0_11 |
masahikofukasawa | 0:7a00359e701e | 24 | |
tkstreet | 23:50c98b286e41 | 25 | // Analog In Pin Number Definitions |
masahikofukasawa | 0:7a00359e701e | 26 | #define ANALOG_IN_PIN P0_5 //P05 |
masahikofukasawa | 0:7a00359e701e | 27 | |
tkstreet | 23:50c98b286e41 | 28 | // I2C Speed Standards |
masahikofukasawa | 0:7a00359e701e | 29 | #define I2C_SPEED_100KHZ 100000 |
masahikofukasawa | 0:7a00359e701e | 30 | #define I2C_SPEED_400KHZ 400000 |
masahikofukasawa | 0:7a00359e701e | 31 | |
tkstreet | 23:50c98b286e41 | 32 | // Sampling rate for ADC |
masahikofukasawa | 11:cef8dc1cf010 | 33 | #define SENSOR_SAMPLING_RATE 0.1 // 10Hz |
masahikofukasawa | 0:7a00359e701e | 34 | |
tkstreet | 22:f44f1018081e | 35 | /** |
tkstreet | 22:f44f1018081e | 36 | * Abstract base class for general AKM sensors. |
tkstreet | 22:f44f1018081e | 37 | */ |
masahikofukasawa | 0:7a00359e701e | 38 | class AkmSensor |
masahikofukasawa | 0:7a00359e701e | 39 | { |
masahikofukasawa | 0:7a00359e701e | 40 | |
masahikofukasawa | 0:7a00359e701e | 41 | public: |
tkstreet | 23:50c98b286e41 | 42 | /** |
tkstreet | 23:50c98b286e41 | 43 | * Error type for debugging purposes. |
tkstreet | 23:50c98b286e41 | 44 | */ |
masahikofukasawa | 0:7a00359e701e | 45 | typedef enum { |
tkstreet | 23:50c98b286e41 | 46 | SUCCESS = 0, /**< Successful termination (0) */ |
tkstreet | 23:50c98b286e41 | 47 | ERROR, /**< Error during execution (1) */ |
masahikofukasawa | 11:cef8dc1cf010 | 48 | // ERROR_DOESNT_SUPPORT, |
masahikofukasawa | 0:7a00359e701e | 49 | } Status; |
masahikofukasawa | 0:7a00359e701e | 50 | |
tkstreet | 23:50c98b286e41 | 51 | /** |
tkstreet | 23:50c98b286e41 | 52 | * Primary IDs for the major categories of sensors. |
tkstreet | 23:50c98b286e41 | 53 | */ |
masahikofukasawa | 0:7a00359e701e | 54 | typedef enum { |
tkstreet | 23:50c98b286e41 | 55 | AKM_PRIMARY_ID_AKD_SPI = 0x0, /**< AKD SPI Devices */ |
tkstreet | 23:50c98b286e41 | 56 | AKM_PRIMARY_ID_UNIPOLAR = 0x1, /**< Unipolar Switches */ |
tkstreet | 23:50c98b286e41 | 57 | AKM_PRIMARY_ID_OMNIPOLAR = 0x2, /**< Omnipolar Switches */ |
tkstreet | 23:50c98b286e41 | 58 | AKM_PRIMARY_ID_LATCH = 0x3, /**< Bipolar Latches */ |
tkstreet | 23:50c98b286e41 | 59 | AKM_PRIMARY_ID_DUAL_OUTPUT = 0x4, /**< Dual Output Switches */ |
tkstreet | 23:50c98b286e41 | 60 | AKM_PRIMARY_ID_ONECHIP_ENCODER = 0x5, /**< One-Chip Encoders */ |
tkstreet | 23:50c98b286e41 | 61 | AKM_PRIMARY_ID_TBD1 = 0x6, /**< Undefined */ |
tkstreet | 23:50c98b286e41 | 62 | AKM_PRIMARY_ID_TBD2 = 0x7, /**< Undefined */ |
tkstreet | 23:50c98b286e41 | 63 | AKM_PRIMARY_ID_LINEAR_SENSOR_LEGACY = 0x8, /**< Linear Sensors (Legacy) */ |
tkstreet | 23:50c98b286e41 | 64 | AKM_PRIMARY_ID_CURRENT_SENSOR = 0x9, /**< Current Sensors */ |
tkstreet | 23:50c98b286e41 | 65 | AKM_PRIMARY_ID_MISC_ANALOG = 0xA, /**< Analog Devices */ |
tkstreet | 23:50c98b286e41 | 66 | AKM_PRIMARY_ID_LINEAR_SENSOR = 0xB, /**< Linear Sensors */ |
tkstreet | 23:50c98b286e41 | 67 | AKM_PRIMARY_ID_MOTOR_DRIVER = 0xC, /**< Motor Drivers */ |
tkstreet | 23:50c98b286e41 | 68 | AKM_PRIMARY_ID_IR_SENSOR = 0xD, /**< IR Sensors */ |
tkstreet | 23:50c98b286e41 | 69 | AKM_PRIMARY_ID_ANGLE_SENSOR = 0xE, /**< Angle Sensors */ |
tkstreet | 23:50c98b286e41 | 70 | AKM_PRIMARY_ID_AKD_I2C = 0xF, /**< AKD I2C Devices */ |
masahikofukasawa | 0:7a00359e701e | 71 | } SensorPrimaryId; |
masahikofukasawa | 0:7a00359e701e | 72 | |
masahikofukasawa | 0:7a00359e701e | 73 | AkmSensor(){} |
masahikofukasawa | 0:7a00359e701e | 74 | virtual ~AkmSensor(){} |
tkstreet | 23:50c98b286e41 | 75 | |
tkstreet | 23:50c98b286e41 | 76 | /** |
tkstreet | 23:50c98b286e41 | 77 | * Process for intializing the selected sensor. |
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 init(const uint8_t id, const uint8_t subid) = 0; |
tkstreet | 23:50c98b286e41 | 82 | |
tkstreet | 23:50c98b286e41 | 83 | /** |
tkstreet | 23:50c98b286e41 | 84 | * Simple flag process to determine if an event has occurred. |
tkstreet | 23:50c98b286e41 | 85 | * |
tkstreet | 23:50c98b286e41 | 86 | * @return TRUE if event has occurred, FALSE if not. |
tkstreet | 23:50c98b286e41 | 87 | */ |
masahikofukasawa | 0:7a00359e701e | 88 | virtual bool isEvent() = 0; |
tkstreet | 23:50c98b286e41 | 89 | |
tkstreet | 23:50c98b286e41 | 90 | /** |
tkstreet | 23:50c98b286e41 | 91 | * Process abstraction for starting sensor operation. |
tkstreet | 23:50c98b286e41 | 92 | * |
tkstreet | 23:50c98b286e41 | 93 | * @return Termination status type for debugging purposes. |
tkstreet | 23:50c98b286e41 | 94 | */ |
masahikofukasawa | 0:7a00359e701e | 95 | virtual Status startSensor() = 0; |
tkstreet | 23:50c98b286e41 | 96 | |
tkstreet | 23:50c98b286e41 | 97 | /** |
tkstreet | 23:50c98b286e41 | 98 | * Process abstraction for starting sensor operation. |
tkstreet | 23:50c98b286e41 | 99 | * |
tkstreet | 23:50c98b286e41 | 100 | * @param sec Number of seconds of operation. |
tkstreet | 23:50c98b286e41 | 101 | * @return Termination status type for debugging purposes. |
tkstreet | 23:50c98b286e41 | 102 | */ |
masahikofukasawa | 0:7a00359e701e | 103 | virtual Status startSensor(const float sec) = 0; |
tkstreet | 23:50c98b286e41 | 104 | |
tkstreet | 23:50c98b286e41 | 105 | /** |
tkstreet | 23:50c98b286e41 | 106 | * Process abstraction for stopping sensor operation. |
tkstreet | 23:50c98b286e41 | 107 | * |
tkstreet | 23:50c98b286e41 | 108 | * @return Termination status type for debugging purposes. |
tkstreet | 23:50c98b286e41 | 109 | */ |
masahikofukasawa | 0:7a00359e701e | 110 | virtual Status stopSensor() = 0; |
tkstreet | 23:50c98b286e41 | 111 | |
tkstreet | 23:50c98b286e41 | 112 | /** |
tkstreet | 23:50c98b286e41 | 113 | * Process abstraction for reading data from the sensor. |
tkstreet | 23:50c98b286e41 | 114 | * |
tkstreet | 23:50c98b286e41 | 115 | * @param msg Message object that will hold the sensor data. |
tkstreet | 23:50c98b286e41 | 116 | * @return Termination status type for debugging purposes. |
tkstreet | 23:50c98b286e41 | 117 | */ |
masahikofukasawa | 0:7a00359e701e | 118 | virtual Status readSensorData(Message* msg) = 0; |
tkstreet | 23:50c98b286e41 | 119 | |
tkstreet | 23:50c98b286e41 | 120 | /** |
tkstreet | 23:50c98b286e41 | 121 | * Primary process for interfacing a sensor with the AKDP. When implemented |
tkstreet | 23:50c98b286e41 | 122 | * in sensor class, it will transfer commands between the the sensor control |
tkstreet | 23:50c98b286e41 | 123 | * class and AkmSensorManager. |
tkstreet | 23:50c98b286e41 | 124 | * |
tkstreet | 23:50c98b286e41 | 125 | * @param in Command message to be processed by sensor. |
tkstreet | 23:50c98b286e41 | 126 | * @param out Message returned from sensor. |
tkstreet | 23:50c98b286e41 | 127 | * @return Termination status type for debugging purposes. |
tkstreet | 23:50c98b286e41 | 128 | */ |
masahikofukasawa | 0:7a00359e701e | 129 | virtual Status requestCommand(Message* in, Message* out) = 0; |
tkstreet | 23:50c98b286e41 | 130 | |
tkstreet | 23:50c98b286e41 | 131 | /** |
tkstreet | 23:50c98b286e41 | 132 | * Get the name of the sensor in char format. |
tkstreet | 23:50c98b286e41 | 133 | * |
tkstreet | 23:50c98b286e41 | 134 | * @return Sensor name as a char array. |
tkstreet | 23:50c98b286e41 | 135 | */ |
masahikofukasawa | 13:d008249f0359 | 136 | virtual char* getSensorName() = 0; |
masahikofukasawa | 0:7a00359e701e | 137 | |
masahikofukasawa | 0:7a00359e701e | 138 | private: |
masahikofukasawa | 0:7a00359e701e | 139 | |
masahikofukasawa | 0:7a00359e701e | 140 | }; |
masahikofukasawa | 0:7a00359e701e | 141 | |
masahikofukasawa | 0:7a00359e701e | 142 | #endif |