Modified for compatibility with Rev.E. hardware
Fork of AkmSensor by
Diff: akmsensor.h
- Revision:
- 34:1ea3357c8d9a
- Parent:
- 29:b488d2c89fba
- Parent:
- 23:50c98b286e41
- Child:
- 37:c76d2edf3426
--- a/akmsensor.h Fri Apr 28 20:32:31 2017 +0000 +++ b/akmsensor.h Wed May 03 18:00:45 2017 +0000 @@ -5,90 +5,171 @@ #include "Message.h" //#include "debug.h" -// SPI -#define SPI_SCK P0_8 //SPI, SCK -#define SPI_MISO P0_9 //SPI, MISO +// SPI Pin Number Definitions +#define SPI_SCK P0_8 // SPI, SCK +#define SPI_MISO P0_9 // SPI, MISO #define SPI_MOSI P0_10 //SPI, MOSI #define SPI_CS P0_11 //SPI, CS #define SPI_DRDY P0_7 //SPI, DRDY -// I2C +// I2C Pin Number Definitions #define I2C_SCL P0_8 //I2C, SCL #define I2C_SDA P0_10 //I2C, SDA -// Digital Port +// Digital Port Pin Number Definitions #define DIGITAL_D0 P0_11 #define DIGITAL_D1 P0_9 -// DRDY Port +// DRDY Port Pin Number Definitions #define I2C_DRDY P0_11 -// Analog In +// Analog In Pin Number Definitions #define ANALOG_IN_PIN P0_5 //P05 +// I2C Speed Standards #define I2C_SPEED_100KHZ 100000 #define I2C_SPEED_400KHZ 400000 +// Sampling rate for ADC #define SENSOR_SAMPLING_RATE 0.1 // 10Hz +/** + * Abstract base class for general AKM sensors. + */ class AkmSensor { public: + /** + * Error type for debugging purposes. + */ typedef enum { - SUCCESS = 0, - ERROR, + + SUCCESS = 0, /**< Successful termination (0) */ + ERROR, /**< Error during execution (1) */ } Status; + /** + * Primary IDs for the major categories of sensors. + */ typedef enum { - AKM_PRIMARY_ID_AKD_SPI = 0x0, - AKM_PRIMARY_ID_UNIPOLAR = 0x1, - AKM_PRIMARY_ID_OMNIPOLAR = 0x2, - AKM_PRIMARY_ID_LATCH = 0x3, - AKM_PRIMARY_ID_DUAL_OUTPUT = 0x4, - AKM_PRIMARY_ID_ONECHIP_ENCODER = 0x5, - AKM_PRIMARY_ID_TBD1 = 0x6, - AKM_PRIMARY_ID_TBD2 = 0x7, - AKM_PRIMARY_ID_DEMO = 0x8, - AKM_PRIMARY_ID_CURRENT_SENSOR = 0x9, - AKM_PRIMARY_ID_MISC_ANALOG = 0xA, - AKM_PRIMARY_ID_LINEAR_SENSOR = 0xB, - AKM_PRIMARY_ID_TBD3 = 0xC, - AKM_PRIMARY_ID_IR_SENSOR = 0xD, - AKM_PRIMARY_ID_ANGLE_SENSOR = 0xE, - AKM_PRIMARY_ID_AKD_I2C = 0xF, + AKM_PRIMARY_ID_AKD_SPI = 0x0, /**< AKD SPI Devices */ + AKM_PRIMARY_ID_UNIPOLAR = 0x1, /**< Unipolar Switches */ + AKM_PRIMARY_ID_OMNIPOLAR = 0x2, /**< Omnipolar Switches */ + AKM_PRIMARY_ID_LATCH = 0x3, /**< Bipolar Latches */ + AKM_PRIMARY_ID_DUAL_OUTPUT = 0x4, /**< Dual Output Switches */ + AKM_PRIMARY_ID_ONECHIP_ENCODER = 0x5, /**< One-Chip Encoders */ + AKM_PRIMARY_ID_TBD1 = 0x6, /**< Undefined */ + AKM_PRIMARY_ID_TBD2 = 0x7, /**< Undefined */ + AKM_PRIMARY_ID_DEMO = 0x8, /**< Demo Sensors */ + AKM_PRIMARY_ID_CURRENT_SENSOR = 0x9, /**< Current Sensors */ + AKM_PRIMARY_ID_MISC_ANALOG = 0xA, /**< Analog Devices */ + AKM_PRIMARY_ID_LINEAR_SENSOR = 0xB, /**< Linear Sensors */ + AKM_PRIMARY_ID_MOTOR_DRIVER = 0xC, /**< Motor Drivers */ + AKM_PRIMARY_ID_IR_SENSOR = 0xD, /**< IR Sensors */ + AKM_PRIMARY_ID_ANGLE_SENSOR = 0xE, /**< Angle Sensors */ + AKM_PRIMARY_ID_AKD_I2C = 0xF, /**< AKD I2C Devices */ } SensorPrimaryId; + virtual ~AkmSensor(){}; + + /** + * Process for intializing the selected sensor. + * + * @return Termination status type for debugging purposes. + */ virtual Status init(const uint8_t id, const uint8_t subid) = 0; + + /** + * Process abstraction for starting sensor operation. + * + * @return Termination status type for debugging purposes. + */ virtual Status startSensor() = 0; + + /** + * Process abstraction for starting sensor operation. + * + * @param sec Number of seconds of operation. + * @return Termination status type for debugging purposes. + */ virtual Status startSensor(const float sec) = 0; + + /** + * Process abstraction for stopping sensor operation. + * + * @return Termination status type for debugging purposes. + */ virtual Status stopSensor() = 0; + + /** + * Process abstraction for reading data from the sensor. + * + * @param msg Message object that will hold the sensor data. + * @return Termination status type for debugging purposes. + */ virtual Status readSensorData(Message* msg) = 0; + + /** + * Primary process for interfacing a sensor with the AKDP. When implemented + * in sensor class, it will transfer commands between the the sensor control + * class and AkmSensorManager. + * + * @param in Command message to be processed by sensor. + * @param out Message returned from sensor. + * @return Termination status type for debugging purposes. + */ virtual Status requestCommand(Message* in, Message* out) = 0; + /** + * Set event flag. + */ virtual void setEvent(){ // MSG("#setEvent called.\r\n"); event = true; } + /** + * Clear event flag. + */ void clearEvent(){ // MSG("#clearEvent called.\r\n"); event = false; } + /** + * Checks if an event has occurred. + * + * @return TRUE if event has occurred, FALSE otherwise. + */ bool isEvent(){ return event; } + /** + * Retrieve the name of the sensor. + * + * @return Name of sensor as a character array. + */ char* getSensorName(){ return sensorName; }; + /** + * Retrieve the primary ID of the sensor. + * + * @return Primary ID as an integer. + */ int getPrimaryId(){ return primaryId; }; + /** + * Retrieve the Sub-ID of the sensor. + * + * @return Sub-ID as an integer. + */ int getSecondaryId(){ return subId; };