本文整理汇总了C#中Windows.Devices.Sensors.Accelerometer类的典型用法代码示例。如果您正苦于以下问题:C# Accelerometer类的具体用法?C# Accelerometer怎么用?C# Accelerometer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Accelerometer类属于Windows.Devices.Sensors命名空间,在下文中一共展示了Accelerometer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: ac_ReadingChanged
async void ac_ReadingChanged(Accelerometer sender, AccelerometerReadingChangedEventArgs args)
{
double x = args.Reading.AccelerationX * 100d;
double y = args.Reading.AccelerationY * 100d;
double z = args.Reading.AccelerationZ * 100d;
System.Diagnostics.Debug.WriteLine("X={0:NO},Y={1:NO},Z={2}", x, y, z);
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
{
if (Math.Abs(x) > 100d || Math.Abs(y) > 60d || Math.Abs(z) > 50d)
{
try
{
int imageIndex = new Random().Next(1, 5);
//this codes is going to read the image file from the storage that in the phone rather than in the computer.
Windows.Storage.StorageFile theFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri(string.Format("ms-appx:///Assets/f{0}.png", imageIndex), UriKind.Absolute));
BitmapImage bitmap = new BitmapImage();
bitmap.SetSource(await theFile.OpenReadAsync());
this.img.Source= bitmap;
}
catch (Exception e)
{
throw e;
}
}
});
}
开发者ID:fqncom,项目名称:tomcraporigami,代码行数:27,代码来源:MainPage.xaml.cs
示例2: ReadingChanged
private void ReadingChanged(Accelerometer sender, AccelerometerReadingChangedEventArgs args)
{
var reading = args.Reading;
Vector current = new Vector(reading.AccelerationX, reading.AccelerationY, reading.AccelerationZ);
var delta = new Vector(current.X - _previousValue.X, current.Y - _previousValue.Y, current.Z - _previousValue.Z);
_previousValue = current;
if (delta.Length() > 1.0) {
Dispatcher.BeginInvoke(() => {
statusTextBlock.Text = "receiving data from accelerometer.";
// Show the numeric values
xTextBlock.Text = "X: " + reading.AccelerationX.ToString("0.00");
yTextBlock.Text = "Y: " + reading.AccelerationY.ToString("0.00");
zTextBlock.Text = "Z: " + reading.AccelerationZ.ToString("0.00");
// Show the values graphically
xLine.X2 = xLine.X1 + reading.AccelerationX * 100;
yLine.Y2 = yLine.Y1 - reading.AccelerationY * 100;
zLine.X2 = zLine.X1 - reading.AccelerationZ * 50;
zLine.Y2 = zLine.Y1 + reading.AccelerationZ * 50;
});
}
}
开发者ID:henriquetomaz,项目名称:win8-samples,代码行数:26,代码来源:BeforeRx.xaml.cs
示例3: acc_ReadingChanged
void acc_ReadingChanged(Accelerometer sender, AccelerometerReadingChangedEventArgs args)
{
Dispatcher.BeginInvoke(() =>
{
accOut.Text = "Accelerometer: <" + args.Reading.AccelerationX + ", " + args.Reading.AccelerationY + ", " + args.Reading.AccelerationZ + ">";
});
}
开发者ID:hutchgard,项目名称:Materials,代码行数:7,代码来源:MainPage.xaml.cs
示例4: accelerometer_ReadingChanged
void accelerometer_ReadingChanged(Accelerometer sender, AccelerometerReadingChangedEventArgs args)
{
double magnitude = Math.Sqrt(
args.Reading.AccelerationX * args.Reading.AccelerationX +
args.Reading.AccelerationY * args.Reading.AccelerationY +
args.Reading.AccelerationZ * args.Reading.AccelerationZ);
if (magnitude > 1.01 && !stepping)
{
stepping = true;
steps += 1;
// Prevent a race condition of the last subscriber unsubscribing
// before we get to the null check.
EventHandler<int> handler = Stepped;
// Event will be null if there are no subscribers
if (handler != null)
{
handler(this, steps);
}
}
else if (magnitude < 1.0)
{
stepping = false;
}
}
开发者ID:tblue1994,项目名称:SoftwareEngineeringProject2015,代码行数:27,代码来源:Pedometer.cs
示例5: MainPage
public MainPage()
{
InitializeComponent();
// this.NavigationCacheMode = NavigationCacheMode.Required;
//DataEntry.saveAll();
//DataEntry.loadAll();
this.accelSensor = Accelerometer.GetDefault();
if (this.accelSensor != null) this.accelSensor.ReadingChanged += new TypedEventHandler<Accelerometer, AccelerometerReadingChangedEventArgs>(myAccelHandler);
this.compSensor = Compass.GetDefault();
if (this.compSensor != null) this.compSensor.ReadingChanged += new TypedEventHandler<Compass, CompassReadingChangedEventArgs>(myCompassHandler);
this.gyroSensor = Gyrometer.GetDefault();
if (this.gyroSensor != null) this.gyroSensor.ReadingChanged += new TypedEventHandler<Gyrometer, GyrometerReadingChangedEventArgs>(myGyroHandler);
this.incliSensor = Inclinometer.GetDefault();
if (this.incliSensor != null) this.incliSensor.ReadingChanged += new TypedEventHandler<Inclinometer, InclinometerReadingChangedEventArgs>(myIncliHandler);
this.lightSensor = LightSensor.GetDefault();
if (this.lightSensor != null) this.lightSensor.ReadingChanged += new TypedEventHandler<LightSensor, LightSensorReadingChangedEventArgs>(myLightHandler);
accelX = accelY = accelZ = comp = gyroX = gyroY = gyroZ = incliYaw = incliPitch = incliRoll = light = 0;
// Sample code to localize the ApplicationBar
//BuildLocalizedApplicationBar();
}
开发者ID:Faroukelkholy,项目名称:ActivityDetector,代码行数:28,代码来源:MainPage.xaml.cs
示例6: AccelerometerObservable
private AccelerometerObservable()
{
_accel = Accelerometer.GetDefault();
#region + Event Subscriptions +
Action<ReadingChangedHandler> subscribeEvent =
h => {
_accel.ReadingChanged += h;
if (_accel.ReportInterval < _reportInterval)
_accel.ReportInterval = _reportInterval;
};
Action<ReadingChangedHandler> unsubscribeEvent =
h => {
_accel.ReadingChanged -= h;
_accel.ReportInterval = 0;
};
#endregion
if (_accel != null) {
_reportInterval = _accel.MinimumReportInterval;
if (_reportInterval < MIN_REPORT_INTERVAL)
_reportInterval = MIN_REPORT_INTERVAL;
_accelObs =
Observable.FromEventPattern<ReadingChangedHandler, AccelerometerReadingChangedEventArgs>
(subscribeEvent, unsubscribeEvent)
.Select(x => ToVector(x.EventArgs.Reading))
.Publish()
.RefCount();
}
else {
_accelObs = Observable.Empty<Vector>();
}
}
开发者ID:henriquetomaz,项目名称:win8-samples,代码行数:35,代码来源:AccelerometerObservable.cs
示例7: InputManager
/// <summary>
/// Initialise the input system. Note that accelerometer input defaults to off.
/// </summary>
/// <param name="game"></param>
public InputManager(Project2Game game) : base(game)
{
// initialisation
useMouseDelta = false;
accelerometerEnabled = false;
mouseDelta = new Vector2();
keyboardManager = new KeyboardManager(game);
mouseManager = new MouseManager(game);
pointerManager = new PointerManager(game);
keyMapping = new KeyMapping();
// get the accelerometer. Returns null if no accelerometer found
accelerometer = Accelerometer.GetDefault();
window = Window.Current.CoreWindow;
// Set up the gesture recognizer. In this game, it only responds to TranslateX, TranslateY and Tap events
gestureRecognizer = new Windows.UI.Input.GestureRecognizer();
gestureRecognizer.GestureSettings = GestureSettings.ManipulationTranslateX |
GestureSettings.ManipulationTranslateY | GestureSettings.Tap;
// Register event handlers for pointer events
window.PointerPressed += OnPointerPressed;
window.PointerMoved += OnPointerMoved;
window.PointerReleased += OnPointerReleased;
// automatically enable accelerometer if we have one
this.AccelerometerEnabled(true);
this.MouseDeltaEnabled(true);
}
开发者ID:nuclearpidgeon,项目名称:graphicsproj2,代码行数:36,代码来源:InputManager.cs
示例8: CalculateDeviceRotation
private async void CalculateDeviceRotation(Accelerometer sender, AccelerometerReadingChangedEventArgs args)
{
// Compute the rotation angle based on the accelerometer's position
var angle = Math.Atan2(args.Reading.AccelerationY, args.Reading.AccelerationX) * toDegrees;
// Since our arrow points upwards insted of the right, we rotate the coordinate system by 90 degrees
angle += 90;
// Ensure that the range of the value is between [0, 360)
if (angle < 0)
{
angle += 360;
}
rotationAngle = angle;
// Update the UI with the new value
await Dispatcher.RunAsync(
CoreDispatcherPriority.Normal,
() =>
{
deviceRotation.Text = rotationAngle.ToString();
UpdateArrowForRotation();
});
}
开发者ID:mbin,项目名称:Win81App,代码行数:25,代码来源:Scenario2.xaml.cs
示例9: AccelerationViewModel
public AccelerationViewModel(AgresivityCalculator calculator)
{
ReportInterval = 5;
_calculator = calculator;
_accelerometer = Accelerometer.GetDefault();
_accelerometer.ReportInterval = ReportInterval;
}
开发者ID:stonemonkey,项目名称:AutoMate,代码行数:7,代码来源:AccelerationViewModel.cs
示例10: Run
/// <summary>
/// Background task entry point.
/// </summary>
/// <param name="taskInstance"></param>
public void Run(IBackgroundTaskInstance taskInstance)
{
Accelerometer = Accelerometer.GetDefault();
if (null != Accelerometer)
{
SampleCount = 0;
// Select a report interval that is both suitable for the purposes of the app and supported by the sensor.
uint minReportIntervalMsecs = Accelerometer.MinimumReportInterval;
Accelerometer.ReportInterval = minReportIntervalMsecs > 16 ? minReportIntervalMsecs : 16;
// Subscribe to accelerometer ReadingChanged events.
Accelerometer.ReadingChanged += new TypedEventHandler<Accelerometer, AccelerometerReadingChangedEventArgs>(ReadingChanged);
// Take a deferral that is released when the task is completed.
Deferral = taskInstance.GetDeferral();
// Get notified when the task is canceled.
taskInstance.Canceled += new BackgroundTaskCanceledEventHandler(OnCanceled);
// Store a setting so that the app knows that the task is running.
ApplicationData.Current.LocalSettings.Values["IsBackgroundTaskActive"] = true;
}
}
开发者ID:RasmusTG,项目名称:Windows-universal-samples,代码行数:29,代码来源:Scenario1_BackgroundTask.cs
示例11: Accelerometer_ReadingChanged
private async void Accelerometer_ReadingChanged(Accelerometer sender, AccelerometerReadingChangedEventArgs args)
{
await toggleAccelerometer.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, new Windows.UI.Core.DispatchedHandler(() =>
{
var val = 0f;
if (togglePID.IsOn)
{
// Limit the accelerometer PID control to 500 RPM max
val = (float)args.Reading.AccelerationZ * -500f;
if (val > 500) val = 500;
if (val < 0) val = 0;
pid.SetPoint = (float)val;
Slider.Value = (int)val;
}
else
{
val = (float)args.Reading.AccelerationZ * -100f;
if (val > 100) val = 100;
if (val < 0) val = 0;
motor.Throttle = (double)val;
Slider.Value = (int)val * 12.0;
}
}));
}
开发者ID:ms-iot,项目名称:pid-control-system,代码行数:25,代码来源:MainPage.xaml.cs
示例12: MainPage
public MainPage()
{
InitializeComponent();
_accelerometer = Accelerometer.GetDefault();
_accelerometer.ReadingChanged += _accelerometer_ReadingChanged;
}
开发者ID:lhlima,项目名称:CollaborationProjects,代码行数:7,代码来源:MainPage.xaml.cs
示例13: accelerometer_Shaken
async void accelerometer_Shaken(Accelerometer sender, AccelerometerShakenEventArgs args)
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
shakes++;
ShakeCount.Text = shakes.ToString();
});
}
开发者ID:Jxperez,项目名称:31DaysOfWindows8,代码行数:8,代码来源:MainPage.xaml.cs
示例14: accelerometer_ReadingChanged
void accelerometer_ReadingChanged(Accelerometer sender, AccelerometerReadingChangedEventArgs args)
{
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
accelerometerReading = args.Reading;
ShowData();
});
}
开发者ID:peepo3663,项目名称:WindowsPhone8,代码行数:8,代码来源:MainPage.xaml.cs
示例15: accelerometer_Shaken
void accelerometer_Shaken(Accelerometer sender, AccelerometerShakenEventArgs args)
{
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
statusTextBlock.Text = "手机在摇动 时间点"
+ args.Timestamp.DateTime.ToLongTimeString();
});
}
开发者ID:peepo3663,项目名称:WindowsPhone8,代码行数:8,代码来源:MainPage.xaml.cs
示例16: Accelerometer_Shaken
async void Accelerometer_Shaken(Accelerometer sender, AccelerometerShakenEventArgs args)
{
var dispatcher = App.Dispatcher;
await dispatcher.RunAsync(CoreDispatcherPriority.Normal, (DispatchedHandler)(() =>
{
_shaken(this, args);
}));
}
开发者ID:schmidp,项目名称:GettingStartedWithMetroApps,代码行数:8,代码来源:AccelerometerAdapter.cs
示例17: Windows8AccelerometerChanged
/// <summary>
/// Reads in the Accelerometer data for windows8 devices.
/// </summary>
private void Windows8AccelerometerChanged(Accelerometer sender, AccelerometerReadingChangedEventArgs args)
{
// For whatever reason, this is insconsistent with windows phone...
// so lets swap the reading here.
_currentReading.X = -(float)args.Reading.AccelerationY;
_currentReading.Y = -(float)args.Reading.AccelerationX;
_currentReading.Z = -(float)args.Reading.AccelerationZ;
}
开发者ID:roydor,项目名称:DancePartyXna,代码行数:11,代码来源:AccelerometerWrapperWindows8.cs
示例18: Stop
public void Stop()
{
if (_accelerometer == null)
{
throw new MvxException("Accelerometer not started");
}
_accelerometer.ReadingChanged -= AccelerometerOnReadingChanged;
_accelerometer = null;
}
开发者ID:jihlee,项目名称:BallControl,代码行数:9,代码来源:SimpleAccelerometer.cs
示例19: OnAccelerometerReadingChanged
private void OnAccelerometerReadingChanged(Accelerometer sender, AccelerometerReadingChangedEventArgs args)
{
Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
this.tbx.Text = string.Format("X: {0}", args.Reading.AccelerationX);
this.tby.Text = string.Format("Y: {0}", args.Reading.AccelerationY);
this.tbz.Text = string.Format("Z: {0}", args.Reading.AccelerationZ);
});
}
开发者ID:TelerikAcademy,项目名称:Windows-Applications,代码行数:9,代码来源:MainPage.xaml.cs
示例20: accelerometer_ReadingChanged
async void accelerometer_ReadingChanged(Accelerometer sender, AccelerometerReadingChangedEventArgs args)
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
XValue.Text = args.Reading.AccelerationX.ToString();
YValue.Text = args.Reading.AccelerationY.ToString();
ZValue.Text = args.Reading.AccelerationZ.ToString();
});
}
开发者ID:BeyondVincent,项目名称:WindowsStoreAppCode,代码行数:9,代码来源:MainPage.xaml.cs
注:本文中的Windows.Devices.Sensors.Accelerometer类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论