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

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

/*
	index[n]: 0  ; BIT 0
			  1  ; BIT 1

	          2  ; BIT 2
	          3  ; BIT 3
			  ....
	data[n]: 0  ; Digital LOW
	         1  ; Digital HIGH
	         
*/

#define MAX_BUTTON_NUMBER 2
#define BUTTON_INDEX	 0
#define SLEEP_INTERVAL 1000

int _tmain(int argc, _TCHAR* argv[])
{
	HANDLE	hGPIO;
	int port_no;
	int	nButton = 0;
	int	nRet = 0;
	int port = 0,mode = 0;
	int n = 0;

	do
    {
		//Open dio
		hGPIO = mxgpio_open();

		for(int i=0; i<MAX_BUTTON_NUMBER; i++)
		{
			//Get digital input
			port_no = BUTTON_INDEX+i;
			nButton = mxgpio_get_data(hGPIO, port_no);
			printf("Button[%d] = %d\n", port_no-BUTTON_INDEX, nButton);
		}

		//Close handle
       mxgpio_close(hGPIO);

		Sleep(SLEEP_INTERVAL);
    } while (1);
	return 0;
}

