private void CoarseFilterValueTextBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key != Key.Return)
            {
                return;
            }
            TxData[0] = Const.ChangeSettingsCommand;
            TxData[1] = Const.sCoarseFilterValue;
            double CoarseFilterValue;

            if (double.TryParse(CoarseFilterValueTextBox.Text, out CoarseFilterValue) == false)
            {
                DataHanlderClass.PrintTextToOutput(TextOutput, "Filter value didn't changed! Data incorrect.");
                return;
            }

            UInt32 u32_CoarseFilterValue = (UInt32)(CoarseFilterValue * 1000);

            TxData[7] = (byte)((u32_CoarseFilterValue & 0xFF000000) >> 24);
            TxData[6] = (byte)((u32_CoarseFilterValue & 0x00FF0000) >> 16);
            TxData[5] = (byte)((u32_CoarseFilterValue & 0x0000FF00) >> 8);
            TxData[4] = (byte)(u32_CoarseFilterValue & 0x000000FF);
            HID_Write(TxData);
            DataHanlderClass.PrintTextToOutput(TextOutput, "Coarse mode filter value changed.");
        }
        private void AutoOffTimerTextBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key != Key.Return)
            {
                return;
            }
            TxData[0] = Const.ChangeSettingsCommand;
            TxData[1] = Const.sAutoOffTimerValueS;
            UInt32 TimerValue;

            if (UInt32.TryParse(AutoOffTimerTextBox.Text, out TimerValue) == false)
            {
                DataHanlderClass.PrintTextToOutput(TextOutput, "Change timer value failed! Data incorrect.");
                return;
            }
            if (TimerValue > Int32.MaxValue)
            {
                return;
            }
            TxData[7] = (byte)((TimerValue & 0xFF000000) >> 24);
            TxData[6] = (byte)((TimerValue & 0x00FF0000) >> 16);
            TxData[5] = (byte)((TimerValue & 0x0000FF00) >> 8);
            TxData[4] = (byte)(TimerValue & 0x000000FF);
            HID_Write(TxData);
            DataHanlderClass.PrintTextToOutput(TextOutput, "Leveling auto off timer changed.");
        }
        private void CoarseModeZeroSizeTextBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key != Key.Return)
            {
                return;
            }
            TxData[0] = Const.ChangeSettingsCommand;
            TxData[1] = Const.sCoarseZeroAreaSize;
            double CoarseZeroAreaSize;

            if (double.TryParse(CoarseModeZeroSizeTextBox.Text, out CoarseZeroAreaSize) == false)
            {
                DataHanlderClass.PrintTextToOutput(TextOutput, "Change area size failed! Data incorrect.");
                return;
            }

            UInt32 u32_CoarseZeroAreaSize = (UInt32)(CoarseZeroAreaSize * 1000);

            TxData[7] = (byte)((u32_CoarseZeroAreaSize & 0xFF000000) >> 24);
            TxData[6] = (byte)((u32_CoarseZeroAreaSize & 0x00FF0000) >> 16);
            TxData[5] = (byte)((u32_CoarseZeroAreaSize & 0x0000FF00) >> 8);
            TxData[4] = (byte)(u32_CoarseZeroAreaSize & 0x000000FF);
            HID_Write(TxData);
            DataHanlderClass.PrintTextToOutput(TextOutput, "Coarse area zone size changed.");
        }
        private void DeleteSensorButton_Click(object sender, RoutedEventArgs e)
        {
            TxData[0] = Const.DELETE_SENSOR;
            if (SensorsInstalledList.Count == 0)
            {
                return;
            }
            byte   CurrentSensorNum = (byte)(SensorsInstalledList.Count - SensListBox.SelectedIndex - 1);
            string CurrentSensorSN  = SensorsInstalledList[CurrentSensorNum];

            if (CurrentSensorSN.StartsWith("10"))
            {
                CurrentSensorNum = byte.Parse(CurrentSensorSN.Substring(0, 2));
            }
            else
            {
                CurrentSensorNum = byte.Parse(CurrentSensorSN.Substring(0, 1));
            }
            TxData[1] = CurrentSensorNum;
            TxData[1]--;
            DataHanlderClass.PrintTextToOutput(TextOutput, string.Format("Sensor {0:0} ", CurrentSensorNum) + " deleted!");
            SensorsInstalledList.Remove(CurrentSensorSN);
            DataHanlderClass.CopyListToComboBox(SensListBox, MainWindow.SensorsInstalledList, true);
            SensLabel[CurrentSensorNum - 1].Content = "Deleted";
            HID_Write(TxData);
        }
        private void UploadFW_Button_Click(object sender, RoutedEventArgs e)
        {
            byte[]         TxFile        = new byte[64];
            OpenFileDialog FW_FileDialog = new OpenFileDialog();

            //FW_FileDialog.Filter = "All files (*.hex)|*.HEX";
            FW_FileDialog.ShowDialog();
            string FW_FilePath = FW_FileDialog.FileName;

            if (FW_FilePath == "")
            {
                return;
            }
            byte[] File = System.IO.File.ReadAllBytes(FW_FilePath);

            /* Send Filename */
            TxFile[0] = Const.SaveFileDefineName;
            TxFile[1] = (byte)FW_FileDialog.SafeFileName.Count();
            for (int i = 0; i < FW_FileDialog.SafeFileName.Count(); i++)
            {
                TxFile[i + 2] = (byte)FW_FileDialog.SafeFileName[i];
            }
            HID_Write(TxFile);
            DataHanlderClass.PrintTextToOutput(TextOutput, string.Format("Uploading file {0} size {1:N0} bytes", FW_FileDialog.SafeFileName, File.Count()));

            TxFile[0] = Const.SaveFileDefineNameCommand;
            byte   PageSize   = Const.FilePageSize;
            UInt32 CurrentPos = 0;

            while (CurrentPos < File.Count())
            {
                if (CurrentPos > File.Count() - PageSize)
                {
                    PageSize = (byte)(File.Count() - CurrentPos);
                }

                /* Copy file content */
                for (int i = 0; i < PageSize; i++)
                {
                    TxFile[i + 2] = (byte)File[CurrentPos + i];
                }
                TxFile[1]   = PageSize;
                CurrentPos += PageSize;

                HID_Write(TxFile);
            }

            TxFile[0] = Const.FileFinishCommand;
            HID_Write(TxFile);

            MW.BootLoaderProgressBar.Value = MW.BootLoaderProgressBar.Maximum = TXQueue.Count();
            FW_ProgressBarThread.Resume();
        }
 private void DeviceTimeLabel_MouseDoubleClick(object sender, MouseButtonEventArgs e)
 {
     TxData[0] = Const.SetTime;
     TxData[1] = (byte)DateTime.Now.Hour;
     TxData[2] = (byte)DateTime.Now.Minute;
     TxData[3] = (byte)DateTime.Now.Second;
     TxData[4] = (byte)(DateTime.Today.Year - 2000);
     TxData[5] = (byte)DateTime.Today.Month;
     TxData[6] = (byte)DateTime.Today.Day;
     TxData[7] = (byte)DateTime.Now.DayOfWeek;
     HID_Write(TxData);
     DataHanlderClass.PrintTextToOutput(TextOutput, "Time on device updated!");
 }
 private static void HID_RX_DataHandler()
 {
     byte[] Buff = new byte[64];
     while (true)
     {
         Thread.Sleep(2);
         if (RxQueue.Count > 0)
         {
             Buff = RxQueue.Dequeue();
             DataHanlderClass.RX_DataHandler(Buff, MW);
         }
     }
 }
        private void StoreSensorToEEPRO(byte SensNum)
        {
            if (SensListBox.SelectedIndex == -1 || SensorsFoundList.Count <= SensListBox.SelectedIndex)
            {
                return;
            }
            string ChoosedSensor = SensorsFoundList[SensListBox.SelectedIndex].Substring(3); //unsafe code!

            DataHanlderClass.PrintTextToOutput(TextOutput, string.Format("Sensor {0:0} ", SensNum + 1) + ChoosedSensor + " installed!");
            TxData    = DataHanlderClass.ConvertStrToHEX(ChoosedSensor, TxData, (byte)ChoosedSensor.Length, 2);
            TxData[0] = Const.InstallNewSensor;
            TxData[1] = SensNum;
            HID_Write(TxData);
        }
        private static void HID_CheckConnectionThread()
        {
            byte[] RxBuff = new byte[65];
            byte[] TxBuff = new byte[65];

Disconnected:
            while (LevelingSystemDevice == null)
            {
                Thread.Sleep(100);
                LevelingSystemDevice = loader.GetDevices(2003, 7003).FirstOrDefault(d => d.MaxInputReportLength == 65);
            }
            DataHanlderClass.ChangeRadioButtonState(MW.ConnectedInd, true, "Connected");
            UpdateZeroData = true;
            if (!LevelingSystemDevice.TryOpen(out USB_Stream))
            {
                MessageBox.Show("Failed to connect to device", "Error!", MessageBoxButton.OK, MessageBoxImage.Error);
                Environment.Exit(2);
            }
            using (USB_Stream)
            {
                while (true)
                {
                    try
                    {
                        RxBuff = USB_Stream.Read();
                        if (TXQueue.Count > 0)
                        {
                            TxBuff = TXQueue.Dequeue();
                            USB_Stream.Write(TxBuff);
                        }
                    }
                    catch
                    {
                        USB_Stream.Close();
                        LevelingSystemDevice = null;
                        DataHanlderClass.ChangeRadioButtonState(MW.ConnectedInd, false, "Disconnected");
                        goto Disconnected;
                    }
                    if (RxBuff != null)
                    {
                        RxQueue.Enqueue(RxBuff);
                    }

                    Thread.Sleep(1);
                }
            }
        }
