Modified for compatibility with Rev.E. hardware

Fork of AkmSensor by AKM Development Platform

Committer:
masahikofukasawa
Date:
Wed May 24 20:23:22 2017 +0000
Revision:
37:c76d2edf3426
Parent:
34:1ea3357c8d9a
Child:
40:42e48427e4b7
Added CQ-32xx, CZ-31xx current sensors.

Who changed what in which revision?

UserRevisionLine numberNew 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 29:b488d2c89fba 6 //#include "debug.h"
masahikofukasawa 0:7a00359e701e 7
tkstreet 23:50c98b286e41 8 // SPI Pin Number Definitions
tkstreet 23:50c98b286e41 9 #define SPI_SCK P0_8 // SPI, SCK
tkstreet 23:50c98b286e41 10 #define SPI_MISO P0_9 // SPI, MISO
masahikofukasawa 0:7a00359e701e 11 #define SPI_MOSI P0_10 //SPI, MOSI
masahikofukasawa 4:af13b985c689 12 #define SPI_CS P0_11 //SPI, CS
masahikofukasawa 7:e269411568c9 13 #define SPI_DRDY P0_7 //SPI, DRDY
masahikofukasawa 0:7a00359e701e 14
tkstreet 23:50c98b286e41 15 // I2C Pin Number Definitions
masahikofukasawa 0:7a00359e701e 16 #define I2C_SCL P0_8 //I2C, SCL
masahikofukasawa 0:7a00359e701e 17 #define I2C_SDA P0_10 //I2C, SDA
masahikofukasawa 0:7a00359e701e 18
tkstreet 23:50c98b286e41 19 // Digital Port Pin Number Definitions
masahikofukasawa 0:7a00359e701e 20 #define DIGITAL_D0 P0_11
masahikofukasawa 0:7a00359e701e 21 #define DIGITAL_D1 P0_9
masahikofukasawa 0:7a00359e701e 22
tkstreet 23:50c98b286e41 23 // DRDY Port Pin Number Definitions
masahikofukasawa 7:e269411568c9 24 #define I2C_DRDY P0_11
masahikofukasawa 0:7a00359e701e 25
tkstreet 23:50c98b286e41 26 // Analog In Pin Number Definitions
masahikofukasawa 0:7a00359e701e 27 #define ANALOG_IN_PIN P0_5 //P05
masahikofukasawa 0:7a00359e701e 28
tkstreet 23:50c98b286e41 29 // I2C Speed Standards
masahikofukasawa 0:7a00359e701e 30 #define I2C_SPEED_100KHZ 100000
masahikofukasawa 0:7a00359e701e 31 #define I2C_SPEED_400KHZ 400000
masahikofukasawa 0:7a00359e701e 32
tkstreet 23:50c98b286e41 33 // Sampling rate for ADC
masahikofukasawa 11:cef8dc1cf010 34 #define SENSOR_SAMPLING_RATE 0.1 // 10Hz
masahikofukasawa 0:7a00359e701e 35
tkstreet 22:f44f1018081e 36 /**
tkstreet 22:f44f1018081e 37 * Abstract base class for general AKM sensors.
tkstreet 22:f44f1018081e 38 */
masahikofukasawa 0:7a00359e701e 39 class AkmSensor
masahikofukasawa 0:7a00359e701e 40 {
masahikofukasawa 0:7a00359e701e 41
masahikofukasawa 0:7a00359e701e 42 public:
tkstreet 23:50c98b286e41 43 /**
tkstreet 23:50c98b286e41 44 * Error type for debugging purposes.
tkstreet 23:50c98b286e41 45 */
masahikofukasawa 0:7a00359e701e 46 typedef enum {
tkstreet 34:1ea3357c8d9a 47
tkstreet 23:50c98b286e41 48 SUCCESS = 0, /**< Successful termination (0) */
tkstreet 23:50c98b286e41 49 ERROR, /**< Error during execution (1) */
masahikofukasawa 0:7a00359e701e 50 } Status;
masahikofukasawa 0:7a00359e701e 51
tkstreet 23:50c98b286e41 52 /**
tkstreet 23:50c98b286e41 53 * Primary IDs for the major categories of sensors.
tkstreet 23:50c98b286e41 54 */
masahikofukasawa 0:7a00359e701e 55 typedef enum {
tkstreet 23:50c98b286e41 56 AKM_PRIMARY_ID_AKD_SPI = 0x0, /**< AKD SPI Devices */
tkstreet 23:50c98b286e41 57 AKM_PRIMARY_ID_UNIPOLAR = 0x1, /**< Unipolar Switches */
tkstreet 23:50c98b286e41 58 AKM_PRIMARY_ID_OMNIPOLAR = 0x2, /**< Omnipolar Switches */
tkstreet 23:50c98b286e41 59 AKM_PRIMARY_ID_LATCH = 0x3, /**< Bipolar Latches */
tkstreet 23:50c98b286e41 60 AKM_PRIMARY_ID_DUAL_OUTPUT = 0x4, /**< Dual Output Switches */
tkstreet 23:50c98b286e41 61 AKM_PRIMARY_ID_ONECHIP_ENCODER = 0x5, /**< One-Chip Encoders */
tkstreet 23:50c98b286e41 62 AKM_PRIMARY_ID_TBD1 = 0x6, /**< Undefined */
masahikofukasawa 37:c76d2edf3426 63 AKM_PRIMARY_ID_CURRENT_SENSOR_3V = 0x7, /**< Current Sensor 3V Output */
tkstreet 34:1ea3357c8d9a 64 AKM_PRIMARY_ID_DEMO = 0x8, /**< Demo Sensors */
masahikofukasawa 37:c76d2edf3426 65 AKM_PRIMARY_ID_CURRENT_SENSOR_5V = 0x9, /**< Current Sensors 5V Output */
tkstreet 23:50c98b286e41 66 AKM_PRIMARY_ID_MISC_ANALOG = 0xA, /**< Analog Devices */
tkstreet 23:50c98b286e41 67 AKM_PRIMARY_ID_LINEAR_SENSOR = 0xB, /**< Linear Sensors */
tkstreet 23:50c98b286e41 68 AKM_PRIMARY_ID_MOTOR_DRIVER = 0xC, /**< Motor Drivers */
tkstreet 23:50c98b286e41 69 AKM_PRIMARY_ID_IR_SENSOR = 0xD, /**< IR Sensors */
tkstreet 23:50c98b286e41 70 AKM_PRIMARY_ID_ANGLE_SENSOR = 0xE, /**< Angle Sensors */
tkstreet 23:50c98b286e41 71 AKM_PRIMARY_ID_AKD_I2C = 0xF, /**< AKD I2C Devices */
masahikofukasawa 0:7a00359e701e 72 } SensorPrimaryId;
masahikofukasawa 0:7a00359e701e 73
tkstreet 34:1ea3357c8d9a 74
masahikofukasawa 27:41aa9fb23a2f 75 virtual ~AkmSensor(){};
tkstreet 23:50c98b286e41 76
tkstreet 23:50c98b286e41 77 /**
tkstreet 23:50c98b286e41 78 * Process for intializing the selected sensor.
tkstreet 23:50c98b286e41 79 *
tkstreet 23:50c98b286e41 80 * @return Termination status type for debugging purposes.
tkstreet 23:50c98b286e41 81 */
masahikofukasawa 0:7a00359e701e 82 virtual Status init(const uint8_t id, const uint8_t subid) = 0;
tkstreet 23:50c98b286e41 83
tkstreet 23:50c98b286e41 84 /**
tkstreet 23:50c98b286e41 85 * Process abstraction for starting sensor operation.
tkstreet 23:50c98b286e41 86 *
tkstreet 23:50c98b286e41 87 * @return Termination status type for debugging purposes.
tkstreet 23:50c98b286e41 88 */
masahikofukasawa 0:7a00359e701e 89 virtual Status startSensor() = 0;
tkstreet 23:50c98b286e41 90
tkstreet 23:50c98b286e41 91 /**
tkstreet 23:50c98b286e41 92 * Process abstraction for starting sensor operation.
tkstreet 23:50c98b286e41 93 *
tkstreet 23:50c98b286e41 94 * @param sec Number of seconds of operation.
tkstreet 23:50c98b286e41 95 * @return Termination status type for debugging purposes.
tkstreet 23:50c98b286e41 96 */
masahikofukasawa 0:7a00359e701e 97 virtual Status startSensor(const float sec) = 0;
tkstreet 23:50c98b286e41 98
tkstreet 23:50c98b286e41 99 /**
tkstreet 23:50c98b286e41 100 * Process abstraction for stopping sensor operation.
tkstreet 23:50c98b286e41 101 *
tkstreet 23:50c98b286e41 102 * @return Termination status type for debugging purposes.
tkstreet 23:50c98b286e41 103 */
masahikofukasawa 0:7a00359e701e 104 virtual Status stopSensor() = 0;
tkstreet 23:50c98b286e41 105
tkstreet 23:50c98b286e41 106 /**
tkstreet 23:50c98b286e41 107 * Process abstraction for reading data from the sensor.
tkstreet 23:50c98b286e41 108 *
tkstreet 23:50c98b286e41 109 * @param msg Message object that will hold the sensor data.
tkstreet 23:50c98b286e41 110 * @return Termination status type for debugging purposes.
tkstreet 23:50c98b286e41 111 */
masahikofukasawa 0:7a00359e701e 112 virtual Status readSensorData(Message* msg) = 0;
tkstreet 23:50c98b286e41 113
tkstreet 23:50c98b286e41 114 /**
tkstreet 23:50c98b286e41 115 * Primary process for interfacing a sensor with the AKDP. When implemented
tkstreet 23:50c98b286e41 116 * in sensor class, it will transfer commands between the the sensor control
tkstreet 23:50c98b286e41 117 * class and AkmSensorManager.
tkstreet 23:50c98b286e41 118 *
tkstreet 23:50c98b286e41 119 * @param in Command message to be processed by sensor.
tkstreet 23:50c98b286e41 120 * @param out Message returned from sensor.
tkstreet 23:50c98b286e41 121 * @return Termination status type for debugging purposes.
tkstreet 23:50c98b286e41 122 */
masahikofukasawa 0:7a00359e701e 123 virtual Status requestCommand(Message* in, Message* out) = 0;
tkstreet 23:50c98b286e41 124
tkstreet 23:50c98b286e41 125 /**
tkstreet 34:1ea3357c8d9a 126 * Set event flag.
tkstreet 34:1ea3357c8d9a 127 */
masahikofukasawa 29:b488d2c89fba 128 virtual void setEvent(){
masahikofukasawa 29:b488d2c89fba 129 // MSG("#setEvent called.\r\n");
masahikofukasawa 29:b488d2c89fba 130 event = true;
masahikofukasawa 29:b488d2c89fba 131 }
masahikofukasawa 29:b488d2c89fba 132
tkstreet 34:1ea3357c8d9a 133 /**
tkstreet 34:1ea3357c8d9a 134 * Clear event flag.
tkstreet 34:1ea3357c8d9a 135 */
masahikofukasawa 29:b488d2c89fba 136 void clearEvent(){
masahikofukasawa 29:b488d2c89fba 137 // MSG("#clearEvent called.\r\n");
masahikofukasawa 29:b488d2c89fba 138 event = false;
masahikofukasawa 29:b488d2c89fba 139 }
masahikofukasawa 29:b488d2c89fba 140
tkstreet 34:1ea3357c8d9a 141 /**
tkstreet 34:1ea3357c8d9a 142 * Checks if an event has occurred.
tkstreet 23:50c98b286e41 143 *
tkstreet 34:1ea3357c8d9a 144 * @return TRUE if event has occurred, FALSE otherwise.
tkstreet 34:1ea3357c8d9a 145 */
masahikofukasawa 27:41aa9fb23a2f 146 bool isEvent(){
masahikofukasawa 27:41aa9fb23a2f 147 return event;
masahikofukasawa 27:41aa9fb23a2f 148 }
masahikofukasawa 27:41aa9fb23a2f 149
tkstreet 34:1ea3357c8d9a 150 /**
tkstreet 34:1ea3357c8d9a 151 * Retrieve the name of the sensor.
tkstreet 34:1ea3357c8d9a 152 *
tkstreet 34:1ea3357c8d9a 153 * @return Name of sensor as a character array.
tkstreet 23:50c98b286e41 154 */
masahikofukasawa 27:41aa9fb23a2f 155 char* getSensorName(){
masahikofukasawa 27:41aa9fb23a2f 156 return sensorName;
masahikofukasawa 27:41aa9fb23a2f 157 };
masahikofukasawa 27:41aa9fb23a2f 158
tkstreet 34:1ea3357c8d9a 159 /**
tkstreet 34:1ea3357c8d9a 160 * Retrieve the primary ID of the sensor.
tkstreet 34:1ea3357c8d9a 161 *
tkstreet 34:1ea3357c8d9a 162 * @return Primary ID as an integer.
tkstreet 34:1ea3357c8d9a 163 */
masahikofukasawa 27:41aa9fb23a2f 164 int getPrimaryId(){
masahikofukasawa 27:41aa9fb23a2f 165 return primaryId;
masahikofukasawa 27:41aa9fb23a2f 166 };
masahikofukasawa 27:41aa9fb23a2f 167
tkstreet 34:1ea3357c8d9a 168 /**
tkstreet 34:1ea3357c8d9a 169 * Retrieve the Sub-ID of the sensor.
tkstreet 34:1ea3357c8d9a 170 *
tkstreet 34:1ea3357c8d9a 171 * @return Sub-ID as an integer.
tkstreet 34:1ea3357c8d9a 172 */
masahikofukasawa 27:41aa9fb23a2f 173 int getSecondaryId(){
masahikofukasawa 27:41aa9fb23a2f 174 return subId;
masahikofukasawa 27:41aa9fb23a2f 175 };
masahikofukasawa 0:7a00359e701e 176
masahikofukasawa 0:7a00359e701e 177 private:
masahikofukasawa 29:b488d2c89fba 178 bool event;
masahikofukasawa 0:7a00359e701e 179
masahikofukasawa 27:41aa9fb23a2f 180 protected:
masahikofukasawa 27:41aa9fb23a2f 181 uint8_t primaryId;
masahikofukasawa 27:41aa9fb23a2f 182 uint8_t subId;
masahikofukasawa 27:41aa9fb23a2f 183 char* sensorName;
masahikofukasawa 27:41aa9fb23a2f 184
masahikofukasawa 27:41aa9fb23a2f 185 AkmSensor(){
masahikofukasawa 27:41aa9fb23a2f 186 event = false;
masahikofukasawa 27:41aa9fb23a2f 187 primaryId = 0;
masahikofukasawa 27:41aa9fb23a2f 188 subId = 0;
masahikofukasawa 27:41aa9fb23a2f 189 sensorName = "";
masahikofukasawa 27:41aa9fb23a2f 190 };
masahikofukasawa 0:7a00359e701e 191 };
masahikofukasawa 0:7a00359e701e 192
masahikofukasawa 0:7a00359e701e 193 #endif