Start To Run http://starttorun.info downloads, reviews, schedules, info... Thu, 21 Sep 2017 14:51:54 +0000 en-US hourly 1 https://wordpress.org/?v=4.8.2 Calculated Field http://starttorun.info/calculated-field/ http://starttorun.info/calculated-field/#respond Wed, 02 Aug 2017 15:11:09 +0000 http://starttorun.info/?p=1330 What? The Calculated Field Connect IQ Data Field allows you to come up with your own simple calculation. Supported operations: + – * / ^ (power) Following variables are available: heartrate, cadence, power, altitude, averagecadence, averageheartrate, averagepower, averagespeed, calories, heading, locationaccuracy, speed, distance, elapsedtime, energyexpenditure, timerTime, totalascent, totaldescent, trainingeffect, maxcadence, maxheartrate, maxpower, maxspeed Download Download ...read more

Dit bericht Calculated Field komt van: Start To Run.

]]>
What?
The Calculated Field Connect IQ Data Field allows you to come up with your own simple calculation. Supported operations:
  • +
  • *
  • /
  • ^ (power)
Following variables are available:
heartrate, cadence, power, altitude, averagecadence, averageheartrate, averagepower, averagespeed, calories, heading, locationaccuracy, speed, distance, elapsedtime, energyexpenditure, timerTime, totalascent, totaldescent, trainingeffect, maxcadence, maxheartrate, maxpower, maxspeed

Download
Download the data field from the connect iq store

Dit bericht Calculated Field komt van: Start To Run.

]]>
http://starttorun.info/calculated-field/feed/ 0
Connect IQ Apps with Source Code http://starttorun.info/connect-iq-apps-with-source-code/ http://starttorun.info/connect-iq-apps-with-source-code/#respond Fri, 31 Mar 2017 06:06:23 +0000 http://starttorun.info/?p=1149 The Connect IQ SDK itself contains a good set of examples (you find these in the samples directory when you download the latest sdk package). Connect IQ Tutorials (Learn Best Practices) If you want to learn to create Connect IQ programs then I would advise you to have a look at the available tutorials. Examples ...read more

Dit bericht Connect IQ Apps with Source Code komt van: Start To Run.

]]>
.
The Connect IQ SDK itself contains a good set of examples (you find these in the samples directory when you download the latest sdk package).

Connect IQ Tutorials (Learn Best Practices)

If you want to learn to create Connect IQ programs then I would advise you to have a look at the available tutorials. Examples an sich are good, but tutorials in addition also explain best practices and the why (in addition to the how).

Tutorials by Peter (Me):
Tutorial Overview
Tutorials by Jim (jim_m_58):

Tutorials by Hermo (HermoT):

Tutorials by Franco Trimboli:

Download Connect IQ Source Code (Learn By Example)

.

There are a lot of Garmin Connect IQ developers that share their Monkey C source code with the world. This section is a collection of links towards these source code repositories. The quality of the code varies a lot from one repo to another: some are prime examples of how to code, others are not…

(When you use something in your own apps be sure to give credit where credit is due and to respect the license of the open source app (usually available in the root of the source code repo))

Apps:
2048
7-Minute Workout
Badminton
Flashlight
Fitness Timer
gImporter
Helicopter
HueCiq
Kraken
LandNav App
Orange Theory
Nest Thermostat
Sailing Timer
Sendpoints
Snapshot Resting Heart Rate
SportMonitor App
SensorViz
Stretch
Squash App
Tabata Timer
Triathlon, Duathlon & Aquathlon
Ultitimer

Data Fields:
Auxiliary Heartrate
Average pace with trend indication
Back To Home
Average Vertical Speed
Bikers Field
Chart Data Fields
Cog Display
Colour Heartrate
Cyclist Datafield
Display GPS
Dozen Run
Current speed in percent of vVo2max
Energy Expenditure Field
FlexiRunner
Heart Rate Runner
HMFields
Laps
Monkey Fuel
My Training Impact
My Training Intensity
ORun
Power Adjuster
PowerField + Tests
Runners Field
Running Economy Field
Snapshot
Snapshot Heartrate
Steps Carousel
Tidy Field
Time To Rest
Trendy Run
Turn Around Reminder
View Distance In 500 Metre Segments
View Time In 15 Minute Segments
W’ Balance

