/************************************************************************/
/* Copyright 1998 MBARI							*/
/************************************************************************/
#ifndef _MOMENTARYPOWERSWITCH_H
#define _MOMENTARYPOWERSWITCH_H
static char MomentaryPowerSwitch_h_id[] = "$Header: /u/oreilly/rov/tmacs/RCS/MomentaryPowerSwitch.h,v 1.2 1998/12/18 21:07:21 oreilly Exp $";

/*
$Log: MomentaryPowerSwitch.h,v $
Revision 1.2  1998/12/18 21:07:21  oreilly
Added documentation

Revision 1.1  1998/02/23 16:12:15  oreilly
Initial revision

*/

#include <values.h>
#include "DmGuiObject.h"
#include "powerTypes.h"
#include "DynamicButton.h"
#include "DmInputDetector.h"

#define SWITCH_REQUEST "SWITCH_REQ"
#define SWITCH_STATUS "SWITCH_STATUS"
#define SWITCH_CURRENT "CURRENT"
#define NoCurrent -MAXSHORT

/*
CLASS 
MomentaryPowerSwitch

DESCRIPTION
Turns power on when pressed in, power off when released

AUTHOR
Tom O'Reilly
*/
class MomentaryPowerSwitch : public DmGuiObject 
{
  public:

  static const char *const statusChangeCallback;

  MomentaryPowerSwitch(const char *name, Widget parent, 
		       const char *switchDmPrefix,
		       const char *switchName,
		       int buttonWidth, int buttonHeight,
		       int period, Boolean showCurrent = True);

  ~MomentaryPowerSwitch();

  virtual const char *className()
  {
    return "MomentaryPowerSwitch";
  }
  
  virtual void updateGui(DM_Item handle = 0);
  virtual void updateFromPeer(DmGuiObject *peer, void *clientData);

  switchStatus status();

  int turnOn();
  int turnOff();

  void setSensitive(Boolean sensitive);
  

  protected:
  Boolean _dummySwitch;
  char *_switchName;
  DynamicButton *_button;
  DmEnumObject *_dmRequest;
  DmEnumObject *_dmStatus;
  DmInt16Object *_dmCurrent;
  DmInputDetector *_statusDetector;
  
  Pixel _noPwrForeground, _noPwrBackground;
  Pixel _onForeground, _onBackground;
  Pixel _offForeground, _offBackground;
  Pixel _faultForeground, _faultBackground;
  Int32 _status;
  Int16 _current;
  
  void toggleState(void);
  int requestState(switchStatus state);
  
  static XtResource _resources[];

  Boolean _showCurrent;
  
  private:

  static void armCallback(Widget w, 
			  XtPointer clientData, 
			  XtPointer callData);

  static void disarmCallback(Widget w, 
			     XtPointer clientData, 
			     XtPointer callData);

};


#endif
