package com.device.zk_r322a;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import android.gpio.GpioJNI;
import android.util.Log;
import android_serialport_api.SerialPort;

public class ZKR322AControl {
	private  SerialPort mSerialPort = null;
	private  OutputStream mOutputStream = null;
	private   InputStream mInputStream = null;
	//private boolean readVal = false;

	public ZKR322AControl() throws SecurityException, IOException {
		mSerialPort = new SerialPort(new File("/dev/ttyS4"), 115200, 8, 'N', 1,0);
		mOutputStream = mSerialPort.getOutputStream();
		mInputStream = mSerialPort.getInputStream();	
	}
	
	public String getData() {
		if (mInputStream == null) return "";
		try {
			int size = mInputStream.available();
			byte[] buffer = new byte[size];
			size = mInputStream.read(buffer);
			if (size > 0) {
				return new String(buffer);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		return "";
	}
	
	public void start() {
		//readVal = true;
	//	GpioJNI.gpio_switch_scan_trig(1);
	}
	
	public void stop() {
		//readVal = false;
	//	GpioJNI.gpio_switch_scan_trig(0);
	}
	
	//public boolean isRead() {
	//	return readVal;
	//}
	
	public void close() {
		if (mSerialPort != null) {
			mSerialPort.close();
		}
	}
	
	
	public void initScan() {
	//	GpioJNI.gpio_switch_scan_rf_ired(0);
	//	GpioJNI.gpio_switch_scan_power(1);
	}
}
