Modified for compatibility with Rev.E. hardware

Fork of AkmSensor by AKM Development Platform

Committer:
tkstreet
Date:
Fri Mar 24 23:01:27 2017 +0000
Revision:
21:966724730ce6
Parent:
15:1238993fd75f
Child:
23:50c98b286e41
Added class documentation

Who changed what in which revision?

UserRevisionLine numberNew 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
masahikofukasawa 0:7a00359e701e 15 class AkmSensorManager {
tkstreet 21:966724730ce6 16
tkstreet 21:966724730ce6 17 public:
masahikofukasawa 0:7a00359e701e 18
tkstreet 21:966724730ce6 19 /** Return status enumeration for debugging.
tkstreet 21:966724730ce6 20 */
masahikofukasawa 0:7a00359e701e 21 typedef enum {
masahikofukasawa 0:7a00359e701e 22 SUCCESS = 0,
masahikofukasawa 0:7a00359e701e 23 ERROR,
masahikofukasawa 0:7a00359e701e 24 } Status;
masahikofukasawa 0:7a00359e701e 25
masahikofukasawa 13:d008249f0359 26 AkmSensorManager(SerialNano* com);
tkstreet 21:966724730ce6 27
tkstreet 21:966724730ce6 28 /** Initialize sensor manager.
tkstreet 21:966724730ce6 29 * @param id Primary ID of daughter board device.
tkstreet 21:966724730ce6 30 * @param subID Secondary ID of daughter board device.
tkstreet 21:966724730ce6 31 * @return Status type: SUCCESS=0.
tkstreet 21:966724730ce6 32 */
masahikofukasawa 10:5c69b067d88a 33 Status init(uint8_t id, uint8_t subid);
tkstreet 21:966724730ce6 34
tkstreet 21:966724730ce6 35 /** Set BLE UART service.
tkstreet 21:966724730ce6 36 * @param service UART service type
tkstreet 21:966724730ce6 37 */
masahikofukasawa 13:d008249f0359 38 void setBleUartService(UARTService* service);
tkstreet 21:966724730ce6 39
tkstreet 21:966724730ce6 40 /** Sets eventConnected flag to TRUE.
tkstreet 21:966724730ce6 41 */
masahikofukasawa 0:7a00359e701e 42 void setEventConnected();
tkstreet 21:966724730ce6 43
tkstreet 21:966724730ce6 44 /** Sets eventDisconnected flag to TRUE.
tkstreet 21:966724730ce6 45 */
masahikofukasawa 0:7a00359e701e 46 void setEventDisconnected();
tkstreet 21:966724730ce6 47
tkstreet 21:966724730ce6 48 /* Sets eventCommandReceived flag to TRUE.
tkstreet 21:966724730ce6 49 * @param buf Command to be parsed and to check the validity.
tkstreet 21:966724730ce6 50 * @return Status type: SUCCESS=0
tkstreet 21:966724730ce6 51 */
masahikofukasawa 0:7a00359e701e 52 Status commandReceived(char* buf);
tkstreet 21:966724730ce6 53
tkstreet 21:966724730ce6 54 /* Checks for an event.
tkstreet 21:966724730ce6 55 * @return Returns SUCCESS(=0) if a sensor event has occurred, or if any of the
tkstreet 21:966724730ce6 56 * eventCommandReceived, eventConnected, or eventDisconnected flags
tkstreet 21:966724730ce6 57 * are set. Returns ERROR otherwise.
tkstreet 21:966724730ce6 58 */
masahikofukasawa 0:7a00359e701e 59 bool isEvent();
tkstreet 21:966724730ce6 60
tkstreet 21:966724730ce6 61 /* Processes eventCommandReceived, eventConnected, eventDisconnected and
tkstreet 21:966724730ce6 62 * sensor events and clears the appropriate flag.
tkstreet 21:966724730ce6 63 * @return Status type: SUCCESS=0.
tkstreet 21:966724730ce6 64 */
masahikofukasawa 0:7a00359e701e 65 Status processEvent();
tkstreet 21:966724730ce6 66
tkstreet 21:966724730ce6 67 /* Get the name of the sensor as a string.
tkstreet 21:966724730ce6 68 * @return Returns the address of the string containing the name.
tkstreet 21:966724730ce6 69 */
masahikofukasawa 13:d008249f0359 70 char* getSensorName();
masahikofukasawa 13:d008249f0359 71
tkstreet 21:966724730ce6 72 /* Processes the stored command, parses the arguments, then uses the
tkstreet 21:966724730ce6 73 * command to throw a message.
tkstreet 21:966724730ce6 74 */
masahikofukasawa 0:7a00359e701e 75 void processCommand();
tkstreet 21:966724730ce6 76
tkstreet 21:966724730ce6 77 /* Converts command from characters to ASCII then executes the command.
tkstreet 21:966724730ce6 78 * @param msg Message containing command to be processed.
tkstreet 21:966724730ce6 79 */
masahikofukasawa 0:7a00359e701e 80 Status throwMessage(const Message *msg);
tkstreet 21:966724730ce6 81
masahikofukasawa 10:5c69b067d88a 82 // void releaseTWI();
tkstreet 21:966724730ce6 83
tkstreet 21:966724730ce6 84 /* Get primary or secondary ID from sensor device.
tkstreet 21:966724730ce6 85 * @param pin Pin number of ID signal.
tkstreet 21:966724730ce6 86 * @param bits Number of bits of precision of value.
tkstreet 21:966724730ce6 87 */
masahikofukasawa 10:5c69b067d88a 88 uint8_t getId(PinName pin, uint8_t bits);
masahikofukasawa 0:7a00359e701e 89
tkstreet 21:966724730ce6 90 private:
masahikofukasawa 0:7a00359e701e 91
masahikofukasawa 0:7a00359e701e 92 AkmSensor* sensor;
masahikofukasawa 0:7a00359e701e 93 SerialNano* serial;
masahikofukasawa 0:7a00359e701e 94 UARTService* uartService;
masahikofukasawa 0:7a00359e701e 95 Message msg;
masahikofukasawa 0:7a00359e701e 96
masahikofukasawa 10:5c69b067d88a 97 uint8_t primaryId;
masahikofukasawa 0:7a00359e701e 98 uint8_t subId;
masahikofukasawa 0:7a00359e701e 99 bool isEnabledBle;
masahikofukasawa 0:7a00359e701e 100 bool isEnabledUsb;
masahikofukasawa 0:7a00359e701e 101 bool eventCommandReceived;
masahikofukasawa 0:7a00359e701e 102 bool eventConnected;
masahikofukasawa 0:7a00359e701e 103 bool eventDisconnected;
masahikofukasawa 0:7a00359e701e 104
masahikofukasawa 0:7a00359e701e 105 char userCommand[20];
masahikofukasawa 0:7a00359e701e 106
masahikofukasawa 0:7a00359e701e 107 AkmSensor* getAkmSensor();
masahikofukasawa 0:7a00359e701e 108 void dataOut(char* str);
coisme 2:11fe67783c4c 109 int16_t getAdcData(MCP342X *mcp3428, MCP342X::AdcChannel ch, MCP342X::SampleSetting s);
masahikofukasawa 0:7a00359e701e 110 };
masahikofukasawa 0:7a00359e701e 111
masahikofukasawa 0:7a00359e701e 112 #endif // AKMSENSORMANAGER_H