/// <summary>
 /// Initializes a new instance of the RegisterTreeNodeComboBox class.
 /// </summary>
 /// <param name="registerAddress">
 /// Fixed register address of tree node. See x_IMU_API.RegisterAddresses.
 /// </param>
 /// <param name="text">
 /// The text of the new tree node.
 /// </param>
 public RegisterTreeNodeComboBox(x_IMU_API.RegisterAddresses registerAddress, string text)
     : base(registerAddress, text)
 {
     ComboBox = new ComboBox();
     ComboBox.Leave += new EventHandler(delegate { ComboBox.Parent.Controls.Remove(ComboBox); });
     ComboBox.DropDownClosed += new EventHandler(delegate { ComboBox.Parent.Controls.Remove(ComboBox); });
 }
 /// <summary>
 /// DigitalIODataReceived to set mouse button states.
 /// </summary>
 /// <remarks>
 /// Sets sampledCount to briefly disable cursor position updates after button down.
 /// </remarks>
 static void xIMUserial_DigitalIODataReceived(object sender, x_IMU_API.DigitalIOdata e)
 {
     if (prevState.AX1 ^ e.State.AX1)    // if left button state changed
     {
         if (e.State.AX1)
         {
             SendInputClass.MouseEvent((int)SendInputClass.MOUSEEVENTF.LEFTDOWN, 0, 0, 0);
             sampledCount = ((x_IMU_API.xIMUserial)sender).PacketsReadCounter.QuaternionDataPackets;
         }
         else
         {
             SendInputClass.MouseEvent((int)SendInputClass.MOUSEEVENTF.LEFTUP, 0, 0, 0);
         }
     }
     if (prevState.AX0 ^ e.State.AX0)    // if right button state changed
     {
         if (e.State.AX0)
         {
             SendInputClass.MouseEvent((int)SendInputClass.MOUSEEVENTF.RIGHTDOWN, 0, 0, 0);
             sampledCount = ((x_IMU_API.xIMUserial)sender).PacketsReadCounter.QuaternionDataPackets;
         }
         else
         {
             SendInputClass.MouseEvent((int)SendInputClass.MOUSEEVENTF.RIGHTUP, 0, 0, 0);
         }
     }
     prevState = e.State;
 }
