How to make haptic buzzer vibrate several times on ANCS event?
I need to produce several consequent vibrations with pause between them when new notification is caught by ANCS MBLEvent.
I tried to use
Does someone know how to do that?
Of course I use
Thanks in advance for any help.
I tried to use
sleepForTimeInterval:
, eventWithPeriod:repeatCount
with following programCommandsToRunOnEvent:
and even recursive blocks - all failed.Does someone know how to do that?
Of course I use
setConfiguration:handler:
to program MetaWear device to log data offline and reacting on events.Thanks in advance for any help.
This discussion has been closed.
Comments
// Whatever should trigger the buzzing
MBLEvent *trigger = self.device.mechanicalSwitch.switchUpdateEvent;
// Program a timer to fire 3 times, 1000 ms apart
MBLTimerEvent *timer = [self.device.timer eventWithPeriod:1000 repeatCount:3 autoStart:NO];
[[timer programCommandsToRunOnEventAsync:^{
// Each time the timer fires we perform a buzz
[self.device.hapticBuzzer startHapticWithDutyCycleAsync:255 pulseWidth:250 completion:nil];
}] continueWithSuccessBlock:^id _Nullable(BFTask * _Nonnull task) {
// Then each time our trigger event occurs we start the timer, thus starting the buzzing
return [trigger programCommandsToRunOnEventAsync:^{
[timer start];
}];
}];
let leftTurnLEDOnEvent: MBLTimerEvent = (self.device.timer?.eventWithPeriod(1000, repeatCount: 5, autoStart: false))!
// Once the LED turns on we want to turn it off after 500 ms
let leftTurnLEDOffEvent: MBLTimerEvent = (self.device.timer?.eventWithPeriod(500, repeatCount: 1, autoStart: false, triggerOnStart: false))!
// This event must shut down the LED
leftTurnLEDOffEvent.programCommandsToRunOnEventAsync {
//self.leftLED.setToDigitalValueAsync(self.NO)
self.device.led?.setLEDOnAsync(false, withOptions: 1)
}.continueWithSuccessBlock { _ in
// This event powers on the LED and then starts the turn-off timer
return leftTurnLEDOnEvent.programCommandsToRunOnEventAsync {
//self.leftLED.setToDigitalValueAsync(self.YES)
self.device.led?.setLEDColorAsync(UIColor.greenColor(), withIntensity: 1.0)
leftTurnLEDOffEvent.start()
}
}.continueWithSuccessBlock { _ in
// Now that these events are programmed, we can start it anytime by calling start
return leftTurnLEDOnEvent.start()
}.success { _ in
print("SUCCESS!")
}.failure { error in
print (error)
}
Code=111 "MetaWear out of memory, can't perform action. Reset the MetaWear and use no more than 8 entities"