Other:
Samples collection
Wraptext class
Watch Faces:
AMD Watchface
Analog 24 hour
Analog Battery Saver
Arc Sin
Aviator Like
Binary Elegance
Binary Elegance HR
Binary Time
Binary System
Chief Dexter
Clean Steps
Daily Stats With Time Watchface
Dark Times
Digital
Divided Time
Dotter
DrawLineAA
Felt
Flip Clock
Formula 1
Full Day
Garmin Mario
Garmin Van Gogh
Helsingborg Marathon
JSClock
KISSFace
Mickey
Lefthand watchface
Malmö FF
Military24Time
MotorcycleFBSide
Nyan Cat
Oz
PolyBug
SimpleWaF
Simplog
Simply Late
Snapshot Watch
StyloMylo
Swaggin’ Numerals
Tidy Watch
Waketest

Widgets:
Activity Widget
#CIQSummit17
Emergency Info
Football Fixtures
Forecastline
Fortune Quote
Hr Widget
Instrument Panel
Iq Meteo
Moon Phase
Show All Infos
Sms
Sun Calc
Timer Widget
Train As One
Word Of The Day
ZuluTime

Android Companion Apps:
gExporter


Did you spot another source code repository that’s not in the list yet?
Let us know in the comments below and we’ll add it to the list.

Dit bericht Connect IQ Apps with Source Code komt van: Start To Run.

]]>
http://starttorun.info/connect-iq-apps-with-source-code/feed/ 0
Eat! Drink! Reminder! (Data Field) http://starttorun.info/eat-drink-reminder-data-field/ http://starttorun.info/eat-drink-reminder-data-field/#comments Thu, 09 Feb 2017 16:02:02 +0000 http://starttorun.info/?p=1121 What? The Eat! Drink! Reminder! Data Field is a Garmin Connect IQ application that you can install on all recent garmin devices. Why? Are you also forgetting on your long run to eat and drink? Not any more… Set the alarm settings and be notified by vibration and/or a beep (vibration and beep not available ...read more

Dit bericht Eat! Drink! Reminder! (Data Field) komt van: Start To Run.

]]>
What?
The Eat! Drink! Reminder! Data Field is a Garmin Connect IQ application that you can install on all recent garmin devices.

Why?
Are you also forgetting on your long run to eat and drink? Not any more… Set the alarm settings and be notified by vibration and/or a beep (vibration and beep not available on some devices). (You have the option to set 5 different alarms.)

Download
From the Connect IQ App Store: https://apps.garmin.com/en-US/apps/b4cfbbbd-b506-4bb6-b627-30fc26a1327c#0

Dit bericht Eat! Drink! Reminder! (Data Field) komt van: Start To Run.

]]>
http://starttorun.info/eat-drink-reminder-data-field/feed/ 4
Steps Carousel Data Field http://starttorun.info/steps-carousel-data-field/ http://starttorun.info/steps-carousel-data-field/#respond Thu, 09 Feb 2017 15:54:55 +0000 http://starttorun.info/?p=1116 What? Steps Carousel is a Data Field for watches that have the ability to install Connect IQ applications (all modern Garmin watches). After pressing start this field shows a carousel with changing information, it shows each value for 5 seconds: Total Steps Active Steps Steps To Go / Steps Done Too Much Goal Percentage (Steps ...read more

Dit bericht Steps Carousel Data Field komt van: Start To Run.

]]>
What?
Steps Carousel is a Data Field for watches that have the ability to install Connect IQ applications (all modern Garmin watches). After pressing start this field shows a carousel with changing information, it shows each value for 5 seconds:
  • Total Steps
  • Active Steps
  • Steps To Go / Steps Done Too Much
  • Goal Percentage (Steps vs Steps Goal)
Ideal for walkers who want to be motivated to reach their daily step goal! 🙂

Download
Steps Carousel Data Field in the Connect IQ Store

Interested in creating an app like this yourself?
Check out my Garmin Connect IQ Tutorial

Dit bericht Steps Carousel Data Field komt van: Start To Run.

]]>
http://starttorun.info/steps-carousel-data-field/feed/ 0
Peter’s (Race) Pacer http://starttorun.info/peters-race-pacer/ http://starttorun.info/peters-race-pacer/#comments Sun, 22 Jan 2017 15:03:22 +0000 http://starttorun.info/?p=1077 Summary Peter’s (Race) Pacer is a Garmin Connect IQ Data Field which resolves 2 issues for me when I’m running a race: Before the race starts I want to see the current time of the day (well actually I want to see, how long till the race starts?) When I pace races it used to ...read more

