Comments (9)
Hi, yes, actually this is the core feature of the app. Well almost, we do 10 second aggregates on the watch, but realtime streaming is the same if you omit the aggregation. Realtime streaming would however put a larger strain on the battery.
from sleep-as-android-garmin-addon.
Oh this is great news. I want to make a juggling catch counter and if I can just get the accel data streamed over to a companion app I'm pretty sure I can do it. Thanks so much for the response, hopefully I can disect this enough to get the accel stuff from it. If you have any guidance I would certainly appreciate it, but no worries if not, just knowing that it is possible and that the way to do it is here is a huge help, I really appreciate your response.
from sleep-as-android-garmin-addon.
Sure, it's pretty easy. The first part is to start the accelerometer and begin listening to data from it, the second part is to send that data to your phone.
Below is a naive implementation which sends the data to the phone as fast as they're collected (I really do not recommend using it as it is because the garmin messaging protocol cannot handle too frequent messages. I have workarounds for it and can tell you more if interested but try to test this and you'll know what I'm talking about).
// Make sure to have your commListener registered
function startSensor() {
var options = {
:period => 4,
:accelerometer => {
:enabled => true,
:sampleRate => 10
},
};
Sensor.registerSensorDataListener(method(:onData), options);
}
function onData(sensorData) {
sendAccelData(sensorData.accelerometerData.x, sensorData.accelerometerData.y, sensorData.accelerometerData.z);
}
function sendAccelData(x,y,z) {
Communications.transmit(x+","+y+","+z, {}, self.commListener);
}
from sleep-as-android-garmin-addon.
Thanks so much for this! My current plan of attack was to just try and strip everything away from the sleep apps until I was left with just accel stuff, but there is so much in there, so building up from accel stuff is definitely preferable.
I put this code into a simple number selector watch app that I know runs. I got an error about commListener being undefined, so I found someone else code defining it as an extension of Communications.ConnectionListener and that at least made the error go away. I also got the permissions added to the manifest.
Now I am getting this error on 'Sensor.registerSensorDataListener(method(:onData), options);' and am not able to build the app:
Invalid '$.Toybox.Lang.Method(sensorData as Any) as Any' passed as parameter 1 of type '$.Toybox.Lang.Method(data as $.Toybox.Sensor.SensorData) as Void'.
//
// Copyright 2015-2021 by Garmin Ltd. or its subsidiaries.
// Subject to Garmin SDK License Agreement and Wearables
// Application Developer Agreement.
//
import Toybox.Application;
import Toybox.Lang;
import Toybox.WatchUi;
import Toybox.Communications;
import Toybox.Sensor;
//! This app demonstrates how to use the Number Picker.
class NumberPickerApp extends Application.AppBase {
// TODO: dedupe
(:background)
class commListener extends Communications.ConnectionListener {
function initialize() {
Communications.ConnectionListener.initialize();
}
function onComplete() {
System.println("Transmit Complete");
}
function onError() {
System.println("Transmit Failed");
}
}
//! Constructor
public function initialize() {
AppBase.initialize();
}
//! Handle app startup
//! @param state Startup arguments
public function onStart(state as Dictionary?) as Void {
startSensor();
}
//! Handle app shutdown
//! @param state Shutdown arguments
public function onStop(state as Dictionary?) as Void {
}
//! Return the initial views for the app
//! @return Array Pair [View, InputDelegate]
public function getInitialView() as Array<Views or InputDelegates>? {
var view = new $.NumberPickerView();
var delegate = new $.BaseInputDelegate(view);
return [view, delegate] as Array<Views or InputDelegates>;
}
// Make sure to have your commListener registered
public function startSensor() {
var options = {
:period => 4,
:accelerometer => {
:enabled => true,
:sampleRate => 10
},
};
Sensor.registerSensorDataListener(method(:onData), options);
}
public function onData(sensorData) {
sendAccelData(sensorData.accelerometerData.x, sensorData.accelerometerData.y, sensorData.accelerometerData.z);
}
public function sendAccelData(x,y,z) {
Communications.transmit(x+","+y+","+z, {}, self.commListener);
}
}
Thanks again, I really appreciate your help!
from sleep-as-android-garmin-addon.
Ah, okay, that's because strict typing was brought to Monkey C after I wrote this. You can either lessen the strictness of the type system by compiling with -l 2 flag, or you'll have to provide types for everything. I'll take a look at that.
from sleep-as-android-garmin-addon.
public function onData(sensorData as Sensor.SensorData) as Void {
sendAccelData(sensorData.accelerometerData.x, sensorData.accelerometerData.y, sensorData.accelerometerData.z);
}
public function sendAccelData(x as Lang.Array<Lang.Number>,y as Lang.Array<Lang.Number>,z as Lang.Array<Lang.Number>) {
Communications.transmit(x+","+y+","+z, {}, new commListener());
}
from sleep-as-android-garmin-addon.
this might work
from sleep-as-android-garmin-addon.
You are a wizard! That fixed the error and it built. I'm going to work on the android end of things now. Thank you so much for your help with this, I really appreciate it!
from sleep-as-android-garmin-addon.
LOL :) Glad to help, good luck with the app :)
from sleep-as-android-garmin-addon.
Related Issues (20)
- Add MARQ Athelete device HOT 1
- Don't trigger Backlight on movement/gesture (Fenix 6 / Power Profiles) HOT 2
- No response since Android 10 HOT 2
- remove tones HOT 1
- Build failed HOT 3
- Sleep -> Starting ... all-nighter
- Alarm starts right after starting tracking HOT 3
- Disable alarm in app settings
- show pulse while sleep tracking
- Watch Crashes (Reboots) when Selecting Open Sleep This Time or Every Time on Bedtime Notification HOT 4
- sleep apnea, low respiratory rate HOT 4
- Additional device support HOT 2
- Unable to Debug the watch app using the ConnectIQ Simulator and the Android Emulator
- Add new Garmin models HOT 2
- New Watch Request - Forerunner 630 HOT 1
- Rename Graphs in sidebar
- High Battery Consumption and Connection Issues with Garmin Addon - Suggestion to Explore Companion SDK HOT 2
- New Watch: Venu 3 HOT 2
- Instinct 2X Solar - SaA Alarm Dismiss stops alert on watch, but Snooze does not HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sleep-as-android-garmin-addon.