Modified for compatibility with Rev.E. hardware

Fork of AkmSensor by AKM Development Platform

akmakd.h

Committer:
tkstreet
Date:
2017-04-13
Revision:
23:50c98b286e41
Parent:
13:d008249f0359
Child:
24:1d37438f31a9

File content as of revision 23:50c98b286e41:

#ifndef AKMAKD_H
#define AKMAKD_H

#include "mbed.h"
#include "SerialNano.h"
#include "akmsensor.h"
#include "akmecompass.h"

/**
 * Collection class for handling commands to all of the specialty AKM 
 * daughter board adapter modules.
 *
 * 3-Axis Electronic Compass Devices: AK8963C, AK8963N, AK09911C, AK09912C,
 * AK09915C, AK09915D, AK09916C, AK09916D, AK09970
 */
class AkmAkd : public AkmSensor
{

public:

    /**
     * List of daughter board adapter devices (5-bit Sub-IDs). Primary ID = 0Fh
     */
    typedef enum {
        SUB_ID_AK8963N              = 0x1A,  /**< AK8963N: ID = 1Ah (26) */
        SUB_ID_AK8963C              = 0x1C,  /**< AK8963C: ID = 1Ch (28) */
        SUB_ID_AK09911C             = 0x0A,  /**< AK09911C: ID = 0Ah (10) */
        SUB_ID_AK09912C             = 0x09,  /**< AK09912C: ID = 09h (9) */
        SUB_ID_AK09915C             = 0x0D,  /**< AK09915C: ID = 0Dh (13) */
        SUB_ID_AK09916C             = 0x0E,  /**< AK09916C: ID = 0Eh (14) */
        SUB_ID_AK09916D             = 0x0F,  /**< AK09916D: ID = 0Fh (15) */
        SUB_ID_AK09915D             = 0x10,  /**< AK09915D: ID = 10h (16) */
    } SubIdAkd;
    
    /**
     * Constructor.
     *
     */
    AkmAkd();

    /**
     * Destructor.
     *
     */
    virtual ~AkmAkd();
    
    /**
     * Process for intializing the selected sensor.
     *
     * @return Termination status type for debugging purposes.
     */
    virtual AkmSensor::Status init(const uint8_t id, const uint8_t subid);
    
    /**
     * Simple flag process to determine if an event has occurred.
     *
     * @return TRUE if event has occurred, FALSE if not.
     */
    virtual bool isEvent();
    
    /**
     * Process abstraction for starting sensor operation.
     *
     * @return Termination status type for debugging purposes.
     */
    virtual AkmSensor::Status startSensor();
    
    /**
     * Process abstraction for starting sensor operation.
     *
     * @param sec Number of seconds of operation.
     * @return Termination status type for debugging purposes.
     */
    virtual AkmSensor::Status startSensor(const float sec);
    
    /**
     * Process abstraction for stopping sensor operation.
     *
     * @return Termination status type for debugging purposes.
     */
    virtual AkmSensor::Status stopSensor();
    
    /**
     * Process abstraction for reading data from the sensor.
     *
     * @param msg Message object that will hold the sensor data.
     * @return Termination status type for debugging purposes.
     */
    virtual AkmSensor::Status readSensorData(Message* msg);
    
    /**
     * Primary process for interfacing a sensor with the AKDP.  When implemented
     * in sensor class, it will transfer commands between the the sensor control
     * class and AkmSensorManager. 
     *
     * @param in Command message to be processed by sensor.
     * @param out Message returned from sensor.
     * @return Termination status type for debugging purposes.
     */
    virtual Status requestCommand(Message* in, Message* out);
    
    /**
     * Get the name of the sensor in char format.
     *
     * @return Sensor name as a char array.
     */
    virtual char* getSensorName();

    /**
     * Checks if data is ready or if there is a data overrun and store the
     * status in 'event'.
     */
    void checkDRDY();
    /**
     * Forces a data ready state by setting 'event' to TRUE.
     */
    void detectDRDY();
    /**
     * For AK8963, returns the type of sensor.
     */
    int getSensorType();
    
private:
    bool            event;    
    uint8_t         primaryId;
    uint8_t         subId;
    char*           sensorName;
    
    Ticker          ticker;
    AkmECompass*    compass;
    InterruptIn*    drdy;
    AkmECompass::OperationMode   mode; 
    AkmECompass::Nsf   nsf; 
    AkmECompass::Sdr   sdr; 
};

#endif