Dit bericht Peter’s (Race) Pacer komt van: Start To Run.

]]>
Summary Peter’s (Race) Pacer is a Garmin Connect IQ Data Field which resolves 2 issues for me when I’m running a race:
  • Before the race starts I want to see the current time of the day (well actually I want to see, how long till the race starts?)
  • When I pace races it used to be doing mental math all the way, now this is no longer necessary as you can fully depend on the average pace/speed, because this data field allows to correct the distance at the kilometer / mile marker by simply pressing the LAP button
While the data field’s primary intent is to race races, you can also use it to run laps around the track, just set the lap distance to 400 meters and press the lap button as you cross the line!…

Installation / Configuration

  • Install the Data Field on your watch by clicking download in the Connect IQ store
  • Customize the data field in the Android App or Garmin Express 
    • Manage Apps
    • Select Peter’s (Race) Pacer
    • Click on the button “…”
    • Configure the settings and hit ok.
  • Configure your watch to use the data field:
    • On the clock face click “Start button”
    • Choose the Activity Profile for which you wish to install this data field for (eg Running)
    • Press the down button
    • Choose Activity Settings
    • Choose Data Screens
    • Choose “Screen 1” (or another screen)
    • Layout: click Start button and click the down button until the layout shows only 1 field 
    • When 1 field is selected press the back button
    • Choose field 1 (and click start button)
    • Choose “Connect IQ”
    • Select “Peter’s (Race) Pacer” from the list (hit start button)
    • All done, hit back, back, back, back…


Usage

(All functionality of this datafield uses about 22k, which is way too much for the older Connect IQ devices (only have 16k memory there). To be able to run the field on older devices I’ve stripped items marked with (*cIQ2) from those devices to be able to run it within the 16k memory limit.)


Before starting the race an initial data screen is shown (*cIQ2), this screen shows you the following data:
  • Time of the day
  • Current heart rate (+ zone indication)
  • Configured Settings Summary (Change these settings in Garmin Express or in the Garmin Connect Android App)
    • Target Pace / Target Speed / Target Finish Time 
    • Target Distance: 5k, 10k, 10 miles, half marathon, marathon or custom distance
    • Lap Size in meter
      • 1 k = 1000 meter
      • 1 mile = 1609.304 meter
      • typical length of track = 400 meter
  • Battery Percentage Remaining
  • Gps Signal Strength Indication



When pressing the START button the race timer will start and a new data screen will be shown, this data screen will show you the following information: 
  • top middle configurable field: current heart rate / average pace / average speed / perfect pace / perfect speed
  • left configurable field: average pace / average speed / current heart rate / perfect speed / perfect pace
  • middle configurable field: speed, smooth speed (5s average), smooth speed (10s average), pace, smooth pace (5s average), smooth pace (10s average)
  • time ahead / behind
  • race timer
  • (adjusted) distance covered (see adjusting distance explanation below)
  • estimated time of arrival
Perfect Pace / Perfect Speed
This field recalculates as you run and gives you the pace you need to run to arrive at the finish with 0 seconds behind / ahead (eg if you run a 10k race and want to arrive in 1 hour (avg pace=6:00min/km) and currently you’re at the 7k point in 41:30, which means you’re 30 seconds ahead, then the perfect pace will show the value 6:10 (min/km) as you can run the next 3k 10 seconds slower to still get in time at the finish line

Adjusting the race distance

In a race when you’re next to the race marker press the LAP button, the distance will now be corrected to the nearest lap position (eg 5.08 will correct to 5, 8.8 will correct to 9, …). After pressing the lap button the distance will be adjusted and all averages will be recalculated against this new distance figure.

When you miss a lap marker don’t worry: do not press LAP and go for the next lap marker. 

When you press the LAP marker by mistake you can undo the (last) correction by pressing the LAP button again (within a 30 second window)

Note: Adjusting the distance by pressing the LAP button has no influence on the recorded distance. (When you come home and look on Garmin Connect the distance will be the recorded GPS distance). If you turned off auto-lap you will see where you pressed the lap button and which mile/kilometer marker corresponded with which GPS distance.

Recommendations

  • Test the data field on a training session so you’re used to the layout.
  • Have a second screen with a native data field configuration as a precaution.

Donations

The data field is fully functional without donating. Donations are optional but encouraged from from within the data field with a small encouragement text. If you find Peter’s (Race) Pacer useful and/or Peter’s (Race) Pacer helps you to achieve your goal you can show your appreciation by donating an amount (suggested donation: 5 euro) on my PayPal account

After donation you will receive a donation key on your paypal email address which which will remove the “Like it? Donate!” message from the data field. (this is a manual process, but normally you should receive a key within 24 hours).

Dit bericht Peter’s (Race) Pacer komt van: Start To Run.

]]>
http://starttorun.info/peters-race-pacer/feed/ 28
Tutorial: Create Connect IQ unit tests http://starttorun.info/tutorial-create-connect-iq-unit-tests/ http://starttorun.info/tutorial-create-connect-iq-unit-tests/#respond Sun, 18 Dec 2016 21:10:19 +0000 http://starttorun.info/?p=999 In the previous tutorials we learned how to set up our project to be able to do unit testing and how to run unit tests. To understand this article it’s rather essential that you’ve read the previous 2 articles, in case you didn’t read those articles yet I’d advise to go back and read it ...read more

