/************************************************************************/
/* Copyright 1995 MBARI							*/
/************************************************************************/
/* $Header: /usr/tiburon/unix/gui/proto/RCS/accall.c,v 1.1 1998/01/28 16:17:12 oreilly Exp $			*/
/* Summary  : Callback Routines for AC Power screen of ROV GUI		*/
/* Filename : accall.c							*/
/* Author   : Bob Herlien (rah)						*/
/* Project  : New ROV							*/
/* $Revision: 1.1 $							*/
/* Created  : 09/19/95							*/
/************************************************************************/
/* Modification History:						*/
/* $Log: accall.c,v $
 * Revision 1.1  1998/01/28 16:17:12  oreilly
 * Initial revision
 *
 * Revision 2.2  96/05/15  11:15:31  11:15:31  bobh (Bob Herlien)
 * Still supporting proto during final vehicle build
 * 
 * Revision 2.0  95/09/20  14:23:00  14:23:00  hebo (Bob Herlien)
 * Support for final vehicle integration.  AC, PDU micros.
 * 
   19sep95, created from regencall.c, rah
*/
/************************************************************************/

#include <sys/types.h>
#include <mbari/types.h>
#include <mbari/const.h>
#include <X11/Intrinsic.h>
#include <Xm/Xm.h>
#include <X11/Xc/Xc.h>
#include "rov.h"
#include "tiburon.h"
#include <acMicro.h>


/********************************/
/*	External Functions	*/
/********************************/

Extern Void	createItems( rovItem **ipp, TimeoutStruct *tp );
Extern Void	startTimeout( TimeoutStruct *tp );
Extern Void	stopTimeout( TimeoutStruct *tp );
Extern Void	updateBarGraph1000( rovItem *ip );
Extern Void	updateInt16BarGraph( rovItem *ip );


/********************************/
/*	Forward Declarations	*/
/********************************/

Void		updateFlt32BarGraph( rovItem *ip );


/********************************/
/*	External Data		*/
/********************************/

Extern AppData	appdata;
Extern Widget	outbdTankBarGraph, inbdTankBarGraph, outbdSumpBarGraph;
Extern Widget	inbdSumpBarGraph, acPressureBarGraph;
Extern Widget	pduWattBarGraph, pduVoltBarGraph, pduTempBarGraph;
Extern Widget	pduPhaseBarGraph, pduPhase1AmpsBarGraph;
Extern Widget	pduPhase2AmpsBarGraph, pduPhase3AmpsBarGraph;


/********************************/
/*	Module Local Data	*/
/********************************/

MLocal rovItem		acPressureItem = 
{ TIBURON_DM_PREFIX "AC_MICRO.MICRO_PRESSURE", DM_FLT32, 1, FALSE, NO_ITEM, 0, 
  &acPressureBarGraph, updateFlt32BarGraph, 0 };

MLocal rovItem		portTankItem = 
{ AC_MICRO_DM_PREFIX OUTBD_TANK_LEVEL_DM, DM_INT16, 1, FALSE, NO_ITEM, 0, 
  &outbdTankBarGraph, updateBarGraph1000, 0 };

MLocal rovItem		stbdTankItem = 
{ AC_MICRO_DM_PREFIX INBD_TANK_LEVEL_DM, DM_INT16, 1, FALSE, NO_ITEM, 0, 
  &inbdTankBarGraph, updateBarGraph1000, 0 };

MLocal rovItem		portSumpItem = 
{ AC_MICRO_DM_PREFIX OUTBD_SUMP_LEVEL_DM, DM_INT16, 1, FALSE, NO_ITEM, 0, 
  &outbdSumpBarGraph, updateBarGraph1000, 0 };

MLocal rovItem		stbdSumpItem = 
{ AC_MICRO_DM_PREFIX INBD_SUMP_LEVEL_DM, DM_INT16, 1, FALSE, NO_ITEM, 0, 
  &inbdSumpBarGraph, updateBarGraph1000, 0 };

