Modified for compatibility with Rev.E. hardware

Fork of AkmSensor by AKM Development Platform

Committer:
tkstreet
Date:
Tue May 01 21:31:15 2018 +0000
Revision:
49:c8f8946129b6
Parent:
43:45225713cd58
Modified for Rev.E. compatibility.

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