Skip to content
This repository was archived by the owner on Jul 20, 2025. It is now read-only.

Commit 329b091

Browse files
author
Stephen Schiffli
committed
Merge branch 'release-2.9.0'
2 parents 0ce1d98 + 7d3d795 commit 329b091

File tree

211 files changed

+11377
-10293
lines changed

Some content is hidden

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

211 files changed

+11377
-10293
lines changed

Docs/gen_api_reference.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
appledoc -p "MetaWear iOS/macOS/tvOS API 2.8.3" --project-version "2.8.3" -c "MBIENTLAB INC" --company-id com.mbientlab --no-create-docset --no-repeat-first-par --ignore .m -o . ../MetaWear/Classes
1+
appledoc -p "MetaWear iOS/macOS/tvOS API 2.9.0" --project-version "2.9.0" -c "MBIENTLAB INC" --company-id com.mbientlab --no-create-docset --no-repeat-first-par --ignore .m -o . ../MetaWear/Classes
22
open html/index.html
33

44
make html

Docs/source/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@
5555
# built documents.
5656
#
5757
# The short X.Y version.
58-
version = '2.8.4'
58+
version = '2.9.0'
5959
# The full version, including alpha/beta/rc tags.
60-
release = '2.8.4'
60+
release = '2.9.0'
6161

6262
# The language for content autogenerated by Sphinx. Refer to documentation
6363
# for a list of supported languages.

Docs/source/gen_api_reference.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
appledoc -p "MetaWear iOS/macOS/tvOS API 2.8.4" --project-version "2.8.4" -c "MBIENTLAB INC" --company-id com.mbientlab --no-create-docset --no-repeat-first-par --ignore .m -o . ../MetaWear/Classes
1+
appledoc -p "MetaWear iOS/macOS/tvOS API 2.9.0" --project-version "2.9.0" -c "MBIENTLAB INC" --company-id com.mbientlab --no-create-docset --no-repeat-first-par --ignore .m -o . ../MetaWear/Classes
22
open html/index.html
33

44
make html

MetaWear.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'MetaWear'
3-
s.version = '2.8.4'
3+
s.version = '2.9.0'
44
s.license = { :type => 'Commercial', :text => 'See https://www.mbientlab.com/terms/', :file => 'LICENSE' }
55
s.homepage = 'https://mbientlab.com'
66
s.summary = 'iOS/macOS/tvOS API and documentation for the MetaWear platform'

MetaWear/Classes/Core/MBLConstants.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ typedef NS_ENUM(uint8_t, MBLFirmwareVersion) {
7474
MBLFirmwareVersion1_3_0,
7575
MBLFirmwareVersion1_3_1,
7676
MBLFirmwareVersion1_3_2,
77-
MBLFirmwareVersion1_3_3
77+
MBLFirmwareVersion1_3_3,
78+
MBLFirmwareVersion1_3_4
7879
};
7980
NSString *MBLFirmwareVersionString(MBLFirmwareVersion version);
8081

MetaWear/Classes/Core/MBLConstants.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#import "MBLConstants.h"
3737
#import "MBLConstants+Private.h"
3838

39-
NSString *const kMBLAPIVersion = @"2.8.4";
39+
NSString *const kMBLAPIVersion = @"2.9.0";
4040

4141
NSString *MBLFirmwareVersionString(MBLFirmwareVersion version)
4242
{
@@ -75,6 +75,8 @@
7575
return @"1.3.2";
7676
case MBLFirmwareVersion1_3_3:
7777
return @"1.3.3";
78+
case MBLFirmwareVersion1_3_4:
79+
return @"1.3.4";
7880
}
7981
}
8082

MetaWear/Classes/Core/MBLData.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ - (BFTask *)simulatedReadAsync:(BOOL)isLocal
7373
}] continueWithExecutor:[BFExecutor simulatorExecutor] withBlock:^id _Nullable(BFTask * _Nonnull task) {
7474
return isLocal ? [super localReadAsync] : [super readAsync];
7575
}] continueOnMetaWearWithSuccessBlock:^id _Nullable(BFTask * _Nonnull task) {
76-
assert(device.command.activatedRegHandler);
76+
NSAssert(device.command.activatedRegHandler, @"activatedRegHandler need to be set.");
7777
device.command.activatedRegHandler(self, nil);
7878
return task;
7979
}] continueOnMetaWearWithBlock:^id _Nullable(BFTask * _Nonnull task) {

MetaWear/Classes/Core/MBLEntityModule.m

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,19 @@ - (BFTask *)performAsyncInitializationForEntity:(MBLEntityEvent *)entity
7070
return [BFTask taskWithResult:nil];
7171
}
7272