Dit bericht Tutorial: Create Connect IQ unit tests komt van: Start To Run.

]]>
how to set up our project to be able to do unit testing and how to run unit tests.
To understand this article it’s rather essential that you’ve read the previous 2 articles, in case you didn’t read those articles yet I’d advise to go back and read it now, start with the article how to create a unit test project.
.

Prerequisites for this tutorial

This tutorial is part of a tutorial series:
This tutorial continues where the last tutorial left of. If you did that tutorial you can continue with your own code base or you can download my project here instead.

First Unit Test: Exposing private variables

Purpose of the test

In our first actual connect IQ unit test we want to verify that the intial value of the Total Steps is set to 0.

Problem

A problem is that we need access to the total steps value to verify it, but that field is private (hidden in MonkeyC terms)…

Solution

The solution is quite easy as our mock StepsCarouselMock inherits from StepsCarouselView we can expose the private variable value in a public getter getValue(). So we add the following function to our mock:
function getValue() {
        return value;
    }
We now have the ability to actually get the value, now let’s go and create the actual unit test:
  • In the file StepsCarouselTests.mc add the code for the first test:
(:test)
function initialStepsTotalIsZero(logger) {
    var view = new StepsCarouselMock();
    var value = view.getValue();
    Toybox.Test.assertEqualMessage(value,0.0,"Initial Steps Total is expected to be 0.0");
    return true;
}
Ok there’s only 4 lines in our test but why are they there? Let’s go over them and explain what they do:
  • var view = new StepsCarouselMock(); -> create a new instance of our mocked StepsCarouselView
  • var value = view.getValue(); -> get the value of the field “value”, in StepsCarouselView this variable is private, but we’ve exposed it’s value in the getValue() function.
  • Toybox.Test.assertEqualMessage(… -> compare the actual value with the expected value and define the message to show when the test fails
  • return true; -> if a test function returns false then the test fails, you can misuse this functionality to do your assertions in this return statement, but personally I prefer to asserts with actual assert functions because I think it’s cleaner and more obvious when a test fails.

Run the tests

Create a run test profile for your project and execute the test, in the console window you should see the following pass by (for each watch target):
------------------------------------------------------------------------------
Executing test helloWorld...
DEBUG (21:13): Hello World
PASS
------------------------------------------------------------------------------
Executing test initialStepsTotalIsZero...
PASS

==============================================================================
RESULTS
Test:                                Status:
helloWorld                           PASS
initialStepsTotalIsZero              PASS
Ran 2 tests

PASSED
Connection Finished
Closing shell and port
Press any key to continue . . .
And also in the summary “run no evil” window you’ll see 2 succeeding tests!

Second unit test: Mock external dependencies

Purpose of the test

we want to verify that when the timer is not running that recorded steps do not increase.

Problem

The problem here that we want to test the compute function, but inside that function there is a dependency on the behaviour of an external component (Toybox.ActivityMonitor)

Solution

The solution for this issue is to replace this external dependency by something that we can access. We will in other words have to create a mock for the Toybox.ActivityMonitor and instead of calling the real one call our mock instead. In our business project we still want to call the real one though…

In the StepsCarouselView.mc file we introduce a new function getActivityMonitorInfo, this function will return the real value of the component:
function getActivityMonitorInfo() {
        return Toybox.ActivityMonitor.getInfo();
    }
In the StepsCarouselView.mc file we replace the calls to Toybox.ActivityMonitor.getInfo() by a call to our newly created function. (replace in the compute function and in the onTimerStart function).

When unit testing we don’t want to depend on this external dependency

So let’s create a new mock which has the same fields as the real function.

Edit the file StepsCarouselMocks.mc and add a mock for the ActivityMonitorInfo… something like this should do it:
class ActivityMonitorInfoMock {
    var steps = 0;
    var stepGoal = 5000;
}
In the StepsCarouselMock we want to be able to inject the ActivityMonitorInfoMock, so let’s add the following to the StepsCarouselMock class:
hidden var activityMonitorInfo = new ActivityMonitorInfoMock();

    function getActivityMonitorInfo() {
        return activityMonitorInfo;
    }

    function setActivityMonitorInfo (info) {
        activityMonitorInfo = info;
    }
We also need to be able to get the recorded steps from the StepsCarouselMock, we learned how to do this in the first unit test, expose the private!
function getStepsRecorded() {
        return stepsRecorded;
    }

Let’s create the unit test

Ok we’re finally ready to create the test now:
(:test)
function whenTimerDoesNotRunRecordedStepsDontIncrease(logger) {
    var view = new StepsCarouselMock();

    // create the ActivityMonitorInfoMock
    var activityMonitorInfo = new ActivityMonitorInfoMock();
    view.setActivityMonitorInfo(activityMonitorInfo);

    // set steps to 15
    activityMonitorInfo.steps = 15;
    
    // inject the ActivityMonitorInfoMock into the StepsCarouselMock
    view.setActivityMonitorInfo(activityMonitorInfo);
    
    // execute business logic
    view.compute(null);

    Toybox.Test.assertEqualMessage(activityMonitorInfo.steps,15,"Steps are 15");
    Toybox.Test.assertEqualMessage(view.getStepsRecorded(),0,"Recorded Steps are 0");

    return true;
}

Want some practice?

If you want some practice, try to create the following unit tests:
  • when the timer runs, then recorded steps should increase
  • when the timer is stopped, then the total steps (of the day) are shown
  • when the timer is stopped, then the label does not change after 5 seconds
  • every 5 seconds the value of the label should change (create the test + fix the bug)

Source Code

You can download the full source code from github

Dit bericht Tutorial: Create Connect IQ unit tests komt van: Start To Run.

]]>
http://starttorun.info/tutorial-create-connect-iq-unit-tests/feed/ 0
Tutorial: Run Connect IQ unit tests http://starttorun.info/tutorial-run-connect-iq-unit-tests/ http://starttorun.info/tutorial-run-connect-iq-unit-tests/#respond Sun, 18 Dec 2016 21:09:29 +0000 http://starttorun.info/?p=990 In the previous tutorial we learned how to set up our project to be able to do unit testing, in case you didn’t read that article yet I’d advise to read it now as it’s rather essential when you also want to be able to set up unit tests for your own projects. So read ...read more

