How can we access tap recognition on the LSM6DS3 in the movesense device? - movesense

For example, I'd like to start the onboard datalogger when a user taps the device, and stop the datalogger when they double-tap.

TAP and DOUBLE_TAP are available in the /System/States -API. However simultaneous TAP & DOUBLE_TAP are not possible from the sensor, so to get both you'll have to do the following:
SUBSCRIBE /System/States/4 (4 == TAP)
When TAP event is received trigger a one_off timer (around 600-800ms is good)
If a second TAP is received before the timer is triggered, reset timer and forward as DOUBLE_TAP event
If timer expires without any TAP detections, forward as TAP event
Other things to consider are:
Users usually want some kind of feedback that the command went thru (e.g. LED blink or mobile sound). Without it they tend to try again and again.
It's a good idea to test the TAP sensitivity etc. with many test subjects. Each person tends to tap differently.
If the IMU (Acc, Gyro / Magn) are subscribed as well, the TAP detection works on the sample rate of measurement subscription. DOUBLE_TAP detection is not reliable with 13 or 26 Hz sample rates.
Full Disclosure: I work for the Movesense team

Related

How to maximize battery life on Movesense sensor?

I have a use case where the Movesense sensor will be used occasionally (say, an hour a day) and I'd like to maximize battery life. Is there a way to put it into a sleep state, and then wake it in response to some user action? For example, shut off Bluetooth and all sensors but the accelerometer, and then wake them up with the accelerometer detects that it's being moved or tapped.
I see that the Movesense sensor can be put in "PowerOff" or "FullPowerOff" state. In these states is it completely shut down, or is it possible to continue to monitor the accelerometer?
Yes, it is possible. You can check hr_wakeup_sample:
https://bitbucket.org/suunto/movesense-device-lib/src/887714f3b42496988cce6055b3ccf8b8c99a6846/samples/hr_wakeup_app/?at=master
The device is waking up when you put your fingers to the metal pins (on the bottom).
Also you can change this line:
asyncPut(WB_RES::LOCAL::COMPONENT_MAX3000X_WAKEUP::ID,
AsyncRequestOptions(NULL, 0, true), (uint8_t) 1);
https://bitbucket.org/suunto/movesense-device-lib/src/887714f3b42496988cce6055b3ccf8b8c99a6846/samples/hr_wakeup_app/HrWakeupApp.cpp?at=master&fileviewer=file-view-default#HrWakeupApp.cpp-132
to use this API:
https://bitbucket.org/suunto/movesense-device-lib/src/887714f3b42496988cce6055b3ccf8b8c99a6846/MovesenseCoreLib/resources/movesense-api/component/lsm6ds3.yaml?at=master&fileviewer=file-view-default#lsm6ds3.yaml-119

Keeping Apple Watch Awake for more than 70 seconds (watchOS 3)

Is there any way to keep an Apple Watch awake for more than 70 seconds? I understand the purpose of turning off the face to save battery life but I'm trying to sample motion data continuously for about 3 minutes and the sampling is interrupted as soon as the face turns off. I've set the watch to stay awake for 70 seconds every time I tap it, but is there any way to prevent it from turning off for > 3 minutes? I found this post from Feb. of 2016 but haven't found any updates confirming or denying the possibility of preventing the watch face from sleeping in watchOS 3.
If you're looking at sampling motion data like the accelerometer or gyroscope, you can create a HKWorkout Session that will keep your app running in the background. While your Watch face will still eventually turn off without tapping, you will still continue to be able to keep sampling your motion data. Note that only one HKWorkout Session can be run at a time. Hope this helps!

Not getting accelerometer and heart rate data when screen is turned off in watchOS 2

I'm working on apple watch app using CMMotionManager and HKWorkoutSession to get both the accelerometer and the heart rate data. The app works fine for a short period of time (70 seconds), but when the screen is turned off, both the heart rate and the accelerometer data just stops.
My question is how could I get a 5 minutes data from both the accelerometer and the heart rate sensors?
To take more time when app is going to background you can use performExpiringActivityWithReason. This is described here https://developer.apple.com/videos/play/wwdc2015/228/?time=345 On my watch it just takes approx 30 seconds
NSProcessInfo.processInfo().performExpiringActivityWithReason("Reason") {
expired in
if !expired {
let delay: Int64 = 30
let delayTime = dispatch_time(DISPATCH_TIME_NOW, delay * Int64(NSEC_PER_SEC))
dispatch_semaphore_wait(semaphore, delayTime)
} else {
dispatch_semaphore_signal(semaphore)
}
}
Since the release of watchOS 2, HKWorkoutSession is the only way to keep an app running when the watch screen goes off. HOWEVER, the app is in a suspended state. Timers and any other process execution is paused until the screen turns back on. Memory allocations for the app however is preserved. During the time the app is suspended, the device's hardware is still collecting data and storing it on the watch's hard drive. When the screen turns back on the the app come out of suspension and any data that was collected by the hardware is returned at that point to the app (assuming the appropriate listeners were subscribed to).
There is not currently a way to continue to send heart rate data (or any data) from the watch to an iPhone after the screen turns off.
watchOS 2 does not allow apps to run while the screen is off. Although there are ways you can get a bit of extra time, such as with performExpiringActivityWithReason, there is no way to ensure that your app runs for a full 5 minutes.
Now, Apple open an API for recording your Accel data Click:CMSensorRecorder
. whenever your app is suspended or killed, the API will continuous run in 50Hz almost 3 days.

Game Center multiplayer, very long connection timeout

I've implemented a 2-player turnbased game using Game Center matchmaking/multiplayer, in other words using GKMatch. It works well. There is just one issue: when one player disconnects (ie. quits the app), it takes a while before the other players gets notified of this (with match:player:didChangeState:). Sometimes even 30 seconds.
That is not a good UX. I don't want a player to wait for nothing if the other player already disconnected 30 seconds ago.
2 questions:
Is this an issue with the sandbox server only?
If not, what can I do to shorten/eliminate this waiting period?
I did not rely on GC's notifyPlayer.. Everything from DC to quit game to receive calls i handle by my own codes..
for my code, when player A presses home button, means in app delegate's applicationDidEnterBackground, a data is sent to the player B to inform that player A has quit the game. This way, when the player A quits, player B will immediately know that player A has quit.. Rather than waiting for gamecenter to notify you..

App not playing sound when screen turned off, but doing everything else as it should?

I have an alarm clock app which works on a timer. When the alarm is meant to go off and the screen is switched off, it should start playing audio from AVAudioPlayer, but it doesn't. Then when i turn the screen back on, i can see that the rest of the code fired as expected (a stop button is now on the screen). How do i get the AVAudioPlayer to play when the screen is turned off?
Is there any way for me to detect that the screen is turned off?
#zoul is correct that using the default audio session category will result in sound form your app being disabled when the user locks the screen. See the Audio Session Programming Guide for direction on which audio session category you should choose.
However, even once your audio session category is set correctly, you'll have another issue to tackle. When the screen is switched off, your application gets suspended per Apple's documentation here: Executing Code in the Background. This means that when the user locks their phone or switches to a different app, your app will stop running and stay in a freeze-dried (task-suspended) state until the user activates your app again. At that point, your app resumes execution as if nothing happened. That's why it appears that your app has continued to function when you unlock the screen.
For alarm behavior, you'll probably want to schedule the delivery of a local notification. A local notification will ensure that the system provides your alert to the user at the time you request, and allows the user to activate your app. See Scheduling the Delivery of Local Notifications for details on how to accomplish this.
Maybe you have the wrong audio category? See the documentation for AVAudioSession, especially the audio category settings.