package cgmblelib.utils;

import cgmblelib.database.entity.PocDevice;
import ist.com.sdk.EDevice;
import ist.com.sdk.EGattMessage;

public class AxisYForGlucoseLevel {
    /***
     * 上下限
     */
    private float[] Y = {0, 6, 12, 18, 24, 30};
    /**
     * 发射器状态
     */
    private EGattMessage mGattMessage;

    AxisYForGlucoseLevel() {
        Y = updateAxis(mGattMessage);
    }

    private static class SingletonInstance {
        private static final AxisYForGlucoseLevel INSTANCE = new AxisYForGlucoseLevel();
    }

    public static AxisYForGlucoseLevel getInstance() {
        return SingletonInstance.INSTANCE;
    }

    public synchronized void setDevice(PocDevice device) {
        if (device != null) {
            EDevice eDevice = EDevice.getEnumDevice(device.getName());
            if (eDevice != null) {
                setGattMessage(eDevice.geteGattMessage());
            }
        }
    }

    public synchronized void setGattMessage(EGattMessage gattMessage) {
        mGattMessage = gattMessage;
        Y = updateAxis(mGattMessage);
    }

    public float[] getAxisY() {
        return Y;
    }

    public float[] getAxisY(PocDevice device) {
        if (device != null) {
            EDevice eDevice = EDevice.getEnumDevice(device.getName());
            return updateAxis(eDevice.geteGattMessage());
        }
        return Y;
    }

    /**
     * @param gattMessage 通道
     * @return 返回坐标轴
     */
    private synchronized float[] updateAxis(EGattMessage gattMessage) {
        try {
            return new float[]{0, 6, 12, 18, 24, 30};
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Y;
    }
}
