package com.phlx.wool.rfid;

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

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


    void PowerOnDevice() {

        try {
            WriteFile("/sys/class/misc/mtgpio/pin", "-wdout94 1");
            Thread.sleep(300);

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

    void PowerOffDevice() {

        try {
            WriteFile("/sys/class/misc/mtgpio/pin", "-wdout94 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();
        }
    }
}