예제 #3
0
 /// <summary>
 /// Applys register to data to associated RegisterTreeNode.
 /// </summary>
 /// <param name="registerAddress">
 /// Register address of tree node. See x_IMU_API.RegisterAddresses.
 /// </param>
 /// <param name="isConfirmed">
 /// A value indicating if the register data being applied should be displayed as confirmed.
 /// </param>
 public void ApplyRegisterData(x_IMU_API.RegisterData registerData, bool isConfirmed)
 {
     RegisterTreeNode registerTreeNode = FindRegisterTreeNode(registerData.Address);
     if (registerTreeNode == null)
     {
         throw new Exception("Register address does have an associated RegisterTreeNode.");
     }
     registerTreeNode.SetFromRegisterData(registerData, isConfirmed);
     RefreshPending = true;
 }
        /// <summary>
        /// Shows <see cref="CSVfileWriter"/> packet counts and file names in <see cref="PassiveMessageBox"/>.
        /// </summary>
        /// <param name="CSVfileWriter">
        /// <see cref="CSVfileWriter"/> object.
        /// </param>
        /// <param name="caption">
        /// Caption of <see cref="PassiveMessageBox"/>.
        /// </param>
        public static void Show(x_IMU_API.CSVfileWriter CSVfileWriter, string caption)
        {
            string dialogText = "No files were created.";

            if (CSVfileWriter.FilesCreated.Length != 0)
            {
                int maxWidth = 0;

                // Measure x_IMU_API.PacketCount property names with a non-zero value for tab spacing
                foreach (PropertyInfo propertyInfo in CSVfileWriter.PacketsWrittenCounter.GetType().GetProperties())
                {
                    if ((int)propertyInfo.GetValue(CSVfileWriter.PacketsWrittenCounter, null) > 0)
                    {
                        int width = TextRenderer.MeasureText(propertyInfo.Name + ":", Control.DefaultFont).Width;
                        maxWidth = width > maxWidth ? width : maxWidth;
                    }
                }

                // Add all property names with a non-zero to dialog text with tab spacing.
                dialogText = "";
                foreach (PropertyInfo propertyInfo in CSVfileWriter.PacketsWrittenCounter.GetType().GetProperties())
                {
                    if ((int)propertyInfo.GetValue(CSVfileWriter.PacketsWrittenCounter, null) > 0)
                    {
                        string lineText = propertyInfo.Name + ":";
                        while (TextRenderer.MeasureText(lineText, Control.DefaultFont).Width < maxWidth)
                        {
                            lineText += " ";
                        }
                        dialogText += lineText + "\t" + propertyInfo.GetValue(CSVfileWriter.PacketsWrittenCounter, null).ToString() + Environment.NewLine;
                    }
                }

                // Add list of file names to dialog text
                dialogText += Environment.NewLine + "Files created:" + Environment.NewLine;
                foreach (string fileName in CSVfileWriter.FilesCreated)
                {
                    dialogText += fileName + Environment.NewLine;
                }
                if (CSVfileWriter.FilesCreated.Length == 0)
                {
                    dialogText += "None.";
                }
            }

            // Display dialog text in PassiveMessageBox
            PassiveMessageBox.Show(dialogText, caption, MessageBoxIcon.Information);
        }
 /// <summary>
 /// Calibrated inertial/magnetic data received event to update objects.
 /// </summary>
 static void xIMUserial_CalInertialMagneticDataReceived(object sender, x_IMU_API.CalInertialAndMagneticData e)
 {
     ballTracking.Gyroscope = new float[] { (e.Gyroscope[0] / 360) * (float)(2 * Math.PI), (e.Gyroscope[1] / 360) * (float)(2 * Math.PI), (e.Gyroscope[2] / 360) * (float)(2 * Math.PI) };
     ballTracking.Update();
     if (form_3Dcuboid != null)
     {
         form_3Dcuboid.TranslationVector = new float[] { ballTracking.Position[0], ballTracking.Position[1], 0.0f };
         form_3Dcuboid.RotationMatrix = ballTracking.RotationMatrix;
     }
     else
     {
         SendInputClass.MouseEvent((int)(SendInputClass.MOUSEEVENTF.MOVE), (int)(ballTracking.Velocity[0] * 25.0), (int)(ballTracking.Velocity[1] * -25.0f), 0);
         if (Math.Sqrt(e.Accelerometer[0] * e.Accelerometer[0] + e.Accelerometer[1] * e.Accelerometer[1] + e.Accelerometer[2] * e.Accelerometer[2]) > 5.0)       // if accelerometer magnitude > 5 g
         {
             SendInputClass.MouseEvent((int)SendInputClass.MOUSEEVENTF.LEFTDOWN, 0, 0, 0);
             SendInputClass.MouseEvent((int)SendInputClass.MOUSEEVENTF.LEFTUP, 0, 0, 0);
         }
     }
 }
