#ifndef G346_COMMON_H_
#define G346_COMMON_H_

#include "ads_data.h"

#include "icd_g346.h"

template<typename K_> void g346_ads_data_setmanip(AdsLogicData& d);

template<typename S_, typename T_, typename K_> void g346_ads_data_map(AdsLogicData& d, Ads1553MsgQ& m, unsigned int off, float scale=1.0f)
{
  d.setFormat(T_::start_bit, T_::set_mask);
  d.setLsb(T_::lsb()*scale);
  g346_ads_data_setmanip<K_>(d);
  d.attachToMsg(&m, off);
}


#define GRIFO_ADS_MAP(D_, name_, S_, f_, T_, M_)\
  (g346_ads_data_map<S_, T_, T_::raw_type_t>(D_, M_, ICD_WOFFSETOF(S_, f_)), (D_).setDataName(name_))

#define GRIFO_ADS_MAP_SCALED(D_, name_, S_, f_, T_, M_, SCALE_)\
  (g346_ads_data_map<S_, T_, T_::raw_type_t>(D_, M_, ICD_WOFFSETOF(S_, f_), SCALE_), (D_).setDataName(name_))

struct g346_simulator_enable
{
  bool rdr;
  bool inu;
  bool ac;

  int inu_smart;
  int simple_sim;
  bool link_spoi_to_cursor;

  bool a5_inhibit_timetag;
  bool a4_inhibit_timetag;

  float nav_drift;
  float ptaz_variation;
  float magnetic_variation;
  float wander_angle;

  unsigned short tt_offset;
  unsigned short ttptaz_offset;
  unsigned short ttroll_offset;
  unsigned short ttpitch_offset;
};

extern g346_simulator_enable grifo_sim_enable;


#include "time_metrics.h"

extern metricRegistered G346Metric;


class IGrifoMode
{
public:
  IGrifoMode():
      actLeftButton(0),
      actRightButton(0),
      actMiddleButtonPress(0),
      actMiddleButtonRelease(0),
      panel(0),
      ctrlDock(0),
      if_gain(0)
  {
  }

  virtual void on_LeftButton(void) {}
  virtual void on_RightButton(void) {}
  virtual void on_MiddleButton(void) {}
  virtual void on_Wheel(int /*delta*/) {}

  virtual void on_ModeEnter() {}
  virtual void on_ModeExit() {}

  AdsDataAction* actLeftButton;
  AdsDataAction* actRightButton;
  AdsDataAction* actMiddleButtonPress;
  AdsDataAction* actMiddleButtonRelease;

  QWidget* panel;
  //QWidget* ctrlDock;
  int ctrlDock;

  int* if_gain;
};

#include "grifobiteform.h"


#endif /*G346_COMMON_H_*/
