Coder Social home page Coder Social logo

Comments (9)

Artaud avatar Artaud commented on May 27, 2024

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.

tjthejuggler avatar tjthejuggler commented on May 27, 2024

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.

Artaud avatar Artaud commented on May 27, 2024

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.

tjthejuggler avatar tjthejuggler commented on May 27, 2024

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.

Artaud avatar Artaud commented on May 27, 2024

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.

Artaud avatar Artaud commented on May 27, 2024
    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.

Artaud avatar Artaud commented on May 27, 2024

this might work

from sleep-as-android-garmin-addon.

tjthejuggler avatar tjthejuggler commented on May 27, 2024

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.

Artaud avatar Artaud commented on May 27, 2024

LOL :) Glad to help, good luck with the app :)

from sleep-as-android-garmin-addon.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.