//
// Widget de configuration du programmateur
//
#ifndef PRG_CONFIGWIDGET
#define PRG_CONFIGWIDGET
#include <qstring.h>
#include <qmainwindow.h>
#include <qcombobox.h>
#include <qlineedit.h>
#include <qcheckbox.h>
#include <qpushbutton.h>
#include <qgroupbox.h>
#include <qhbox.h>
#include <qvbox.h>
#include <qwidgetstack.h>
#include <qtimer.h>
#include <qbuttongroup.h>

#include "ConfigWidget.h"

class hardware ;
class QRadioButton ;
class port ;
class QSlider ;


class PrgConfigWidget : public ConfigWidget
{
	Q_OBJECT
private:
  hardware *phard ;

  QComboBox *dev ; 
  QComboBox *vpp ; 
	QComboBox *vdd ; 
	QComboBox *clock ; 
	QComboBox *din ; 
	QComboBox *dout ;
  //++Mirko!!
  QComboBox *drw ;
  //--Mirko!!
    
	QCheckBox *ivpp ;    
	QCheckBox *ivdd ;    
	QCheckBox *iclock ;    
	QCheckBox *idin ;    
	QCheckBox *idout ;
  //++Mirko!!
	QCheckBox *idrw ;
  //--Mirko!!
  
  QCheckBox *cbvpp;
  QCheckBox *cbvdd;
  QCheckBox *cbclock;
  QCheckBox *cbdatain;
  QCheckBox *cbdataout;
  //++Mirko!!
  QCheckBox *cbrw;
  //--Mirko!!

  /** This list  must be built before any port allocation
       by calling the static function availableParports
  */
  static QStringList parports_;
  static QStringList serports_;

  QGroupBox * groupverif ;
  QPushButton *bstopverify ;
  QVBox *central ;
  QPushButton *bsendbits ;
  QTimer *timersendbits , *timerpolldataout ;

  /**  */
  QRadioButton *butpar, *butser , *butser555;
  QButtonGroup *radiobuttons ;

  /** */
  QComboBox *parportlist, *serportlist  , *ser555portlist ;
  QSlider *delay_slider ;

  /**  */
  
  //++Mirko!!
  void reconfigCombos(port* aport, int vp, int vd, int cl, int out, int in, int
          rw, int clkdelay );
  //--Mirko!!
  
  void send_bits( unsigned int d , int nbb) ;
  
  QComboBox *stdh ;
  QPushButton *stdsav ;
  /** A dummy programmer name which acts as a combobox title */
  const QString null_prog_name;

public:
	PrgConfigWidget(hardware *h)  ;
	static void availablePorts() ;
  /** Search the pin number pin in the string list list.
\return The index of the found pin , or -1 if not found
 */
  static int findPin(const QStringList &list, int pin);
  /** Convert a pin name to pin number 
(a pin name must be a numeric decimal string  eventually followed by a blank and an arbitrary text) */
  static int pinNumber(const QString& pinname);
  /** Extract the pin name from the Pin number+pin name string */
  static const QString pinName(const QString &pinname);
  
  virtual QString configName() ;
  virtual QString configTitle() ;
  virtual QPixmap icon() ;

public slots:
	virtual void doApply() ;
  /** No descriptions */
  void driverSelected(int);
  /** Continuously send bits to programmer board */
  void sendBits();
  void slotvpp() ;
  void slotvdd() ;
  void slotclock() ;
  void slotdataout() ;
  void slotrw();
  void slotrwchange(const QString & string);
  void slotupdatedatain() ;
  void slotSendBits();
  /** Changes pin/port  configuration when a new standard hardware is selected */
  void slotStdHardware(const QString& name) ;
  /** Creates a new hardware profile */
  void slotSaveHardware();
signals:
	void PrgConfigChanged() ;  
} ;
#endif

