package UVC;

import jGPIO.Linux_C_lib_DirectMapping;
import jGPIO.jGPIO;

// https://github.com/allanbian1017/uvc-ctrl/blob/master/uvc-ctrl.c
// https://github.com/makenai/node-uvc-control/blob/master/lib/constants.js
// https://www.kernel.org/doc/html/v4.10/media/uapi/v4l/user-func.html
// https://github.com/spotify/linux/blob/master/include/asm-generic/ioctl.h
// https://developer.sony.com/develop/spresense/developer-tools/api-reference/api-references-spresense-sdk/group__video__ioctl.html
// https://developer.sony.com/develop/spresense/developer-tools/api-reference/api-references-spresense-sdk/video_8h_source.html

// gak jadi kepake

@SuppressWarnings("unused")
public class UVC_Control {
	private final String devicepath;
	
	// request
	
	private final int RC_UNDEFINED=0x00;
	private final int SET_CUR=0x01;
	private final int GET_CUR=0x81;
	private final int GET_MIN=0x82;
	private final int GET_MAX=0x83;
	private final int GET_RES=0x84;
	private final int GET_LEN=0x85;
	private final int GET_INFO=0x86;
	private final int GET_DEF=0x87;
	
	// control
	private final int CT_CONTROL_UNDEFINED = 0;
	private final int CT_FOCUS_ABSOLUTE_CONTROL=0x06;
	private final int CT_FOCUS_AUTO_CONTROL=0x08;
	private final int CT_ZOOM_ABSOLUTE_CONTROL=0x0B;
	private final int CT_ZOOM_RELATIVE_CONTROL=0x0C;
	private final int CT_PANTILT_ABSOLUTE_CONTROL=0x0D;
	private final int CT_PANTILT_RELATIVE_CONTROL=0x0E;
	
	int camerahandle = -1;
	private final int O_RDWR = 0x00000002;
	Linux_C_lib_DirectMapping linuxmap;
	
	public UVC_Control(String path) {
		devicepath = path.trim();
		linuxmap = new Linux_C_lib_DirectMapping();
		
	}
	
	
	public boolean Open() {
		camerahandle = linuxmap.open(devicepath, O_RDWR);
		return camerahandle<0 ? false : true;
	}
	
	public void Close() {
		if (camerahandle>=0) {
			jGPIO.libC.close(camerahandle);
		}
		camerahandle = -1;
	}
	
	public boolean IsOpened() {
		return (camerahandle >=0);
	}
	
	
}
