public DialogResultSetting(SettingWindow settingWindow, SettingFBGA settingFBGA, SettingMIC settingMIC, SettingECG settingECG)
 {
     SettingWindow = settingWindow;
     SettingFBGA   = settingFBGA;
     SettingMIC    = settingMIC;
     SettingECG    = settingECG;
 }
 public void SendSetting(SettingFBGA fbgaSetting)
 {
     try
     {
         Initialize(fbgaSetting);
     }
     catch (Exception ex) {
         Log log = new Log();
         log.LogMessageToFile(TAG + "SendSetting:" + ex.Message);
     }
 }
        private void OnOKClicked(object parameter)
        {
            List <ModuleChannel> displaySelection = new  List <ModuleChannel>()
            {
                display1Selection, display2Selection, display3Selection, display4Selection, display5Selection, display6Selection
            };
            SettingWindow windowResult = new SettingWindow(Int32.Parse(TimeAxisSelectedItem), settingWindow.UserTabDisplays, displaySelection, settingWindow.TabEnabled);

            SettingFBGA fbgaResult = new SettingFBGA(settingFBGA.NumberOfChannels, integrationTime, sledPower, _highDynamicRangeMode, settingFBGA.SelectedDisplays);
            SettingMIC  micResult  = new SettingMIC(settingMIC.NumberOfChannels, MIC1MuteSelected, MIC2MuteSelected, MIC3MuteSelected, MIC4MuteSelected, HighPassFilterSelected, MICSyncSelected, settingMIC.SelectedDisplays);
            SettingECG  ecgResult  = new SettingECG(settingECG.NumberOfChannels, false, ecgGain, ECGCH4modeSelectedItem, sensP, sensN, settingECG.SelectedDisplays);

            this.CloseDialogWithResult(parameter as Window, new DialogResultSetting(windowResult, fbgaResult, micResult, ecgResult));
        }
        public MainWindow()
        {
            try
            {
                Log log = new Log();
                log.LogMessageToFile("Program started!!!");
                InitializeComponent();

                OpenGlDisplay openGLDisplay1 = new OpenGlDisplay(openGLControl1, false, 1f, 0f, 0f);
                OpenGlDisplay openGLDisplay2 = new OpenGlDisplay(openGLControl2, false, 1f, 0f, 0f);
                OpenGlDisplay openGLDisplay3 = new OpenGlDisplay(openGLControl3, false, 1f, 0f, 0f);
                OpenGlDisplay openGLDisplay4 = new OpenGlDisplay(openGLControl4, false, 1f, 0f, 0f);
                OpenGlDisplay openGLDisplay5 = new OpenGlDisplay(openGLControl5, false, 1f, 0f, 0f);
                OpenGlDisplay openGLDisplay6 = new OpenGlDisplay(openGLControl6, false, 1f, 0f, 0f);


                SettingProgram settingProgramDataHandler = SettingService.LoadSettingProgram();
                SettingWindow  settingWindowDataHandler  = SettingService.LoadSettingWindow();
                SettingFBGA    settingFBGADataHandler    = SettingService.LoadSettingFBGA();
                SettingMIC     settingMICDataHandler     = SettingService.LoadSettingMIC();
                SettingECG     settingECGDataHandler     = SettingService.LoadSettingECG();
                SettingACC     settingACCDataHandler     = SettingService.LoadSettingACC();
                SettingPPG     settingPPGDataHandler     = SettingService.LoadSettingPPG();

                TreeViewViewModel treeViewHandler = new TreeViewViewModel();
                Tree.DataContext = treeViewHandler;

                OpenGLDispatcher openGLDispatcherHandler =
                    new OpenGLDispatcher(openGLDisplay1, openGLDisplay2, openGLDisplay3, openGLDisplay4, openGLDisplay5, openGLDisplay6,
                                         settingMICDataHandler.NumberOfChannels, settingFBGADataHandler.NumberOfChannels, settingECGDataHandler.NumberOfChannels, settingACCDataHandler.NumberOfChannels, settingPPGDataHandler.NumberOfChannels);

                MainWindowViewModel mainWindowHandler = new MainWindowViewModel(treeViewHandler, openGLDispatcherHandler, settingProgramDataHandler, settingWindowDataHandler, settingFBGADataHandler, settingMICDataHandler, settingECGDataHandler, settingACCDataHandler, settingPPGDataHandler);
                treeViewHandler.addParent(mainWindowHandler);
                DataContext = mainWindowHandler;

                device = new Device(mainWindowHandler);
            }
            catch (Exception ex)
            {
                Log log = new Log();
                log.LogMessageToFile(ex.Message);
                Dialogs.DialogMessage.DialogMessageViewModel dvm    = new Dialogs.DialogMessage.DialogMessageViewModel(Dialogs.DialogMessage.DialogImageTypeEnum.Error, ex.Message);
                Dialogs.DialogService.DialogResult           result = Dialogs.DialogService.DialogService.OpenDialog(dvm);
            }
        }
 public void TurnOnOffSLED(SettingFBGA fbgaSetting, bool turnOn)
 {
     try
     {
         if (turnOn)
         {
             mwlsModule.InitSLED(fbgaSetting.SLEDPower);
         }
         else
         {
             mwlsModule.TurnOffSLED(fbgaSetting.SLEDPower);
         }
     }
     catch (InitMWLSException ex)
     {
         throw ex;
     }
     catch (TurnOnMWLSException ex)
     {
         throw ex;
     }
 }
        public DialogSettingViewModel(SettingWindow settingWindow, SettingFBGA settingFBGA, SettingMIC settingMIC, SettingECG settingECG) : base("Settings")
        {
            this.okCommand     = new DelegateCommand(OnOKClicked);
            this.cancelCommand = new DelegateCommand(OnCancelClicked);

            TimeAxisSelectedItem = settingWindow.TimeAxis.ToString();
            #region DISPLAY_CH_NUMBERS
            int      micNoChannels  = settingWindow.UserTabDisplays.ElementAt(0);
            int      fbgaNoChannels = settingWindow.UserTabDisplays.ElementAt(1);
            int      ecgNoChannels  = settingWindow.UserTabDisplays.ElementAt(2);
            int      accNoChannels  = settingWindow.UserTabDisplays.ElementAt(3);
            int      ppgNoChannels  = settingWindow.UserTabDisplays.ElementAt(4);
            string[] items          = new string[micNoChannels + fbgaNoChannels + ecgNoChannels + 3 * accNoChannels + ppgNoChannels];
            int      index          = 0;
            for (int i = 0; i < micNoChannels; i++)
            {
                items[index++] = "MIC_CH" + (i + 1).ToString();
            }
            for (int i = 0; i < fbgaNoChannels; i++)
            {
                items[index++] = "FBGA_CH" + (i + 1).ToString();
            }
            for (int i = 0; i < ecgNoChannels; i++)
            {
                items[index++] = "ECG_CH" + (i + 1).ToString();
            }
            for (int i = 0; i < accNoChannels; i++)
            {
                items[index++] = "ACC_CH" + (i + 1).ToString() + "x";
            }
            for (int i = 0; i < accNoChannels; i++)
            {
                items[index++] = "ACC_CH" + (i + 1).ToString() + "y";
            }
            for (int i = 0; i < accNoChannels; i++)
            {
                items[index++] = "ACC_CH" + (i + 1).ToString() + "z";
            }
            for (int i = 0; i < ppgNoChannels; i++)
            {
                items[index++] = "PPG_CH" + (i + 1).ToString();
            }
            UserTabDisplay1 = new List <string>(items);
            UserTabDisplay2 = new List <string>(items);
            UserTabDisplay3 = new List <string>(items);
            UserTabDisplay4 = new List <string>(items);
            UserTabDisplay5 = new List <string>(items);
            UserTabDisplay6 = new List <string>(items);

            #endregion
            #region DISPLAY_SELECTION
            display1Selection = new ModuleChannel(settingWindow.UserTabSelectedDisplays.ElementAt(0));
            if (String.Compare("MIC", display1Selection.ModuleName) == 0)
            {
                UserTabDisplay1SelectedItem = "MIC_CH" + display1Selection.ChannelNumber.ToString() + display1Selection.Axis;
            }
            if (String.Compare("FBGA", display1Selection.ModuleName) == 0)
            {
                UserTabDisplay1SelectedItem = "FBGA_CH" + display1Selection.ChannelNumber.ToString() + display1Selection.Axis;
            }
            if (String.Compare("ECG", display1Selection.ModuleName) == 0)
            {
                UserTabDisplay1SelectedItem = "ECG_CH" + display1Selection.ChannelNumber.ToString() + display1Selection.Axis;
            }
            if (String.Compare("ACC", display1Selection.ModuleName) == 0)
            {
                UserTabDisplay1SelectedItem = "ACC_CH" + display1Selection.ChannelNumber.ToString() + display1Selection.Axis;
            }
            if (String.Compare("PPG", display1Selection.ModuleName) == 0)
            {
                UserTabDisplay1SelectedItem = "PPG_CH" + display1Selection.ChannelNumber.ToString() + display1Selection.Axis;
            }

            display2Selection = new ModuleChannel(settingWindow.UserTabSelectedDisplays.ElementAt(1));
            if (String.Compare("MIC", display2Selection.ModuleName) == 0)
            {
                UserTabDisplay2SelectedItem = "MIC_CH" + display2Selection.ChannelNumber.ToString() + display2Selection.Axis;
            }
            if (String.Compare("FBGA", display2Selection.ModuleName) == 0)
            {
                UserTabDisplay2SelectedItem = "FBGA_CH" + display2Selection.ChannelNumber.ToString() + display2Selection.Axis;
            }
            if (String.Compare("ECG", display2Selection.ModuleName) == 0)
            {
                UserTabDisplay2SelectedItem = "ECG_CH" + display2Selection.ChannelNumber.ToString() + display2Selection.Axis;
            }
            if (String.Compare("ACC", display2Selection.ModuleName) == 0)
            {
                UserTabDisplay2SelectedItem = "ACC_CH" + display2Selection.ChannelNumber.ToString() + display2Selection.Axis;
            }
            if (String.Compare("PPG", display2Selection.ModuleName) == 0)
            {
                UserTabDisplay2SelectedItem = "PPG_CH" + display2Selection.ChannelNumber.ToString() + display2Selection.Axis;
            }

            display3Selection = new ModuleChannel(settingWindow.UserTabSelectedDisplays.ElementAt(2));
            if (String.Compare("MIC", display3Selection.ModuleName) == 0)
            {
                UserTabDisplay3SelectedItem = "MIC_CH" + display3Selection.ChannelNumber.ToString() + display3Selection.Axis;
            }
            if (String.Compare("FBGA", display3Selection.ModuleName) == 0)
            {
                UserTabDisplay3SelectedItem = "FBGA_CH" + display3Selection.ChannelNumber.ToString() + display3Selection.Axis;
            }
            if (String.Compare("ECG", display3Selection.ModuleName) == 0)
            {
                UserTabDisplay3SelectedItem = "ECG_CH" + display3Selection.ChannelNumber.ToString() + display3Selection.Axis;
            }
            if (String.Compare("ACC", display3Selection.ModuleName) == 0)
            {
                UserTabDisplay3SelectedItem = "ACC_CH" + display3Selection.ChannelNumber.ToString() + display3Selection.Axis;
            }
            if (String.Compare("PPG", display3Selection.ModuleName) == 0)
            {
                UserTabDisplay3SelectedItem = "PPG_CH" + display3Selection.ChannelNumber.ToString() + display3Selection.Axis;
            }

            display4Selection = new ModuleChannel(settingWindow.UserTabSelectedDisplays.ElementAt(3));
            if (String.Compare("MIC", display4Selection.ModuleName) == 0)
            {
                UserTabDisplay4SelectedItem = "MIC_CH" + display4Selection.ChannelNumber.ToString() + display4Selection.Axis;
            }
            if (String.Compare("FBGA", display4Selection.ModuleName) == 0)
            {
                UserTabDisplay4SelectedItem = "FBGA_CH" + display4Selection.ChannelNumber.ToString() + display4Selection.Axis;
            }
            if (String.Compare("ECG", display4Selection.ModuleName) == 0)
            {
                UserTabDisplay4SelectedItem = "ECG_CH" + display4Selection.ChannelNumber.ToString() + display4Selection.Axis;
            }
            if (String.Compare("ACC", display4Selection.ModuleName) == 0)
            {
                UserTabDisplay4SelectedItem = "ACC_CH" + display4Selection.ChannelNumber.ToString() + display4Selection.Axis;
            }
            if (String.Compare("PPG", display4Selection.ModuleName) == 0)
            {
                UserTabDisplay4SelectedItem = "PPG_CH" + display4Selection.ChannelNumber.ToString() + display4Selection.Axis;
            }

            display5Selection = new ModuleChannel(settingWindow.UserTabSelectedDisplays.ElementAt(4));
            if (String.Compare("MIC", display5Selection.ModuleName) == 0)
            {
                UserTabDisplay5SelectedItem = "MIC_CH" + display5Selection.ChannelNumber.ToString() + display5Selection.Axis;
            }
            if (String.Compare("FBGA", display5Selection.ModuleName) == 0)
            {
                UserTabDisplay5SelectedItem = "FBGA_CH" + display5Selection.ChannelNumber.ToString() + display5Selection.Axis;
            }
            if (String.Compare("ECG", display5Selection.ModuleName) == 0)
            {
                UserTabDisplay5SelectedItem = "ECG_CH" + display5Selection.ChannelNumber.ToString() + display5Selection.Axis;
            }
            if (String.Compare("ACC", display5Selection.ModuleName) == 0)
            {
                UserTabDisplay5SelectedItem = "ACC_CH" + display5Selection.ChannelNumber.ToString() + display5Selection.Axis;
            }
            if (String.Compare("PPG", display5Selection.ModuleName) == 0)
            {
                UserTabDisplay5SelectedItem = "PPG_CH" + display5Selection.ChannelNumber.ToString() + display5Selection.Axis;
            }

            display6Selection = new ModuleChannel(settingWindow.UserTabSelectedDisplays.ElementAt(5));
            if (String.Compare("MIC", display6Selection.ModuleName) == 0)
            {
                UserTabDisplay6SelectedItem = "MIC_CH" + display6Selection.ChannelNumber.ToString() + display6Selection.Axis;
            }
            if (String.Compare("FBGA", display6Selection.ModuleName) == 0)
            {
                UserTabDisplay6SelectedItem = "FBGA_CH" + display6Selection.ChannelNumber.ToString() + display6Selection.Axis;
            }
            if (String.Compare("ECG", display6Selection.ModuleName) == 0)
            {
                UserTabDisplay6SelectedItem = "ECG_CH" + display6Selection.ChannelNumber.ToString() + display6Selection.Axis;
            }
            if (String.Compare("ACC", display6Selection.ModuleName) == 0)
            {
                UserTabDisplay6SelectedItem = "ACC_CH" + display6Selection.ChannelNumber.ToString() + display6Selection.Axis;
            }
            if (String.Compare("PPG", display6Selection.ModuleName) == 0)
            {
                UserTabDisplay6SelectedItem = "PPG_CH" + display6Selection.ChannelNumber.ToString() + display6Selection.Axis;
            }
            #endregion
            this.settingWindow = settingWindow;
            TabWindowEnabled   = settingWindow.TabEnabled;
            if (!TabWindowEnabled)
            {
                TabFBGASelected = true;
            }

            this.settingFBGA = settingFBGA;
            FbgaIntegrationTimeSelectedItem = settingFBGA.IntegrationTime.ToString();
            SLEDPowerSelectedItem           = String.Format(new System.Globalization.CultureInfo("en-GB"), "{0:#0.0#}", settingFBGA.SLEDPower);
            HighDynamicRangeModeChecked     = settingFBGA.HighDynamicRange;

            this.settingMIC        = settingMIC;
            MIC1MuteSelected       = settingMIC.MuteMIC1;
            MIC2MuteSelected       = settingMIC.MuteMIC2;
            MIC3MuteSelected       = settingMIC.MuteMIC3;
            MIC4MuteSelected       = settingMIC.MuteMIC4;
            HighPassFilterSelected = settingMIC.HighPassFilter;
            MICSyncSelected        = settingMIC.SyncTest;

            this.settingECG        = settingECG;
            EcgGainSelectedItem    = settingECG.Gain.ToString();
            ECGCH4modeSelectedItem = settingECG.CH4Mode;
            #region SENSP_SELECTION
            if ((settingECG.SensP & 0x80) == 0x80)
            {
                SensP8Selected = true;
            }
            else
            {
                SensP8Selected = false;
            }
            if ((settingECG.SensP & 0x40) == 0x40)
            {
                SensP7Selected = true;
            }
            else
            {
                SensP7Selected = false;
            }
            if ((settingECG.SensP & 0x20) == 0x20)
            {
                SensP6Selected = true;
            }
            else
            {
                SensP6Selected = false;
            }
            if ((settingECG.SensP & 0x10) == 0x10)
            {
                SensP5Selected = true;
            }
            else
            {
                SensP5Selected = false;
            }
            if ((settingECG.SensP & 0x08) == 0x08)
            {
                SensP4Selected = true;
            }
            else
            {
                SensP4Selected = false;
            }
            if ((settingECG.SensP & 0x04) == 0x04)
            {
                SensP3Selected = true;
            }
            else
            {
                SensP3Selected = false;
            }
            if ((settingECG.SensP & 0x02) == 0x02)
            {
                SensP2Selected = true;
            }
            else
            {
                SensP2Selected = false;
            }
            if ((settingECG.SensP & 0x01) == 0x01)
            {
                SensP1Selected = true;
            }
            else
            {
                SensP1Selected = false;
            }
            #endregion
            #region SENSN_SELECTION
            if ((settingECG.SensN & 0x80) == 0x80)
            {
                SensN8Selected = true;
            }
            else
            {
                SensN8Selected = false;
            }
            if ((settingECG.SensN & 0x40) == 0x40)
            {
                SensN7Selected = true;
            }
            else
            {
                SensN7Selected = false;
            }
            if ((settingECG.SensN & 0x20) == 0x20)
            {
                SensN6Selected = true;
            }
            else
            {
                SensN6Selected = false;
            }
            if ((settingECG.SensN & 0x10) == 0x10)
            {
                SensN5Selected = true;
            }
            else
            {
                SensN5Selected = false;
            }
            if ((settingECG.SensN & 0x08) == 0x08)
            {
                SensN4Selected = true;
            }
            else
            {
                SensN4Selected = false;
            }
            if ((settingECG.SensN & 0x04) == 0x04)
            {
                SensN3Selected = true;
            }
            else
            {
                SensN3Selected = false;
            }
            if ((settingECG.SensN & 0x02) == 0x02)
            {
                SensN2Selected = true;
            }
            else
            {
                SensN2Selected = false;
            }
            if ((settingECG.SensN & 0x01) == 0x01)
            {
                SensN1Selected = true;
            }
            else
            {
                SensN1Selected = false;
            }
            #endregion
        }
 public virtual void Reset(SettingFBGA fbgaSetting)
 {
     Initialize(fbgaSetting);
     stopAcquisition();
     startAcquisition(false);
 }
        public void TryInitialize(SettingFBGA fbgaSetting)
        {
            int a;

            int[]         pdwHW        = new int[2];
            int[]         pdwFW        = new int[2];
            StringBuilder stringlpszSN = new StringBuilder(10);

            string lpszSystemFileDirectory = System.IO.Directory.GetCurrentDirectory();

            fbgaMwlsStatus = USBDeviceStateEnum.NOT_INITIALIZED;

            if (22002082 != DLL_Get_DLL_Version())
            {
                return;
            }


            a = DLL_Connect_System(lpszSystemFileDirectory);
            if (a != 0)
            {
                return;
            }
            dllLibOpened = true;

            /* if (!DLL_Is_Device_OK())
             * {
             *   return;
             * }
             *
             * if (!DLL_Get_Device_SN(stringlpszSN)) return;
             * if (!DLL_Get_HW_FW_REV(pdwHW, pdwFW)) return;
             * if (512 != DLL_Get_Pixel_Count())
             * {
             *   return;
             * }
             * //set device sensor mode to 0(HighSensitive) 1(High Dynamic)
             * if (fbgaSetting.HighDynamicRange)
             * {
             *   if (!DLL_Set_Sensor_Mode(1)) return;
             * }
             * else
             * {
             *   if (!DLL_Set_Sensor_Mode(0)) return;
             * }
             * //set device sample integration time (1000us) and sample rate (500Hz) Tsr>Tint
             * if (!DLL_Set_IntegrationTime_SampleRate(500, 500)) return;
             *
             */
            /*try{
             *   mwlsModule.InitSLED(fbgaSetting.SLEDPower);
             * }
             * catch (InitMWLSException ex){
             *  fbgaMwlsStatus = USBDeviceStateEnum.INITIALIZED;
             *  return;
             * }
             * catch (TurnOnMWLSException ex){
             *  fbgaMwlsStatus = USBDeviceStateEnum.INITIALIZED_OFF;
             *  return;
             * }*/
            fbgaMwlsStatus = USBDeviceStateEnum.INITIALIZED;
        }
        public void Initialize(SettingFBGA fbgaSetting)
        {
            int a;

            int[]         pdwHW        = new int[2];
            int[]         pdwFW        = new int[2];
            StringBuilder stringlpszSN = new StringBuilder(10);

            string lpszSystemFileDirectory = System.IO.Directory.GetCurrentDirectory();

            fbgaMwlsStatus = USBDeviceStateEnum.NOT_INITIALIZED;

            if (22002082 != DLL_Get_DLL_Version())
            {
                throw new FBGAException("FBGA initialization failed: DLL version is not verified");
            }


            a = DLL_Connect_System(lpszSystemFileDirectory);
            switch (a)
            {
            case 0:
                break;

            case 1:
                throw new FBGAException("FBGA initialization failed: Device is acquiring spectrum in continuous mode");

            case 2:
                throw new FBGAException("FBGA initialization failed: Create USB instance failed");

            case 3:
                throw new FBGAException("FBGA initialization failed: No or multiple FBGA connected");

            case 4:
                throw new FBGAException("FBGA initialization failed: Initialize device failed");

            case 5:
                throw new FBGAException("FBGA initialization failed: Wrong sensor type");

            case 6:
                throw new FBGAException("FBGA initialization failed: Allocate memory failed");

            case 7:
                throw new FBGAException("FBGA initialization failed: Load system configuration file faile");

            case 8:
                throw new FBGAException("FBGA initialization failed: Load calibration data file faile");

            default:
                throw new FBGAException("FBGA initialization failed: Device not detected");
            }
            if (!DLL_Is_Device_OK())
            {
                throw new FBGAException("FBGA initialization failed: Device not OK");
            }

            if (!DLL_Get_Device_SN(stringlpszSN))
            {
                throw new FBGAException("FBGA initialization failed: Get device serial number error");
            }
            if (!DLL_Get_HW_FW_REV(pdwHW, pdwFW))
            {
                throw new FBGAException("FBGA initialization failed: Get HW FW error");
            }
            if (512 != DLL_Get_Pixel_Count())
            {
                throw new FBGAException("FBGA initialization failed: Device pixel count != 512");
            }
            //set device sensor mode to 0(HighSensitive) 1(High Dynamic)
            if (fbgaSetting.HighDynamicRange)
            {
                if (!DLL_Set_Sensor_Mode(1))
                {
                    throw new FBGAException("FBGA initialization failed: Set sensor mode error");
                }
            }
            else
            {
                if (!DLL_Set_Sensor_Mode(0))
                {
                    throw new FBGAException("FBGA initialization failed: Set sensor mode error");
                }
            }
            //set device sample integration time (1000us) and sample rate (500Hz) Tsr>Tint
            if (!DLL_Set_IntegrationTime_SampleRate(fbgaSetting.IntegrationTime, 5000))
            {
                throw new FBGAException("FBGA initialization failed: Set integrationTime/samplingRate error");
            }
            fbgaMwlsStatus = USBDeviceStateEnum.INITIALIZED;
        }