Modified for compatibility with Rev.E. hardware

Fork of AkmSensor by AKM Development Platform

akmsensormanager.h

Committer:
tkstreet
Date:
2017-03-24
Revision:
21:966724730ce6
Parent:
15:1238993fd75f
Child:
23:50c98b286e41

File content as of revision 21:966724730ce6:

#ifndef AKMSENSORMANAGER_H
#define AKMSENSORMANAGER_H

#include "mbed.h"
#include "SerialNano.h"
#include "akmsensor.h"
#include "Message.h"
#include "debug.h"
#include "ble/BLE.h"
#include "mcp342x.h"

#define ANALOG_SENSOR_ID             P0_4
#define ANALOG_SENSOR_ID_SUB         P0_5

class AkmSensorManager {

  public:
    
    /** Return status enumeration for debugging.
     */
    typedef enum {
        SUCCESS = 0,
        ERROR,
    } Status;
    
    AkmSensorManager(SerialNano* com);
    
    /** Initialize sensor manager.
     *  @param id Primary ID of daughter board device.
     *  @param subID Secondary ID of daughter board device.
     *  @return Status type: SUCCESS=0.
     */
    Status init(uint8_t id, uint8_t subid);
    
    /** Set BLE UART service.
     *  @param service UART service type
     */
    void setBleUartService(UARTService* service);
    
    /** Sets eventConnected flag to TRUE.
     */
    void setEventConnected();
    
    /** Sets eventDisconnected flag to TRUE.
     */
    void setEventDisconnected();
    
    /* Sets eventCommandReceived flag to TRUE.
     * @param buf Command to be parsed and to check the validity.
     * @return Status type: SUCCESS=0
     */
    Status commandReceived(char* buf);
    
    /* Checks for an event.
     * @return Returns SUCCESS(=0) if a sensor event has occurred, or if any of the 
     *         eventCommandReceived, eventConnected, or eventDisconnected flags
     *         are set. Returns ERROR otherwise.
     */
    bool isEvent();
    
    /* Processes eventCommandReceived, eventConnected, eventDisconnected and
     * sensor events and clears the appropriate flag.
     * @return Status type: SUCCESS=0.
     */
    Status processEvent();
    
    /* Get the name of the sensor as a string.
     * @return Returns the address of the string containing the name.
     */
    char* getSensorName();
    
    /* Processes the stored command, parses the arguments, then uses the 
     * command to throw a message.
     */
    void processCommand();
    
    /* Converts command from characters to ASCII then executes the command.
     * @param msg Message containing command to be processed.
     */
    Status throwMessage(const Message *msg);
    
//    void releaseTWI();

    /* Get primary or secondary ID from sensor device.
     * @param pin Pin number of ID signal.
     * @param bits Number of bits of precision of value.
     */
    uint8_t getId(PinName pin, uint8_t bits);
    
  private:
    
    AkmSensor* sensor;
    SerialNano* serial;
    UARTService* uartService;
    Message msg;

    uint8_t         primaryId;
    uint8_t         subId;
    bool isEnabledBle;
    bool isEnabledUsb;
    bool eventCommandReceived;
    bool eventConnected;
    bool eventDisconnected;

    char userCommand[20];
    
    AkmSensor* getAkmSensor();
    void dataOut(char* str);
    int16_t getAdcData(MCP342X *mcp3428, MCP342X::AdcChannel ch, MCP342X::SampleSetting s);
};

#endif // AKMSENSORMANAGER_H