-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLightSensor.cs
More file actions
69 lines (67 loc) · 1.48 KB
/
LightSensor.cs
File metadata and controls
69 lines (67 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Threading;
using Windows.Devices.Sensors;
using System.Threading.Tasks;
namespace Produire.Sensor
{
public class 光センサー : IProduireClass
{
private LightSensor _lightsensor;
/// <summary>
/// センサーから計測してその結果を返します。
/// </summary>
[自分で]
public 光量情報 計測()
{
if (_lightsensor == null) _lightsensor = LightSensor.GetDefault();
if (_lightsensor != null)
{
var reading = _lightsensor.GetCurrentReading();
return new 光量情報(reading);
}
else
return null;
}
/// <summary>
/// 測定に使用するセンサーをデバイスIDで選択します。
/// </summary>
[自分から]
public bool 選択(string ID)
{
Task<LightSensor> t1 = null;
Task.Run(() =>
{
t1 = LightSensor.FromIdAsync(ID).AsTask<LightSensor>();
}).Wait();
_lightsensor = t1.Result;
return _lightsensor != null;
}
public string デバイス名
{
get { return _lightsensor.DeviceId; }
}
}
public class 光量情報 : IProduireClass
{
LightSensorReading reading;
public 光量情報(LightSensorReading args)
{
this.reading = args;
}
public float 光量
{
get { return reading.IlluminanceInLux; }
}
public DateTimeOffset 測定時刻
{
get { return reading.Timestamp; }
}
public TimeSpan 測定回数
{
get { return reading.PerformanceCount.Value; }
}
}
}