/* #define  MYLIB */
#include <stdio.h>
#include <graphics.h>
#include <dos.h>
#include <stdlib.h>
#include <conio.h>
#include "ISO813.H"


int	 iLine;
WORD 	 iAdBuf[510];
/* WORD	 wDaFreq=90; */
/* WORD	 wAdClk;     */

WORD 	 wPlot0[512]; /*  transformed into wave form  */
WORD     wBase = 0x220, wChannel=0, wGainCode=0;


/* -------------------------------------------------------------------- */
void graphic_init(void)
{
   int driver,mode,char_size;

   driver=EGA;
   mode=EGAHI;
   initgraph(&driver,&mode,"");
   setactivepage(0);
   setvisualpage(0);
   setcolor(0);
   setbkcolor(15);
   settextstyle(SMALL_FONT,HORIZ_DIR,6);
}

/*--------------------------------------------------------------------- */
void draw(void)
{
   int i;

   cleardevice();
   setcolor(RED);

   for(i=0; i<501; i++)	/* channel 0's data and its wave form */
	wPlot0[i]=100+(WORD)(iAdBuf[i]/20);
   for(i=0; i<500; i++)	/* plot channel 0's wave form */
        line(10+i,wPlot0[i],10+i+1,wPlot0[i+1]);
   delay(1000);
}



/* -------------------------------------------------------------------- */
int main(void)
{

    int rtErr;
    DWORD t0 , t1 , i, dt;

    /* ArrayTimes = 0; */
    /* ErrorTimes = 0; */

    rtErr = ISO813_DriverInit();
    if (rtErr){
	printf("\ISO813 Driver open error!");
	return 0;
    };


    rtErr = ISO813_Check_Address( wBase );
    if (rtErr){
	printf("\nISO813 Board Address 0x220 Error");
	return 0;
    }


    graphic_init();

    for(;;){
	if (kbhit() != 0 ) {
		getch();
		break;
	}
	for(i=0; i<510; i++) iAdBuf[i]=0;  /* Clear the value of buffer */
	rtErr = ISO813_ADs_Hex(wBase, wChannel, wGainCode, iAdBuf, 510 );
	draw();    /*Draw the wave, both correct and incorrect values*/
   }

   getch();
   cleardevice();
   closegraph();
   ISO813_DriverClose();
   return 0;
}

