Skip to content

Commit

Permalink
Dirty Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
britiger committed Jan 6, 2020
0 parents commit d747ca2
Show file tree
Hide file tree
Showing 19 changed files with 277 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/bin/*
17 changes: 17 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>CriticalMapsSender</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>connectiq.builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>connectiq.projectNature</nature>
</natures>
</projectDescription>
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 Christopher

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
6 changes: 6 additions & 0 deletions barrels.jungle
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Do not hand edit this file. To make changes right click
# on the project and select "Configure Monkey Barrels".

CriticalMapsAPIBarrel = ../CriticalMapsAPIBarrel/bin/CriticalMapsAPIBarrel.barrel
base.barrelPath = $(base.barrelPath);$(CriticalMapsAPIBarrel)

19 changes: 19 additions & 0 deletions manifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!-- 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="3">
<iq:application entry="CriticalMapsSenderApp" id="b0e45c9ffc8d49fcb87c7a001fea2b08" launcherIcon="@Drawables.LauncherIcon" minSdkVersion="3.0.0" name="@Strings.AppName" type="widget" version="0.0.0">
<iq:products>
<iq:product id="edge1030"/>
</iq:products>
<iq:permissions>
<iq:uses-permission id="Background"/>
<iq:uses-permission id="Communications"/>
<iq:uses-permission id="Positioning"/>
</iq:permissions>
<iq:languages>
<iq:language>deu</iq:language>
<iq:language>eng</iq:language>
</iq:languages>
<iq:barrels>
<iq:depends name="CriticalMapsAPIBarrel" version="0.1.0"/>
</iq:barrels>
</iq:application>
</iq:manifest>
1 change: 1 addition & 0 deletions monkey.jungle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
project.manifest = manifest.xml
4 changes: 4 additions & 0 deletions resources/drawables/drawables.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<drawables>
<bitmap id="LauncherIcon" filename="launcher_icon.png" />
<bitmap id="cm_logo" filename="logo-icon-192.png" />
</drawables>
Binary file added resources/drawables/launcher_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/drawables/logo-icon-192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/drawables/monkey.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions resources/layouts/layout.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<layout id="MainLayout">
<label x="center" y="5" text="@Strings.prompt" color="Graphics.COLOR_WHITE" justification="Graphics.TEXT_JUSTIFY_CENTER" />
<button x="center" y="50" width="192" height="192" behavior="onImagePress">
<state id="stateDefault" bitmap="@Drawables.cm_logo" />
</button>

<label id="t_next" x="20" y="260" text="@Strings.t_cm_next" />
<label id="v_next" x="right" y="260" text="0 km" />
<label id="t_count" x="20" y="290" text="@Strings.t_cm_count" />
<label id="v_count" x="right" y="290" text="0" />
<label id="outputtext" x="left" y="340" text="-" color="Graphics.COLOR_WHITE" justification="Graphics.TEXT_JUSTIFY_LEFT" font="Graphics.FONT_SMALL" />
</layout>
3 changes: 3 additions & 0 deletions resources/settings/properties.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<properties>
<property id="deviceId" type="string"></property>
</properties>
5 changes: 5 additions & 0 deletions resources/settings/settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<settings>
<setting propertyKey="@Properties.deviceId" title="@Strings.deviceIdTitle">
<settingConfig type="alphaNumeric" />
</setting>
</settings>
11 changes: 11 additions & 0 deletions resources/strings/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<strings>
<string id="AppName">CriticalMapsSender</string>

<string id="prompt">Critical Maps</string>

<string id="t_cm_next">Next CM</string>
<string id="t_cm_count">Count Nearby</string>

<string id="deviceIdTitle">Device Id</string>

</strings>
34 changes: 34 additions & 0 deletions source/CriticalMapsSenderApp.mc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Toybox.Application;
using Toybox.WatchUi;

using CriticalMapsAPIBarrel;

class CriticalMapsSenderApp extends Application.AppBase {

static var id;

function initialize() {
AppBase.initialize();

var mySettings = System.getDeviceSettings();
self.id = mySettings.uniqueIdentifier;

System.println("DeviceID: " + self.id);
}

// 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() {
System.println(CriticalMapsAPIBarrel.getDeviceId());
return [ new CriticalMapsSenderView(), new CriticalMapsSenderDelegate() ];
}

}
28 changes: 28 additions & 0 deletions source/CriticalMapsSenderDelegate.mc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Toybox.WatchUi;

class CriticalMapsSenderDelegate extends WatchUi.BehaviorDelegate {

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

function onImagePress() {
CriticalMapsSenderWeb.sendPositionData();
}

function onMenu() {
var menu = new WatchUi.Menu();
menu.setTitle("CM Menu");
menu.addItem("DeviceId:", :item_info);

menu.addItem(CriticalMapsSenderApp.id.substring( 0, 20), :item_info);
menu.addItem(CriticalMapsSenderApp.id.substring(20, 40), :item_info);

menu.addItem("Last Rsp: " + lastResponse, :item_info);
menu.addItem("Num Rsp: " + numResponse, :item_info);

WatchUi.pushView(menu, new CriticalMapsSenderMenuDelegate(), WatchUi.SLIDE_UP);
return true;
}

}
18 changes: 18 additions & 0 deletions source/CriticalMapsSenderMenuDelegate.mc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Toybox.WatchUi;
using Toybox.System;
using Toybox.Communications;

class CriticalMapsSenderMenuDelegate extends WatchUi.MenuInputDelegate {

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

function onMenuItem(item) {
if (item == :item_info) {
System.println("Show Info");
CriticalMapsSenderWeb.sendPositionData();
}
}

}
56 changes: 56 additions & 0 deletions source/CriticalMapsSenderView.mc
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using Toybox.WatchUi;

var outText = "";

class CriticalMapsSenderView extends WatchUi.View {

var myTimer = new Timer.Timer();

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

function onLayout(dc) {
setLayout(Rez.Layouts.MainLayout(dc));
}

function onShow() {
sendUpdate();
myTimer.start(method(:sendUpdate), 30000, true);
}

function onUpdate(dc) {
if(chatText.equals("")) {
outPutText("# Positions send: " + numResponse);
} else {
outPutText(chatText);
System.println(chatText);
}

var v_count = View.findDrawableById("v_count");
var v_next = View.findDrawableById("v_next");

v_count.setText(countCM10+"");
if (nearestCM == 999) {
v_next.setText("you are alone.");
} else {
v_next.setText(nearestCM.format("%.2f") + " km");
}

View.onUpdate(dc);
}

function outPutText(text) {
var lab = View.findDrawableById("outputtext");
lab.setText(text + "");
}

function sendUpdate() {
CriticalMapsSenderWeb.sendPositionData();
WatchUi.requestUpdate();
}

function onHide() {
}

}
41 changes: 41 additions & 0 deletions source/CriticalMapsSenderWeb.mc
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Toybox.Background;
using Toybox.System;
using Toybox.Position;
using Toybox.Time;
using Toybox.Communications;
using Toybox.Math;

using CriticalMapsAPIBarrel as CM;

//const BASEURL = "http://192.168.0.8:8088/"; // Test
const BASEURL = "https://api.criticalmaps.net/";

var lastResponse = -1;
var numResponse = 0;
var nearestCM = 0;
var countCM10 = 0;
var chatText = "";

(:background)
class CriticalMapsSenderWeb extends Toybox.System.ServiceDelegate {

function initialize() {
System.ServiceDelegate.initialize();
}

function sendPositionData() {
var callback = new Lang.Method($, :callbackCM);
CM.sendPositionData(callback);
}
}

function callbackCM(responseCode, data) {
var result = CM.callbackCM(responseCode, data);
lastResponse = result["responseCode"];
if (lastResponse == 200){
numResponse += 1;
nearestCM = result["nearestCM"];
countCM10 = result["countCM10"];
chatText = result["chatText"];
}
}

0 comments on commit d747ca2

Please sign in to comment.