package com.example.iot_controlhost.utils.mainboard;

import com.example.iot_controlhost.utils.global.HardwareSetting;
import com.example.iot_controlhost.utils.log.MyLog;

/**
 * @Description
 * @Author DuanKaiji
 * @CreateTime 2024年01月05日 14:33:49
 */
public class MyAPIContext {
    private static API myAPI;
    private static MyAPIContext myAPIContext;
    private boolean canUse;

    public static MyAPIContext getInstance() {
        synchronized (MyAPIContext.class) {
            if (myAPIContext == null) {
                synchronized (MyAPIContext.class) {
                    if (myAPIContext == null) {
                        myAPIContext = new MyAPIContext();
                    }
                }
            }
        }
        return myAPIContext;
    }

    private MyAPIContext() {
        if (HardwareSetting.isZCAndroid()) {
            myAPI = new ZCAPI();
        } else if (HardwareSetting.isYSAndroid()) {
            myAPI = new YSAPI();
        } else {
            MyLog.app("未匹配到主板，不使用主板API");
            canUse = false;
            return;
        }
        canUse = true;
    }

    public void feet() {
        if (canUse) {
            myAPI.feed();
        }
    }

    public void init() {
        if (canUse) {
            myAPI.init();
        }
    }

    public void shutDown() {
        if (canUse) {
            myAPI.shutDown();
        }
    }

    public void reBoot() {
        if (canUse) {
            myAPI.reBoot();
        }
    }
}
