Esempio n. 1
0
        /// <summary>
        /// Basic ping function the check if the device is responding
        /// </summary>
        /// <param name="busDevice"></param>
        /// <returns></returns>
        public static async Task <bool> PingDevice(BusDevice busDevice)
        {
            try
            {
                Byte[] ba = await busDevice.PropertyRead(0x00, 0x01);

                UInt16 ui = BitConverter.ToUInt16(ba, 0);
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Esempio n. 2
0
        private static async Task <RawMetaData> GetRawDeviceMetadata(BusDevice busDevice, Dictionary <string, RawKnxDeviceMetadata> pReadlist, int throttling = 300)
        {
            // Sanity Checks
            // Read 0x00 0x01, we are expecting a zero here per KNX Standard
            Byte[] ba = await busDevice.PropertyRead(0x00, 0x01);

            UInt16 ui = BitConverter.ToUInt16(ba, 0);

            Byte[] ba2 = await busDevice.PropertyRead(0x00, 0x02);

            string s = ASCIIEncoding.ASCII.GetString(ba2);



            RawMetaData rawData = new RawMetaData(RawMetaData.ReadListDefinition.Empty);

            rawData.ReadList = pReadlist;

            foreach (RawKnxDeviceMetadata kvp in rawData.ReadList.Values)
            {
                Thread.Sleep(throttling);
                kvp.TriedReading = true;
                try
                {
                    Byte[] baValue = await busDevice.PropertyRead <byte[]>((Byte)kvp.ObjectId, (Byte)kvp.ValueId);

                    kvp.ReadSuccessful   = true;
                    kvp.RawPropertyValue = baValue;
                }
                catch (Exception Ex)
                {
                    Console.WriteLine(Ex.ToString());
                    kvp.ReadSuccessful = false;
                }
            }

            return(rawData);
        }
Esempio n. 3
0
        public Options(BusDevice bus_device, int deviceNum)
        {
            InitializeComponent();
            device    = deviceNum;
            scpDevice = bus_device;
            ledColor color = Global.loadColor(device);

            redBar.Value                 = color.red;
            greenBar.Value               = color.green;
            blueBar.Value                = color.blue;
            rumbleBoostBar.Value         = ScpControl.Global.loadRumbleBoost(device);
            batteryLed.Checked           = ScpControl.Global.getLedAsBatteryIndicator(device);
            flashLed.Checked             = ScpControl.Global.getFlashWhenLowBattery(device);
            touchCheckBox.Checked        = Global.getTouchEnabled(device);
            touchSensitivityBar.Value    = Global.getTouchSensitivity(device);
            leftTriggerMiddlePoint.Text  = Global.getLeftTriggerMiddle(device).ToString();
            rightTriggerMiddlePoint.Text = Global.getRightTriggerMiddle(device).ToString();
            ledColor lowColor = Global.loadLowColor(device);

            touchpadJitterCompensation.Checked = Global.getTouchpadJitterCompensation(device);
            lowerRCOffCheckBox.Checked         = Global.getLowerRCOff(device);
            tapSensitivityBar.Value            = Global.getTapSensitivity(device);
            scrollSensitivityBar.Value         = Global.getScrollSensitivity(device);
            flushHIDQueue.Checked         = Global.getFlushHIDQueue(device);
            advColorDialog.OnUpdateColor += advColorDialog_OnUpdateColor;

            // Force update of color choosers
            colorChooserButton.BackColor    = Color.FromArgb(color.red, color.green, color.blue);
            lowColorChooserButton.BackColor = Color.FromArgb(lowColor.red, lowColor.green, lowColor.blue);
            pictureBox.BackColor            = colorChooserButton.BackColor;
            lowRedValLabel.Text             = lowColor.red.ToString();
            lowGreenValLabel.Text           = lowColor.green.ToString();
            lowBlueValLabel.Text            = lowColor.blue.ToString();

            #region watch sixaxis data
            Timer sixaxisTimer = new Timer();
            sixaxisTimer.Tick +=
                (delegate
            {
                if (tBsixaxisGyroX == null)
                {
                    tBsixaxisGyroX = new TrackBar();
                    tBsixaxisGyroY = new TrackBar();
                    tBsixaxisGyroZ = new TrackBar();
                    tBsixaxisAccelX = new TrackBar();
                    tBsixaxisAccelY = new TrackBar();
                    tBsixaxisAccelZ = new TrackBar();
                    TrackBar[] allSixAxes = { tBsixaxisGyroX,  tBsixaxisGyroY,  tBsixaxisGyroZ,
                                              tBsixaxisAccelX, tBsixaxisAccelY, tBsixaxisAccelZ };
                    foreach (TrackBar t in allSixAxes)
                    {
                        ((System.ComponentModel.ISupportInitialize)(t)).BeginInit();
                        t.Anchor = AnchorStyles.Bottom;
                        t.AutoSize = false;
                        t.Enabled = false;
                        t.Minimum = -0x8000;
                        t.Maximum = 0x7fff;
                        t.Size = new Size(100, 19);
                        t.TickFrequency = 0x2000;     // calibrated to ~1G
                    }
                    // tBsixaxisGyroX
                    tBsixaxisGyroX.Location = new Point(450, 248);
                    tBsixaxisGyroX.Name = "tBsixaxisGyroX";
                    // tBsixaxisGyroY
                    tBsixaxisGyroY.Location = new Point(450, 248 + 20);
                    tBsixaxisGyroY.Name = "tBsixaxisGyroY";
                    // tBsixaxisGyroZ
                    tBsixaxisGyroZ.Location = new Point(450, 248 + 20 + 20);
                    tBsixaxisGyroZ.Name = "tBsixaxisGyroZ";
                    // tBsixaxisAccelX
                    tBsixaxisAccelX.Location = new Point(450 + 100 + 10, 248);
                    tBsixaxisAccelX.Name = "tBsixaxisAccelX";
                    // tBsixaxisAccelY
                    tBsixaxisAccelY.Location = new Point(450 + 100 + 10, 248 + 20);
                    tBsixaxisAccelY.Name = "tBsixaxisAccelY";
                    // tBsixaxisAccelZ
                    tBsixaxisAccelZ.Location = new Point(450 + 100 + 10, 248 + 20 + 20);
                    tBsixaxisAccelZ.Name = "tBsixaxisAccelZ";
                    foreach (TrackBar t in allSixAxes)
                    {
                        Controls.Add(t);
                        ((System.ComponentModel.ISupportInitialize)(t)).EndInit();
                    }
                }
                byte[] inputData = scpDevice.GetInputData(device);
                if (inputData != null)
                {
                    // MEMS gyro data is all calibrated to roughly -1G..1G for values -0x2000..0x1fff
                    // Enough additional acceleration and we are no longer mostly measuring Earth's gravity...
                    // We should try to indicate setpoints of the calibration when exposing this measurement....

                    // R side of controller upward
                    Int16 x = (Int16)((UInt16)(inputData[20] << 8) | inputData[21]);
                    tBsixaxisGyroX.Value = (x + tBsixaxisGyroX.Value * 2) / 3;
                    // touchpad and button face side of controller upward
                    Int16 y = (Int16)((UInt16)(inputData[22] << 8) | inputData[23]);
                    tBsixaxisGyroY.Value = (y + tBsixaxisGyroY.Value * 2) / 3;
                    // audio/expansion ports upward and light bar/shoulders/bumpers/USB port downward
                    Int16 z = (Int16)((UInt16)(inputData[24] << 8) | inputData[25]);
                    tBsixaxisGyroZ.Value = (z + tBsixaxisGyroZ.Value * 2) / 3;
                    // pitch upward/backward
                    Int16 pitch = (Int16)((UInt16)(inputData[14] << 8) | inputData[15]);
                    tBsixaxisAccelX.Value = (pitch + tBsixaxisAccelX.Value * 2) / 3;     // smooth out
                    // yaw leftward/counter-clockwise/turn to port or larboard side
                    Int16 yaw = (Int16)((UInt16)(inputData[16] << 8) | inputData[17]);
                    tBsixaxisAccelY.Value = (yaw + tBsixaxisAccelY.Value * 2) / 3;
                    // roll left/L side of controller down/starboard raising up
                    Int16 roll = (Int16)((UInt16)(inputData[18] << 8) | inputData[19]);
                    tBsixaxisAccelZ.Value = (roll + tBsixaxisAccelZ.Value * 2) / 3;
                }
            });
            sixaxisTimer.Interval = 1000 / 60;
            this.FormClosing     += delegate { sixaxisTimer.Stop(); };
            sixaxisTimer.Start();
            #endregion
        }