Modified for compatibility with Rev.E. hardware

Fork of AkmSensor by AKM Development Platform

Committer:
tkstreet
Date:
Wed Nov 08 21:56:17 2017 +0000
Revision:
43:45225713cd58
Parent:
39:3821886c902e
Child:
49:c8f8946129b6
Moved all pin definitions to akdphwinfo header.  Removed redundant library inclusions.

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