Skip to content

Commit

Permalink
Merge pull request PunchThrough#24 from PunchThrough/changing-handler…
Browse files Browse the repository at this point in the history
…s-to-properties

handlers as properties
  • Loading branch information
karelkalthoff authored Aug 11, 2016
2 parents 65c4238 + 95dd834 commit 9087d6c
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions source/PTDBean.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ @interface PTDBean () <CBPeripheralDelegate, AppMessagingLayerDelegate, OAD_Dele
@property (nonatomic, readwrite) NSString *sketchName;
@property (nonatomic, assign) NSInteger targetFirmwareVersion;
@property (nonatomic, copy) void (^sketchErasedHandler)(BOOL sketchErased);
@property (nonatomic, copy) void (^firmwareVersionAvailableHandler)(BOOL firmwareAvailable, NSError *error);
@property (nonatomic, copy) void (^hardwareVersionAvailableHandler)(BOOL hardwareAvailable, NSError *error);

@end

Expand All @@ -53,9 +55,6 @@ @implementation PTDBean
BeanArduinoOADLocalState localArduinoOADState;
NSTimer* arduinoOADStateTimout;
NSTimer* arduinoOADChunkSendTimer;

void (^firmwareVersionAvailableHandler)(BOOL firmwareAvailable, NSError *error);
void (^hardwareVersionAvailableHandler)(BOOL hardwareAvailable, NSError *error);
NSDate* firmwareUpdateStartTime;

}
Expand Down Expand Up @@ -322,7 +321,7 @@ - (void)checkFirmwareVersionAvailableWithHandler:(void (^)(BOOL firmwareAvailabl
if ( [self firmwareVersion] ) {
handler( YES, nil );
} else {
firmwareVersionAvailableHandler = handler; // Wait until device info is valid
self.firmwareVersionAvailableHandler = handler; // Wait until device info is valid
}
}

Expand All @@ -331,7 +330,7 @@ - (void)checkHardwareVersionAvailableWithHandler:(void (^)(BOOL hardwareAvailabl
if ( [self hardwareVersion] ) {
handler( YES, nil );
} else {
hardwareVersionAvailableHandler = handler; // Wait until device info is valid
self.hardwareVersionAvailableHandler = handler; // Wait until device info is valid
}
}

Expand Down Expand Up @@ -927,9 +926,9 @@ -(void)batteryProfileDidUpdate

- (void)hardwareVersionDidUpdate
{
if (hardwareVersionAvailableHandler){
[self checkHardwareVersionAvailableWithHandler:hardwareVersionAvailableHandler];
hardwareVersionAvailableHandler = nil;
if (self.hardwareVersionAvailableHandler){
[self checkHardwareVersionAvailableWithHandler:self.hardwareVersionAvailableHandler];
self.hardwareVersionAvailableHandler = nil;
}
}

Expand All @@ -941,9 +940,9 @@ - (void)firmwareVersionDidUpdate
// Don't send firmware version back to handler when firmware update is still in progress
if (self.updateInProgress) return;

if (firmwareVersionAvailableHandler) {
[self checkFirmwareVersionAvailableWithHandler:firmwareVersionAvailableHandler];
firmwareVersionAvailableHandler = nil;
if (self.firmwareVersionAvailableHandler) {
[self checkFirmwareVersionAvailableWithHandler:self.firmwareVersionAvailableHandler];
self.firmwareVersionAvailableHandler = nil;
}
}

Expand Down

0 comments on commit 9087d6c

Please sign in to comment.