Skip to content
This repository was archived by the owner on Jan 4, 2021. It is now read-only.

Commit e5fbcca

Browse files
committed
Commit for api v0.3.0
1 parent b8c8eba commit e5fbcca

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1574
-493
lines changed

MetaWear.DotNet/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@
3232
// by using the '*' as shown below:
3333
// [assembly: AssemblyVersion("1.0.*")]
3434
[assembly: AssemblyVersion("1.0.0.0")]
35-
[assembly: AssemblyFileVersion("0.2.0")]
35+
[assembly: AssemblyFileVersion("0.3.0")]

MetaWear.DotNetStandard/MetaWear.DotNetStandard.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
<AssemblyName>MbientLab.MetaWear.DotNetStandard</AssemblyName>
66
<RootNamespace>MbientLab.MetaWear.DotNetStandard</RootNamespace>
77
<DelaySign>false</DelaySign>
8+
<FileVersion>0.3.0.0</FileVersion>
9+
<AssemblyVersion>1.0.0.0</AssemblyVersion>
810
</PropertyGroup>
911

1012
<Import Project="..\MetaWear\MetaWear.projitems" Label="Shared" />

MetaWear.Impl/AccelerometerBma255.cs

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,46 +27,48 @@ public void Configure(FlatHoldTime? holdTime = null, float? theta = null) {
2727
Write((byte) (holdTime ?? FlatHoldTime._512ms), theta ?? 5.6889f);
2828
}
2929
}
30-
protected class Bma255MotionDataProducer : BoschMotionDataProducer {
30+
private class Bma255MotionDataProducer : BoschMotionDataProducer {
3131
private byte[] InitialMotionConfig => new byte[] { 0x00, 0x14, 0x14 };
3232

3333
internal Bma255MotionDataProducer(DataTypeBase dataTypeBase, IModuleBoardBridge bridge) :
3434
base(dataTypeBase, bridge) {
3535
}
3636

37-
public override void ConfigureAny(int? Count = null, float? Threshold = null) {
38-
ConfigureAnyInner(InitialMotionConfig, Count, Threshold);
37+
public override void ConfigureAny(int? count = null, float? threshold = null) {
38+
ConfigureAnyInner(InitialMotionConfig, count, threshold);
3939
}
4040

41-
public override void ConfigureNo(int? Duration = null, float? Threshold = null) {
41+
public override void ConfigureNo(int? duration = null, float? threshold = null) {
4242
byte[] config = InitialMotionConfig;
43-
if (Duration.HasValue) {
43+
if (duration.HasValue) {
4444
config[0] &= 0x3;
4545

46-
if (Duration >= 1000 && Duration <= 16000) {
47-
config[0] |= (byte)(((Duration - 1000) / 1000) << 2);
48-
} else if (Duration >= 20000 && Duration <= 80000) {
49-
config[0] |= (byte) ((((byte)(Duration - 20000) / 4000) << 2) | 0x40);
50-
} else if (Duration >= 88000 && Duration <= 336000) {
51-
config[0] |= (byte) ((((byte)(Duration - 88000) / 8000) << 2) | 0x80);
46+
if (duration >= 1000 && duration <= 16000) {
47+
config[0] |= (byte)(((duration - 1000) / 1000) << 2);
48+
} else if (duration >= 20000 && duration <= 80000) {
49+
config[0] |= (byte) ((((byte)(duration - 20000) / 4000) << 2) | 0x40);
50+
} else if (duration >= 88000 && duration <= 336000) {
51+
config[0] |= (byte) ((((byte)(duration - 88000) / 8000) << 2) | 0x80);
5252
}
5353
}
5454

55-
if (Threshold.HasValue) {
56-
config[2] = (byte)(Threshold / BOSCH_NO_MOTION_THS_STEPS[(accelerometer as AccelerometerBma255).DataScaleIndex]);
55+
if (threshold.HasValue) {
56+
config[2] = (byte)(threshold / BOSCH_NO_MOTION_THS_STEPS[(accelerometer as AccelerometerBma255).DataScaleIndex]);
5757
}
5858

59+
mask = 0x78;
5960
bridge.sendCommand(ACCELEROMETER, MOTION_CONFIG, config);
6061
}
6162

62-
public override void ConfigureSlow(byte? Count = null, float? Threshold = null) {
63-
ConfigureSlowInner(InitialMotionConfig, Count, Threshold);
63+
public override void ConfigureSlow(byte? count = null, float? threshold = null) {
64+
ConfigureSlowInner(InitialMotionConfig, count, threshold);
6465
}
6566
}
6667

6768
[DataMember] private readonly byte[] accDataConfig = new byte[] { 0x0b, 0x03 };
6869

6970
private IBma255FlatDataProducer flatDetector;
71+
private IMotionDataProducer motionProducer;
7072
private TimedTask<byte[]> readConfigTask;
7173

7274
protected override float DataScale {
@@ -104,21 +106,29 @@ protected override int DataScaleIndex {
104106

105107
protected override byte MaxOrientHys => 0x7;
106108

107-
IBma255FlatDataProducer IAccelerometerBma255.Flat {
109+
IBma255FlatDataProducer IAccelerometerBma255.Flat => Flat as IBma255FlatDataProducer;
110+
111+
public override IFlatDataProducer Flat {
108112
get {
109113
if (flatDetector == null) {
110114
flatDetector = new Bma255FlatDataProducer(flatDataType, bridge);
111115
}
112116
return flatDetector;
113117
}
114118
}
115-
public override IFlatDataProducer Flat => Flat;
116119

117120
protected override byte[] InitialLowHighGConfig => new byte[] { 0x09, 0x30, 0x81, 0x0f, 0xc0 };
118121

119122
protected override float LowHighGDurationStep => 2.0f;
120123

121-
public override IMotionDataProducer Motion => throw new NotImplementedException();
124+
public override IMotionDataProducer Motion {
125+
get {
126+
if (motionProducer == null) {
127+
motionProducer = new Bma255MotionDataProducer(motionDataType, bridge);
128+
}
129+
return motionProducer;
130+
}
131+
}
122132

123133
protected override void init() {
124134
base.init();
@@ -131,7 +141,7 @@ protected override void init() {
131141
public AccelerometerBma255(IModuleBoardBridge bridge) : base(bridge) {
132142
}
133143

134-
public void Configure(OutputDataRate odr, DataRange range) {
144+
public void Configure(OutputDataRate odr = OutputDataRate._125Hz, DataRange range = DataRange._2g) {
135145
accDataConfig[0] &= 0xe0;
136146
accDataConfig[0] |= (byte) (odr + 8);
137147

MetaWear.Impl/AccelerometerBmi160.cs

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ private static void applyDetectorMode(byte[] config, StepDetectorMode mode) {
3535
}
3636
}
3737
internal new static string createIdentifier(DataTypeBase dataType) {
38-
switch (dataType.eventConfig[1]) {
38+
switch (Util.clearRead(dataType.eventConfig[1])) {
3939
case STEP_DETECTOR_INTERRUPT:
4040
return "step-detector";
4141
case STEP_COUNTER_DATA:
@@ -79,12 +79,12 @@ internal Bmi160FlatDataProducer(DataTypeBase dataTypeBase, IModuleBoardBridge br
7979

8080
}
8181

82-
public override void Configure(ushort? Hold = null, float? Theta = null) {
83-
Configure((FlatHoldTime) Util.closestIndexUShort(HOLD_TIMES, Hold ?? 640), Theta);
82+
public override void Configure(ushort? hold = null, float? theta = null) {
83+
Configure((FlatHoldTime) Util.closestIndexUShort(HOLD_TIMES, hold ?? 640), theta);
8484
}
8585

86-
public void Configure(FlatHoldTime? Hold = null, float? Theta = null) {
87-
Write((byte) (Hold ?? FlatHoldTime._640ms), Theta ?? 5.6889f);
86+
public void Configure(FlatHoldTime? hold = null, float? theta = null) {
87+
Write((byte) (hold ?? FlatHoldTime._640ms), theta ?? 5.6889f);
8888
}
8989
}
9090

@@ -95,55 +95,57 @@ internal Bmi160MotionDataProducer(DataTypeBase dataTypeBase, IModuleBoardBridge
9595
base(dataTypeBase, bridge) {
9696
}
9797

98-
public override void ConfigureAny(int? Count = null, float? Threshold = null) {
98+
public override void ConfigureAny(int? count = null, float? threshold = null) {
9999
byte[] config = InitialMotionConfig;
100100
config[3] &= (~0x2) & 0xff;
101101

102-
ConfigureAnyInner(config, Count, Threshold);
102+
ConfigureAnyInner(config, count, threshold);
103103
}
104104

105-
public override void ConfigureNo(int? Duration = null, float? Threshold = null) {
105+
public override void ConfigureNo(int? duration = null, float? threshold = null) {
106106
byte[] config = InitialMotionConfig;
107107
config[3] |= 0x1;
108108

109-
if (Duration.HasValue) {
109+
if (duration.HasValue) {
110110
config[0] &= 0x3;
111111

112-
if (Duration >= 1280 && Duration <= 20480) {
113-
config[0] |= (byte) (((byte)(Duration / 1280f - 1)) << 2);
114-
} else if (Duration >= 25600 && Duration <= 102400) {
115-
config[0] |= (byte) ((((byte)(Duration / 5120f - 5)) << 2) | 0x40);
116-
} else if (Duration >= 112640 && Duration <= 430080) {
117-
config[0] |= (byte) ((((byte)(Duration / 10240f - 11)) << 2) | 0x80);
112+
if (duration >= 1280 && duration <= 20480) {
113+
config[0] |= (byte) (((byte)(duration / 1280f - 1)) << 2);
114+
} else if (duration >= 25600 && duration <= 102400) {
115+
config[0] |= (byte) ((((byte)(duration / 5120f - 5)) << 2) | 0x40);
116+
} else if (duration >= 112640 && duration <= 430080) {
117+
config[0] |= (byte) ((((byte)(duration / 10240f - 11)) << 2) | 0x80);
118118
}
119119
}
120120

121-
if (Threshold.HasValue) {
122-
config[2] = (byte)(Threshold / BOSCH_NO_MOTION_THS_STEPS[(accelerometer as AccelerometerBmi160).DataScaleIndex]);
121+
if (threshold.HasValue) {
122+
config[2] = (byte)(threshold / BOSCH_NO_MOTION_THS_STEPS[(accelerometer as AccelerometerBmi160).DataScaleIndex]);
123123
}
124124

125+
mask = 0x38;
125126
bridge.sendCommand(ACCELEROMETER, MOTION_CONFIG, config);
126127
}
127128

128-
public void ConfigureSignificant(SkipTime? Skip = null, ProofTime? Proof = null) {
129+
public void ConfigureSignificant(SkipTime? skip = null, ProofTime? proof = null) {
129130
byte[] config = InitialMotionConfig;
130131
config[3] |= 0x2;
131132

132-
if (Skip.HasValue) {
133-
config[3] |= (byte) ((int) Skip << 2);
133+
if (skip.HasValue) {
134+
config[3] |= (byte) ((int) skip << 2);
134135
}
135-
if (Proof.HasValue) {
136-
config[3] |= (byte)((int) Proof << 4);
136+
if (proof.HasValue) {
137+
config[3] |= (byte)((int) proof << 4);
137138
}
138139

140+
mask = 0x7;
139141
bridge.sendCommand(ACCELEROMETER, MOTION_CONFIG, config);
140142
}
141143

142-
public override void ConfigureSlow(byte? Count = null, float? Threshold = null) {
144+
public override void ConfigureSlow(byte? count = null, float? threshold = null) {
143145
byte[] config = InitialMotionConfig;
144146
config[3] &= (~0x1) & 0xff;
145147

146-
ConfigureSlowInner(config, Count, Threshold);
148+
ConfigureSlowInner(config, count, threshold);
147149
}
148150
}
149151

@@ -172,25 +174,25 @@ public IStepDetectorDataProducer StepDetector {
172174
return stepDetector;
173175
}
174176
}
175-
IBmi160FlatDataProducer IAccelerometerBmi160.Flat {
177+
IBmi160FlatDataProducer IAccelerometerBmi160.Flat => Flat as IBmi160FlatDataProducer;
178+
public override IFlatDataProducer Flat {
176179
get {
177180
if (flatDetector == null) {
178181
flatDetector = new Bmi160FlatDataProducer(flatDataType, bridge);
179182
}
180183
return flatDetector;
181184
}
182185
}
183-
public override IFlatDataProducer Flat => Flat;
184186

185-
IBmi160MotionDataProducer IAccelerometerBmi160.Motion {
187+
IBmi160MotionDataProducer IAccelerometerBmi160.Motion => Motion as IBmi160MotionDataProducer;
188+
public override IMotionDataProducer Motion {
186189
get {
187190
if (motion == null) {
188191
motion = new Bmi160MotionDataProducer(motionDataType, bridge);
189192
}
190193
return motion;
191194
}
192195
}
193-
public override IMotionDataProducer Motion => Motion;
194196

195197
protected override float DataScale {
196198
get {
@@ -251,13 +253,8 @@ protected override void init() {
251253
response => readConfigTask.SetResult(response));
252254
}
253255

254-
public void Configure(OutputDataRate odr, DataRange range) {
255-
accDataConfig[0] &= 0xf0;
256-
accDataConfig[0] |= (byte)(odr + 1);
257-
258-
accDataConfig[0] &= 0xf;
259-
accDataConfig[0] |= (byte) ((FREQUENCIES[(int)odr] < 12.5f) ? 0x80 : 0x20);
260-
256+
public void Configure(OutputDataRate odr = OutputDataRate._100Hz, DataRange range = DataRange._2g, FilterMode filter = FilterMode.Normal) {
257+
accDataConfig[0] = (byte) (((int) odr + 1) | ((FREQUENCIES[(int)odr] < 12.5f) ? 0x80 : (int)filter << 4));
261258
accDataConfig[1] &= 0xf0;
262259
accDataConfig[1] |= RANGE_BIT_MASKS[(int) range];
263260

0 commit comments

Comments
 (0)