Browse code

code and UX cleaning

Louis authored on24/10/2022 18:11:43
Showing3 changed files
... ...
@@ -71,16 +71,17 @@ static void prv_select_click_handler(ClickRecognizerRef recognizer, void *contex
71 71
 }
72 72
 
73 73
 static void prv_up_click_handler(ClickRecognizerRef recognizer, void *context) {
74
-  //text_layer_set_text(s_other_text_layer, "Up");
74
+  text_layer_set_text(s_other_text_layer, "Tracking stopped, sending...");
75
+  send_message("exit");
75 76
 }
76 77
 
77 78
 static void prv_down_click_handler(ClickRecognizerRef recognizer, void *context) {
78
-  //text_layer_set_text(s_other_text_layer, "Down");
79
+  text_layer_set_text(s_other_text_layer, "Tracking stopped, sending...");
79 80
   send_message("exit");
80 81
 }
81 82
 
82 83
 static void prv_back_click_handler(ClickRecognizerRef recognizer, void *context) {
83
-  //text_layer_set_text(s_other_text_layer, "Down");
84
+  //text_layer_set_text(s_other_text_layer, "back");
84 85
   //send_message("exit");
85 86
 }
86 87
 
... ...
@@ -120,14 +121,14 @@ static void prv_window_unload(Window *window) {
120 121
 void comm_is_ready() {
121 122
 
122 123
   // set the text
123
-  text_layer_set_text(s_speed_text_layer, "Press a button to start");
124
-  text_layer_set_text(s_other_text_layer, "Welcome to Bike Companion ! JSready");
124
+  text_layer_set_text(s_speed_text_layer, "Press Select");
125
+  text_layer_set_text(s_other_text_layer, "Welcome to Bike Companion ! JS is ready");
125 126
 
126 127
 }
127 128
 
128 129
 static void inbox_received_callback(DictionaryIterator *iter, void *context) {
129 130
   // A new message has been successfully received
130
-  APP_LOG(APP_LOG_LEVEL_DEBUG, "New message! ");
131
+  APP_LOG(APP_LOG_LEVEL_INFO, "New message! ");
131 132
 
132 133
   size = dict_size(iter);
133 134
 
... ...
@@ -138,7 +139,7 @@ static void inbox_received_callback(DictionaryIterator *iter, void *context) {
138 139
     //Pebblekit JS is ready ! Safe to send messages
139 140
     s_js_ready = true;
140 141
     comm_is_ready();
141
-    APP_LOG(APP_LOG_LEVEL_DEBUG, "received jsready message on watch... ");
142
+    //APP_LOG(APP_LOG_LEVEL_DEBUG, "received jsready message on watch... ");
142 143
   }
143 144
 
144 145
   // Read latitude returns
... ...
@@ -150,7 +151,7 @@ static void inbox_received_callback(DictionaryIterator *iter, void *context) {
150 151
 
151 152
     // Display in the TextLayer
152 153
     //text_layer_set_text(s_speed_text_layer, lf_latitude);
153
-    APP_LOG(APP_LOG_LEVEL_DEBUG, "latitude message received : %s",s_latitude);
154
+    //APP_LOG(APP_LOG_LEVEL_DEBUG, "latitude message received : %s",s_latitude);
154 155
   }else{
155 156
     //APP_LOG(APP_LOG_LEVEL_DEBUG, "not latitude message... ");
156 157
   }
... ...
@@ -164,7 +165,7 @@ static void inbox_received_callback(DictionaryIterator *iter, void *context) {
164 165
 
165 166
     // Display in the TextLayer
166 167
     //text_layer_set_text(s_speed_text_layer, lf_longitude);
167
-    APP_LOG(APP_LOG_LEVEL_DEBUG, "longitude message received : %s",s_longitude);
168
+    //APP_LOG(APP_LOG_LEVEL_DEBUG, "longitude message received : %s",s_longitude);
168 169
   }else{
169 170
     //APP_LOG(APP_LOG_LEVEL_DEBUG, "not longitude message... ");
170 171
   }
... ...
@@ -178,7 +179,7 @@ static void inbox_received_callback(DictionaryIterator *iter, void *context) {
178 179
 
179 180
     // Display in the TextLayer
180 181
     //text_layer_set_text(s_speed_text_layer, lf_accuracy);
181
-    APP_LOG(APP_LOG_LEVEL_DEBUG, "accuracy message received : %s",s_accuracy);
182
+    //APP_LOG(APP_LOG_LEVEL_DEBUG, "accuracy message received : %s",s_accuracy);
182 183
   }else{
183 184
     //APP_LOG(APP_LOG_LEVEL_DEBUG, "not accuracy message... ");
184 185
   }
... ...
@@ -192,7 +193,7 @@ static void inbox_received_callback(DictionaryIterator *iter, void *context) {
192 193
 
193 194
     // Display in the TextLayer
194 195
     //text_layer_set_text(s_speed_text_layer, lf_altitude);
195
-    APP_LOG(APP_LOG_LEVEL_DEBUG, "altitude message received : %s",altitude_tuple->value->cstring);
196
+    //APP_LOG(APP_LOG_LEVEL_DEBUG, "altitude message received : %s",altitude_tuple->value->cstring);
196 197
   }else{
197 198
     //APP_LOG(APP_LOG_LEVEL_DEBUG, "not altitude message... ");
198 199
   }
... ...
@@ -206,7 +207,7 @@ static void inbox_received_callback(DictionaryIterator *iter, void *context) {
206 207
 
207 208
     // Display in the TextLayer
208 209
     //text_layer_set_text(s_speed_text_layer, lf_altitude_accuracy);
209
-    APP_LOG(APP_LOG_LEVEL_DEBUG, "altitude_accuracy message received : %s",s_altitude_accuracy);
210
+    //APP_LOG(APP_LOG_LEVEL_DEBUG, "altitude_accuracy message received : %s",s_altitude_accuracy);
210 211
   }else{
211 212
     //APP_LOG(APP_LOG_LEVEL_DEBUG, "not altitude_accuracy message... ");
212 213
   }
... ...
@@ -220,7 +221,7 @@ static void inbox_received_callback(DictionaryIterator *iter, void *context) {
220 221
 
221 222
     // Display in the TextLayer
222 223
     //text_layer_set_text(s_speed_text_layer, lf_timestamp);
223
-    APP_LOG(APP_LOG_LEVEL_DEBUG, "timestamp message received : %s",s_timestamp);
224
+    //APP_LOG(APP_LOG_LEVEL_DEBUG, "timestamp message received : %s",s_timestamp);
224 225
   }else{
225 226
     //APP_LOG(APP_LOG_LEVEL_DEBUG, "not timestamp message... ");
226 227
   }
... ...
@@ -235,7 +236,7 @@ static void inbox_received_callback(DictionaryIterator *iter, void *context) {
235 236
     //uint i_speed=atoi(s_speed);
236 237
     // Display in the TextLayer
237 238
     //text_layer_set_text(s_speed_text_layer, lf_speed);
238
-    APP_LOG(APP_LOG_LEVEL_DEBUG, "speed message received : %s ",s_speed);
239
+    //APP_LOG(APP_LOG_LEVEL_DEBUG, "speed message received : %s ",s_speed);
239 240
   }else{
240 241
     //APP_LOG(APP_LOG_LEVEL_DEBUG, "not speed message... ");
241 242
   }
... ...
@@ -249,7 +250,7 @@ static void inbox_received_callback(DictionaryIterator *iter, void *context) {
249 250
     //uint i_max_speed=atoi(s_max_speed);
250 251
     // Display in the TextLayer
251 252
     //text_layer_set_text(s_max_speed_text_layer, lf_max_speed);
252
-    APP_LOG(APP_LOG_LEVEL_DEBUG, "max_speed message received : %s ",s_max_speed);
253
+    //APP_LOG(APP_LOG_LEVEL_DEBUG, "max_speed message received : %s ",s_max_speed);
253 254
   }else{
254 255
     //APP_LOG(APP_LOG_LEVEL_DEBUG, "not max_speed message... ");
255 256
   }
... ...
@@ -261,31 +262,29 @@ static void inbox_received_callback(DictionaryIterator *iter, void *context) {
261 262
   if(status_tuple) {
262 263
     memset(s_status,'\0',sizeof(s_status));
263 264
     strncpy(s_status, status_tuple->value->cstring, 4);
264
-    /*if (strcmp(s_status,"KO")== 0){
265
-      //find a way to exit 
266
-    }else{*/
267
-      APP_LOG(APP_LOG_LEVEL_DEBUG, "status message received : %s",s_status);
268
-
269
-      // DEBUG concatenate all data received
270
-      memset(s_msg,'\0',sizeof(s_msg));
271
-      strncpy(s_msg, "Acc. ",5);
272
-      strcat(s_msg, s_accuracy);
273
-      strcat(s_msg, "    Alt. ");
274
-      strcat(s_msg, s_altitude);
275
-      strcat(s_msg, "\n Max. ");
276
-      strcat(s_msg, s_max_speed);
277
-      //strcat(s_msg, "\n Lat. ");
278
-      //strcat(s_msg, s_latitude);
279
-      //strcat(s_msg, "\n Long. ");
280
-      //strcat(s_msg, s_longitude);
281
-      //strcat(s_msg, "\n Time. ");
282
-      //strcat(s_msg, s_timestamp);
283
-
284
-      APP_LOG(APP_LOG_LEVEL_DEBUG, "to display : %s ",s_msg);
285
-
286
-      text_layer_set_text(s_speed_text_layer, s_speed);
287
-      text_layer_set_text(s_other_text_layer, s_msg);
288
-   // }
265
+    //APP_LOG(APP_LOG_LEVEL_DEBUG, "status message received : %s",s_status);
266
+
267
+    // DEBUG concatenate all data received
268
+    /*
269
+    memset(s_msg,'\0',sizeof(s_msg));
270
+    strncpy(s_msg, "Acc. ",5);
271
+    strcat(s_msg, s_accuracy);
272
+    strcat(s_msg, "    Alt. ");
273
+    strcat(s_msg, s_altitude);
274
+    strcat(s_msg, "\n Max. ");
275
+    strcat(s_msg, s_max_speed);
276
+    strcat(s_msg, "\n Lat. ");
277
+    strcat(s_msg, s_latitude);
278
+    strcat(s_msg, "\n Long. ");
279
+    strcat(s_msg, s_longitude);
280
+    strcat(s_msg, "\n Time. ");
281
+    strcat(s_msg, s_timestamp);
282
+    */
283
+
284
+    //APP_LOG(APP_LOG_LEVEL_DEBUG, "to display : %s ",s_msg);
285
+
286
+    text_layer_set_text(s_speed_text_layer, s_speed);
287
+    text_layer_set_text(s_other_text_layer, s_msg);
289 288
   }else{
290 289
     //APP_LOG(APP_LOG_LEVEL_DEBUG, "not status message... ");
291 290
   }
... ...
@@ -340,7 +339,7 @@ static void prv_deinit(void) {
340 339
 int main(void) {
341 340
   prv_init();
342 341
 
343
-  APP_LOG(APP_LOG_LEVEL_DEBUG, "Done initializing, pushed window: %p", s_window);
342
+  //APP_LOG(APP_LOG_LEVEL_DEBUG, "Done initializing, pushed window: %p", s_window);
344 343
 
345 344
   app_event_loop();
346 345
   prv_deinit();
... ...
@@ -1,8 +1,6 @@
1
-module.exports = [
2
-    {
1
+module.exports = [{
3 2
         "type": "section",
4
-        "items": [
5
-            {
3
+        "items": [{
6 4
                 "type": "heading",
7 5
                 "defaultValue": "Locate Me"
8 6
             },
... ...
@@ -14,27 +12,13 @@ module.exports = [
14 12
             {
15 13
                 "type": "input",
16 14
                 "messageKey": "ping_location_url",
17
-                "label": "full URL (https://domain/path/endpoint.php) of server getting the location"
18
-            },
19
-            {
20
-                "type": "input",
21
-                "messageKey": "ping_location_login",
22
-                "label": "Login (unused)"
23
-            },
24
-            {
25
-                "type": "input",
26
-                "messageKey": "ping_location_password",
27
-                "label": "Password (unused)",
28
-                "attributes": {
29
-                    "type": "password"
30
-                }
15
+                "label": "Full URL of server getting the location (https://domain/path/endpoint.php)"
31 16
             }
32 17
         ]
33 18
     },
34 19
     {
35 20
         "type": "section",
36
-        "items": [
37
-            {
21
+        "items": [{
38 22
                 "type": "heading",
39 23
                 "defaultValue": "strava"
40 24
             },
... ...
@@ -45,19 +29,13 @@ module.exports = [
45 29
             },
46 30
             {
47 31
                 "type": "text",
48
-                "defaultValue": "Grant this application access to upload to Strava<br/><a onclick='return confirm(&quot;Have you saved your changes? They would be lost if you continue.&quot;)' href='https://www.strava.com/oauth/authorize?client_id=94880&response_type=code&redirect_uri=http://strava.jonget.fr&approval_prompt=force&state=bike_companion&scope=activity:write'><img src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMEAAAAwCAYAAACojB4gAAAAAXNSR0IArs4c6QAADR9JREFUeAHtXHeQVdUZ/51HXQJIkapLEZCSoQgKZJAioCMgJUgInaD+YTIxGVvixGgymjDORE000YzoJEPGGDFGOoRESei9994E6b0ve0++3/f2XO67u5TH7mayL+ebeXtPu+ee893v97V77wKePAc8BzwHPAc8BzwHPAf+rzlgYrtnPfqLdfuq50CJ5oCV1Ud/upnSsS2Zffv2DahTp87vSpUqVSfW56ueAyWaA7m5uV8JPZWdnT1RNkIwKMUtQZmcnJy9pUuXru0G+KPnQCZx4MqVKwfLlClTT/aU4/YVB0GWtfa86/RHz4FM5IAxpoLs64LbW8IV8o5xUMS6fdVzICM4kCLncRBkxA79JjwH0uGAB0E63PJjM5IDHgQZeVv9ptLhgAdBOtzyYzOSAx4EGXlb/abS4YAHQTrc8mMzkgMeBBl5W/2m0uGAB0E63PJjM5IDHgQZeVv9ptLhgAdBOtzyYzOSA/G3SDNyk/9Lmzp9+jQuXryImjVrXnNZQRDg6NGjqFixIipU4GsuN0k7VsHu3QCcOgzUqAdTpzGQ3RwoUw74agdwcOeNJ8qqCGRVAo5/lX9s+a8BNesD1e/I3+da5Dy7YibMg4/JHAeAPbIeR82+IXPL/I5kn1jzhasBtRsCXPOqfwAVqwJN7rvaV4ylYgPB8ePHsXjxYhw5cgTyVirq1auH9u3bo1w5uSEliA4fPozy5cujcuXKRbLqlStXYuvWrXjiiSeQSCRw+fJlkFfVqlVD2bJl9Rrnzp3DpEmT0KFDB7Ru3frG1z2yD8Fbj8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/HiIxQjJvbPjGjhH9N0hukJMjUq6k090C6QKlQH6+FE6sheIPBDD12Ut8tCN7hGDeaXVn6urpGVakTuT7nI4DZ8TnDiYrBIczCQVkjwICslAf3rJ50AcBDEVUfI36HfgOZAuBzwI0uWYH59xHPAgyLhb6jeULgc8CNLlmB+fcRzwIMi4W+o3lC4HPAjS5Zgfn3Ec8CDIuFvqN5QuBzwI0uWYH59xHPAgyLhb6jeULgc8CNLlmB+fcRyIg8DKl0tHM26XfkOeA3kcyJPv5OePeW1xEATyvv1YDwQvM5nIAcq1/HMH+bgBKf/3J/4WKb9l5Mvvd8iP3z7G+6XJk+dAieQAtf9F+e2XH9/NlldikxQXctZpHQiGeF/yDP/Xc6DkcoBAoPDTEqS4RCV3S37lngOeA54DngOF58B/AH8SWKEMYwLkAAAAAElFTkSuQmCC'/></a>"
49
-            },
50
-            {
51
-                "type": "toggle",
52
-                "messageKey": "strava_automatic_upload",
53
-                "label": "Automatic upload at the end of the track"
32
+                "defaultValue": "Grant this application access to upload to Strava<br/><i>(unsaved config will be lost)</i><br/><a href='https://www.strava.com/oauth/authorize?client_id=94880&response_type=code&redirect_uri=http://strava.jonget.fr&approval_prompt=force&state=bike_companion&scope=activity:write'><img src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMEAAAAwCAYAAACojB4gAAAAAXNSR0IArs4c6QAADR9JREFUeAHtXHeQVdUZ/51HXQJIkapLEZCSoQgKZJAioCMgJUgInaD+YTIxGVvixGgymjDORE000YzoJEPGGDFGOoRESei9994E6b0ve0++3/f2XO67u5TH7mayL+ebeXtPu+ee893v97V77wKePAc8BzwHPAc8BzwHPAf+rzlgYrtnPfqLdfuq50CJ5oCV1Ud/upnSsS2Zffv2DahTp87vSpUqVSfW56ueAyWaA7m5uV8JPZWdnT1RNkIwKMUtQZmcnJy9pUuXru0G+KPnQCZx4MqVKwfLlClTT/aU4/YVB0GWtfa86/RHz4FM5IAxpoLs64LbW8IV8o5xUMS6fdVzICM4kCLncRBk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bnMuj6BF+Mh131z3AqU6ESTNdULRx23kxBQJF4alxKmtR+KA/gJFtkJ/0mnMH0GC1PqrO17gScFbtvEyx9+zubwtw/WPtN43ZAu176LMAunaZt/MMgGglxgZmW/eYzYbvGFnzqXQwUj14riOZKDfELeVFqe/rq0axHdEqmPwkWCmTUB46OKWyZ2pjrYCxwrWsQCBRYWqsSRRLwWtGkdtY42LMn8y3d1G2SfLrbuvvVPnE/cp/pGNYTor35LMGRlae40SfGpcbv0xSp/fQ1BONfdMNg5DUKlxFi9ifxnlifWg3D/uCFrnBBsJE0Z+K34pJJkBt8vxUSL34GdOiHYOyjsIsm6TlGAJQYJ4og77kCg/ng8Yawkn4lJR4cA/ODD7RcmD+iPOX9DyQ1hxSKHQSFWaw/Nw0OyMMrbF8Oy9y9ZGtQqToMXaAWnUV6YgZf/HiIxQjJvbPjGjhH9N0hukJMjUq6k090C6QKlQH6+FE6sheIPBDD12Ut8tCN7hGDeaXVn6urpGVakTuT7nI4DZ8TnDiYrBIczCQVkjwICslAf3rJ50AcBDEVUfI36HfgOZAuBzwI0uWYH59xHPAgyLhb6jeULgc8CNLlmB+fcRzwIMi4W+o3lC4HPAjS5Zgfn3Ec8CDIuFvqN5QuBzwI0uWYH59xHPAgyLhb6jeULgc8CNLlmB+fcRyIg8DKl0tHM26XfkOeA3kcyJPv5OePeW1xEATyvv1YDwQvM5nIAcq1/HMH+bgBKf/3J/4WKb9l5Mvvd8iP3z7G+6XJk+dAieQAtf9F+e2XH9/NlldikxQXctZpHQiGeF/yDP/Xc6DkcoBAoPDTEqS4RCV3S37lngOeA54DngOF58B/AH8SWKEMYwLkAAAAAElFTkSuQmCC'/></a>"
54 33
             }
55 34
         ]
56 35
     },
57 36
     {
58 37
         "type": "section",
59
-        "items": [
60
-            {
38
+        "items": [{
61 39
                 "type": "heading",
62 40
                 "defaultValue": "Send GPX to another server"
63 41
             },
... ...
@@ -69,28 +47,10 @@ module.exports = [
69 47
             {
70 48
                 "type": "input",
71 49
                 "messageKey": "gpx_web_url",
72
-                "label": "full URL (https://domain/path/endpoint.php) of server getting the GPX"
73
-            },
74
-            {
75
-                "type": "input",
76
-                "messageKey": "gpx_web_login",
77
-                "label": "Login (unused)"
78
-            },
79
-            {
80
-                "type": "input",
81
-                "messageKey": "gpx_web_password",
82
-                "label": "Password (unused)",
83
-                "attributes": {
84
-                    "type": "password"
85
-                }
50
+                "label": "Full URL of server receiving the GPX (https://domain/path/endpoint.php)"
86 51
             }
87 52
         ]
88 53
     },
89
-    {
90
-        "type": "toggle",
91
-        "messageKey": "debug",
92
-        "label": "Debug"
93
-    },
94 54
     {
95 55
         "type": "submit",
96 56
         "id": "submitButton",
... ...
@@ -16,156 +16,126 @@ var client_id = "94880";
16 16
 var client_secret = "08dc170f0fe38f39dd327bea82a28db4400e6f00";
17 17
 
18 18
 var firstlocationOptions = {
19
-  'enableHighAccuracy': true, // default = false (quick and dirty mode), can be true (more accurate but need more power and time)
20
-  'timeout': 60000, //60s timeout to get a first good signal
21
-  'maximumAge': 0 // no cache
19
+    'enableHighAccuracy': true, // default = false (quick and dirty mode), can be true (more accurate but need more power and time)
20
+    'timeout': 60000, //60s timeout to get a first good signal
21
+    'maximumAge': 0 // no cache
22 22
 };
23 23
 var locationOptions = {
24
-  'enableHighAccuracy': true, // default = false (quick and dirty mode), can be true (more accurate but need more power and time)
25
-  'timeout': 5000, //5s timeout to get a good signal
26
-  'maximumAge': 0 // no cache
24
+    'enableHighAccuracy': true, // default = false (quick and dirty mode), can be true (more accurate but need more power and time)
25
+    'timeout': 5000, //5s timeout to get a good signal
26
+    'maximumAge': 0 // no cache
27 27
 };
28 28
 
29
-Pebble.addEventListener('showConfiguration', function (e) {
30
-  clay.config = clayConfig;
31
-  console.log("Clay config is showing...")
32
-  Pebble.openURL(clay.generateUrl());
29
+Pebble.addEventListener('showConfiguration', function(e) {
30
+    clay.config = clayConfig;
31
+    console.log("Clay config is showing...")
32
+    Pebble.openURL(clay.generateUrl());
33 33
 });
34 34
 
35
-Pebble.addEventListener('webviewclosed', function (t) {
36
-  if (!t || t.response) {
37
-    console.log("Clay config is submitted : " + t.response)
38
-    try {
39
-      if (data = JSON.parse(t.response), data.code && data.scope == "read,activity:write") {
40
-        // data looks like this :
41
-        // {"code":"db896b06f89804997a8088320fba755e6299c0d6","scope":"read,activity:write","state":"bike_companion"}
42
-        // so need to parse it correctly
43
-        //var grantcode = JSON.parse(data.strava.value)
44
-        if (data.state == "bike_companion" && data.scope == "read,activity:write") {
45
-          getTokens(data.code);
46
-        } else {
47
-          console.log("Error on response returned : scope is " + grantcode.scope + " and state is " + grantcode.state);
35
+Pebble.addEventListener('webviewclosed', function(t) {
36
+    if (!t || t.response) {
37
+        console.log("Clay config is submitted : " + t.response)
38
+        try {
39
+            if (data = JSON.parse(t.response), data.code && data.scope == "read,activity:write") {
40
+                if (data.state == "bike_companion" && data.scope == "read,activity:write") {
41
+                    getTokens(data.code);
42
+                } else {
43
+                    console.log("Error on response returned : scope is " + grantcode.scope + " and state is " + grantcode.state);
44
+                }
45
+            } else {
46
+                clay.getSettings(t.response);
47
+                console.log("Clay settings in Localstorage looks like " + localStorage.getItem("clay-settings"));
48
+            }
49
+        } catch (t) {
50
+            console.log("Oauth parsing error, continue on saving clay settings");
51
+            clay.getSettings(t.response);
52
+            var claysettings = JSON.parse(localStorage.getItem('clay-settings'))
53
+            claysettings.strava_enabled = false;
54
+            localStorage.setItem("clay-settings", JSON.stringify("claysettings"));
55
+            console.log("Clay settings in Localstorage looks like " + localStorage.getItem("clay-settings"));
48 56
         }
49
-      } else {
50
-        clay.getSettings(t.response);
51
-        console.log("Clay settings in Localstorage looks like " + localStorage.getItem("clay-settings"));
52
-      }
53
-    } catch (t) {
54
-      console.log("Oauth parsing error, continue on saving clay settings");
55
-      clay.getSettings(t.response);
56
-      console.log("Clay settings in Localstorage looks like " + localStorage.getItem("clay-settings"));
57
-      //set strava to false
58
-    }
59 57
 
60
-    // dict is not used as intended to send settings to watch
61
-
62
-    /* assess if needed to send setting to watch as already in phone (done with "getsettings")
63
-    m.live_mmt_enable = dict[p.live_mmt_enable]
64
-    m.live_mmt_login = dict[p.live_mmt_login]
65
-    m.live_mmt_password = dict[p.live_mmt_password]
66
-    m.live_jayps_enable = dict[p.live_jayps_enable]
67
-    m.live_jayps_login = dict[p.live_jayps_login]
68
-    m.live_jayps_password = dict[p.live_jayps_password]
69
-    m.strava_automatic_upload = dict[p.strava_automatic_upload]
70
-
71
-    i = dict[p.debug]
72
-    console.log("debug:" + i)
73
-    g.setDebug(i)
74
-    h.setDebug(i)
75
-    b.setDebug(i)
76
-    y.setDebug(i)
77
-    m.setDebug(i)
78
-
79
-    m.save()
80
-    // Assess if needed to send settings values to watch side
81
-    /*
82
-    Pebble.sendAppMessage(dict, function(e) {
83
-        console.log('Sent config data to Pebble');
84
-    }, function(e) {
85
-        console.log('Failed to send config data!');
86
-        console.log(JSON.stringify(e));
87
-    });*/
88
-  }
58
+    }
89 59
 });
90 60
 
91 61
 
92 62
 // Store location in Pebble app local storage
93 63
 //
94 64
 function storeLocation(position) {
95
-  var latitude = position.coords.latitude;
96
-  var longitude = position.coords.longitude;
97
-  var timestamp = position.timestamp;
98
-  localStorage.setItem("latitude", latitude);
99
-  localStorage.setItem("longitude", longitude);
100
-  localStorage.setItem("timestamp", timestamp);
101
-  // console.log("Stored location " + position.coords.latitude + ',' + position.coords.longitude);
65
+    var latitude = position.coords.latitude;
66
+    var longitude = position.coords.longitude;
67
+    var timestamp = position.timestamp;
68
+    localStorage.setItem("latitude", latitude);
69
+    localStorage.setItem("longitude", longitude);
70
+    localStorage.setItem("timestamp", timestamp);
71
+    // console.log("Stored location " + position.coords.latitude + ',' + position.coords.longitude);
102 72
 }
103 73
 
104 74
 // Get location from Pebble app local storage
105 75
 //
106 76
 function getLocation() {
107
-  if (localStorage.getItem("latitude") || localStorage.getItem("longitude") || localStorage.getItem("timestamp")) {
108
-    var la = localStorage.getItem("latitude");
109
-    var lo = localStorage.getItem("longitude");
110
-    var ti = localStorage.getItem("timestamp");
111
-    var co = { "latitude": la, "longitude": lo };
112
-    var pos = { "coords": co, "timestamp": ti };
113
-    // console.log("Stored location " + pos.co.la + ',' + pos.co.lo);
114
-    return pos;
115
-  } else {
116
-    return null;
117
-  }
77
+    if (localStorage.getItem("latitude") || localStorage.getItem("longitude") || localStorage.getItem("timestamp")) {
78
+        var la = localStorage.getItem("latitude");
79
+        var lo = localStorage.getItem("longitude");
80
+        var ti = localStorage.getItem("timestamp");
81
+        var co = { "latitude": la, "longitude": lo };
82
+        var pos = { "coords": co, "timestamp": ti };
83
+        // console.log("Stored location " + pos.co.la + ',' + pos.co.lo);
84
+        return pos;
85
+    } else {
86
+        return null;
87
+    }
118 88
 }
119 89
 
120 90
 // Get max speed of the run
121 91
 //
122 92
 function getMaxSpeed(lastSpeed) {
123
-  oldmax = localStorage.getItem("maxSpeed") || -1;
124
-  if (oldmax < lastSpeed) {
125
-    maxSpeed = lastSpeed
126
-  } else if (oldmax > lastSpeed) {
127
-    maxSpeed = oldmax
128
-  } else {
129
-    maxSpeed = oldmax
130
-  }
131
-  localStorage.setItem("maxSpeed", maxSpeed);
132
-  return maxSpeed
93
+    oldmax = localStorage.getItem("maxSpeed") || -1;
94
+    if (oldmax < lastSpeed) {
95
+        maxSpeed = lastSpeed
96
+    } else if (oldmax > lastSpeed) {
97
+        maxSpeed = oldmax
98
+    } else {
99
+        maxSpeed = oldmax
100
+    }
101
+    localStorage.setItem("maxSpeed", maxSpeed);
102
+    return maxSpeed
133 103
 }
134 104
 
135 105
 // split float number into an array of int (null returned instead of 0 for decimal)
136 106
 //
137 107
 function splitFloatNumber(num) {
138
-  const intStr = num.toString().split('.')[0];
139
-  const decimalStr = num.toString().split('.')[1];
140
-  return [Number(intStr), Number(decimalStr)];
108
+    const intStr = num.toString().split('.')[0];
109
+    const decimalStr = num.toString().split('.')[1];
110
+    return [Number(intStr), Number(decimalStr)];
141 111
 
142 112
 }
143 113
 
144 114
 // Build GPX headers
145 115
 //
146 116
 function GPXHeadersBuilder(timestamp, name, type) {
147
-  var headers = '<?xml version="1.0" encoding="UTF-8"?><gpx creator="Pebble with barometer" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd" version="1.1" xmlns="http://www.topografix.com/GPX/1/1"><metadata><time>' + timestamp + '</time></metadata><trk><name>' + name + '</name><type>' + type + '</type><trkseg>';
148
-  var ret = localStorage.setItem("GPX", headers);
149
-  return true;
117
+    var headers = '<?xml version="1.0" encoding="UTF-8"?><gpx creator="Pebble with barometer" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd" version="1.1" xmlns="http://www.topografix.com/GPX/1/1"><metadata><time>' + timestamp + '</time></metadata><trk><name>' + name + '</name><type>' + type + '</type><trkseg>';
118
+    var ret = localStorage.setItem("GPX", headers);
119
+    return true;
150 120
 }
151 121
 
152 122
 // Build GPX track point
153 123
 //
154 124
 function GPXtrkptBuilder(lat, lon, ele, timestamp) {
155
-  var GPX = localStorage.getItem("GPX");
156
-  var trkpt = '<trkpt lat="' + lat + '" lon="' + lon + '"><ele>' + ele + '</ele><time>' + timestamp + '</time></trkpt>';
157
-  localStorage.setItem("GPX", GPX + trkpt);
158
-  return true;
125
+    var GPX = localStorage.getItem("GPX");
126
+    var trkpt = '<trkpt lat="' + lat + '" lon="' + lon + '"><ele>' + ele + '</ele><time>' + timestamp + '</time></trkpt>';
127
+    localStorage.setItem("GPX", GPX + trkpt);
128
+    return true;
159 129
 }
160 130
 
161 131
 // Build GPX footer
162 132
 //
163 133
 function GPXfooterBuilder() {
164
-  var GPX = localStorage.getItem("GPX");
165
-  var footer = '</trkseg></trk></gpx>';
166
-  var ret = localStorage.setItem("GPX", GPX + footer);
167
-  //console.log("GPX closed : " + GPX + footer);
168
-  return ret;
134
+    var GPX = localStorage.getItem("GPX");
135
+    var footer = '</trkseg></trk></gpx>';
136
+    var ret = localStorage.setItem("GPX", GPX + footer);
137
+    //console.log("GPX closed : " + GPX + footer);
138
+    return ret;
169 139
 }
170 140
 
171 141
 //------------------------------------------
... ...
@@ -173,402 +143,397 @@ function GPXfooterBuilder() {
173 143
 //------------------------------------------
174 144
 
175 145
 function getTokens(code) {
176
-  // call to strava api to get tokens in exchange of temp code
177
-  // need to use strava.jonget.fr to proxy request and hide secret
178
-  var url = "https://www.strava.com/oauth/token?client_id=" + client_id + "&client_secret=" + client_secret + "&code=" + code + "&grant_type=authorization_code";
179
-  var xhr = new XMLHttpRequest();
180
-  xhr.timeout = 10000; // time in milliseconds
181
-
182
-  xhr.open("POST", url, false);
183
-
184
-  xhr.onload = function () {
185
-    //console.log('------xhr onloaded')
186
-    if (xhr.readyState === 4) {
187
-      console.log('------xhr request returned :', xhr.responseText);
188
-      response_json = JSON.parse(xhr.responseText);
189
-
190
-      var tokenjson = {
191
-        access_token: response_json.access_token,
192
-        refresh_token: response_json.refresh_token,
193
-        expiry: response_json.expires_at
194
-      };
195
-      localStorage.setItem("strava_tokens", JSON.stringify(tokenjson));
146
+    // call to strava api to get tokens in exchange of temp code
147
+    // need to use strava.jonget.fr to proxy request and hide secret
148
+    var url = "https://www.strava.com/oauth/token?client_id=" + client_id + "&client_secret=" + client_secret + "&code=" + code + "&grant_type=authorization_code";
149
+    var xhr = new XMLHttpRequest();
150
+    xhr.timeout = 10000; // time in milliseconds
151
+
152
+    xhr.open("POST", url, false);
153
+
154
+    xhr.onload = function() {
155
+        //console.log('------xhr onloaded')
156
+        if (xhr.readyState === 4) {
157
+            console.log('------xhr request returned :', xhr.responseText);
158
+            response_json = JSON.parse(xhr.responseText);
159
+
160
+            var tokenjson = {
161
+                access_token: response_json.access_token,
162
+                refresh_token: response_json.refresh_token,
163
+                expiry: response_json.expires_at
164
+            };
165
+            localStorage.setItem("strava_tokens", JSON.stringify(tokenjson));
196 166
 
197
-    }
198
-  };
167
+        }
168
+    };
199 169
 
200
-  xhr.send();
170
+    xhr.send();
201 171
 
202 172
 }
203 173
 
204 174
 function refreshTokens(refresh_token) {
205
-  // call to strava api to get tokens in exchange of refresh code
206
-  // need to use strava.jonget.fr to proxy request and hide secret
207
-  var url = "https://www.strava.com/oauth/token?client_id=" + client_id + "&client_secret=" + client_secret + "&refresh_token=" + refresh_token + "&grant_type=refresh_token";
208
-  var xhr = new XMLHttpRequest();
209
-  xhr.timeout = 10000; // time in milliseconds
210
-
211
-  xhr.open("POST", url, false);
212
-
213
-  xhr.onload = function () {
214
-    //console.log('------xhr onloaded')
215
-    if (xhr.readyState === 4) {
216
-      //console.log('------xhr request returned with ' + xhr.status);
217
-      response_json = JSON.parse(xhr.txt);
218
-
219
-      var tokenjson = {
220
-        access_token: response_json.access_token,
221
-        refresh_token: response_json.refresh_token,
222
-        expiry: response_json.expires_at
223
-      };
224
-      localStorage.setItem("strava_tokens", JSON.stringify(tokenjson));
175
+    // call to strava api to get tokens in exchange of refresh code
176
+    // need to use strava.jonget.fr to proxy request and hide secret
177
+    var url = "https://www.strava.com/oauth/token?client_id=" + client_id + "&client_secret=" + client_secret + "&refresh_token=" + refresh_token + "&grant_type=refresh_token";
178
+    var xhr = new XMLHttpRequest();
179
+    xhr.timeout = 10000; // time in milliseconds
180
+
181
+    xhr.open("POST", url, false);
182
+
183
+    xhr.onload = function() {
184
+        //console.log('------xhr onloaded')
185
+        if (xhr.readyState === 4) {
186
+            //console.log('------xhr request returned with ' + xhr.status);
187
+            response_json = JSON.parse(xhr.txt);
188
+
189
+            var tokenjson = {
190
+                access_token: response_json.access_token,
191
+                refresh_token: response_json.refresh_token,
192
+                expiry: response_json.expires_at
193
+            };
194
+            localStorage.setItem("strava_tokens", JSON.stringify(tokenjson));
225 195
 
226
-    }
227
-  };
196
+        }
197
+    };
228 198
 
229
-  xhr.send();
199
+    xhr.send();
230 200
 
231 201
 }
232 202
 
233 203
 // Send GPX to Strava profile
234 204
 function SendToStrava() {
235
-  console.log('--- GPX upload to strava');
236
-  var gpxfile = localStorage.getItem("GPX");
237
-
238
-  var tokens = localStorage.getItem("strava_tokens");
239
-
240
-  var bearer = JSON.parse(tokens).access_token;
241
-  params = {
242
-    url: "https://www.strava.com/api/v3/uploads",
243
-    method: "POST",
244
-    data: { description: "desc", data_type: "gpx" },
245
-    files: { file: gpxfile },
246
-    authorization: "Bearer " + bearer,
247
-    callback: function (e) {
248
-      var message = "";
249
-      // what is 'r'
250
-      // what is 'e'
251
-      // what is 'o'
252
-      // what is 'z'
253
-      if (console.log(e.status + " - " + e.txt), 201 == e.status) {
254
-        message = "Your activity has been created";
255
-        localStorage.setItem("strava_uploaded", true);
256
-      } else if (400 == e.status) {
257
-        message = "An error has occurred. If you've already uploaded the current activity, please delete it in Strava.";
258
-      } else if (401 == e.status) {
259
-        message = "Error - Unauthorized. Please check your credentials in the settings.", o.setAccessToken("");
260
-      } else {
205
+    console.log('--- GPX upload to strava');
206
+    var gpxfile = localStorage.getItem("GPX");
207
+
208
+    var tokens = localStorage.getItem("strava_tokens");
209
+
210
+    var bearer = JSON.parse(tokens).access_token;
211
+    params = {
212
+        url: "https://www.strava.com/api/v3/uploads",
213
+        method: "POST",
214
+        data: { description: "desc", data_type: "gpx" },
215
+        files: { file: gpxfile },
216
+        authorization: "Bearer " + bearer,
217
+        callback: function(e) {
218
+            var message = "";
219
+            if (console.log(e.status + " - " + e.txt), 201 == e.status) {
220
+                message = "Your activity has been created";
221
+                localStorage.setItem("strava_uploaded", true);
222
+            } else if (400 == e.status) {
223
+                message = "An error has occurred. If you've already uploaded the current activity, please delete it in Strava.";
224
+            } else if (401 == e.status) {
225
+                message = "Error - Unauthorized. Please check your credentials in the settings."
226
+            } else {
227
+                try {
228
+                    response_json = JSON.parse(e.txt)
229
+                    response_json.error ? (console.log("error:" + response_json.error), message = response_json.error) : response_json.status && (console.log("status:" + response_json.status))
230
+                } catch (e) {
231
+                    console.log("Error log, " + e)
232
+                }
233
+            }
234
+            message && Pebble.showSimpleNotificationOnPebble("Ventoo SE - Strava", message)
235
+        }
236
+    }
237
+    var XHR = new XMLHttpRequest;
238
+    var n = this;
239
+    console.log(params.url);
240
+    XHR.open(params.method, params.url, !0);
241
+    var body = "";
242
+    var boundary = Math.random().toString().substring(2);
243
+    XHR.setRequestHeader("content-type", "multipart/form-data; charset=utf-8; boundary=" + boundary)
244
+    XHR.setRequestHeader("Authorization", params.authorization);
245
+    for (var i in params.data) body += "--" + boundary + '\r\nContent-Disposition: form-data; name="' + i + '"\r\n\r\n' + params.data[i] + "\r\n";
246
+    for (var i in params.files) body += "--" + boundary + '\r\nContent-Disposition: form-data; name="' + i + '" ; filename=test.gpx\r\n\r\n' + params.files[i] + "\r\n";
247
+    body += "--" + boundary + "--\r\n"
248
+
249
+    XHR.onreadystatechange = function() {
261 250
         try {
262
-          response_json = JSON.parse(e.txt)
263
-          response_json.error ? (console.log("error:" + response_json.error), message = response_json.error, o.setAccessToken("")) : response_json.status && (console.log("status:" + response_json.status), z = response_json.status)
251
+            4 == XHR.readyState && (n.status = XHR.status, n.txt = XHR.responseText, n.xml = XHR.responseXML, params.callback && params.callback(n))
264 252
         } catch (e) {
265
-          console.log("Error log, " + e)
253
+            console.error("Error2 loading, ", e)
266 254
         }
267
-      }
268
-      message && Pebble.showSimpleNotificationOnPebble("Ventoo SE - Strava", message)
269 255
     }
270
-  }
271
-  var XHR = new XMLHttpRequest;
272
-  var n = this;
273
-  console.log(params.url);
274
-  XHR.open(params.method, params.url, !0);
275
-  var body = "";
276
-  var boundary = Math.random().toString().substring(2);
277
-  XHR.setRequestHeader("content-type", "multipart/form-data; charset=utf-8; boundary=" + boundary)
278
-  XHR.setRequestHeader("Authorization", params.authorization);
279
-  for (var i in params.data) body += "--" + boundary + '\r\nContent-Disposition: form-data; name="' + i + '"\r\n\r\n' + params.data[i] + "\r\n";
280
-  for (var i in params.files) body += "--" + boundary + '\r\nContent-Disposition: form-data; name="' + i + '" ; filename=test.gpx\r\n\r\n' + params.files[i] + "\r\n";
281
-  body += "--" + boundary + "--\r\n"
282
-
283
-  XHR.onreadystatechange = function () {
284
-    // what is 'n'
285
-    try {
286
-      4 == XHR.readyState && (n.status = XHR.status, n.txt = XHR.responseText, n.xml = XHR.responseXML, params.callback && params.callback(n))
287
-    } catch (e) {
288
-      console.error("Error2 loading, ", e)
289
-    }
290
-  }
291
-  XHR.send(body)
256
+    XHR.send(body)
292 257
 }
293 258
 
294 259
 
295 260
 // Send GPX to web server (need configuration on serverside)
296 261
 // TODO : secure it ?
297 262
 function PostToWeb() {
298
-  console.log('--- GPX upload to custom web server');
299
-  var GPX = localStorage.getItem("GPX");
300
-  var url = JSON.parse(localStorage.getItem('clay-settings')).gpx_web_url + "?name=pebblegpx&type=application/gpx+xml";
301
-  var xhr = new XMLHttpRequest();
302
-  xhr.timeout = 10000; // time in milliseconds
303
-
304
-  xhr.open("POST", url, false);
305
-
306
-  //console.log('------ CSV / xhr opened')
307
-  xhr.onload = function () {
308
-    //console.log('------xhr onloaded')
309
-    if (xhr.readyState === 4) {
310
-      //console.log('------xhr request returned with ' + xhr.status);
311
-      //console.log(this.responseText);
312
-      localStorage.setItem("custom_uploaded", true);
313
-      if (xhr.status == 200) {
314
-        //console.log('--> HTTP 200');
315
-        return true;
316
-      } else {
317
-        //console.log('--> HTTP ' + xhr.status);
318
-        return false;
319
-      }
320
-    }
321
-  };
263
+    console.log('--- GPX upload to custom web server');
264
+    var GPX = localStorage.getItem("GPX");
265
+    var url = JSON.parse(localStorage.getItem('clay-settings')).gpx_web_url + "?name=pebblegpx&type=application/gpx+xml";
266
+    var xhr = new XMLHttpRequest();
267
+    xhr.timeout = 10000; // time in milliseconds
268
+
269
+    xhr.open("POST", url, false);
270
+
271
+    //console.log('------ CSV / xhr opened')
272
+    xhr.onload = function() {
273
+        //console.log('------xhr onloaded')
274
+        if (xhr.readyState === 4) {
275
+            //console.log('------xhr request returned with ' + xhr.status);
276
+            //console.log(this.responseText);
277
+            localStorage.setItem("custom_uploaded", true);
278
+            if (xhr.status == 200) {
279
+                //console.log('--> HTTP 200');
280
+                return true;
281
+            } else {
282
+                //console.log('--> HTTP ' + xhr.status);
283
+                return false;
284
+            }
285
+        }
286
+    };
322 287
 
323
-  //send CSV in body
324
-  xhr.send(GPX);
288
+    //send CSV in body
289
+    xhr.send(GPX);
325 290
 
326 291
 }
327 292
 
328 293
 // Send location to web server for instant location (no live tracking)
329 294
 // TODO : secure it ?
330 295
 function instantLocationUpdate(pos) {
331
-  console.log('--- Instant location update');
332
-  // console.log(" location is " + new_pos.coords.latitude + ',' + new_pos.coords.longitude + ' , acc. ' + new_pos.coords.accuracy);
333
-
334
-  var url = JSON.parse(localStorage.getItem('clay-settings')).ping_location_url + "?lat=" + pos.coords.latitude + "&long=" + pos.coords.longitude + "&acc=" + pos.coords.accuracy + "&timestamp=" + pos.timestamp;
335
-  var xhr = new XMLHttpRequest();
336
-  xhr.timeout = 10000; // time in milliseconds
337
-
338
-  xhr.open("POST", url);
339
-
340
-  //console.log('------ instant / xhr opened')
341
-  xhr.onload = function () {
342
-    //console.log('------xhr onloaded')
343
-    if (xhr.readyState === 4) {
344
-      //console.log('------xhr request returned with ' + xhr.status);
345
-      //console.log(this.responseText);
346
-      if (xhr.status == 200) {
347
-        //console.log('--> HTTP 200');
348
-        return true;
349
-      } else {
350
-        //console.log('--> HTTP ' + xhr.status);
351
-        return false;
352
-      }
353
-    }
354
-  };
296
+    console.log('--- Instant location update');
297
+    // console.log(" location is " + new_pos.coords.latitude + ',' + new_pos.coords.longitude + ' , acc. ' + new_pos.coords.accuracy);
298
+
299
+    var url = JSON.parse(localStorage.getItem('clay-settings')).ping_location_url + "?lat=" + pos.coords.latitude + "&long=" + pos.coords.longitude + "&acc=" + pos.coords.accuracy + "&timestamp=" + pos.timestamp;
300
+    var xhr = new XMLHttpRequest();
301
+    xhr.timeout = 10000; // time in milliseconds
302
+
303
+    xhr.open("POST", url);
304
+
305
+    //console.log('------ instant / xhr opened')
306
+    xhr.onload = function() {
307
+        //console.log('------xhr onloaded')
308
+        if (xhr.readyState === 4) {
309
+            //console.log('------xhr request returned with ' + xhr.status);
310
+            //console.log(this.responseText);
311
+            if (xhr.status == 200) {
312
+                //console.log('--> HTTP 200');
313
+                return true;
314
+            } else {
315
+                //console.log('--> HTTP ' + xhr.status);
316
+                return false;
317
+            }
318
+        }
319
+    };
355 320
 
356
-  //send without body
357
-  xhr.send();
321
+    //send without body
322
+    xhr.send();
358 323
 
359 324
 }
360 325
 
361 326
 // called in case of successful geoloc gathering and sends the coordinate to watch
362 327
 //
363 328
 function locationSuccess(new_pos) {
364
-  console.log('--- locationSuccess');
365
-  // console.log(" location is " + new_pos.coords.latitude + ',' + new_pos.coords.longitude + ' , acc. ' + new_pos.coords.accuracy);
329
+    console.log('--- locationSuccess');
330
+    // console.log(" location is " + new_pos.coords.latitude + ',' + new_pos.coords.longitude + ' , acc. ' + new_pos.coords.accuracy);
366 331
 
367
-  var prev_pos = getLocation();
368
-  storeLocation(new_pos);
369
-  if (prev_pos === null) {
370
-    console.log('--- start building gpx');
332
+    var prev_pos = getLocation();
333
+    storeLocation(new_pos);
334
+    if (prev_pos === null) {
335
+        console.log('--- start building gpx');
371 336
 
372 337
 
373
-    // Start the GPX file
374
-    GPXHeadersBuilder(new Date(new_pos.timestamp).toISOString(), "test", "18");
338
+        // Start the GPX file
339
+        GPXHeadersBuilder(new Date(new_pos.timestamp).toISOString(), "test", "18");
375 340
 
376
-  } else {
377
-    //clear watch of new position to avoid overlap
378
-    //navigator.geolocation.clearWatch(geoloc_id);
379
-    //console.log('--- watch geoloc cleared');
380
-    //var speed = speed_from_distance_and_time(prev_pos, new_pos);
381
-
382
-    //get speed from geoloc API isntead of calculate it
383
-    // speed is initially in m/s, get it at km/h
384
-    if (new_pos.coords.speed === null) {
385
-      var speed = 0;
386 341
     } else {
387
-      var speed = new_pos.coords.speed * 3.6;
388
-    }
342
+        //clear watch of new position to avoid overlap
343
+        //navigator.geolocation.clearWatch(geoloc_id);
344
+        //console.log('--- watch geoloc cleared');
345
+        //var speed = speed_from_distance_and_time(prev_pos, new_pos);
346
+
347
+        //get speed from geoloc API isntead of calculate it
348
+        // speed is initially in m/s, get it at km/h
349
+        if (new_pos.coords.speed === null) {
350
+            var speed = 0;
351
+        } else {
352
+            var speed = new_pos.coords.speed * 3.6;
353
+        }
389 354
 
390
-    // Prepare display on watch
391
-    // now it's only raw data
392
-    // init strings
393
-    var latitudeString = "";
394
-    var longitudeString = "";
395
-    var accuracyString = "";
396
-    var altitudeString = "";
397
-    var speedString = "";
398
-
399
-    //formating for precision and max size
400
-    latitudeString = new_pos.coords.latitude.toString().substring(0, 12);
401
-    longitudeString = new_pos.coords.longitude.toString().substring(0, 12);
402
-    accuracyString = new_pos.coords.accuracy.toString().substring(0, 4);
403
-    //console.log("split num : " + new_pos.coords.altitude);
404
-    altitudeString = splitFloatNumber(new_pos.coords.altitude)[0].toString().substring(0, 5);
405
-    timestampISO = new Date(new_pos.timestamp).toISOString();
406
-    //console.log("split num : " + speed);
407
-    if (isNaN(speed)) {
408
-      speedString = "---";
409
-    } else {
410
-      speedString = splitFloatNumber(speed)[0].toString().substring(0, 3) + "." + splitFloatNumber(speed)[1].toString().substring(0, 1);
411
-      if (speedString == "0.N") {
412
-        speedString = "0.0";
413
-      }
355
+        // Prepare display on watch
356
+        // now it's only raw data
357
+        // init strings
358
+        var latitudeString = "";
359
+        var longitudeString = "";
360
+        var accuracyString = "";
361
+        var altitudeString = "";
362
+        var speedString = "";
363
+
364
+        //formating for precision and max size
365
+        latitudeString = new_pos.coords.latitude.toString().substring(0, 12);
366
+        longitudeString = new_pos.coords.longitude.toString().substring(0, 12);
367
+        accuracyString = new_pos.coords.accuracy.toString().substring(0, 4);
368
+        //console.log("split num : " + new_pos.coords.altitude);
369
+        altitudeString = splitFloatNumber(new_pos.coords.altitude)[0].toString().substring(0, 5);
370
+        timestampISO = new Date(new_pos.timestamp).toISOString();
371
+        //console.log("split num : " + speed);
372
+        if (isNaN(speed)) {
373
+            speedString = "---";
374
+        } else {
375
+            speedString = splitFloatNumber(speed)[0].toString().substring(0, 3) + "." + splitFloatNumber(speed)[1].toString().substring(0, 1);
376
+            if (speedString == "0.N") {
377
+                speedString = "0.0";
378
+            }
414 379
 
415
-      //console.log("split num : " + getMaxSpeed(speed));
416
-      maxSpeedString = splitFloatNumber(getMaxSpeed(speed))[0].toString().substring(0, 3);
417
-    }
380
+            //console.log("split num : " + getMaxSpeed(speed));
381
+            maxSpeedString = splitFloatNumber(getMaxSpeed(speed))[0].toString().substring(0, 3);
382
+        }
418 383
 
419
-    //add a new datapoint to GPX file
420
-    GPXtrkptBuilder(latitudeString, longitudeString, altitudeString, timestampISO);
384
+        //add a new datapoint to GPX file
385
+        GPXtrkptBuilder(latitudeString, longitudeString, altitudeString, timestampISO);
421 386
 
422 387
 
423 388
 
424
-    // Build message
425
-    message = "OK";
426
-    var dict = {
427
-      'accuracy': accuracyString,
428
-      'altitude': altitudeString,
429
-      'speed': speedString,
430
-      'max_speed': maxSpeedString,
431
-      'status': message
432
-    };
389
+        // Build message
390
+        message = "OK";
391
+        var dict = {
392
+            'accuracy': accuracyString,
393
+            'altitude': altitudeString,
394
+            'speed': speedString,
395
+            'max_speed': maxSpeedString,
396
+            'status': message
397
+        };
433 398
 
434
-    // Send the message
435
-    Pebble.sendAppMessage(dict, function () {
436
-      console.log('Message sent successfully: ' + JSON.stringify(dict));
437
-    }, function (e) {
438
-      console.log('Message (' + JSON.stringify(dict) + ') failed: ' + JSON.stringify(e));
439
-    });
440
-  }
399
+        // Send the message
400
+        Pebble.sendAppMessage(dict, function() {
401
+            console.log('Message sent successfully: ' + JSON.stringify(dict));
402
+        }, function(e) {
403
+            console.log('Message (' + JSON.stringify(dict) + ') failed: ' + JSON.stringify(e));
404
+        });
405
+    }
441 406
 
442 407
 }
443 408
 
444 409
 function locationError(err) {
445 410
 
446
-  console.warn('location error (' + err.code + '): ' + err.message);
411
+    console.warn('location error (' + err.code + '): ' + err.message);
447 412
 
448 413
 }
449 414
 
450 415
 
451 416
 function get_coordinate() {
452
-  console.log('--- Starting regular getCurrentPosition loop using setInterval at 1 sec');
417
+    console.log('--- Starting regular getCurrentPosition loop using setInterval at 1 sec');
453 418
 
454
-  locationInterval = setInterval(function () {
455
-    navigator.geolocation.getCurrentPosition(locationSuccess, locationError, locationOptions);
456
-  }, 1000);
419
+    locationInterval = setInterval(function() {
420
+        navigator.geolocation.getCurrentPosition(locationSuccess, locationError, locationOptions);
421
+    }, 1000);
457 422
 
458
-  if (locate_me) {
459
-    instantLocationInterval = setInterval(function () {
460
-      navigator.geolocation.getCurrentPosition(instantLocationUpdate, locationError, locationOptions);
461
-    }, 60000);
462
-  }
423
+    if (locate_me) {
424
+        instantLocationInterval = setInterval(function() {
425
+            navigator.geolocation.getCurrentPosition(instantLocationUpdate, locationError, locationOptions);
426
+        }, 60000);
427
+    }
463 428
 
464 429
 }
465 430
 
466 431
 function init() {
467
-  // local storage init
468
-  try {
469
-    //console.log("Clay settings = " + localStorage.getItem('clay-settings'));
470
-    gpx_to_strava = JSON.parse(localStorage.getItem('clay-settings')).strava_enabled;
471
-    gpx_to_web = JSON.parse(localStorage.getItem('clay-settings')).gpx_web_enabled;
472
-    locate_me = JSON.parse(localStorage.getItem('clay-settings')).ping_location_enabled;
473
-
474
-    console.log("Locate_me = " + locate_me);
475
-    console.log("Strava = " + gpx_to_strava);
476
-    console.log("Custom web = " + gpx_to_web);
477
-
478
-    var ce = gpx_to_web;
479
-    var cu = localStorage.getItem("custom_uploaded");
480
-    var se = gpx_to_strava;
481
-    var su = localStorage.getItem("strava_uploaded");
482
-
483
-    //checking token freshness (expiry >4h)
484
-    var delay = (Date.now() + 14400000) / 1000
485
-    if (se) {
486
-      if (JSON.parse(localStorage.getItem("strava_tokens")).expiry < delay) {
487
-        console.log("Strava oAuth token expiring or expired, refreshing it")
488
-        refreshTokens(JSON.parse(localStorage.getItem("strava_tokens")).refresh_token);
489
-      } else {
490
-        console.log("token (" + JSON.parse(localStorage.getItem("strava_tokens")).access_token + ")valid for 4h min, continuing")
491
-      }
492
-    }
493
-  } catch (e) { }
432
+    // local storage init
433
+    try {
434
+        //console.log("Clay settings = " + localStorage.getItem('clay-settings'));
435
+        gpx_to_strava = JSON.parse(localStorage.getItem('clay-settings')).strava_enabled;
436
+        gpx_to_web = JSON.parse(localStorage.getItem('clay-settings')).gpx_web_enabled;
437
+        locate_me = JSON.parse(localStorage.getItem('clay-settings')).ping_location_enabled;
438
+
439
+        console.log("Locate_me = " + locate_me);
440
+        console.log("Strava = " + gpx_to_strava);
441
+        console.log("Custom web = " + gpx_to_web);
442
+
443
+        var ce = gpx_to_web;
444
+        var cu = localStorage.getItem("custom_uploaded");
445
+        var se = gpx_to_strava;
446
+        var su = localStorage.getItem("strava_uploaded");
447
+
448
+        //checking token freshness (expiry >4h)
449
+        var delay = (Date.now() + 14400000) / 1000
450
+        if (se) {
451
+            if (JSON.parse(localStorage.getItem("strava_tokens")).expiry < delay) {
452
+                console.log("Strava oAuth token expiring or expired, refreshing it")
453
+                refreshTokens(JSON.parse(localStorage.getItem("strava_tokens")).refresh_token);
454
+            } else {
455
+                console.log("token (" + JSON.parse(localStorage.getItem("strava_tokens")).access_token + ")valid for 4h min, continuing")
456
+            }
457
+        }
458
+    } catch (e) {}
494 459
 
495
-  if ((se && !su) || (ce && !cu)) {
496
-    //posting any missed XHR from previous ride session
497
-    if (ce) {
498
-      PostToWeb();
499
-    }
500
-    if (se) {
501
-      SendToStrava();
460
+    if ((se && !su) || (ce && !cu)) {
461
+        //posting any missed XHR from previous ride session
462
+        if (ce) {
463
+            PostToWeb();
464
+        }
465
+        if (se) {
466
+            SendToStrava();
467
+        }
468
+    } else {
469
+        localStorage.setItem("GPX", "");
470
+        localStorage.setItem("maxSpeed", "");
471
+        localStorage.setItem("latitude", "");
472
+        localStorage.setItem("longitude", "");
473
+        localStorage.setItem("timestamp", "");
474
+        localStorage.setItem("custom_uploaded", false);
475
+        localStorage.setItem("strava_uploaded", false);
502 476
     }
503
-  } else {
504
-    localStorage.setItem("GPX", "");
505
-    localStorage.setItem("maxSpeed", "");
506
-    localStorage.setItem("latitude", "");
507
-    localStorage.setItem("longitude", "");
508
-    localStorage.setItem("timestamp", "");
509
-    localStorage.setItem("custom_uploaded", false);
510
-    localStorage.setItem("strava_uploaded", false);
511
-  }
512
-  // clear any other var to do
513
-  clearInterval(locationInterval);
514
-  clearInterval(instantLocationInterval);
515
-  navigator.geolocation.getCurrentPosition(null, locationError, firstlocationOptions);
477
+    // clear any other var to do
478
+    clearInterval(locationInterval);
479
+    clearInterval(instantLocationInterval);
480
+    navigator.geolocation.getCurrentPosition(null, locationError, firstlocationOptions);
516 481
 
517 482
 }
518 483
 
519 484
 // Get JS readiness events
520
-Pebble.addEventListener('ready', function (e) {
521
-  console.log('PebbleKit JS is ready');
522
-  // Update Watch on this
523
-  Pebble.sendAppMessage({ 'JSReady': 1 });
485
+Pebble.addEventListener('ready', function(e) {
486
+    console.log('PebbleKit JS is ready');
487
+    // Update Watch on this
488
+    Pebble.sendAppMessage({ 'JSReady': 1 });
524 489
 
525
-  init();
490
+    init();
526 491
 });
527 492
 
528 493
 // Get AppMessage events
529
-Pebble.addEventListener('appmessage', function (e) {
530
-  // Get the dictionary from the message
531
-  var dict = e.payload;
532
-  //console.log(dict[0].toString());
533
-  switch (dict[0]) {
534
-    case 'get':
535
-      get_coordinate();
536
-      break;
537
-    case 'exit':
538
-      clearInterval(instantLocationInterval);
539
-      clearInterval(locationInterval);
540
-      gpx_to_strava = JSON.parse(localStorage.getItem('clay-settings')).strava_enabled;
541
-      gpx_to_web = JSON.parse(localStorage.getItem('clay-settings')).gpx_web_enabled;
542
-      locate_me = JSON.parse(localStorage.getItem('clay-settings')).ping_location_enabled;
543
-
544
-      //End GPX file
545
-      GPXfooterBuilder();
546
-      if (gpx_to_strava) {
547
-        //send to strava through API
548
-        SendToStrava();
549
-      }
550
-      if (gpx_to_web) {
551
-        // send CSV to web server through API
552
-        PostToWeb();
553
-      }
554
-      if (locate_me) {
555
-        var prev_pos = getLocation();
556
-        instantLocationUpdate(prev_pos);
557
-      }
558
-
559
-      // Send the message
560
-      var dict = {
561
-        'status': "EXIT"
562
-      };
563
-      Pebble.sendAppMessage(dict, function () {
564
-        console.log('Message sent successfully: ' + JSON.stringify(dict));
565
-      }, function (e) {
566
-        console.log('Message (' + JSON.stringify(dict) + ') failed: ' + JSON.stringify(e));
567
-      });
568
-
569
-      break;
570
-    default:
571
-      console.log('Sorry. I don\'t understand your request :' + dict[0]);
572
-  }
494
+Pebble.addEventListener('appmessage', function(e) {
495
+    // Get the dictionary from the message
496
+    var dict = e.payload;
497
+    //console.log(dict[0].toString());
498
+    switch (dict[0]) {
499
+        case 'get':
500
+            get_coordinate();
501
+            break;
502
+        case 'exit':
503
+            clearInterval(instantLocationInterval);
504
+            clearInterval(locationInterval);
505
+            gpx_to_strava = JSON.parse(localStorage.getItem('clay-settings')).strava_enabled;
506
+            gpx_to_web = JSON.parse(localStorage.getItem('clay-settings')).gpx_web_enabled;
507
+            locate_me = JSON.parse(localStorage.getItem('clay-settings')).ping_location_enabled;
508
+
509
+            //End GPX file
510
+            GPXfooterBuilder();
511
+            if (gpx_to_strava) {
512
+                //send to strava through API
513
+                SendToStrava();
514
+            }
515
+            if (gpx_to_web) {
516
+                // send CSV to web server through API
517
+                PostToWeb();
518
+            }
519
+            if (locate_me) {
520
+                var prev_pos = getLocation();
521
+                instantLocationUpdate(prev_pos);
522
+            }
523
+
524
+            // Send the message
525
+            var dict = {
526
+                'status': "EXIT"
527
+            };
528
+            Pebble.sendAppMessage(dict, function() {
529
+                console.log('Message sent successfully: ' + JSON.stringify(dict));
530
+            }, function(e) {
531
+                console.log('Message (' + JSON.stringify(dict) + ') failed: ' + JSON.stringify(e));
532
+            });
533
+
534
+            break;
535
+        default:
536
+            console.log('Sorry. I don\'t understand your request :' + dict[0]);
537
+    }
573 538
 
574 539
 });
575 540
\ No newline at end of file