Dit bericht Tutorial: Run Connect IQ unit tests komt van: Start To Run.

]]>
previous tutorial we learned how to set up our project to be able to do unit testing, in case you didn’t read that article yet I’d advise to read it now as it’s rather essential when you also want to be able to set up unit tests for your own projects. So read the article how to create a unit test project first now. 🙂

Prerequisites for this tutorial

This tutorial is part of a tutorial series:
This tutorial continues where the last tutorial left of. If you did that tutorial you can continue with your code base or you can just download my project here instead.

Create the first unit test

First we’ll create a easy “hello world” Connect IQ unit test to get us started.
  • Create a new file StepsCarouselTests.mc under the source folder
  • In this new file we say hello world and return true to indicate succes:
The contents of the StepsCarouselTests.mc file will be:
(:test)
function helloWorld(logger) {
    logger.debug("Hello World");
    return true;
}

Running unit tests

Since Connect IQ 2.3.1 it is possible to run unit tests from within the eclipse editor (in previous versions we had to rely on the command line).

The first thing we do is a create a no “Run No Evil” run profile, we do this by going to the menu run -> run configurations -> run no evil test. Click on the new launch configuration button in the button bar and create the following test profile (Select the watches you want to run the tests on by ticking the boxes – here we have all available watch targets of this test project enabled):



Now we only have to run the test, click the run button!

