Hi folks!
I'm new at sw development for garmin devices.
Because I'm a wheelchair triathlete and there is no wheelchair app on garmin, I'm using the normal Bicycle and Running apps for Handbike and Racing Wheelchair.
I've bought the garmin bikespeed sensor to record my speed data indoor. Because i've not found a way to use this sensor in the garmin running apps, I've deicded to programm my own very simple Indoor Wheelchair app.
There are some problems i've run into while programming, but i've made an app which is working in the simulator.
But on my garmin fenix5 if i start the fit recording (the "on select" function) i'll get no more speed data.
The hartrate data is fine, eighter with external hartrate sensor or with the internal one in the watch.
Here's my code:
using Toybox.WatchUi; using Toybox.System; using Toybox.Graphics; using Toybox.Lang; using Toybox.Activity; using Toybox.ActivityMonitor; using Toybox.ActivityRecording; using Toybox.Timer; using Toybox.AntPlus; using Toybox.FitContributor; using Toybox.Sensor; using Toybox.Time.Gregorian; using Toybox.Communications; var session = null; // set up session variable var speed,heartrate,field_heartrate=null,field_speed=null; var activityInfo = new Activity.Info(); var time=null; var x=0; //var sensorInfo = new Sensor.Info(); class RacingWheelchairDelegate extends WatchUi.BehaviorDelegate { function timerCallback(){ WatchUi.requestUpdate(); } function initialize() { BehaviorDelegate.initialize(); } function onMenu(){ System.println("onMenu"); if ((session!=null) && !(session.isRecording())){ System.println("session saved!"); session.save(); Sensor.unregisterSensorDataListener();//listener mehtod deaktivieren Sensor.setEnabledSensors([]); //disable all sensors field_heartrate = null; field_speed = null; session = null; } } // use the select Start/Stop or touch for recording function onSelect() { System.println("onSelect"); if (Toybox has :ActivityRecording ) { // check device for activity recording if ((session == null)) { session = ActivityRecording.createSession({ // set up recording session :name=>"Indoor Wheelchair", // set session name :sport=>ActivityRecording.SPORT_RUNNING, // set sport type :subSport=>ActivityRecording.SUB_SPORT_GENERIC // set sub sport type }); //Felder welche im FIT file gespeichert werden field_speed = session.createField("speed", 0, FitContributor.DATA_TYPE_FLOAT, {:mesgType=>FitContributor.MESG_TYPE_RECORD,:units=>"m/s"}); field_heartrate = session.createField("heartrate", 1, FitContributor.DATA_TYPE_SINT32, {:mesgType=>FitContributor.MESG_TYPE_RECORD,:units=>"bpm"}); session.start(); // call start session System.println("Session started"); } else if ((session != null) && session.isRecording()) { session.stop(); x=1; } else if ((session != null)) { session.start(); } } return true; // return true for onSelect function } } class RacingWheelchairView extends WatchUi.View { function initialize() { View.initialize(); } // Load your resources here function onLayout(dc) { //Bike speed Sensor aktivieren Sensor.setEnabledSensors([Sensor.SENSOR_BIKESPEED,Sensor.SENSOR_HEARTRATE]); Sensor.enableSensorEvents(method(:onSensor)); } function onSensor(sensorInfo){ speed = sensorInfo.speed; heartrate = sensorInfo.heartRate; if(speed != null){ speed = speed*3.6; speed = speed.format("%.1f"); } if((field_heartrate != null) && (heartrate != null)){ field_heartrate.setData(heartrate); } if((field_speed !=null) && (speed != null)){ field_speed.setData(sensorInfo.speed); } WatchUi.requestUpdate(); } // Called when this View is brought to the foreground. Restore // the state of this View and prepare it to be shown. This includes // loading resources into memory. function onShow() { } // Update the view function onUpdate(dc) { System.println("onUpdate"); //zeit aktualisieren var sec = 0,min = 0,hour = 0; if(session != null){ time = activityInfo.timerTime; sec = time/1000; min = sec / 60; hour = min / 60; min = min % 60; sec = sec % 60; } activityInfo = activityInfo.getActivityInfo(); //hintergrund schwarz malen dc.setColor(Graphics.COLOR_BLACK, Graphics.COLOR_TRANSPARENT); dc.fillRectangle(0, 0, dc.getWidth(), dc.getHeight()); //texte schreiben dc.setColor(Graphics.COLOR_WHITE, Graphics.COLOR_BLACK); if(time/*activityInfo.timerTime*/ != null){ dc.drawText(dc.getWidth()/2 , 50, Graphics.FONT_LARGE,hour + ":" + min + ":" + sec, Graphics.TEXT_JUSTIFY_CENTER); } if(speed!=null){ dc.drawText(dc.getWidth()/2 , 100, Graphics.FONT_LARGE, speed + "km/h", Graphics.TEXT_JUSTIFY_CENTER); } else{ dc.drawText(dc.getWidth()/2 , 100, Graphics.FONT_LARGE, "no speed" , Graphics.TEXT_JUSTIFY_CENTER); } if(heartrate!=null){ dc.drawText(dc.getWidth()/2 , 150, Graphics.FONT_LARGE, heartrate+"bpm", Graphics.TEXT_JUSTIFY_CENTER); } else{ dc.drawText(dc.getWidth()/2 , 150, Graphics.FONT_LARGE, "no heartrate", Graphics.TEXT_JUSTIFY_CENTER); } //linien zeichnen dc.setColor(Graphics.COLOR_BLUE, Graphics.COLOR_TRANSPARENT); dc.drawLine(0, 90, dc.getWidth(),90); dc.drawLine(0, 150, dc.getWidth(), 150); } // Called when this View is removed from the screen. Save the // state of this View here. This includes freeing resources from // memory. function onHide() { } }
What am I doing wrong?
Sorry for the german comments and other failures.... I've tryed so much but i can't do it..
Thanks for the help!
Regards Andreas