Modified for compatibility with Rev.E. hardware

Fork of AkmSensor by AKM Development Platform

akmsensormanager.h

Committer:
masahikofukasawa
Date:
2017-03-11
Revision:
27:41aa9fb23a2f
Parent:
16:d85be9bafb80
Child:
29:b488d2c89fba

File content as of revision 27:41aa9fb23a2f:

#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
#define MAX_SENSOR_NUM               5

class AkmSensorManager {
    public:
    
    typedef enum {
        SUCCESS = 0,
        ERROR,
    } Status;
    
    AkmSensorManager(SerialNano* com);
    Status init(uint8_t id, uint8_t subid);
    void setBleUartService(UARTService* service);
    void setEventConnected();
    void setEventDisconnected();
    Status commandReceived(char* buf);
    bool isEvent();
    Status processEvent();
    char* getSensorName();
    
    void processCommand();
    Status throwMessage(const Message *msg);
//    void releaseTWI();
    uint8_t getId(PinName pin, uint8_t bits);
    
    private:
    
    AkmSensor* sensor[MAX_SENSOR_NUM];
    SerialNano* serial;
    UARTService* uartService;
    Message msg;
    Timeout t;

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

    char userCommand[20];
    
    bool checkAkmSensor();
    void dataOut(char* str);
    int16_t getAdcData(MCP342X *mcp3428, MCP342X::AdcChannel ch, MCP342X::SampleSetting s);
    void dummyCallbackForCommandReceived();
    char* my_strcat(char* str1, char* str2);
};

#endif // AKMSENSORMANAGER_H