예제 #6
0
 /// <summary>
 /// Writes register data to xIMUfile object for each child nodes recursively from a root tree node.
 /// </summary>
 /// <param name="xIMUfile">
 /// xIMUfile object to write to.
 /// </param>
 /// <param name="rootNode">
 /// Root node of all child nodes for which a write register packet will be written.
 /// </param>
 private void WriteAllChildRegisterTreeNode(x_IMU_API.xIMUfile xIMUfile, TreeNode rootNode)
 {
     foreach (TreeNode childNode in rootNode.Nodes)
     {
         if (childNode is RegisterTreeNode)
         {
             try
             {
                 xIMUfile.WriteWriteRegisterPacket((childNode as RegisterTreeNode).ConvertToRegisterData());
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
         else if (childNode.Nodes.Count > 0)
         {
             WriteAllChildRegisterTreeNode(xIMUfile, childNode);    // for all child nodes recursively
         }
     }
 }
예제 #7
0
 /// <summary>
 /// PortScanner AsyncScanProgressChanged event updates progress dialog and checks for user cancellation.
 /// </summary>
 private void portScanner_AsyncScanProgressChanged(object sender, x_IMU_API.AsyncScanProgressChangedEventArgs e)
 {
     this.EndInvoke(this.BeginInvoke(new MethodInvoker(delegate
     {
         if (autoConnectProgressDialog.HasUserCancelled)
         {
             ((x_IMU_API.PortScanner)sender).CancelAnsycScan();
         }
         else
         {
             autoConnectProgressDialog.Line3 = e.ProgressMessage;
         }
     })));
 }
예제 #8
0
 /// <summary>
 /// DigitalIOpanel OutputChanged event sends digital I/O packet.
 /// </summary>
 private void digitalIOpanel_OutputChanged(object sender, x_IMU_API.DigitalPortBits e)
 {
     try
     {
         xIMUserial.SendDigitalIOpacket(new x_IMU_API.DigitalIOdata(e));
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
예제 #9
0
 /// <summary>
 /// Register data received event parses data to registerDataBuffer and displays warning if incompatible firmware version detected.
 /// </summary>
 private void xIMUserial_RegisterDataReceived(object sender, x_IMU_API.RegisterData e)
 {
     if (!Enum.IsDefined(typeof(x_IMU_API.RegisterAddresses), (int)e.Address))
     {
         PassiveMessageBox.Show("Register data received with unknown address 0x" + string.Format("{0:X4}", (ushort)e.Address) + ".", "Error", MessageBoxIcon.Error);
     }
     else
     {
         registerDataBuffer[(int)e.Address] = e;
         if ((e.Address == x_IMU_API.RegisterAddresses.FirmwareVersionMajorNum) && (!Enum.IsDefined(typeof(x_IMU_API.CompatibleFirmwareVersions), (int)e.Value)))
         {
             PassiveMessageBox.Show("The detected x-IMU firmware version is not fully compatible with this version of the x-IMU GUI and API." + Environment.NewLine + Environment.NewLine +
                                    "Please download and install the latest x-IMU software and firmware available from www.x-io.co.uk.", "Warning", MessageBoxIcon.Warning);
         }
     }
 }
예제 #10
0
 /// <summary>
 /// xIMUserial RawBatteryAndThermometerDataReceived event updates oscilloscope.
 /// </summary>
 private void xIMUserial_RawBatteryAndThermometerDataReceived(object sender, x_IMU_API.RawBatteryAndThermometerData e)
 {
     //batteryOscilloscope.Caption = "Raw Battery Data (lsb)";
     //thermometerOscilloscope.Caption = "Raw Thermometer Data (lsb)";
     batteryOscilloscope.AddScopeData(e.BatteryVoltage, 0.0f, 0.0f);
     thermometerOscilloscope.AddScopeData(e.Thermometer, 0.0f, 0.0f);
 }
예제 #11
0
 /// <summary>
 /// xIMUserial CalInertialAndMagneticDataReceived event updates oscilloscope.
 /// </summary>
 private void xIMUserial_CalInertialAndMagneticDataReceived(object sender, x_IMU_API.CalInertialAndMagneticData e)
 {
     gyroscopeOscilloscope.Caption = "Calibrated Gyroscope Data (˚/s)";
     accelerometerOscilloscope.Caption = "Calibrated Accelerometer Data (g)";
     magnetometerOscilloscope.Caption = "Calibrated Magnetometer Data (G)";
     gyroscopeOscilloscope.AddScopeData(e.Gyroscope[0], e.Gyroscope[1], e.Gyroscope[2]);
     accelerometerOscilloscope.AddScopeData(e.Accelerometer[0], e.Accelerometer[1], e.Accelerometer[2]);
     magnetometerOscilloscope.AddScopeData(e.Magnetometer[0], e.Magnetometer[1], e.Magnetometer[2]);
 }
예제 #12
0
 /// <summary>
 /// xIMUserial CalBatteryAndThermometerDataReceived event updates oscilloscope.
 /// </summary>
 private void xIMUserial_CalBatteryAndThermometerDataReceived(object sender, x_IMU_API.CalBatteryAndThermometerData e)
 {
     batteryOscilloscope.Caption = "Calibrated Battery Data (V)";
     thermometerOscilloscope.Caption = "Calibrated Thermometer Data (˚C)";
     batteryOscilloscope.AddScopeData(e.BatteryVoltage, 0.0f, 0.0f);
     thermometerOscilloscope.AddScopeData(e.Thermometer, 0.0f, 0.0f);
 }
예제 #13
0
 /// <summary>
 /// xIMUfile xIMUdataRead event writes xIMUdata to file using binaryFileConverterCSVfileWriter.
 /// </summary>
 void xIMUfile_xIMUdataRead(object sender, x_IMU_API.xIMUdata e)
 {
     try
     {
         binaryFileConverterCSVfileWriter.WriteData(e);
     }
     catch { }
 }
예제 #14
0
 /// <summary>
 /// xIMUfile AsyncReadProgressChanged event updates binaryFileConverterProgressDialog and checks for user cancellation.
 /// </summary>
 void xIMUfile_AsyncReadProgressChanged(object sender, x_IMU_API.AsyncReadProgressChangedEventArgs e)
 {
     this.EndInvoke(this.BeginInvoke(new MethodInvoker(delegate
     {
         if (binaryFileConverterProgressDialog.HasUserCancelled)
         {
             ((x_IMU_API.xIMUfile)sender).CancelAnsycRead();
         }
         else
         {
             binaryFileConverterProgressDialog.Value = (uint)e.ProgressPercentage;
             binaryFileConverterProgressDialog.Line3 = e.ProgressMessage;
         }
     })));
 }
예제 #15
0
 /// <summary>
 /// xIMUfile AsyncReadCompleted event closes files, displays CSVfileWriterResults dialog and re-enables form controls.
 /// </summary>
 void xIMUfile_AsyncReadCompleted(object sender, x_IMU_API.AsyncReadCompletedEventArgs e)
 {
     binaryFileConverterCSVfileWriter.CloseFiles();
     ((x_IMU_API.xIMUfile)sender).Close();
     if (!e.Cancelled)
     {
         CSVfileWriterResults.Show(binaryFileConverterCSVfileWriter, "Binary File Conversion Results");
     }
     this.EndInvoke(this.BeginInvoke(new MethodInvoker(delegate
     {
         button_convertBinaryFileConvert.Text = "Convert";
         textBox_convertBinaryFileFilePath.Enabled = true;
         button_convertBinaryFileConvert.Enabled = true;
         button_convertBinaryFileBrowse.Enabled = true;
         binaryFileConverterProgressDialog.CloseDialog();
     })));
 }
예제 #16
0
 /// <summary>
 /// xIMUserial RawADXL345busDataReceived event updates oscilloscope.
 /// </summary>
 void xIMUserial_RawADXL345busDataReceived(object sender, x_IMU_API.RawADXL345busData e)
 {
     ADXL345_Aoscilloscope.Caption = "Raw ADXL234 A Data (lsb)";
     ADXL345_Boscilloscope.Caption = "Raw ADXL234 B Data (lsb)";
     ADXL345_Coscilloscope.Caption = "Raw ADXL234 C Data (lsb)";
     ADXL345_Doscilloscope.Caption = "Raw ADXL234 D Data (lsb)";
     ADXL345_Aoscilloscope.AddScopeData(e.ADXL345_A[0], e.ADXL345_A[1], e.ADXL345_A[2]);
     ADXL345_Boscilloscope.AddScopeData(e.ADXL345_B[0], e.ADXL345_B[1], e.ADXL345_B[2]);
     ADXL345_Coscilloscope.AddScopeData(e.ADXL345_C[0], e.ADXL345_C[1], e.ADXL345_C[2]);
     ADXL345_Doscilloscope.AddScopeData(e.ADXL345_D[0], e.ADXL345_D[1], e.ADXL345_D[2]);
 }
예제 #17
0
 /// <summary>
 /// xIMUserial RawAnalogueInputDataReceived event updates oscilloscope.
 /// </summary>
 void xIMUserial_RawAnalogueInputDataReceived(object sender, x_IMU_API.RawAnalogueInputData e)
 {
     analogueInputAX0AX1oscilloscope.Caption = "Raw Analogue Input AX0 AX1 Data (lsb)";
     analogueInputAX2AX3oscilloscope.Caption = "Raw Analogue Input AX2 AX3 Data (lsb)";
     analogueInputAX4AX5oscilloscope.Caption = "Raw Analogue Input AX4 AX5 Data (lsb)";
     analogueInputAX6AX7oscilloscope.Caption = "Raw Analogue Input AX6 AX7 Data (lsb)";
     analogueInputAX0AX1oscilloscope.AddScopeData(e.AX0, e.AX1, 0.0f);
     analogueInputAX2AX3oscilloscope.AddScopeData(e.AX2, e.AX3, 0.0f);
     analogueInputAX4AX5oscilloscope.AddScopeData(e.AX4, e.AX5, 0.0f);
     analogueInputAX6AX7oscilloscope.AddScopeData(e.AX6, e.AX7, 0.0f);
 }
예제 #18
0
 /// <summary>
 /// xIMUserial xIMUdataReceived event writes xIMUdata to file using hardIronCalCSVfileWriter.
 /// </summary>
 void xIMUserial_CalInertialAndMagneticDataReceivedHardIronCal(object sender, x_IMU_API.CalInertialAndMagneticData e)
 {
     if (hardIronCalCSVfileWriter != null)
     {
         try
         {
             hardIronCalCSVfileWriter.WriteCalInertialAndMagneticData(e);
         }
         catch { }
     }
 }
예제 #19
0
 /// <summary>
 /// xIMUserial RawInertialAndMagneticDataReceived event updates oscilloscope.
 /// </summary>
 private void xIMUserial_RawInertialAndMagneticDataReceived(object sender, x_IMU_API.RawInertialAndMagneticData e)
 {
     gyroscopeOscilloscope.Caption = "Raw Gyroscope Data (lsb)";
     accelerometerOscilloscope.Caption = "Raw Accelerometer Data (lsb)";
     magnetometerOscilloscope.Caption = "Raw Magnetometer Data (lsb)";
     gyroscopeOscilloscope.AddScopeData(e.Gyroscope[0], e.Gyroscope[1], e.Gyroscope[2]);
     accelerometerOscilloscope.AddScopeData(e.Accelerometer[0], e.Accelerometer[1], e.Accelerometer[2]);
     magnetometerOscilloscope.AddScopeData(e.Magnetometer[0], e.Magnetometer[1], e.Magnetometer[2]);
 }
예제 #20
0
 /// <summary>
 /// xIMUserial CommandDataReceived event displays message in PassiveMessageBox if enabled by CheckBox.
 /// </summary>
 private void xIMUserial_CommandDataReceived(object sender, x_IMU_API.CommandData e)
 {
     if (checkBox_displayCommandConfirmations.Checked)
     {
         PassiveMessageBox.Show("Command confirmed: " + e.GetMessage(), "Message From x-IMU", MessageBoxIcon.Information);
     }
 }
예제 #21
0
 /// <summary>
 /// xIMUserial xIMUdataReceived event writes xIMUdata to file using dataLoggerCSVfileWriter.
 /// </summary>
 void xIMUserial_xIMUdataReceived(object sender, x_IMU_API.xIMUdata e)
 {
     if (dataLoggerCSVfileWriter != null)
     {
         try
         {
             dataLoggerCSVfileWriter.WriteData(e);
         }
         catch { }
     }
 }
예제 #22
0
 /// <summary>
 /// xIMUserial DateTimeDataReceived event parses data to dateTimeDataBuffer. 
 /// </summary>
 private void xIMUserial_DateTimeDataReceived(object sender, x_IMU_API.DateTimeData e)
 {
     dateTimeDataBuffer = e;
 }
예제 #23
0
 /// <summary>
 /// PortScanner AsyncScanCompleted event opens x-IMU serial port if successful.
 /// </summary>
 private void portScanner_AsyncScanCompleted(object sender, x_IMU_API.AsyncScanCompletedEventArgs e)
 {
     try
     {
         if (e.Cancelled)
         {
             throw new Exception();
         }
         this.EndInvoke(this.BeginInvoke(new MethodInvoker(delegate
         {
             comboBox_portName.Text = e.PortAssignments[0].PortName;
             OpenPort();
             autoConnectProgressDialog.CloseDialog();
         })));
         PassiveMessageBox.Show("Connected to x-IMU " + e.PortAssignments[0].DeviceID + " on " + e.PortAssignments[0].PortName + ".", "Information", MessageBoxIcon.Information);
     }
     catch
     {
         this.EndInvoke(this.BeginInvoke(new MethodInvoker(delegate
         {
             ClosePort();
             autoConnectProgressDialog.CloseDialog();
         })));
     }
 }
예제 #24
0
 /// <summary>
 /// xIMUserial DigitalIODataReceived event parses DigitalIOdata to DigitalIOpanel.
 /// </summary>
 private void xIMUserial_DigitalIODataReceived(object sender, x_IMU_API.DigitalIOdata e)
 {
     form_digitalIOpanel.Direction = e.Direction;
     form_digitalIOpanel.State = e.State;
 }
예제 #25
0
 /// <summary>
 /// PWMoutputPanel ValuesChanged event to send PWMoutputData packet.
 /// </summary>
 void PWMoutputPanel_ValuesChanged(object sender, x_IMU_API.PWMoutputData e)
 {
     try
     {
         xIMUserial.SendPWMoutputPacket(e);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
예제 #26
0
 /// <summary>
 /// xIMUserial ErrorDataReceived received event displays error in PassiveMessageBox.
 /// </summary>
 private void xIMUserial_ErrorDataReceived(object sender, x_IMU_API.ErrorData e)
 {
     PassiveMessageBox.Show("Error: " + e.GetMessage(), "Message From x-IMU", MessageBoxIcon.Error);
 }
예제 #27
0
 /// <summary>
 /// Shows <see cref="CSVfileWriter"/> packet counts and file names in <see cref="PassiveMessageBox"/>.
 /// </summary>
 /// <param name="CSVfileWriter">
 /// <see cref="CSVfileWriter"/> object.
 /// </param>
 public static void Show(x_IMU_API.CSVfileWriter CSVfileWriter)
 {
     Show(CSVfileWriter, "CSVfileWriterResults");
 }
예제 #28
0
 /// <summary>
 /// xIMUserial PWMoutputDataReceived event parses PWMoutputData to PWMoutputPanel.
 /// </summary>
 void xIMUserial_PWMoutputDataReceived(object sender, x_IMU_API.PWMoutputData e)
 {
     form_PWMoutputPanel.PWMoutputData = e;
 }
예제 #29
0
파일: main.cs 프로젝트: liqul/imu-demo
 static void xIMUserial_CalInertialAndMagneticDataReceived_updateIMU(object sender, x_IMU_API.CalInertialAndMagneticData e)
 {
     AHRS.Update(deg2rad(e.Gyroscope[0]), deg2rad(e.Gyroscope[1]), deg2rad(e.Gyroscope[2]), e.Accelerometer[0], e.Accelerometer[1], e.Accelerometer[2]);
 }
예제 #30
0
 /// <summary>
 /// xIMUserial QuaternionDataReceived event updates oscilloscope.
 /// </summary>
 private void xIMUserial_QuaternionDataReceived(object sender, x_IMU_API.QuaternionData e)
 {
     float[] euler = e.ConvertToEulerAngles();
     eulerAnglesOscilloscope.Caption = "Euler Angles Data (˚)";
     eulerAnglesOscilloscope.AddScopeData(euler[0], euler[1], euler[2]);
     form_3Dcuboid.RotationMatrix = e.ConvertToRotationMatrix();
 }