protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); /*PlotView view = FindViewById<PlotView>(Resource.Id.plot_view); * * GraphFactory<int> graphFactory = new GraphFactory<int>(); * view.Model = graphFactory.createGraph(GraphType.Line, new GraphEffect(), new List<int>());*/ SlidingDrawer menuSlider = FindViewById <SlidingDrawer>(Resource.Id.menuSlider); Button MenuButton1 = FindViewById <Button>(Resource.Id.MenuButton1); MenuButton1.Click += delegate { StartActivity(typeof(Question1)); menuSlider.Close(); }; }
private void SteerEnableSwitch_OnClick() { string SendData; int result; byte[] bytes; try { if (SteerEnableSwitch.Checked) { if (SensorMode == 0 || SensorMode == 2) //Xamarin { if (Accelerometer.IsMonitoring == false) { Accelerometer.Start(Speed); } } if (SensorMode == 1) //Android.Hardware { StartSensor(Android.Hardware.SensorType.Gravity); } if (SensorMode == 3) //Android.Hardware { StartSensor(Android.Hardware.SensorType.Accelerometer); StartSensor(Android.Hardware.SensorType.LinearAcceleration); } ////^^^^^^^^^^^^^^^^^^^^DEBUG List^^^^^^^^^^^^^^^^^^^^^^^^^^ //// 获取传感器管理器 //SensorManager sensorManager = (SensorManager)GetSystemService(SensorService); //// 获取全部传感器列表 //System.Collections.Generic.IList<Sensor> sensors = sensorManager.GetSensorList(SensorType.All); //String strLog = ""; //int i = 0; //foreach (Sensor item in sensors) //{ // strLog += (++i + "-" + item.Name + "\r\n"); //} //RunOnUiThread(() => textView3.Text = strLog); ////vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv } else { if (SensorMode == 0 || SensorMode == 2) //Xamarin { if (Accelerometer.IsMonitoring == true) { Accelerometer.Stop(); } } if (SensorMode == 1 || SensorMode == 3) //Android.Hardware { mSensorManager.UnregisterListener(this); } } while (SteerEnableSwitch.Checked) { RunOnUiThread(() => textView5.Text = AccelerometerData1); RunOnUiThread(() => textView1.Text = AccelerometerData2); //sThrottle = Throttle.Pressed ? 1 : 0; //sBrake = Brake.Pressed ? 1 : 0; sThrottle = 100 - Throttle.Top * 100 / cntThrottle.Height; sBrake = 100 - Brake.Top * 100 / cntBrake.Height; sAngle = GetWheelData(); //sClearAngle = btnClearAngle.Pressed ? 1 : 0; if (btnSet.Pressed) { sSet = -1; } else if (btnReset.Pressed) { sSet = 1; } else { sSet = 0; }; if (btnSetSrd.Pressed) { sSetSR = -1; } else if (btnSetSru.Pressed) { sSetSR = 1; } else { sSetSR = 0; }; //键盘控制 if (btnGearUp.Pressed) { sGear = 1; } else if (btnGearDown.Pressed) { sGear = -1; } else { sGear = 0; } //vJoy if (btnGearUp.Pressed) { sGearUp = 1; } else { sGearUp = 0; } if (btnGearDown.Pressed) { sGearDn = 1; } else { sGearDn = 0; } SendData = "A=" + sAngle + ",T=" + sThrottle + ",B=" + sBrake + ",Gu=" + sGearUp + ",Gd=" + sGearDn + ",G=" + sGear + ",S=" + sSet + ",SR=" + sSetSR; //",C=" + sClearAngle; //if (sGear != 0) sGear = 0; RunOnUiThread(() => textView4.Text = $" B={sBrake} T={sThrottle} A={sAngle.ToString("0.0")}"); if (IsConnected == true) { bytes = Encoding.Unicode.GetBytes(SendData + "0@"); result = Sct[1].Send(bytes); //textView4.Text = result.ToString(); } if (Throttle.Pressed == false) { RunOnUiThread(() => sldThrottle.Close()); } if (Brake.Pressed == false) { RunOnUiThread(() => sldBrake.Close()); } Thread.Sleep(2); } } catch (Exception ex) { RunOnUiThread(() => textView2.Text = ex.Message); } }