Skip to content

Commit

Permalink
Merge branch 'release-2.9.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephen Schiffli committed Aug 25, 2017
2 parents 0ce1d98 + 7d3d795 commit 329b091
Show file tree
Hide file tree
Showing 211 changed files with 11,377 additions and 10,293 deletions.
2 changes: 1 addition & 1 deletion Docs/gen_api_reference.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
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
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
open html/index.html

make html
Expand Down
4 changes: 2 additions & 2 deletions Docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@
# built documents.
#
# The short X.Y version.
version = '2.8.4'
version = '2.9.0'
# The full version, including alpha/beta/rc tags.
release = '2.8.4'
release = '2.9.0'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
2 changes: 1 addition & 1 deletion Docs/source/gen_api_reference.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
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
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
open html/index.html

make html
Expand Down
2 changes: 1 addition & 1 deletion MetaWear.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'MetaWear'
s.version = '2.8.4'
s.version = '2.9.0'
s.license = { :type => 'Commercial', :text => 'See https://www.mbientlab.com/terms/', :file => 'LICENSE' }
s.homepage = 'https://mbientlab.com'
s.summary = 'iOS/macOS/tvOS API and documentation for the MetaWear platform'
Expand Down
3 changes: 2 additions & 1 deletion MetaWear/Classes/Core/MBLConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ typedef NS_ENUM(uint8_t, MBLFirmwareVersion) {
MBLFirmwareVersion1_3_0,
MBLFirmwareVersion1_3_1,
MBLFirmwareVersion1_3_2,
MBLFirmwareVersion1_3_3
MBLFirmwareVersion1_3_3,
MBLFirmwareVersion1_3_4
};
NSString *MBLFirmwareVersionString(MBLFirmwareVersion version);

Expand Down
4 changes: 3 additions & 1 deletion MetaWear/Classes/Core/MBLConstants.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#import "MBLConstants.h"
#import "MBLConstants+Private.h"

NSString *const kMBLAPIVersion = @"2.8.4";
NSString *const kMBLAPIVersion = @"2.9.0";

NSString *MBLFirmwareVersionString(MBLFirmwareVersion version)
{
Expand Down Expand Up @@ -75,6 +75,8 @@
return @"1.3.2";
case MBLFirmwareVersion1_3_3:
return @"1.3.3";
case MBLFirmwareVersion1_3_4:
return @"1.3.4";
}
}

Expand Down
2 changes: 1 addition & 1 deletion MetaWear/Classes/Core/MBLData.m
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ - (BFTask *)simulatedReadAsync:(BOOL)isLocal
}] continueWithExecutor:[BFExecutor simulatorExecutor] withBlock:^id _Nullable(BFTask * _Nonnull task) {
return isLocal ? [super localReadAsync] : [super readAsync];
}] continueOnMetaWearWithSuccessBlock:^id _Nullable(BFTask * _Nonnull task) {
assert(device.command.activatedRegHandler);
NSAssert(device.command.activatedRegHandler, @"activatedRegHandler need to be set.");
device.command.activatedRegHandler(self, nil);
return task;
}] continueOnMetaWearWithBlock:^id _Nullable(BFTask * _Nonnull task) {
Expand Down
50 changes: 41 additions & 9 deletions MetaWear/Classes/Core/MBLEntityModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,19 @@ - (BFTask *)performAsyncInitializationForEntity:(MBLEntityEvent *)entity
return [BFTask taskWithResult:nil];
}