MLocal rovItem		pduWattItem = 
{  TIBURON_DM_PREFIX "PDU_MICRO.WATTAGE", DM_FLT32, 1, FALSE, NO_ITEM, 0, 
  &pduWattBarGraph, updateFlt32BarGraph, 0 };

MLocal rovItem		pduVoltItem = 
{  TIBURON_DM_PREFIX "PDU_MICRO.VOLTAGE", DM_INT16, 1, FALSE, NO_ITEM, 0, 
  &pduVoltBarGraph, updateInt16BarGraph, 0 };

MLocal rovItem		pduTempItem = 
{  TIBURON_DM_PREFIX "PDU_MICRO.TRANSFORMER_TEMPERATURE", DM_INT16, 1, FALSE, NO_ITEM, 0, 
  &pduTempBarGraph, updateInt16BarGraph, 0 };

MLocal rovItem		pduPhase1AmpsItem = 
{  TIBURON_DM_PREFIX "PDU_MICRO.PHASE1_AMPERAGE", DM_INT16, 1, FALSE, NO_ITEM, 0, 
  &pduPhase1AmpsBarGraph, updateInt16BarGraph, 0 };

MLocal rovItem		pduPhase2AmpsItem = 
{  TIBURON_DM_PREFIX "PDU_MICRO.PHASE2_AMPERAGE", DM_INT16, 1, FALSE, NO_ITEM, 0, 
  &pduPhase2AmpsBarGraph, updateInt16BarGraph, 0 };

MLocal rovItem		pduPhase3AmpsItem = 
{  TIBURON_DM_PREFIX "PDU_MICRO.PHASE3_AMPERAGE", DM_INT16, 1, FALSE, NO_ITEM, 0, 
  &pduPhase3AmpsBarGraph, updateInt16BarGraph, 0 };

MLocal rovItem		*acRovItems[] =
{ &acPressureItem, &portTankItem, &stbdTankItem, &portSumpItem, &stbdSumpItem,
  &pduWattItem, &pduVoltItem, &pduTempItem, &pduPhase1AmpsItem,
  &pduPhase2AmpsItem, &pduPhase3AmpsItem, NULLR };

MLocal TimeoutStruct	acTimeoutStruct = 
{ &appdata.power_update, 0, acRovItems, 0, "AC Power Screen", NULLF };



/************************************************************************/
/* Function    : updateFlt32BarGraph					*/
/* Purpose     : Update Callback for Floating point BarGraph		*/
/* Inputs      : Pointer to rovItem					*/
/* Outputs     : None							*/
/************************************************************************/
    Void
updateFlt32BarGraph( rovItem *ip )
{
    XcVType	vval;

    rdm_read( ip->dmitem, (char *)&vval.fval, sizeof(Flt32) );

    XcBGUpdateValue( *ip->widget, &vval );

} /* updateFlt32BarGraph() */


/************************************************************************/
/* Function    : acSelect						*/
/* Purpose     : Callback function to select the AC Power screen	*/
/* Inputs      : Select Struct Ptr					*/
/* Outputs     : None							*/
/************************************************************************/
    Void
acSelect( Select *sp )
{
    startTimeout( &acTimeoutStruct );

} /* acSelect() */


/************************************************************************/
/* Function    : acUnselect						*/
/* Purpose     : Callback function to unselect the AC Power screen	*/
/* Inputs      : Select Struct Ptr					*/
/* Outputs     : None							*/
/************************************************************************/
    Void
acUnselect( Select *sp )
{
    stopTimeout( &acTimeoutStruct );

} /* acUnselect() */


/************************************************************************/
/* Function    : initAC							*/
/* Purpose     : Initialize AC Power screen				*/
/* Inputs      : None							*/
/* Outputs     : None							*/
/************************************************************************/
    Void
initAC( Void )
{
    createItems( acRovItems, &acTimeoutStruct );

} /* initAC() */