You’ll see several simulators flash by and when finished you see the results in the run no evil box, you can drill into the details by clicking on the “>” icon.

Source Code

You can download the full source code from github

Up next

In the next tutorial we’ll learn how to create unit tests which actually evaluate business logic.
.

Dit bericht Tutorial: Run Connect IQ unit tests komt van: Start To Run.

]]>
http://starttorun.info/tutorial-run-connect-iq-unit-tests/feed/ 0
Tutorial: How to create a Connect IQ unit test project http://starttorun.info/tutorial-how-to-create-connect-iq-unit-test-project/ http://starttorun.info/tutorial-how-to-create-connect-iq-unit-test-project/#respond Sun, 18 Dec 2016 21:08:37 +0000 http://starttorun.info/?p=952 Unit testing is important, yet I haven’t seen a single Connect IQ sample project that explains how to implement a Connect IQ unit test. It’s my hope that this blog will inspire many Connect IQ app authors to start writing accompanying unit test projects. 🙂 Why unit tests are important For me the reasons to ...read more

Dit bericht Tutorial: How to create a Connect IQ unit test project komt van: Start To Run.

]]>
It’s my hope that this blog will inspire many Connect IQ app authors to start writing accompanying unit test projects. 🙂

Why unit tests are important

For me the reasons to write unit tests are:
  • Test Automation: no need to redo the same set of tests manually over and over again with each release
  • Avoid regression issues
  • Document expected behaviour
  • Makes me confident to refactor and/or make changes

Prerequisites for this tutorial

This tutorial is part of a tutorial series:
This tutorial continues where the last tutorial (3: Using string resources) left of. If you did that tutorial you can continue with your code base or you can just download my project from here instead.

Start the dev environment

Start Eclipse and open the Steps Carousel project (File -> Open projects from file system ->) Your Project Explorer should look like this:

Set up the connect IQ Test Project

While it’s possible to write unit test code in the same connect IQ project as the project where your business logic resides, I wouldn’t advise to do so because (also in the release build) the test code will consume extra space and memory (even when marking the test extras with the (:debug_only) annotation).

To solve this extra memory issue we will set up a new project that is of the same type as the project that we want to test (in our case this project type is thus a Data Field).

File -> New -> Connect IQ Project


For the other screens we specify the same values as we specified when we created the “main” project, namely: Data Field and the watch types you’ll support:


Complex Data Type:


The Languages you’ll support:

Link the test project to the business project

Due to the memory issue that we wanted to address by creating two different projects, we now made a new problem for ourselves: how do we keep the files in sync between the test project and the business project?

We could copy files from the business project to the test project each time we want to run the tests, but this would be prone to mistakes so if we can avoid to having to copy files manually we will do so… 🙂

Luckily Eclipse comes to the rescue as it has a built-in option to create a copy by linking to another file or folder, to do this use CTRL+LMB (left mouse button) on the item you want to copy and drag it to the location above where you want to copy it to (eg when copying the strings folder copy it to the resources folder in the test project)

After releasing the left mouse button you will be presented by a window. Choose the option Link to files and folders

Now let’s do this “linked copy” for all the items that we want to link (copy from business project towards test project):
  • resources\drawables (choose yes to overwrite)
  • resources\strings (choose yes to overwrite)
  • resources-dut (choose yes to overwrite)
  • resources-eng (choose yes to overwrite)
  • source\StepsCarouselView.mc
If you did above steps correctly your project explorer will look similar to:

Mock the StepsCarousel view

The file StepsCarouselTestView.mc is the main entry point for the Steps Carousel Data Field application. This file was automatically generated when we set up the project and at the moment it isn’t any different from any other Data Field project that we created before.

We don’t want to create a new data field…

What we want is to create a new class (StepsCarouselTestsView) that knows about our real class (StepsCarouselView) but allows us to intercept and/or replace calls to the real class.

In testing jargon this is called as creating a mock, stub, test double, fake object, there are many names…

We implement this mock by using inheritance and let the StepsCarouselTestsView class inherit from the StepsCarouselView class.
We get rid of all the usings and all the function calls except for the initialize() function where we just call the initializer of the StepsCarouselView class. After all these changes the content of StepsCarouselTestsView will contain the following:
class StepsCarouselTestsView extends StepsCarouselView {
    function initialize() {
        StepsCarouselView.initialize();
    }
}

Change the run configuration