Exemple #10
0
        static private void GetSettingCommandHandler(byte[] data, MainWindow MW)
        {
            if (data[1] != Const.GetSettingsCommand)
            {
                return;
            }

            UInt32 AutoOffTimerValue = ConvertToU32(data, 2);

            DataHanlderClass.ChangeTextBoxText(MW.AutoOffTimerTextBox, string.Format("{0}", AutoOffTimerValue));

            byte PositionNumber = data[6];

            DataHanlderClass.ChangeTextBoxText(MW.PositionTextBox, string.Format("{0}", PositionNumber));

            double NormZeroSize = (double)(ConvertToU32(data, 13)) / 1000;

            DataHanlderClass.ChangeTextBoxText(MW.NormZeroSizeTextBox, string.Format("{0}", NormZeroSize));

            double CoarseModeZeroSize = (double)(ConvertToU32(data, 21)) / 1000;

            DataHanlderClass.ChangeTextBoxText(MW.CoarseModeZeroSizeTextBox, string.Format("{0}", CoarseModeZeroSize));

            double NormFilterValue = (double)(ConvertToU32(data, 17)) / 1000;

            DataHanlderClass.ChangeTextBoxText(MW.NormFilterValueTextBox, string.Format("{0}", NormFilterValue));

            double CoarseFilterValue = (double)(ConvertToU32(data, 25)) / 1000;

            DataHanlderClass.ChangeTextBoxText(MW.CoarseFilterValueTextBox, string.Format("{0}", CoarseFilterValue));

            UInt16 SI7005_ReadInterval = ConvertToU16(data, 7);

            DataHanlderClass.ChangeTextBoxText(MW.SI7005_ReadIntervalTextBox, string.Format("{0}", SI7005_ReadInterval));

            UInt16 BMP180_ReadInterval = ConvertToU16(data, 9);

            DataHanlderClass.ChangeTextBoxText(MW.BMP180_ReadIntervalTextBox, string.Format("{0}", BMP180_ReadInterval));

            UInt16 SDCardLogInterval = ConvertToU16(data, 11);

            DataHanlderClass.ChangeTextBoxText(MW.SDCardLogIntervalTextBox, string.Format("{0}", SDCardLogInterval));
        }
        private void SDCardLogIntervalTextBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key != Key.Return)
            {
                return;
            }
            TxData[0] = Const.ChangeSettingsCommand;
            TxData[1] = Const.sLogToSDint;
            UInt16 LogToSDint;

            if (UInt16.TryParse(SDCardLogIntervalTextBox.Text, out LogToSDint) == false)
            {
                DataHanlderClass.PrintTextToOutput(TextOutput, "Change interval value failed! Data incorrect.");
                return;
            }
            TxData[5] = (byte)((LogToSDint & 0x0000FF00) >> 8);
            TxData[4] = (byte)(LogToSDint & 0x000000FF);
            HID_Write(TxData);
            DataHanlderClass.PrintTextToOutput(TextOutput, "SD logging interval changed.");
        }
 private void PositionTextBox_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.Key != Key.Return)
     {
         return;
     }
     TxData[0] = Const.ChangeSettingsCommand;
     TxData[1] = Const.sPositionNum;
     if (byte.TryParse(PositionTextBox.Text, out TxData[4]) == false)
     {
         DataHanlderClass.PrintTextToOutput(TextOutput, "Change timer value failed! Data incorrect.");
         return;
     }
     if (TxData[4] > 16)
     {
         return;
     }
     HID_Write(TxData);
     DataHanlderClass.PrintTextToOutput(TextOutput, "Leveling position changed.");
 }
 private void Button_Click_1(object sender, RoutedEventArgs e)
 {
     DataHanlderClass.PrintTextToOutput(MW.TextOutput, "", true);
 }