#include "A628.h"

/************************************************************************/
/* wConfigCode : A626_UNIPOLAR_5V, A626_UNIPOLAR_10V
                 A626_BIPOLAR_5V , A626_BIPOLAR_10v             
                 
   return : NoError
	    DAChannelError
*/

WORD A626_DaFloat(WORD wBase, WORD wChannel, WORD wConfigCode, float fDaValue)
{
   WORD high,low,base,wHexValue;

   if(wChannel>=6) return(A626_DaChannelError);

   if( wConfigCode<A626_UNIPOLAR_5V || wConfigCode>A626_BIPOLAR_10V )
      return( A626_ConfigCodeError );

   switch( wConfigCode )
   {
      case A626_UNIPOLAR_5V:
		wHexValue=(WORD)((4095.0F/5.0F)*fDaValue);
		break;
      case A626_UNIPOLAR_10V:
		wHexValue=(WORD)((4095.0F/10.0F)*fDaValue);
		break;
      case A626_BIPOLAR_5V:
		wHexValue=(WORD)((4095.0F/10.0F)*(fDaValue+5.0F));
		break;
      case A626_BIPOLAR_10V:
		wHexValue=(WORD)((4095.0F/20.0F)*(fDaValue+10.0F));
		break;
   }

   return A626_DaHex(wBase, wChannel, wHexValue );
   
}


WORD A628_DaFloat(WORD wBase, WORD wChannel, WORD wConfigCode, float fDaValue)
{
   WORD high,low,base,wHexValue;

   if(wChannel>=8) return(A628_DaChannelError);

   if( wConfigCode<A628_UNIPOLAR_5V || wConfigCode>A628_BIPOLAR_10V )
      return( A628_ConfigCodeError );

   switch( wConfigCode )
   {
      case A628_UNIPOLAR_5V:
		wHexValue=(WORD)((4095.0F/5.0F)*fDaValue);
		break;
      case A628_UNIPOLAR_10V:
		wHexValue=(WORD)((4095.0F/10.0F)*fDaValue);
		break;
      case A628_BIPOLAR_5V:
		wHexValue=(WORD)((4095.0F/10.0F)*(fDaValue+5.0F));
		break;
      case A628_BIPOLAR_10V:
		wHexValue=(WORD)((4095.0F/20.0F)*(fDaValue+10.0F));
		break;
   }

   return A628_DaHex(wBase, wChannel, wHexValue );
   
}



