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