After doing the above changes you have a working project. You can this by changing your run configuration to run your test project (Run -> Run Configurations -> Choose A Project -> Steps Carousel Tests -> Run)

Clean up the test project

We have some generated items in our test project that we don’t need, let’s do some cleanup and delete the following items:
  • resources\layouts (delete folder)
  • source\StepsCarouselTestsBackground.mc (delete file)

Call the mock a mock!

  • Rename the file StepsCarouselTestsView.mc to StepsCarouselMocks.mc
  • Rename the class StepsCarouselTestsView to StepsCarouselMock
  • In the file StepsCarouselTestsApp replace StepsCarouselTestsView by StepsCarouselMock
StepsCarouselTestsApp.mc file will contain:
using Toybox.Application as App;

class StepsCarouselTestsApp extends App.AppBase {

    function initialize() {
        AppBase.initialize();
    }

    // onStart() is called on application start up
    function onStart(state) {
    }

    // onStop() is called when your application is exiting
    function onStop(state) {
    }

    //! Return the initial view of your application here
    function getInitialView() {
        return [ new StepsCarouselMock() ];
    }

}
StepsCarouselMocks.mc file will contain:
class StepsCarouselMock extends StepsCarouselView {
    function initialize() {
        StepsCarouselView.initialize();
    }
}

Source Code

You can download the full source code from github

What’s next?

In this tutorial we set up the test framework to be able to do unit testing, in the next tutorial we’re going to create a unit test and run it. .

Dit bericht Tutorial: How to create a Connect IQ unit test project komt van: Start To Run.

]]>
http://starttorun.info/tutorial-how-to-create-connect-iq-unit-test-project/feed/ 0
Garmin Connect IQ Tutorial Overview http://starttorun.info/garmin-connect-iq-tutorial-overview/ http://starttorun.info/garmin-connect-iq-tutorial-overview/#respond Fri, 16 Dec 2016 15:42:49 +0000 http://starttorun.info/?p=972 Garmin Connect IQ is the application development platform for newer Garmin watches. The program language is called MonkeyC. It allows you to create custom watch faces, data fields, apps and widgets and run these creations on your Garmin watch. In this tutorial series we’ll learn how to program this application development, both basic and more ...read more

Dit bericht Garmin Connect IQ Tutorial Overview komt van: Start To Run.

]]>
Garmin Connect IQ is the application development platform for newer Garmin watches. The program language is called MonkeyC. It allows you to create custom watch faces, data fields, apps and widgets and run these creations on your Garmin watch.

In this tutorial series we’ll learn how to program this application development, both basic and more advanced topics are being covered. On this page you see an overview of the tutorials, as time progresses this page will be updated with links to the new tutorials, so if you are interested in Connect IQ development keep a close watch on this page! 😉

Tutorial Overview

Setup

  1. Setting up the Connect IQ development environment

Create a data field

  1. Layout with layouts.xml
  2. Layout with dc.draw() calls
  3. Using string resources

Unit tests

  1. Create the unit test project
  2. Run unit tests
  3. Create unit tests

Application properties

  1. Define application settings
  2. Unit test application settings

Dit bericht Garmin Connect IQ Tutorial Overview komt van: Start To Run.

]]>
http://starttorun.info/garmin-connect-iq-tutorial-overview/feed/ 0
Tutorial: Connect IQ string resources http://starttorun.info/tutorial-connect-iq-string-resources/ http://starttorun.info/tutorial-connect-iq-string-resources/#comments Tue, 13 Dec 2016 10:10:38 +0000 http://starttorun.info/?p=945 Prerequisites a working development environment, see how to set this up here.a finished solution of Tutorial Create a Connect IQ Data Field With Direct dc.draw() calls (you can download my solution file here) Why? For people it’s usually more enjoyable if they can use a program in their mother tongue. Create the main resource Edit the ...read more

Dit bericht Tutorial: Connect IQ string resources komt van: Start To Run.

]]>
.

Prerequisites



Why?

For people it’s usually more enjoyable if they can use a program in their mother tongue.

Create the main resource


Edit the main resources of the application by navigating to resources -> strings -> strings.xml. Right click and choose Open With -> Text Editor and provde the resource names and resource values:
<strings>
    <string id="AppName">Steps Carousel</string>
    <string id="TotalSteps">Total</string>
    <string id="ActiveSteps">Steps</string>
    <string id="StepsToDo">To Go</string>
    <string id="GoalPercentage">Goal (%)</string>