return [[BFTask taskFromMetaWearWithBlock:^id _Nonnull{
assert(entity.index == 0xFF);
return [[BFTask taskFromMetaWearWithBlock:^id _Nonnull {
NSError *error = nil;
if (entity.index != 0xFF) {
error = [NSError errorWithDomain:kMBLErrorDomain
code:kMBLErrorOperationInvalid
userInfo:@{NSLocalizedDescriptionKey : @"Can't initialize entity that's already initialized"}];
}
if (self.entities.count >= self.maxEntities) {
NSError *error = [NSError errorWithDomain:kMBLErrorDomain
error = [NSError errorWithDomain:kMBLErrorDomain
code:kMBLErrorInsufficientMemory
userInfo:@{NSLocalizedDescriptionKey : [NSString stringWithFormat:@"MetaWear out of memory, can't perform action. Reset the MetaWear and use no more than %d entities", self.maxEntities]}];
}
if (error) {
return [BFTask taskWithError:error];
}
[self.entities addObject:entity];
Expand All @@ -98,7 +105,12 @@ - (BFTask *)performAsyncDeinitializationForEntity:(MBLEntityEvent *)entity
}

return [[BFTask taskFromMetaWearWithBlock:^id _Nonnull{
assert(entity.index != 0xFF);
if (entity.index == 0xFF) {
NSError *error = [NSError errorWithDomain:kMBLErrorDomain
code:kMBLErrorOperationInvalid
userInfo:@{NSLocalizedDescriptionKey : @"Can't deinitialize entity that's not initialized"}];
return [BFTask taskWithError:error];
}
return [self.removeEntity writeByteAsync:entity.index];
}] continueOnMetaWearWithSuccessBlock:^id _Nullable(BFTask * _Nonnull task) {
entity.index = 0xFF;
Expand All @@ -114,7 +126,12 @@ - (BFTask *)performAsyncActivationForEntity:(MBLEntityEvent *)entity
}

return [BFTask taskFromMetaWearWithBlock:^id _Nonnull{
assert(entity.index != 0xFF);
if (entity.index == 0xFF) {
NSError *error = [NSError errorWithDomain:kMBLErrorDomain
code:kMBLErrorOperationInvalid
userInfo:@{NSLocalizedDescriptionKey : @"Can't deinitialize entity that's not initialized"}];
return [BFTask taskWithError:error];
}
return [self.activateEntity writeByteAsync:entity.index];
}];
}
Expand All @@ -126,7 +143,12 @@ - (BFTask *)performAsyncDeactivationForEntity:(MBLEntityEvent *)entity
}

return [BFTask taskFromMetaWearWithBlock:^id _Nonnull{
assert(entity.index != 0xFF);
if (entity.index == 0xFF) {
NSError *error = [NSError errorWithDomain:kMBLErrorDomain
code:kMBLErrorOperationInvalid
userInfo:@{NSLocalizedDescriptionKey : @"Can't deinitialize entity that's not initialized"}];
return [BFTask taskWithError:error];
}
return [self.deactivateEntity writeByteAsync:entity.index];
}];
}
Expand All @@ -139,7 +161,12 @@ - (BFTask *)startNotificationsForEntity:(MBLEntityEvent *)entity

return [[BFTask taskFromMetaWearWithBlock:^id _Nonnull{
// Turn on notifications for this filter
assert(entity.index != 0xFF);
if (entity.index == 0xFF) {
NSError *error = [NSError errorWithDomain:kMBLErrorDomain
code:kMBLErrorOperationInvalid
userInfo:@{NSLocalizedDescriptionKey : @"Can't start notifications for entity that's not initialized"}];
return [BFTask taskWithError:error];
}
uint8_t packet[] = { entity.index, 0x1 };
return [self.notificationEnable writeDataAsync:[NSData dataWithBytes:&packet length:2]];
}] continueOnMetaWearWithSuccessBlock:^id _Nullable(BFTask * _Nonnull task) {
Expand All @@ -164,12 +191,17 @@ - (BFTask *)stopNotificationsAsyncForEntity:(MBLEntityEvent *)entity
// Turn off global notifications
return [self.globalNotifications stopNotificationsAsync];
}
assert(self.activeNotifications >= 0);
NSAssert(self.activeNotifications >= 0, @"Start/Stop notification calls unbalanced.");
self.activeNotifications = MAX(self.activeNotifications, 0);
return nil;
}] continueOnMetaWearWithSuccessBlock:^id _Nullable(BFTask * _Nonnull task) {
// Turn off notifications for this filter
assert(entity.index != 0xFF);
if (entity.index == 0xFF) {
NSError *error = [NSError errorWithDomain:kMBLErrorDomain
code:kMBLErrorOperationInvalid
userInfo:@{NSLocalizedDescriptionKey : @"Can't stop notifications for entity that's not initialized"}];
return [BFTask taskWithError:error];
}
uint8_t data[] = { entity.index, 0x0 };
return [self.notificationEnable writeDataAsync:[NSData dataWithBytes:&data length:2]];
}];
Expand Down
13 changes: 12 additions & 1 deletion MetaWear/Classes/Core/MBLEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,24 @@ typedef void (^MBLNotificationHandler)(ResultType __nullable obj, NSError *__nul

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

/**
Create a new event that subtracts a rolling average of the current event. This
uses a recursive average technique so the answers are approximate. This can be
thought of as a HIGH-PASS filter.
Event callbacks will be provided the same object as the input.
@param depth Number of samples to average (works fastest if a power of 2)
@returns New event representing average of input
*/
- (MBLFilter<ResultType> *)highPassOfEventWithDepth:(uint8_t)depth;

/**
Create a new event that compares the current event's value to one or more data points
@param op Operation type to perform
Expand Down
54 changes: 54 additions & 0 deletions MetaWear/Classes/Core/MBLEvent.m
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,11 @@ typedef struct __attribute__((packed)) {

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

- (MBLFilter *)highPassOfEventWithDepth:(uint8_t)depth
{
// High pass filter showed up in firmware 1.3.4
NSString *curVersion = self.module.device.deviceInfo.firmwareRevision;
if ([MBLConstants versionString:curVersion isLessThan:@"1.3.4"]) {
return nil;
}
return [self vectorAverageWithDepth:depth highPass:YES];
}

typedef struct __attribute__((packed)) {
uint8_t filter_id;
uint8_t outputlen:2;
uint8_t inputlen:2;
uint8_t issigned:1;
uint8_t mode:1;
uint8_t :2;
uint8_t depth;
uint8_t vectorlen;
} df_lowmem_avg_param_t;

- (MBLFilter *)vectorAverageWithDepth:(uint8_t)depth highPass:(BOOL)highPass
{
uint8_t length = self.format.type == MBLFormatTypeArray
? self.format.length / self.format.elements
: self.format.length;
if (length > 4) {
[NSException raise:@"Invalid Filter" format:@"Can't use event with size > 4, %d invalid", self.format.length];
}
df_lowmem_avg_param_t params = {0};
params.filter_id = 3;
params.outputlen = length - 1;
params.inputlen = length - 1;
params.issigned = self.format.isSigned;
params.mode = highPass ? 1 : 0;
params.depth = depth;
params.vectorlen = self.format.elements - 1;

// We make a copy of the formatter because we the filter will remove any offset
MBLFormat *formatClone = [self.format copy];
formatClone.offset = 0;

MBLFilter *filter = [[MBLFilter alloc] initWithTrigger:self
filterParameters:[NSData dataWithBytes:&params length:sizeof(df_lowmem_avg_param_t)]
format:formatClone];
return filter;
}



typedef struct __attribute__((packed)) {
uint8_t filter_id;
Expand Down
46 changes: 33 additions & 13 deletions MetaWear/Classes/Core/MBLMetaWear.m
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,12 @@ - (BFTask *)initializeModulesIfNeededAsync

- (BFTask *)resetModulesAsync
{
assert(self.peripheral && self.peripheral.state == MBLConnectionStateConnected);
if (!(self.peripheral && self.peripheral.state == MBLConnectionStateConnected)) {
NSError *error = [NSError errorWithDomain:kMBLErrorDomain
code:kMBLErrorOperationInvalid
userInfo:@{NSLocalizedDescriptionKey : @"Can't reset modules without being connected."}];
return [BFTask taskWithError:error];
}
uint32_t magicKey = self.testDebug.magicKey;

return [[[BFTask taskFromMetaWearWithBlock:^id _Nonnull{
Expand Down Expand Up @@ -604,8 +609,14 @@ - (void)showFastCodingWarnings:(id<MBLRestorable>)configuration

- (BFTask *)setConfigurationAsync:(id<MBLRestorable>)configuration
{
if ([MBLConstants isSimulatorQueue]) {
NSError *error = [NSError errorWithDomain:kMBLErrorDomain
code:kMBLErrorOperationInvalid
userInfo:@{NSLocalizedDescriptionKey : @"Can't set a configuration within a programCommandsToRunOnEventAsync: block"}];
return [BFTask taskWithError:error];
}

BFTaskCompletionSource *source = [BFTaskCompletionSource taskCompletionSource];
assert(![MBLConstants isSimulatorQueue] && "Can't set a configuration within a programCommandsToRunOnEventAsync: block");
dispatch_async([MBLConstants metaWearQueue], ^{
if (self.state != MBLConnectionStateConnected) {
[source trySetError:[NSError errorWithDomain:kMBLErrorDomain
Expand Down Expand Up @@ -1508,7 +1519,12 @@ - (void)setupMetaWear

- (BFTask<NSNumber *> *)sanityCheck
{
assert(!_noencode_programedByOtherApp);
if (_noencode_programedByOtherApp) {
NSError *error = [NSError errorWithDomain:kMBLErrorDomain
code:kMBLErrorOperationInvalid
userInfo:@{NSLocalizedDescriptionKey : @"Can't sanityCheck in limited mode"}];
return [BFTask taskWithError:error];
}
// Perform some sanity checks on all the module state
NSMutableArray *tasks = [NSMutableArray array];
for (id obj in self.modules) {
Expand Down Expand Up @@ -1543,7 +1559,7 @@ -(void)peripheral:(id<MBLBluetoothPeripheral>)peripheral didUpdateValueForCharac
}
#endif
if (characteristic == metawearCommandCharacteristic || characteristic == metawearNotification6Characteristic) {
assert(characteristic.value.length);
NSAssert(characteristic.value.length, @"Didn't expect to receive an empty value.");
if (!characteristic.value.length) {
return;
}
Expand Down Expand Up @@ -1580,13 +1596,13 @@ -(void)peripheral:(id<MBLBluetoothPeripheral>)peripheral didUpdateValueForCharac
if ([module respondsToSelector:@selector(recievedData:error:)]) {
[module recievedData:characteristic.value error:error];
} else {
assert(NO && "No module found");
NSAssert(NO, @"No module found");
}
} else if (moduleId == self.testDebug.moduleInfo.moduleId) {
if ([self.testDebug respondsToSelector:@selector(recievedData:error:)]) {
[self.testDebug recievedData:characteristic.value error:error];
} else {
assert(NO && "No testDebug module found");
NSAssert(NO, @"No testDebug module found");
}
}
} else if (characteristic == batteryLifeCharacteristic) {
Expand Down Expand Up @@ -1730,13 +1746,17 @@ - (void)connectionCompleteWithError:(NSError *)error
[tasks addObject:[self.testDebug deviceConnected]];
return [BFTask taskForCompletionOfAllTasks:tasks];
}] continueOnMetaWearWithBlock:^id _Nullable(BFTask * _Nonnull t) {
assert(!t.error);
MBLLog(MBLLogLevelInfo, @"Connection Success %@", self.deviceInfo.firmwareRevision);
[[MBLAnalytics sharedManager] postEventForDevice:self.identifier
eventCategory:[@"connect " stringByAppendingString:kMBLAPIVersion]
eventAction:@"success"
eventLabel:self.deviceInfo.firmwareRevision];
[self invokeConnectionHandlers:nil];
if (t.error) {
self.state = MBLConnectionStateConnecting;
[self connectionCompleteWithError:t.error];
} else {
MBLLog(MBLLogLevelInfo, @"Connection Success %@", self.deviceInfo.firmwareRevision);
[[MBLAnalytics sharedManager] postEventForDevice:self.identifier
eventCategory:[@"connect " stringByAppendingString:kMBLAPIVersion]
eventAction:@"success"
eventLabel:self.deviceInfo.firmwareRevision];
[self invokeConnectionHandlers:nil];
}
return nil;
}];
}
Expand Down
8 changes: 5 additions & 3 deletions MetaWear/Classes/Core/MBLMetaWearManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ - (void)retrieveSavedMetaWearsWithHandler:(MBLArrayHandler)handler

- (void)startScanForMetaWears:(BOOL)metaWears metaBoots:(BOOL)metaBoots duplicates:(NSNumber *)duplicates handler:(MBLArrayHandler)handler;
{
assert(handler);
NSAssert(handler, @"Can't start scanning without handler");
if (metaWears) {
[self.metaWearBlocks addObject:handler];
if (self.discoveredMetaWears.count) {
Expand Down Expand Up @@ -386,9 +386,11 @@ - (instancetype)init
[[NSUserDefaults standardUserDefaults] synchronize];
// Delete the cachce folder
NSError *error;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-variable"
BOOL success = [[NSFileManager defaultManager] removeItemAtPath:[self logFilename:nil] error:&error];
if (error) { NSLog(@"%@", error); }
assert(success);
#pragma clang diagnostic pop
NSAssert(success, @"File remove error: %@", error);
}
}
return self;
Expand Down

0 comments on commit 329b091

Please sign in to comment.