Modified for compatibility with Rev.E. hardware
Fork of AkmSensor by
ap1017ctrl.h@37:c76d2edf3426, 2017-05-24 (annotated)
- Committer:
- masahikofukasawa
- Date:
- Wed May 24 20:23:22 2017 +0000
- Revision:
- 37:c76d2edf3426
- Parent:
- 36:aafd15b3291b
- Child:
- 47:221ec4b404ec
Added CQ-32xx, CZ-31xx current sensors.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tkstreet | 25:76c11ab5060e | 1 | #ifndef AP1017CTRL_H |
tkstreet | 25:76c11ab5060e | 2 | #define AP1017CTRL_H |
tkstreet | 25:76c11ab5060e | 3 | |
tkstreet | 25:76c11ab5060e | 4 | #include "mbed.h" |
tkstreet | 25:76c11ab5060e | 5 | #include "akmsensor.h" |
tkstreet | 25:76c11ab5060e | 6 | #include "AP1017.h" |
tkstreet | 25:76c11ab5060e | 7 | |
tkstreet | 26:4e436b0cbaf8 | 8 | /** |
tkstreet | 26:4e436b0cbaf8 | 9 | * Class for handling commands issued to the AP1017 motor driver. |
tkstreet | 26:4e436b0cbaf8 | 10 | */ |
tkstreet | 25:76c11ab5060e | 11 | class Ap1017Ctrl : public AkmSensor |
tkstreet | 25:76c11ab5060e | 12 | { |
tkstreet | 25:76c11ab5060e | 13 | public: |
tkstreet | 25:76c11ab5060e | 14 | |
tkstreet | 25:76c11ab5060e | 15 | /** |
tkstreet | 25:76c11ab5060e | 16 | * Device Sub-ID. |
tkstreet | 25:76c11ab5060e | 17 | */ |
tkstreet | 25:76c11ab5060e | 18 | typedef enum { |
masahikofukasawa | 37:c76d2edf3426 | 19 | SUB_ID_AP1017 = 0x02, /**< AP1017: ID = 02h (5bit ID)*/ |
tkstreet | 25:76c11ab5060e | 20 | } SubIdMotorDriver; |
tkstreet | 25:76c11ab5060e | 21 | |
tkstreet | 25:76c11ab5060e | 22 | // Constructors and Destructors |
tkstreet | 25:76c11ab5060e | 23 | Ap1017Ctrl(); |
tkstreet | 25:76c11ab5060e | 24 | virtual ~Ap1017Ctrl(); |
tkstreet | 25:76c11ab5060e | 25 | |
tkstreet | 25:76c11ab5060e | 26 | // Public Member Functions |
tkstreet | 25:76c11ab5060e | 27 | /** |
tkstreet | 25:76c11ab5060e | 28 | * Process for intializing the selected sensor. |
tkstreet | 25:76c11ab5060e | 29 | * |
tkstreet | 25:76c11ab5060e | 30 | * @return Termination status type for debugging purposes. |
tkstreet | 25:76c11ab5060e | 31 | */ |
tkstreet | 25:76c11ab5060e | 32 | virtual AkmSensor::Status init(const uint8_t id, const uint8_t subid); |
tkstreet | 25:76c11ab5060e | 33 | |
tkstreet | 25:76c11ab5060e | 34 | /** |
tkstreet | 25:76c11ab5060e | 35 | * Simple flag process to determine if an event has occurred. |
tkstreet | 25:76c11ab5060e | 36 | * |
tkstreet | 25:76c11ab5060e | 37 | * @return TRUE if event has occurred, FALSE if not. |
tkstreet | 25:76c11ab5060e | 38 | */ |
tkstreet | 25:76c11ab5060e | 39 | virtual bool isEvent(); |
tkstreet | 25:76c11ab5060e | 40 | |
tkstreet | 25:76c11ab5060e | 41 | /** |
tkstreet | 25:76c11ab5060e | 42 | * Process abstraction for starting sensor operation. |
tkstreet | 25:76c11ab5060e | 43 | * |
tkstreet | 25:76c11ab5060e | 44 | * @return Termination status type for debugging purposes. |
tkstreet | 25:76c11ab5060e | 45 | */ |
tkstreet | 25:76c11ab5060e | 46 | virtual AkmSensor::Status startSensor(); |
tkstreet | 25:76c11ab5060e | 47 | |
tkstreet | 25:76c11ab5060e | 48 | /** |
tkstreet | 25:76c11ab5060e | 49 | * Process abstraction for starting sensor operation. |
tkstreet | 25:76c11ab5060e | 50 | * |
tkstreet | 36:aafd15b3291b | 51 | * @param freq PWM frequency in Hz (2000 Hz by default). |
tkstreet | 25:76c11ab5060e | 52 | * @return Termination status type for debugging purposes. |
tkstreet | 25:76c11ab5060e | 53 | */ |
tkstreet | 36:aafd15b3291b | 54 | virtual AkmSensor::Status startSensor(const float freq); |
tkstreet | 25:76c11ab5060e | 55 | |
tkstreet | 25:76c11ab5060e | 56 | /** |
tkstreet | 25:76c11ab5060e | 57 | * Process abstraction for stopping sensor operation. |
tkstreet | 25:76c11ab5060e | 58 | * |
tkstreet | 25:76c11ab5060e | 59 | * @return Termination status type for debugging purposes. |
tkstreet | 25:76c11ab5060e | 60 | */ |
tkstreet | 25:76c11ab5060e | 61 | virtual AkmSensor::Status stopSensor(); |
tkstreet | 25:76c11ab5060e | 62 | |
tkstreet | 25:76c11ab5060e | 63 | /** |
tkstreet | 25:76c11ab5060e | 64 | * Process abstraction for reading data from the sensor. |
tkstreet | 25:76c11ab5060e | 65 | * |
tkstreet | 25:76c11ab5060e | 66 | * @param msg Message object that will hold the sensor data. |
tkstreet | 25:76c11ab5060e | 67 | * @return Termination status type for debugging purposes. |
tkstreet | 25:76c11ab5060e | 68 | */ |
tkstreet | 25:76c11ab5060e | 69 | virtual AkmSensor::Status readSensorData(Message* msg); |
tkstreet | 25:76c11ab5060e | 70 | |
tkstreet | 25:76c11ab5060e | 71 | /** |
tkstreet | 25:76c11ab5060e | 72 | * Primary process for interfacing a sensor with the AKDP. When implemented |
tkstreet | 25:76c11ab5060e | 73 | * in sensor class, it will transfer commands between the the sensor control |
tkstreet | 25:76c11ab5060e | 74 | * class and AkmSensorManager. |
tkstreet | 25:76c11ab5060e | 75 | * |
tkstreet | 25:76c11ab5060e | 76 | * @param in Command message to be processed by sensor. |
tkstreet | 25:76c11ab5060e | 77 | * @param out Message returned from sensor. |
tkstreet | 25:76c11ab5060e | 78 | * @return Termination status type for debugging purposes. |
tkstreet | 25:76c11ab5060e | 79 | */ |
tkstreet | 25:76c11ab5060e | 80 | virtual Status requestCommand(Message* in, Message* out); |
tkstreet | 25:76c11ab5060e | 81 | |
tkstreet | 25:76c11ab5060e | 82 | /** |
tkstreet | 25:76c11ab5060e | 83 | * Get the name of the sensor in char format. |
tkstreet | 25:76c11ab5060e | 84 | * |
tkstreet | 25:76c11ab5060e | 85 | * @return Sensor name as a char array. |
tkstreet | 25:76c11ab5060e | 86 | */ |
tkstreet | 25:76c11ab5060e | 87 | virtual char* getSensorName(); |
tkstreet | 26:4e436b0cbaf8 | 88 | |
tkstreet | 36:aafd15b3291b | 89 | // Interrupt Service Routines |
tkstreet | 36:aafd15b3291b | 90 | void pwmPeriod(); |
tkstreet | 36:aafd15b3291b | 91 | void pwmOnPulse(); |
tkstreet | 25:76c11ab5060e | 92 | |
tkstreet | 25:76c11ab5060e | 93 | private: |
tkstreet | 36:aafd15b3291b | 94 | //bool event; |
tkstreet | 25:76c11ab5060e | 95 | uint8_t primaryId; |
tkstreet | 25:76c11ab5060e | 96 | uint8_t subId; |
tkstreet | 25:76c11ab5060e | 97 | char* sensorName; |
tkstreet | 25:76c11ab5060e | 98 | |
tkstreet | 36:aafd15b3291b | 99 | DigitalOut* inputA; |
tkstreet | 36:aafd15b3291b | 100 | DigitalOut* inputB; |
tkstreet | 36:aafd15b3291b | 101 | I2C* i2cMotor; |
tkstreet | 36:aafd15b3291b | 102 | |
tkstreet | 25:76c11ab5060e | 103 | AP1017* ap1017; |
tkstreet | 36:aafd15b3291b | 104 | Ticker pwm; |
tkstreet | 36:aafd15b3291b | 105 | Ticker pulse; |
tkstreet | 36:aafd15b3291b | 106 | uint8_t index; |
tkstreet | 36:aafd15b3291b | 107 | float freq; |
tkstreet | 26:4e436b0cbaf8 | 108 | float interval; // Timer interrupt interval |
tkstreet | 25:76c11ab5060e | 109 | }; |
tkstreet | 25:76c11ab5060e | 110 | |
tkstreet | 25:76c11ab5060e | 111 | #endif |