// RstExample.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <windows.h>
#include <commctrl.h>
#include "mxgpio.h"


#define MAX_SOCKET_NUMBER 2
#define RST_INDEX	 5
#define RST_OFF	 0
#define RST_ON	 1


int _tmain(int argc, _TCHAR* argv[])
{
	HANDLE	hMxRst;
	int port_no=0;
	int	nLED = 0;
	int port = 0,mode = 0;
	int n = 0;
	int on = 1;
	int data=0;
	int	input=0,output=0;

	bool inverseFlag=false;
	
	WCHAR sin,smode;
	printf("Mini PCIE Power Contol Test Program\n");
	printf("\t (0) Exit Program\n");
    printf("\t (1) Display Power reset condition\n");
    printf("\t (2) Set Power \n");

	sin=getwchar();
	n=_wtoi(&sin);

	do
    {
        switch (n)
        {
			case 1:
				//Open power control
				hMxRst=mxgpio_open();

				for(int i = 0; i < MAX_SOCKET_NUMBER; i++)
				{
					//Get digital input
					input = mxgpio_get_data(hMxRst, RST_INDEX + i);
					if( input == RST_OFF){
						printf("Socket%d is waiting for reset.\n",i+1);
					}else if( input == RST_ON){
						printf("Socket%d is on reseting\n",i+1);
					}
				}
				//Close LED
                mxgpio_close(hMxRst);
                break;

			case 2:
				//Get Port Number
				getwchar();
				printf("Input the Socket Number (1 ~ %d) = \n",MAX_SOCKET_NUMBER);
				smode = getwchar();
				port_no = _wtoi(&smode) + RST_INDEX;
			
				if( (_wtoi(&smode) >(MAX_SOCKET_NUMBER-1)) || (_wtoi(&smode) < 0) ){
					printf("The port value you input must betwwen 1 ~ %d ",MAX_SOCKET_NUMBER);
					break;
				}

				//Get Value
                /*getwchar();
                printf("Input the value (0 or 1) = ");
				smode = getwchar();
				data = _wtoi(&smode);
		
				if( (data!=0) || (data!=1) ){
					printf("The value you input must be 0 or 1. ");
					break;
				}*/

				//Open power
				hMxRst = mxgpio_open();

				//Reset LED
				getwchar();
                printf("Input 0 or 1 = ");
				smode = getwchar();
				data = _wtoi(&smode);
		
				if( (data!=0) && (data!=1) ){
					printf("The value you input must be 0 or 1. ");
					break;
				}

				//Close LED
				mxgpio_close(hMxRst);
                
				
				break;
		}
		getwchar();
		printf("\n");
		printf("Mini PCIE Power Contol Test Program\n");
		printf("\t (0) Exit Program\n");
		printf("\t (1) Display Power condition\n");
		printf("\t (2) Set Power on/off \n");
        sin = getwchar();
        n = _wtoi(&sin);
    } while (n != 0);
	return 0;
}

