/* Get Digital Input for i-8048 modules.

   Author: Moki Matsushima

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2, or (at your option)
   any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software Foundation,
   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */

/* File level history (record changes for this file here.)

   v 1.0.0  27 May 2016 by Winson
     Use 8048W API to replace old code.

   v 0.0.0  1 Feb 2008 by Moki Matsushima
     create, blah blah... */

#include <stdio.h>
#include "msw.h"
#include "i8048W.h"

int main(int argc, char **argv)
{
	int slot,Ret,Id,ch;
	char *status;

	for(slot=1;slot<9;slot++)
	{
		Ret = Open_Slot(slot);
		if (Ret == 0) {
                        Id = inb(slot,0);
                        if(Id == 0x48)
                        {
				break;
                        }
			Close_Slot(slot);
                }
        }

	if(slot == 9)
	{
		printf("There is no I-8048W module in slot.\n");
		return FAILURE;
	}

	printf("Open module I-8048W on Slot%d\n",slot);

	Ret = I8048W_DI_ALL(slot);
	printf("0~7 bit corresponding I-8048W 0~7 channel\n");
	printf("Read All DI channel: %d\n",Ret);

	ch = 0;  //channel
	Ret = I8048W_DI_Ch(slot,ch);

	if(Ret)
		status = "ON";
	else
		status = "OFF";

	printf("Channel %d: %s\n",ch, status);

	Close_Slot(slot);
	return SUCCESS;
}

