package com.phlx.anchorcollect_p.rfid;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

/**
 * 上电操作
 */
class DeviceControl {


    void PowerOnDevice() {

        try {
            //RM_7088_MT2
            //手持机
            WriteFile("/sys/class/misc/mtgpio/pin", "-wdout94 1");

            //pad RM_SD100T_MT1
//            WriteFile("/sys/bus/platform/drivers/mediatek-pinctrl/10005000.pinctrl/mt_gpio", "mode75 0");
//            WriteFile("/sys/bus/platform/drivers/mediatek-pinctrl/10005000.pinctrl/mt_gpio", "out75 1");
//            WriteFile("/sys/bus/platform/drivers/mediatek-pinctrl/10005000.pinctrl/mt_gpio", "out55 1");

            //RM_SD100T_MT1
//            WriteFile("/sys/bus/platform/drivers/mediatek-pinctrl/10005000.pinctrl/mt_gpio", "out55 1");

            Thread.sleep(300);

        } catch (IOException | InterruptedException e) {
            e.printStackTrace();
        }
    }

    void PowerOffDevice() {

        try {
            //RM_7088_MT2
            //手持机
            WriteFile("/sys/class/misc/mtgpio/pin", "-wdout94 0");

            //pad RM_SD100T_MT1
//            WriteFile("/sys/bus/platform/drivers/mediatek-pinctrl/10005000.pinctrl/mt_gpio", "out75 0");
//            WriteFile("/sys/bus/platform/drivers/mediatek-pinctrl/10005000.pinctrl/mt_gpio", "out55 0");

            //RM_SD100T_MT1
//            WriteFile("/sys/bus/platform/drivers/mediatek-pinctrl/10005000.pinctrl/mt_gpio", "out55 0");

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private void WriteFile(String path, String value) throws IOException {
        File DeviceName = new File(path);
        if (DeviceName.exists()) {
            BufferedWriter CtrlFile = new BufferedWriter(new FileWriter(DeviceName, false));
            CtrlFile.write(value);
            CtrlFile.flush();
            CtrlFile.close();
        }
    }
}