Skip to content

Commit

Permalink
Initial code commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
pintail105 committed Mar 26, 2018
1 parent 5bf9753 commit 9685dd0
Show file tree
Hide file tree
Showing 12 changed files with 1,134 additions and 0 deletions.
37 changes: 37 additions & 0 deletions manifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!-- This is a generated file. It is highly recommended that you DO NOT edit this file. --><iq:manifest xmlns:iq="http://www.garmin.com/xml/connectiq" version="0">
<iq:application entry="SailingToolsApp" id="19c834541e6a47568d0094120c7a142e" launcherIcon="@Drawables.LauncherIcon" minSdkVersion="1.3.0" name="@Strings.AppName" type="watch-app">
<iq:products>
<iq:product id="fenix5s"/>
<iq:product id="oregon7xx"/>
<iq:product id="rino7xx"/>
<iq:product id="edge820"/>
<iq:product id="fr230"/>
<iq:product id="fr630"/>
<iq:product id="edge1030"/>
<iq:product id="d2bravo_titanium"/>
<iq:product id="fenixchronos"/>
<iq:product id="fr235"/>
<iq:product id="fr935"/>
<iq:product id="edge_1000"/>
<iq:product id="descentmk1"/>
<iq:product id="fenix3"/>
<iq:product id="fenix5"/>
<iq:product id="d2bravo"/>
<iq:product id="d2charlie"/>
<iq:product id="fr735xt"/>
<iq:product id="edge_520"/>
<iq:product id="fenix5x"/>
<iq:product id="vivoactive3"/>
<iq:product id="approachs60"/>
<iq:product id="fenix3_hr"/>
</iq:products>
<iq:permissions>
<iq:uses-permission id="Fit"/>
<iq:uses-permission id="Positioning"/>
<iq:uses-permission id="Sensor"/>
</iq:permissions>
<iq:languages>
<iq:language>eng</iq:language>
</iq:languages>
</iq:application>
</iq:manifest>
3 changes: 3 additions & 0 deletions resources/drawables/drawables.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<drawables>
<bitmap id="LauncherIcon" filename="sailboat_icon.png" />
</drawables>
Binary file added resources/drawables/sailboat_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions resources/layouts/layout.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<layout id="MainLayout">
</layout>
68 changes: 68 additions & 0 deletions resources/resources.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<resources>
<strings>
<string id="AppName">Sailing Tools</string>

<string id="menu_load_waypoint">Load waypoint</string>
<string id="menu_start_timer">Start timer</string>
<string id="menu_back">Back</string>
<string id="menu_save">Save and Exit</string>
<string id="menu_discard">Discard and Exit</string>
<string id="menu_unfollow">Stop Following</string>
<string id="menu_saveTarget">Save</string>

<string id="pickerChooserTitle">Choose Waypoint</string>

<string id="title_slot01">Slot 01</string>
<string id="title_slot02">Slot 02</string>
<string id="title_slot03">Slot 03</string>
<string id="title_slot04">Slot 04</string>
<string id="title_slot05">Slot 05</string>
<string id="title_slot06">Slot 06</string>
<string id="title_slot07">Slot 07</string>
<string id="title_slot08">Slot 08</string>
<string id="title_slot09">Slot 09</string>
<string id="title_start_pin">Start Pin</string>
<string id="title_cmte_boat">Committee Boat</string>
</strings>
<menu id="MainMenu">
<menu-item id="load_waypoint">@Strings.menu_load_waypoint</menu-item>
<menu-item id="start_timer">@Strings.menu_start_timer</menu-item>
<menu-item id="back">@Strings.menu_back</menu-item>
</menu>
<menu id="StopMenu">
<menu-item id="back">@Strings.menu_back</menu-item>
<menu-item id="save">@Strings.menu_save</menu-item>
<menu-item id="discard">@Strings.menu_discard</menu-item>
</menu>
<menu id="TargetMenu">
<menu-item id="back">@Strings.menu_back</menu-item>
<menu-item id="unfollow">@Strings.menu_unfollow</menu-item>
<menu-item id="save">@Strings.menu_saveTarget</menu-item>
</menu>
<properties>
<property id="slot01" type="string">MKE North Gap;43.044235;-87.880455</property>
<property id="slot02" type="string">MKE Main Gap;43.02631;-87.881882</property>
<property id="slot03" type="string">MKE South Gap;43.007965;-87.876808</property>
<property id="slot04" type="string">MKE MAST Bouy;43.03661;-87.846336</property>
<property id="slot05" type="string">MKE Green Bell Bouy;42.989051;-87.830694</property>
<property id="slot06" type="string"></property>
<property id="slot07" type="string"></property>
<property id="slot08" type="string"></property>
<property id="slot09" type="string"></property>
<property id="start_pin" type="string">Start Pin</property>
<property id="cmte_boat" type="string">Start Pin</property>
</properties>
<settings>
<setting propertyKey="@Properties.slot01" title="@Strings.title_slot01"><settingConfig type="alphaNumeric"/></setting>
<setting propertyKey="@Properties.slot02" title="@Strings.title_slot02"><settingConfig type="alphaNumeric"/></setting>
<setting propertyKey="@Properties.slot03" title="@Strings.title_slot03"><settingConfig type="alphaNumeric"/></setting>
<setting propertyKey="@Properties.slot04" title="@Strings.title_slot04"><settingConfig type="alphaNumeric"/></setting>
<setting propertyKey="@Properties.slot05" title="@Strings.title_slot05"><settingConfig type="alphaNumeric"/></setting>
<setting propertyKey="@Properties.slot06" title="@Strings.title_slot06"><settingConfig type="alphaNumeric"/></setting>
<setting propertyKey="@Properties.slot07" title="@Strings.title_slot07"><settingConfig type="alphaNumeric"/></setting>
<setting propertyKey="@Properties.slot08" title="@Strings.title_slot08"><settingConfig type="alphaNumeric"/></setting>
<setting propertyKey="@Properties.slot09" title="@Strings.title_slot09"><settingConfig type="alphaNumeric"/></setting>
<setting propertyKey="@Properties.start_pin" title="@Strings.title_start_pin"><settingConfig type="alphaNumeric"/></setting>
<setting propertyKey="@Properties.cmte_boat" title="@Strings.title_cmte_boat"><settingConfig type="alphaNumeric"/></setting>
</settings>
</resources>
87 changes: 87 additions & 0 deletions source/BearingArrow.mc
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
//!
//! Copyright 2017-2018 by Dan Perik
//!

