ườ Tr ọ ự ng ĐH Khoa H c T Nhiên TP.HCM
TRUNG TÂM TIN H CỌ
ậ
L p trình Windows Phone Module 4 – Bài 7: Sensors
ạ
ầ
GV Biên so n: Tr n Duy Thanh
2014
Nội dung
• Khái niệm Sensors
• Orientation – Cảm biến xoay màn hình
• Accelerometer – Cảm biến gia tốc kế
• Compass – Cảm biến la bàn số
• Gyroscope – Cảm biến con quay hồi chuyển
2
ế ị ả ứ Sensors Thi t b c m ng
1. Khái niệm Sensors
•
3
ế ị ả ứ Sensors Thi t b c m ng
2. Orientation – Cảm biến xoay màn hình
4
ế ị ả ứ Sensors Thi t b c m ng
3. Accelerometer – Cảm biến gia tốc kế
using Microsoft.Devices.Sensors;
using Microsoft.Xna.Framework;
5
ế ị ả ứ Sensors Thi t b c m ng
3. Accelerometer – Cảm biến gia tốc kế Accelerometer accelerometer = new Accelerometer();
accelerometer.TimeBetweenUpdates =
TimeSpan.FromMilliseconds(10);
accelerometer.CurrentValueChanged +=
accelerometer_CurrentValueChanged;
accelerometer.Start();
6
ế ị ả ứ Sensors Thi t b c m ng
3. Accelerometer – Cảm biến gia tốc kế private void accelerometer_CurrentValueChanged(
object sender,
SensorReadingEventArgs e)
{
AccelerometerReading reading = e.SensorReading;
Vector3 acceleration = reading.Acceleration;
//acceleration.X, acceleration.Y, acceleration.Z
}
7
ế ị ả ứ Sensors Thi t b c m ng
4. Compass – Cảm biến la bàn số
8
ế ị ả ứ Sensors Thi t b c m ng
4. Compass – Cảm biến la bàn số Compass compass=new Compass();
compass.TimeBetweenUpdates =
TimeSpan.FromMilliseconds(33);
compass.CurrentValueChanged +=
compass_CurrentValueChanged;
// for calibration.
compass.Calibrate += compass_Calibrate;
compass.Start();
9
ế ị ả ứ Sensors Thi t b c m ng
4. Compass – Cảm biến la bàn số private double headingAccuracy;
private void compass_CurrentValueChanged(
object sender,
SensorReadingEventArgs
double trueHeading = e.SensorReading.TrueHeading;
float headingRadians =
MathHelper.ToRadians((float)trueHeading);
headingAccuracy =
Math.Abs(e.SensorReading.HeadingAccuracy);
//xử lý headingAccuracy
10
}
ế ị ả ứ Sensors Thi t b c m ng
5. Gyroscope – Cảm biến con quay hồi chuyển
11
ế ị ả ứ Sensors Thi t b c m ng
5. Gyroscope – Cảm biến con quay hồi chuyển
private Gyroscope gyroscope;
gyroscope = new Gyroscope();
gyroscope.TimeBetweenUpdates =
TimeSpan.FromMilliseconds(20);
gyroscope.CurrentValueChanged +=
gyroscope_CurrentValueChanged;
12
ế ị ả ứ Sensors Thi t b c m ng
gyroscope.Start();
5. Gyroscope – Cảm biến con quay hồi chuyển
private void gyroscope_CurrentValueChanged(
object sender,
SensorReadingEventArgs e)
{
Vector3 currentRotationRate =
e.SensorReading.RotationRate;
currentRotationRate.X
currentRotationRate.Y
currentRotationRate.Z
}
13
ế ị ả ứ Sensors Thi t b c m ng
Thảo luận
14
ế ị ả ứ Sensors Thi t b c m ng