- (void)viewDidLoad {
[super viewDidLoad];
// Data notifications are received through NSNotificationCenter.
// Posted whenever a TLMMyo connects
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didConnectDevice:)
name:TLMHubDidConnectDeviceNotification
object:nil];
// Posted whenever a TLMMyo disconnects.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didDisconnectDevice:)
name:TLMHubDidDisconnectDeviceNotification
object:nil];
...
// Posted when a new pose is available from a TLMMyo.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didReceivePoseChange:)
name:TLMMyoDidReceivePoseChangedNotification
object:nil];
}
- (void)didReceivePoseChange:(NSNotification *)notification {
// Retrieve the pose from the NSNotification's userInfo with the kTLMKeyPose key.
TLMPose *pose = notification.userInfo[kTLMKeyPose];
self.currentPose = pose;
// Handle the cases of the TLMPoseType enumeration, and change the color of helloLabel based on the pose we receive.
switch (pose.type) {
case TLMPoseTypeUnknown:
case TLMPoseTypeRest:
case TLMPoseTypeDoubleTap:
// Changes helloLabel's font to Helvetica Neue when the user is in a rest or unknown pose.
self.helloLabel.text = @"Hello Myo";
self.helloLabel.font = [UIFont fontWithName:@"Helvetica Neue" size:50];
self.helloLabel.textColor = [UIColor blackColor];
break;
case TLMPoseTypeFist:
// Changes helloLabel's font to Noteworthy when the user is in a fist pose.
self.helloLabel.text = @"Fist";
self.helloLabel.font = [UIFont fontWithName:@"Noteworthy" size:50];
self.helloLabel.textColor = [UIColor greenColor];
break;
case TLMPoseTypeWaveIn:
// Changes helloLabel's font to Courier New when the user is in a wave in pose.
self.helloLabel.text = @"Wave In";
self.helloLabel.font = [UIFont fontWithName:@"Courier New" size:50];
self.helloLabel.textColor = [UIColor greenColor];
break;
case TLMPoseTypeWaveOut:
// Changes helloLabel's font to Snell Roundhand when the user is in a wave out pose.
self.helloLabel.text = @"Wave Out";
self.helloLabel.font = [UIFont fontWithName:@"Snell Roundhand" size:50];
self.helloLabel.textColor = [UIColor greenColor];
break;
case TLMPoseTypeFingersSpread:
// Changes helloLabel's font to Chalkduster when the user is in a fingers spread pose.
self.helloLabel.text = @"Fingers Spread";
self.helloLabel.font = [UIFont fontWithName:@"Chalkduster" size:50];
self.helloLabel.textColor = [UIColor greenColor];
break;
}
// Unlock the Myo whenever we receive a pose
if (pose.type == TLMPoseTypeUnknown || pose.type == TLMPoseTypeRest) {
// Causes the Myo to lock after a short period.
[pose.myo unlockWithType:TLMUnlockTypeTimed];
} else {
// Keeps the Myo unlocked until specified.
// This is required to keep Myo unlocked while holding a pose, but if a pose is not being held, use
// TLMUnlockTypeTimed to restart the timer.
[pose.myo unlockWithType:TLMUnlockTypeHold];
// Indicates that a user action has been performed.
[pose.myo indicateUserAction];
}
}