Search code examples
iosobjective-cmyo

Vibrate Myo Armband programmatically


How can I can vibrate Myo programmatically.

I could vibrate in TLMHubDidConnectDeviceNotification, but I could use it in TLMMyoDidReceiveOrientationEventNotification because in this notification a don't have a instance of TLMMyo.

Eg: Vibration in TLMHubDidConnectDeviceNotification

TLMMyo *myo = notification.userInfo[kTLMKeyMyo];

[myo vibrateWithLength:TLMVibrationLengthLong];
[myo vibrateWithLength:TLMVibrationLengthMedium];
[myo vibrateWithLength:TLMVibrationLengthShort];

I also try to save the instance in a @property but in TLMMyoDidReceiveOrientationEventNotificationthis instance is nil.

PS: Question in Myo Developer Forum


Solution

  • Seems like there's a bug with that notification. In the meantime, you can access TLMMyos on the TLMHub singleton's myoDevices method. If you're using multiple Myo devices, you can identify the one you want to use using the identifier property on TLMMyo.

    I'll look into getting the notification fixed in the long term though.

    TLMMyo *myo = [[[TLMHub sharedHub] myoDevices] firstObject];
    
    if (myo.identifier == self.identifier) {
        [myo vibrateWithLength:TLMVibrationLengthLong];
        [myo vibrateWithLength:TLMVibrationLengthMedium];
        [myo vibrateWithLength:TLMVibrationLengthShort];
    }