</strings>

Create the translated resources

For each language that we will support we now have to create values in the corresponding resources group.
In this tutorial we’re going to provide resources for the dutch language.

  • Copy the strings folder from the main resources to the language specific folder (resources-dut in our example) (CTRL+Click&Drag – Choose Copy Files and Folders)
  • Edit the strings.xml file (Right Click. Open With -> Text Editor) and provide the translations:
<strings>
    <string id="AppName">Steps Carousel</string>
    <string id="TotalSteps">Totaal</string>
    <string id="ActiveSteps">Stappen</string>
    <string id="StepsToDo">Te Gaan</string>
    <string id="GoalPercentage">Doel (%)</string>
</strings>

Alter the code to use the resources

The resources internal representation is a number (and not the actual text).
To show the actual text from the resource (in the current language) an extra function call is necessary.
We change the variable name from label to labelResource and initialize it with the resource value for the TotalSteps. We also change the variable name mValue to just be named as value:
hidden var value = 0.0f;
    hidden var labelResource = Rez.Strings.TotalSteps;
In the compute function we do a similar replace and change all the label statements to their resource equivalence, the final result of your replace will be that your compute function looks as follows:
// The given info object contains all the current workout
    // information. Calculate a value and save it locally in this method.
    function compute(info) {
        var activityMonitorInfo = Toybox.ActivityMonitor.getInfo();
        if (timerRunning) {
            stepsRecorded = activityMonitorInfo.steps - stepsNonActive;
             ticker++;
        }

        var timerSlot = (ticker % 20);  // modulo the number of fields (4) * number of seconds to show the field (5)

        if (timerSlot <= 4) {  // first slot?
			labelResource = Rez.Strings.TotalSteps;
            value = activityMonitorInfo.steps;
        } else if (timerSlot <= 9) {
            labelResource = Rez.Strings.ActiveSteps;
            value = stepsRecorded;
        } else if (timerSlot <= 14) {
            labelResource = Rez.Strings.StepsToDo;
            value = (activityMonitorInfo.stepGoal - activityMonitorInfo.steps);
            if (value < 0) {
                value = 0;
            }
        } else if (timerSlot <= 19) {
            labelResource = Rez.Strings.GoalPercentage;
            value = (activityMonitorInfo.steps * 100.0) / activityMonitorInfo.stepGoal;
        } else {
            value = 0;
        }
    }
To display the actual label text, we call the Ui.loadResource() function on the labelResource in the onUpdate function, after your modifications the function will look as:
// Display the value you computed here. This will be called
    // once a second when the data field is visible.
    function onUpdate(dc) {
        var width = dc.getWidth();
        var height = dc.getHeight();
        var textCenter = Gfx.TEXT_JUSTIFY_CENTER | Gfx.TEXT_JUSTIFY_VCENTER;
        var backgroundColor = getBackgroundColor();
        // set background color
        dc.setColor(backgroundColor, Graphics.COLOR_TRANSPARENT);
        dc.fillRectangle (0, 0, width, height);
        // set foreground color
        dc.setColor((backgroundColor == Gfx.COLOR_BLACK) ? Gfx.COLOR_WHITE : Gfx.COLOR_BLACK, Graphics.COLOR_TRANSPARENT);

        // do layout
        if (isSingleFieldLayout()) {
            dc.drawText(width / 2, height / 2 - 40, Gfx.FONT_TINY, Ui.loadResource(labelResource), textCenter);
            dc.drawText(width / 2, height / 2 + 7, Gfx.FONT_NUMBER_THAI_HOT, value.format(valueFormat), textCenter);
        } else {
            dc.drawText(width / 2, 5 + (height - 55) / 2, Gfx.FONT_TINY, Ui.loadResource(labelResource), textCenter);
            dc.drawText(width / 2, (height - 23) - (height - 55) / 2 - 1, Gfx.FONT_NUMBER_HOT, value.format(valueFormat), textCenter);
        }
    }

Test your data field

In the simulator:

  • Start the timer (Data Fields -> Timer -> Start Activity)
  • Change the language (Settings -> Language ->)

Source Code

You can download the full source code from github or download a local copy here


In the next tutorial we’ll learn how to create a unit test project

Dit bericht Tutorial: Connect IQ string resources komt van: Start To Run.

]]>
http://starttorun.info/tutorial-connect-iq-string-resources/feed/ 1