73-
return [[BFTask taskFromMetaWearWithBlock:^id _Nonnull{
74-
assert(entity.index == 0xFF);
73+
return [[BFTask taskFromMetaWearWithBlock:^id _Nonnull {
74+
NSError *error = nil;
75+
if (entity.index != 0xFF) {
76+
error = [NSError errorWithDomain:kMBLErrorDomain
77+
code:kMBLErrorOperationInvalid
78+
userInfo:@{NSLocalizedDescriptionKey : @"Can't initialize entity that's already initialized"}];
79+
}
7580
if (self.entities.count >= self.maxEntities) {
76-
NSError *error = [NSError errorWithDomain:kMBLErrorDomain
81+
error = [NSError errorWithDomain:kMBLErrorDomain
7782
code:kMBLErrorInsufficientMemory
7883
userInfo:@{NSLocalizedDescriptionKey : [NSString stringWithFormat:@"MetaWear out of memory, can't perform action. Reset the MetaWear and use no more than %d entities", self.maxEntities]}];
84+
}
85+
if (error) {
7986
return [BFTask taskWithError:error];
8087
}
8188
[self.entities addObject:entity];
@@ -98,7 +105,12 @@ - (BFTask *)performAsyncDeinitializationForEntity:(MBLEntityEvent *)entity
98105
}
99106

100107
return [[BFTask taskFromMetaWearWithBlock:^id _Nonnull{
101-
assert(entity.index != 0xFF);
108+
if (entity.index == 0xFF) {
109+
NSError *error = [NSError errorWithDomain:kMBLErrorDomain
110+
code:kMBLErrorOperationInvalid
111+
userInfo:@{NSLocalizedDescriptionKey : @"Can't deinitialize entity that's not initialized"}];
112+
return [BFTask taskWithError:error];
113+
}
102114
return [self.removeEntity writeByteAsync:entity.index];
103115
}] continueOnMetaWearWithSuccessBlock:^id _Nullable(BFTask * _Nonnull task) {
104116
entity.index = 0xFF;
@@ -114,7 +126,12 @@ - (BFTask *)performAsyncActivationForEntity:(MBLEntityEvent *)entity
114126
}
115127

116128
return [BFTask taskFromMetaWearWithBlock:^id _Nonnull{
117-
assert(entity.index != 0xFF);
129+
if (entity.index == 0xFF) {
130+
NSError *error = [NSError errorWithDomain:kMBLErrorDomain
131+
code:kMBLErrorOperationInvalid
132+
userInfo:@{NSLocalizedDescriptionKey : @"Can't deinitialize entity that's not initialized"}];
133+
return [BFTask taskWithError:error];
134+
}
118135
return [self.activateEntity writeByteAsync:entity.index];
119136
}];
120137
}
@@ -126,7 +143,12 @@ - (BFTask *)performAsyncDeactivationForEntity:(MBLEntityEvent *)entity
126143
}
127144

128145
return [BFTask taskFromMetaWearWithBlock:^id _Nonnull{
129-
assert(entity.index != 0xFF);
146+
if (entity.index == 0xFF) {
147+
NSError *error = [NSError errorWithDomain:kMBLErrorDomain
148+
code:kMBLErrorOperationInvalid
149+
userInfo:@{NSLocalizedDescriptionKey : @"Can't deinitialize entity that's not initialized"}];
150+
return [BFTask taskWithError:error];
151+
}
130152
return [self.deactivateEntity writeByteAsync:entity.index];
131153
}];
132154
}
@@ -139,7 +161,12 @@ - (BFTask *)startNotificationsForEntity:(MBLEntityEvent *)entity
139161

140162
return [[BFTask taskFromMetaWearWithBlock:^id _Nonnull{
141163
// Turn on notifications for this filter
142-
assert(entity.index != 0xFF);
164+
if (entity.index == 0xFF) {
165+
NSError *error = [NSError errorWithDomain:kMBLErrorDomain
166+
code:kMBLErrorOperationInvalid
167+
userInfo:@{NSLocalizedDescriptionKey : @"Can't start notifications for entity that's not initialized"}];
168+
return [BFTask taskWithError:error];
169+
}
143170
uint8_t packet[] = { entity.index, 0x1 };
144171
return [self.notificationEnable writeDataAsync:[NSData dataWithBytes:&packet length:2]];
145172
}] continueOnMetaWearWithSuccessBlock:^id _Nullable(BFTask * _Nonnull task) {
@@ -164,12 +191,17 @@ - (BFTask *)stopNotificationsAsyncForEntity:(MBLEntityEvent *)entity
164191
// Turn off global notifications
165192
return [self.globalNotifications stopNotificationsAsync];
166193
}
167-
assert(self.activeNotifications >= 0);
194+
NSAssert(self.activeNotifications >= 0, @"Start/Stop notification calls unbalanced.");
168195
self.activeNotifications = MAX(self.activeNotifications, 0);
169196
return nil;
170197
}] continueOnMetaWearWithSuccessBlock:^id _Nullable(BFTask * _Nonnull task) {
171198
// Turn off notifications for this filter
172-
assert(entity.index != 0xFF);
199+
if (entity.index == 0xFF) {
200+
NSError *error = [NSError errorWithDomain:kMBLErrorDomain
201+
code:kMBLErrorOperationInvalid
202+
userInfo:@{NSLocalizedDescriptionKey : @"Can't stop notifications for entity that's not initialized"}];
203+
return [BFTask taskWithError:error];
204+
}
173205
uint8_t data[] = { entity.index, 0x0 };
174206
return [self.notificationEnable writeDataAsync:[NSData dataWithBytes:&data length:2]];
175207
}];

MetaWear/Classes/Core/MBLEvent.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,13 +306,24 @@ typedef void (^MBLNotificationHandler)(ResultType __nullable obj, NSError *__nul
306306

307307
/**
308308
Create a new event that averages the output data of the current event. This
309-
uses a recursive average technique so the answers are approximate.
309+
uses a recursive average technique so the answers are approximate. This can be
310+
thought of as a LOW-PASS filter.
310311
Event callbacks will be provided the same object as the input.
311312
@param depth Number of samples to average (works fastest if a power of 2)
312313
@returns New event representing average of input
313314
*/
314315
- (MBLFilter<ResultType> *)averageOfEventWithDepth:(uint8_t)depth;
315316

317+
/**
318+
Create a new event that subtracts a rolling average of the current event. This
319+
uses a recursive average technique so the answers are approximate. This can be
320+
thought of as a HIGH-PASS filter.
321+
Event callbacks will be provided the same object as the input.
322+
@param depth Number of samples to average (works fastest if a power of 2)
323+
@returns New event representing average of input
324+
*/
325+
- (MBLFilter<ResultType> *)highPassOfEventWithDepth:(uint8_t)depth;
326+
316327
/**
317328
Create a new event that compares the current event's value to one or more data points
318329
@param op Operation type to perform

MetaWear/Classes/Core/MBLEvent.m

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,11 @@ typedef struct __attribute__((packed)) {
383383

384384
- (MBLFilter *)averageOfEventWithDepth:(uint8_t)depth
385385
{
386+
// A new vector implemntation showed up in firmware 1.3.4
387+
NSString *curVersion = self.module.device.deviceInfo.firmwareRevision;
388+
if (![MBLConstants versionString:curVersion isLessThan:@"1.3.4"]) {
389+
return [self vectorAverageWithDepth:depth highPass:NO];
390+
}
386391
const int outputSize = 4;
387392
if (self.format.length > outputSize) {
388393
[NSException raise:@"Invalid Filter" format:@"Can't use event with size > 4, %d invalid", self.format.length];
@@ -405,6 +410,55 @@ - (MBLFilter *)averageOfEventWithDepth:(uint8_t)depth
405410
return filter;
406411
}
407412

413+
- (MBLFilter *)highPassOfEventWithDepth:(uint8_t)depth
414+
{
415+
// High pass filter showed up in firmware 1.3.4
416+
NSString *curVersion = self.module.device.deviceInfo.firmwareRevision;
417+
if ([MBLConstants versionString:curVersion isLessThan:@"1.3.4"]) {
418+
return nil;
419+
}
420+
return [self vectorAverageWithDepth:depth highPass:YES];
421+
}
422+
423+
typedef struct __attribute__((packed)) {
424+
uint8_t filter_id;
425+
uint8_t outputlen:2;
426+
uint8_t inputlen:2;
427+
uint8_t issigned:1;
428+
uint8_t mode:1;
429+
uint8_t :2;
430+
uint8_t depth;
431+
uint8_t vectorlen;
432+
} df_lowmem_avg_param_t;
433+
434+
- (MBLFilter *)vectorAverageWithDepth:(uint8_t)depth highPass:(BOOL)highPass
435+
{
436+
uint8_t length = self.format.type == MBLFormatTypeArray
437+
? self.format.length / self.format.elements
438+
: self.format.length;
439+
if (length > 4) {
440+
[NSException raise:@"Invalid Filter" format:@"Can't use event with size > 4, %d invalid", self.format.length];
441+
}
442+
df_lowmem_avg_param_t params = {0};
443+
params.filter_id = 3;
444+
params.outputlen = length - 1;
445+
params.inputlen = length - 1;
446+
params.issigned = self.format.isSigned;
447+
params.mode = highPass ? 1 : 0;
448+
params.depth = depth;
449+
params.vectorlen = self.format.elements - 1;
450+
451+
// We make a copy of the formatter because we the filter will remove any offset
452+
MBLFormat *formatClone = [self.format copy];
453+
formatClone.offset = 0;
454+
455+
MBLFilter *filter = [[MBLFilter alloc] initWithTrigger:self
456+
filterParameters:[NSData dataWithBytes:&params length:sizeof(df_lowmem_avg_param_t)]
457+
format:formatClone];
458+
return filter;
459+
}
460+
461+
408462

409463
typedef struct __attribute__((packed)) {
410464
uint8_t filter_id;

0 commit comments

Comments
 (0)