using Toybox.System as Sys;
using Toybox.Lang as Lang;
using Toybox.WatchUi as Ui;
using Toybox.Graphics as Gfx;
using Toybox.Position as Position;
using Toybox.Math as Math;

class BearingArrow {

// center_x, center_y
// h = arrow height
// r = radius
var h, sideLen; //, r, center_x, center_y, sideLen;

var color_border, color_interior;

function initialize() {
setHeight( 10 ); // Set default arrow height (in pixels)
setColors( Gfx.COLOR_LT_GRAY, Gfx.COLOR_DK_RED );
}

function setHeight( h_new ) {
self.h = h_new;
self.sideLen = Math.sqrt(2 * Math.pow(self.h, 2));
}

function setColors( color_border, color_interior ) {
self.color_border = color_border;
self.color_interior = color_interior;
}

/*function setSizes( dc ) {
}
*/

function draw(dc, bearing) {
var maxWidth = dc.getWidth();
var maxHeight = dc.getHeight();
var center_x = maxWidth / 2;
var center_y = maxHeight / 2;
var r = 0;
// set r to maximum of center_x, center_y
if (center_x < center_y ) {
r = center_y;
} else {
r = center_x;
}

var brg = Math.toRadians(bearing);

var pts = [[0,0],[0,0],[0,0]]; // array of coordinates

// arrow tip
pts[0][0] = center_x + (Math.sin(brg) * r);
pts[0][1] = center_y - (Math.cos(brg) * r);

// If this is a semi-circle watch (like the Forerunner 235), then be sure tip is within view
if (pts[0][1] < 0 ) {
pts[0][1] = 0;
pts[0][0] = Math.tan(brg) * center_y + center_x;
} else if (pts[0][1] > maxHeight) {
pts[0][1] = maxHeight;
pts[0][0] = center_x - Math.tan(brg) * center_y;
}

// Get inner arrow points
// calculate position of line in reverse direction of bearing +/- 45 degrees (3 * pi/4)
pts[1][0] = pts[0][0] + Math.sin(brg-(Math.PI/4.0 * 3.0)) * self.sideLen;
pts[1][1] = pts[0][1] - Math.cos(brg-(Math.PI/4.0 * 3.0)) * self.sideLen;
pts[2][0] = pts[0][0] + Math.sin(brg+(Math.PI/4.0 * 3.0)) * self.sideLen;
pts[2][1] = pts[0][1] - Math.cos(brg+(Math.PI/4.0 * 3.0)) * self.sideLen;

//dc.drawLine(self.center_x, self.center_y, pts[0][0], pts[0][1]); // draw line from center to tip of arrow

dc.setColor( self.color_interior, Gfx.COLOR_TRANSPARENT );
dc.fillPolygon( pts ); // fill polygon

dc.setColor( self.color_border, Gfx.COLOR_TRANSPARENT );
dc.drawLine(pts[0][0], pts[0][1], pts[1][0], pts[1][1]); // draw side 1
dc.drawLine(pts[0][0], pts[0][1], pts[2][0], pts[2][1]); // draw side 2
dc.drawLine(pts[1][0], pts[1][1], pts[2][0], pts[2][1]); // draw bottom
}
}
42 changes: 42 additions & 0 deletions source/GeoCalcs.mc
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//!
//! Copyright 2017-2018 by Dan Perik
//!

using Toybox.System as Sys;
using Toybox.Lang as Lang;
using Toybox.Position as Position;
using Toybox.Math as Math;

class GeoCalcs {

// see: http://www.movable-type.co.uk/scripts/latlong.html

// Need to pass Postion.Location objects
static function getDistance(loc1, loc2) {
var lat1 = loc1.toRadians()[0];
var lon1 = loc1.toRadians()[1];
var lat2 = loc2.toRadians()[0];
var lon2 = loc2.toRadians()[1];
var φ1 = lat1, φ2 = lat2, Δλ = (lon2-lon1);
//var R = 6371e3; // gives d in metres
//var R = 6371; // gives d in kilometres
var R = 3440.0695; // gives d in nautical miles : 3440.06954644
var d = Math.acos( Math.sin1)*Math.sin2) + Math.cos1)*Math.cos2) * Math.cos(Δλ) ) * R;

return d;
}

static function getBearing_deg(loc1, loc2) {
var lat1 = loc1.toRadians()[0];
var lon1 = loc1.toRadians()[1];
var lat2 = loc2.toRadians()[0];
var lon2 = loc2.toRadians()[1];
var y = Math.sin(lon2-lon1) * Math.cos(lat2);
var x = Math.cos(lat1)*Math.sin(lat2) -
Math.sin(lat1)*Math.cos(lat2)*Math.cos(lon2-lon1);
var brng = Math.toDegrees(Math.atan2(y, x));

return brng;
}
}

Loading

0 comments on commit 9685dd0

Please sign in to comment.