Modified for compatibility with Rev.E. hardware
Fork of AkmSensor by
akmsensormanager.h@34:1ea3357c8d9a, 2017-05-03 (annotated)
- Committer:
- tkstreet
- Date:
- Wed May 03 18:00:45 2017 +0000
- Revision:
- 34:1ea3357c8d9a
- Parent:
- 29:b488d2c89fba
- Parent:
- 24:1d37438f31a9
- Child:
- 39:3821886c902e
Release RevD7.015. Merged D7.014 with new documentation and updates to AP1017 driver.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
masahikofukasawa | 0:7a00359e701e | 1 | #ifndef AKMSENSORMANAGER_H |
masahikofukasawa | 0:7a00359e701e | 2 | #define AKMSENSORMANAGER_H |
masahikofukasawa | 0:7a00359e701e | 3 | |
masahikofukasawa | 0:7a00359e701e | 4 | #include "mbed.h" |
masahikofukasawa | 0:7a00359e701e | 5 | #include "SerialNano.h" |
masahikofukasawa | 0:7a00359e701e | 6 | #include "akmsensor.h" |
masahikofukasawa | 0:7a00359e701e | 7 | #include "Message.h" |
coisme | 2:11fe67783c4c | 8 | #include "debug.h" |
masahikofukasawa | 12:c06cd8b76358 | 9 | #include "ble/BLE.h" |
coisme | 2:11fe67783c4c | 10 | #include "mcp342x.h" |
masahikofukasawa | 29:b488d2c89fba | 11 | #include "akmakd.h" |
masahikofukasawa | 0:7a00359e701e | 12 | |
masahikofukasawa | 0:7a00359e701e | 13 | #define ANALOG_SENSOR_ID P0_4 |
masahikofukasawa | 0:7a00359e701e | 14 | #define ANALOG_SENSOR_ID_SUB P0_5 |
masahikofukasawa | 29:b488d2c89fba | 15 | #define MAX_SENSOR_NUM 2 |
masahikofukasawa | 0:7a00359e701e | 16 | |
tkstreet | 23:50c98b286e41 | 17 | /** |
tkstreet | 23:50c98b286e41 | 18 | * Unified manager class for all sensors to interact with AkmSensor. |
tkstreet | 23:50c98b286e41 | 19 | */ |
masahikofukasawa | 0:7a00359e701e | 20 | class AkmSensorManager { |
tkstreet | 21:966724730ce6 | 21 | |
masahikofukasawa | 29:b488d2c89fba | 22 | public: |
tkstreet | 34:1ea3357c8d9a | 23 | |
tkstreet | 23:50c98b286e41 | 24 | /** |
tkstreet | 23:50c98b286e41 | 25 | * Return status enumeration for debugging. |
tkstreet | 21:966724730ce6 | 26 | */ |
masahikofukasawa | 0:7a00359e701e | 27 | typedef enum { |
tkstreet | 23:50c98b286e41 | 28 | SUCCESS = 0, /**< Successful execution (0) */ |
tkstreet | 23:50c98b286e41 | 29 | ERROR, /**< Error in execution (1) */ |
masahikofukasawa | 0:7a00359e701e | 30 | } Status; |
masahikofukasawa | 0:7a00359e701e | 31 | |
tkstreet | 23:50c98b286e41 | 32 | /** |
tkstreet | 23:50c98b286e41 | 33 | * Class constructor with an initial serial connection. |
tkstreet | 23:50c98b286e41 | 34 | */ |
masahikofukasawa | 13:d008249f0359 | 35 | AkmSensorManager(SerialNano* com); |
tkstreet | 21:966724730ce6 | 36 | |
tkstreet | 23:50c98b286e41 | 37 | /** |
tkstreet | 23:50c98b286e41 | 38 | * Initialize sensor manager. |
tkstreet | 23:50c98b286e41 | 39 | * |
tkstreet | 23:50c98b286e41 | 40 | * @param id Primary ID of daughter board device. |
tkstreet | 23:50c98b286e41 | 41 | * @param subID Secondary ID of daughter board device. |
tkstreet | 23:50c98b286e41 | 42 | * @return Status type: SUCCESS=0. |
tkstreet | 21:966724730ce6 | 43 | */ |
masahikofukasawa | 10:5c69b067d88a | 44 | Status init(uint8_t id, uint8_t subid); |
tkstreet | 21:966724730ce6 | 45 | |
tkstreet | 23:50c98b286e41 | 46 | /** |
tkstreet | 23:50c98b286e41 | 47 | * Set BLE UART service. |
tkstreet | 23:50c98b286e41 | 48 | * |
tkstreet | 23:50c98b286e41 | 49 | * @param service UART service type |
tkstreet | 21:966724730ce6 | 50 | */ |
masahikofukasawa | 13:d008249f0359 | 51 | void setBleUartService(UARTService* service); |
tkstreet | 21:966724730ce6 | 52 | |
tkstreet | 23:50c98b286e41 | 53 | /** |
tkstreet | 23:50c98b286e41 | 54 | * Sets eventConnected flag to TRUE. |
tkstreet | 21:966724730ce6 | 55 | */ |
masahikofukasawa | 0:7a00359e701e | 56 | void setEventConnected(); |
tkstreet | 21:966724730ce6 | 57 | |
tkstreet | 23:50c98b286e41 | 58 | /** |
tkstreet | 23:50c98b286e41 | 59 | * Sets eventDisconnected flag to TRUE. |
tkstreet | 21:966724730ce6 | 60 | */ |
masahikofukasawa | 0:7a00359e701e | 61 | void setEventDisconnected(); |
tkstreet | 21:966724730ce6 | 62 | |
tkstreet | 23:50c98b286e41 | 63 | /** |
tkstreet | 23:50c98b286e41 | 64 | * Sets eventCommandReceived flag to TRUE. |
tkstreet | 23:50c98b286e41 | 65 | * |
tkstreet | 21:966724730ce6 | 66 | * @param buf Command to be parsed and to check the validity. |
tkstreet | 21:966724730ce6 | 67 | * @return Status type: SUCCESS=0 |
tkstreet | 21:966724730ce6 | 68 | */ |
masahikofukasawa | 0:7a00359e701e | 69 | Status commandReceived(char* buf); |
tkstreet | 21:966724730ce6 | 70 | |
tkstreet | 23:50c98b286e41 | 71 | /** |
tkstreet | 23:50c98b286e41 | 72 | * Checks if an event has occurred. |
tkstreet | 23:50c98b286e41 | 73 | * |
tkstreet | 21:966724730ce6 | 74 | * @return Returns SUCCESS(=0) if a sensor event has occurred, or if any of the |
tkstreet | 21:966724730ce6 | 75 | * eventCommandReceived, eventConnected, or eventDisconnected flags |
tkstreet | 21:966724730ce6 | 76 | * are set. Returns ERROR otherwise. |
tkstreet | 21:966724730ce6 | 77 | */ |
masahikofukasawa | 0:7a00359e701e | 78 | bool isEvent(); |
tkstreet | 21:966724730ce6 | 79 | |
tkstreet | 23:50c98b286e41 | 80 | /** |
tkstreet | 23:50c98b286e41 | 81 | * Main function that processes input, output, and connection events. |
tkstreet | 23:50c98b286e41 | 82 | * |
tkstreet | 21:966724730ce6 | 83 | * @return Status type: SUCCESS=0. |
tkstreet | 21:966724730ce6 | 84 | */ |
masahikofukasawa | 0:7a00359e701e | 85 | Status processEvent(); |
tkstreet | 21:966724730ce6 | 86 | |
tkstreet | 23:50c98b286e41 | 87 | /** |
tkstreet | 23:50c98b286e41 | 88 | * Get the name of the sensor as a string. |
tkstreet | 23:50c98b286e41 | 89 | * |
tkstreet | 21:966724730ce6 | 90 | * @return Returns the address of the string containing the name. |
tkstreet | 21:966724730ce6 | 91 | */ |
masahikofukasawa | 13:d008249f0359 | 92 | char* getSensorName(); |
masahikofukasawa | 13:d008249f0359 | 93 | |
tkstreet | 23:50c98b286e41 | 94 | /** |
tkstreet | 23:50c98b286e41 | 95 | * Processes the stored command, parses the arguments, then uses the |
tkstreet | 21:966724730ce6 | 96 | * command to throw a message. |
tkstreet | 21:966724730ce6 | 97 | */ |
masahikofukasawa | 0:7a00359e701e | 98 | void processCommand(); |
tkstreet | 21:966724730ce6 | 99 | |
tkstreet | 23:50c98b286e41 | 100 | /** |
tkstreet | 23:50c98b286e41 | 101 | * Processes command and arguments in message from char to ASCII and |
tkstreet | 23:50c98b286e41 | 102 | * sends to BLE and/or USB serial device(s). |
tkstreet | 23:50c98b286e41 | 103 | * |
tkstreet | 21:966724730ce6 | 104 | * @param msg Message containing command to be processed. |
tkstreet | 23:50c98b286e41 | 105 | * @return Status type: SUCCESS=0 |
tkstreet | 21:966724730ce6 | 106 | */ |
masahikofukasawa | 0:7a00359e701e | 107 | Status throwMessage(const Message *msg); |
tkstreet | 21:966724730ce6 | 108 | |
masahikofukasawa | 10:5c69b067d88a | 109 | // void releaseTWI(); |
tkstreet | 21:966724730ce6 | 110 | |
tkstreet | 23:50c98b286e41 | 111 | /** |
tkstreet | 23:50c98b286e41 | 112 | * Get primary or secondary ID from sensor device. |
tkstreet | 23:50c98b286e41 | 113 | * |
tkstreet | 23:50c98b286e41 | 114 | * @param pin Pin number of ID or SubID signal. |
tkstreet | 21:966724730ce6 | 115 | * @param bits Number of bits of precision of value. |
tkstreet | 23:50c98b286e41 | 116 | * @return Returns the integer ID or SubID value. |
tkstreet | 21:966724730ce6 | 117 | */ |
masahikofukasawa | 10:5c69b067d88a | 118 | uint8_t getId(PinName pin, uint8_t bits); |
masahikofukasawa | 29:b488d2c89fba | 119 | void detectDRDY(); |
masahikofukasawa | 29:b488d2c89fba | 120 | |
masahikofukasawa | 29:b488d2c89fba | 121 | private: |
masahikofukasawa | 0:7a00359e701e | 122 | |
masahikofukasawa | 27:41aa9fb23a2f | 123 | AkmSensor* sensor[MAX_SENSOR_NUM]; |
masahikofukasawa | 0:7a00359e701e | 124 | SerialNano* serial; |
masahikofukasawa | 0:7a00359e701e | 125 | UARTService* uartService; |
masahikofukasawa | 0:7a00359e701e | 126 | Message msg; |
masahikofukasawa | 16:d85be9bafb80 | 127 | Timeout t; |
masahikofukasawa | 0:7a00359e701e | 128 | |
masahikofukasawa | 29:b488d2c89fba | 129 | InterruptIn* interrupt; |
masahikofukasawa | 29:b488d2c89fba | 130 | |
masahikofukasawa | 10:5c69b067d88a | 131 | uint8_t primaryId; |
masahikofukasawa | 0:7a00359e701e | 132 | uint8_t subId; |
masahikofukasawa | 29:b488d2c89fba | 133 | uint8_t sensorIndex; |
masahikofukasawa | 29:b488d2c89fba | 134 | uint8_t sensorNum; |
masahikofukasawa | 0:7a00359e701e | 135 | bool isEnabledBle; |
masahikofukasawa | 0:7a00359e701e | 136 | bool isEnabledUsb; |
masahikofukasawa | 29:b488d2c89fba | 137 | |
masahikofukasawa | 0:7a00359e701e | 138 | bool eventCommandReceived; |
masahikofukasawa | 0:7a00359e701e | 139 | bool eventConnected; |
masahikofukasawa | 0:7a00359e701e | 140 | bool eventDisconnected; |
masahikofukasawa | 29:b488d2c89fba | 141 | char userCommand[20]; |
masahikofukasawa | 0:7a00359e701e | 142 | |
masahikofukasawa | 29:b488d2c89fba | 143 | AkmAkd::InterruptMode drdyType; |
masahikofukasawa | 0:7a00359e701e | 144 | |
masahikofukasawa | 27:41aa9fb23a2f | 145 | bool checkAkmSensor(); |
masahikofukasawa | 0:7a00359e701e | 146 | void dataOut(char* str); |
coisme | 2:11fe67783c4c | 147 | int16_t getAdcData(MCP342X *mcp3428, MCP342X::AdcChannel ch, MCP342X::SampleSetting s); |
masahikofukasawa | 16:d85be9bafb80 | 148 | void dummyCallbackForCommandReceived(); |
masahikofukasawa | 27:41aa9fb23a2f | 149 | char* my_strcat(char* str1, char* str2); |
masahikofukasawa | 0:7a00359e701e | 150 | }; |
masahikofukasawa | 0:7a00359e701e | 151 | |
masahikofukasawa | 0:7a00359e701e | 152 | #endif // AKMSENSORMANAGER_H |