| ... | ... |
@@ -41,7 +41,30 @@ typedef enum {
|
| 41 | 41 |
|
| 42 | 42 |
|
| 43 | 43 |
static void prv_select_click_handler(ClickRecognizerRef recognizer, void *context) {
|
| 44 |
- text_layer_set_text(s_other_text_layer, "Select"); |
|
| 44 |
+ text_layer_set_text(s_other_text_layer, "Select - sending get geoloc"); |
|
| 45 |
+ |
|
| 46 |
+ // Declare the dictionary's iterator |
|
| 47 |
+ DictionaryIterator *out_iter; |
|
| 48 |
+ |
|
| 49 |
+ // Prepare the outbox buffer for this message |
|
| 50 |
+ AppMessageResult result = app_message_outbox_begin(&out_iter); |
|
| 51 |
+ |
|
| 52 |
+ if(result == APP_MSG_OK) {
|
|
| 53 |
+ // Add an item to ask for geoloc |
|
| 54 |
+ msg = "get"; |
|
| 55 |
+ dict_write_cstring(out_iter, status, msg); |
|
| 56 |
+ |
|
| 57 |
+ // Send this message |
|
| 58 |
+ result = app_message_outbox_send(); |
|
| 59 |
+ if(result != APP_MSG_OK) {
|
|
| 60 |
+ APP_LOG(APP_LOG_LEVEL_ERROR, "Error sending the outbox: %d", (int)result); |
|
| 61 |
+ } |
|
| 62 |
+ } else {
|
|
| 63 |
+ // The outbox cannot be used right now |
|
| 64 |
+ APP_LOG(APP_LOG_LEVEL_ERROR, "Error preparing the outbox: %d", (int)result); |
|
| 65 |
+ } |
|
| 66 |
+ // Button click provider |
|
| 67 |
+ // window_set_click_config_provider(s_window, click_config_provider); |
|
| 45 | 68 |
} |
| 46 | 69 |
|
| 47 | 70 |
static void prv_up_click_handler(ClickRecognizerRef recognizer, void *context) {
|
| ... | ... |
@@ -63,7 +86,7 @@ static void prv_window_load(Window *window) {
|
| 63 | 86 |
GRect bounds = layer_get_bounds(window_layer); |
| 64 | 87 |
|
| 65 | 88 |
s_speed_text_layer = text_layer_create(GRect(0, 0, bounds.size.w, bounds.size.h/2)); |
| 66 |
- |
|
| 89 |
+ |
|
| 67 | 90 |
text_layer_set_background_color(s_speed_text_layer, GColorBlack); |
| 68 | 91 |
text_layer_set_text_color(s_speed_text_layer, GColorWhite); |
| 69 | 92 |
text_layer_set_font(s_speed_text_layer, fonts_get_system_font(FONT_KEY_BITHAM_42_BOLD)); |
| ... | ... |
@@ -71,9 +94,9 @@ static void prv_window_load(Window *window) {
|
| 71 | 94 |
text_layer_set_text(s_speed_text_layer, "Press a button"); |
| 72 | 95 |
layer_add_child(window_layer, text_layer_get_layer(s_speed_text_layer)); |
| 73 | 96 |
|
| 74 |
- |
|
| 97 |
+ |
|
| 75 | 98 |
s_other_text_layer = text_layer_create(GRect(0, bounds.size.h/2,bounds.size.w, bounds.size.h/2)); |
| 76 |
- |
|
| 99 |
+ |
|
| 77 | 100 |
text_layer_set_background_color(s_other_text_layer, GColorClear); |
| 78 | 101 |
text_layer_set_text_color(s_other_text_layer, GColorBlack); |
| 79 | 102 |
text_layer_set_font(s_other_text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14)); |
| ... | ... |
@@ -91,29 +114,6 @@ void comm_is_ready() {
|
| 91 | 114 |
// set the text |
| 92 | 115 |
text_layer_set_text(s_other_text_layer, "Welcome to Bike Companion ! JSready"); |
| 93 | 116 |
|
| 94 |
- // Declare the dictionary's iterator |
|
| 95 |
- DictionaryIterator *out_iter; |
|
| 96 |
- |
|
| 97 |
- // Prepare the outbox buffer for this message |
|
| 98 |
- AppMessageResult result = app_message_outbox_begin(&out_iter); |
|
| 99 |
- |
|
| 100 |
- if(result == APP_MSG_OK) {
|
|
| 101 |
- // Add an item to ask for weather data |
|
| 102 |
- msg = "get"; |
|
| 103 |
- dict_write_cstring(out_iter, status, msg); |
|
| 104 |
- |
|
| 105 |
- // Send this message |
|
| 106 |
- result = app_message_outbox_send(); |
|
| 107 |
- if(result != APP_MSG_OK) {
|
|
| 108 |
- APP_LOG(APP_LOG_LEVEL_ERROR, "Error sending the outbox: %d", (int)result); |
|
| 109 |
- } |
|
| 110 |
- } else {
|
|
| 111 |
- // The outbox cannot be used right now |
|
| 112 |
- APP_LOG(APP_LOG_LEVEL_ERROR, "Error preparing the outbox: %d", (int)result); |
|
| 113 |
- } |
|
| 114 |
- // Button click provider |
|
| 115 |
- // window_set_click_config_provider(s_window, click_config_provider); |
|
| 116 |
- |
|
| 117 | 117 |
} |
| 118 | 118 |
|
| 119 | 119 |
static void inbox_received_callback(DictionaryIterator *iter, void *context) {
|
| ... | ... |
@@ -6,12 +6,13 @@ var messageKeys = require('message_keys');
|
| 6 | 6 |
|
| 7 | 7 |
var message; |
| 8 | 8 |
|
| 9 |
-var locationInterval; |
|
| 9 |
+//var locationInterval; |
|
| 10 | 10 |
var locationOptions = {
|
| 11 | 11 |
'enableHighAccuracy': true, // default = false (quick and dirty mode), can be true (more accurate but need more power and time) |
| 12 |
- 'timeout': 2000, //2s timeout |
|
| 13 |
- 'maximumAge': 1000 // 1s cache |
|
| 12 |
+ 'timeout': 5000, //2s timeout |
|
| 13 |
+ 'maximumAge': 0 // no cache |
|
| 14 | 14 |
}; |
| 15 |
+var geoloc_id; |
|
| 15 | 16 |
|
| 16 | 17 |
// Store location in Pebble app local storage |
| 17 | 18 |
// |
| ... | ... |
@@ -133,23 +134,28 @@ function padStart(string, max_length, padding) {
|
| 133 | 134 |
// called in case of successful geoloc gathering and sends the coordinate to watch |
| 134 | 135 |
// |
| 135 | 136 |
function locationSuccess(new_pos) {
|
| 137 |
+ console.log('--- locationSuccess');
|
|
| 138 |
+ console.log(" location is " + new_pos.coords.latitude + ',' + new_pos.coords.longitude + ' , acc. ' + new_pos.coords.accuracy);
|
|
| 139 |
+ |
|
| 136 | 140 |
var prev_pos = getLocation(); |
| 137 | 141 |
storeLocation(new_pos); |
| 138 | 142 |
if (prev_pos === null) {
|
| 139 |
- GPXHeadersBuilder(timestampISO = new Date(new_pos.timestamp).toISOString(), "test", "18"); |
|
| 140 |
- return null; |
|
| 143 |
+ console.log('--- start building gpx');
|
|
| 144 |
+ // Start the GPX file |
|
| 145 |
+ GPXHeadersBuilder(new Date(new_pos.timestamp).toISOString(), "test", "18"); |
|
| 141 | 146 |
} else {
|
| 147 |
+ //clear watch of new position to avoid overlap |
|
| 148 |
+ //navigator.geolocation.clearWatch(geoloc_id); |
|
| 149 |
+ //console.log('--- watch geoloc cleared');
|
|
| 142 | 150 |
var speed = speed_from_distance_and_time(prev_pos, new_pos); |
| 143 | 151 |
|
| 144 | 152 |
// Prepare display on watch |
| 145 | 153 |
// now it's only raw data |
| 146 |
- //init strings |
|
| 154 |
+ // init strings |
|
| 147 | 155 |
var latitudeString = ""; |
| 148 | 156 |
var longitudeString = ""; |
| 149 | 157 |
var accuracyString = ""; |
| 150 | 158 |
var altitudeString = ""; |
| 151 |
- //var altitudeAccuracyString = ""; |
|
| 152 |
- //var timestampString = ""; |
|
| 153 | 159 |
var speedString = ""; |
| 154 | 160 |
|
| 155 | 161 |
//formating for precision and max size |
| ... | ... |
@@ -163,12 +169,8 @@ function locationSuccess(new_pos) {
|
| 163 | 169 |
if (speedString == "NaN") {
|
| 164 | 170 |
speedString = "---"; |
| 165 | 171 |
} |
| 166 |
- // logging |
|
| 167 |
- /*console.log('Your current position at ' + timestampString + ' is:');
|
|
| 168 |
- console.log('Coordinates: ' + latitudeString+ ', ' + longitudeString+' ; with a ' + accuracyString + 'm accuracy');
|
|
| 169 |
- console.log('Altitude: ' + altitudeString + 'm ; with a ' + altitudeAccuracyString + 'm accuracy');
|
|
| 170 |
- console.log('Speed: ' + speedString + ' km/h.');
|
|
| 171 |
- */ |
|
| 172 |
+ |
|
| 173 |
+ //add a new datapoint to GPX file |
|
| 172 | 174 |
GPXtrkptBuilder(latitudeString, longitudeString, altitudeString, timestampISO); |
| 173 | 175 |
|
| 174 | 176 |
console.log('GPX: ' + localStorage.getItem("GPX"));
|
| ... | ... |
@@ -176,16 +178,11 @@ function locationSuccess(new_pos) {
|
| 176 | 178 |
// Build message |
| 177 | 179 |
message = "OK"; |
| 178 | 180 |
var dict = {
|
| 179 |
- //'latitude': padStart(latitudeString, 12, '0'), |
|
| 180 |
- //'longitude': padStart(longitudeString, 12, '0'), |
|
| 181 | 181 |
'accuracy': accuracyString, |
| 182 | 182 |
'altitude': altitudeString, |
| 183 |
- //'altitude_accuracy': padStart(altitudeAccuracyString, 3, '0'), |
|
| 184 |
- //'timestamp': padStart(timestampString, 13, '0'), |
|
| 185 | 183 |
'speed': speedString, |
| 186 | 184 |
'status': message |
| 187 | 185 |
}; |
| 188 |
- //console.log('Message to send: ' + JSON.stringify(dict));
|
|
| 189 | 186 |
|
| 190 | 187 |
// Send the message |
| 191 | 188 |
Pebble.sendAppMessage(dict, function () {
|
| ... | ... |
@@ -194,129 +191,38 @@ function locationSuccess(new_pos) {
|
| 194 | 191 |
console.log('Message (' + JSON.stringify(dict) + ') failed: ' + JSON.stringify(e));
|
| 195 | 192 |
}); |
| 196 | 193 |
} |
| 194 |
+ |
|
| 195 |
+ // restart the watch |
|
| 196 |
+ //geoloc_id = navigator.geolocation.watchPosition(locationSuccess, locationError, locationOptions); |
|
| 197 | 197 |
} |
| 198 | 198 |
|
| 199 | 199 |
function locationError(err) {
|
| 200 |
+ //clear watch of new position to avoid overlap |
|
| 201 |
+ //navigator.geolocation.clearWatch(geoloc_id); |
|
| 202 |
+ |
|
| 200 | 203 |
console.warn('location error (' + err.code + '): ' + err.message);
|
| 201 |
- /* // No app when no location |
|
| 202 |
- Pebble.sendAppMessage({
|
|
| 203 |
- 'WEATHER_CITY_KEY': 'Loc Unavailable', |
|
| 204 |
- 'WEATHER_TEMPERATURE_KEY': 'N/A' |
|
| 205 |
- });*/ |
|
| 204 |
+ |
|
| 205 |
+ // restart the watch |
|
| 206 |
+ //geoloc_id = navigator.geolocation.watchPosition(locationSuccess, locationError, locationOptions); |
|
| 206 | 207 |
} |
| 207 | 208 |
|
| 208 | 209 |
function get_coordinate() {
|
| 209 |
- console.log('---- get_coordinate');
|
|
| 210 |
+ /*console.log('---- start geoloc');
|
|
| 210 | 211 |
navigator.geolocation.getCurrentPosition(locationSuccess, locationError, locationOptions); |
| 211 |
- |
|
| 212 |
+ */ |
|
| 212 | 213 |
} |
| 213 | 214 |
|
| 214 |
-/* |
|
| 215 |
-function switch_home(bool) {
|
|
| 216 |
- var response; |
|
| 217 |
- console.log('---- authenticate');
|
|
| 218 |
- if (sid != ""){
|
|
| 219 |
- status = ""; |
|
| 220 |
- console.log('---- get_status');
|
|
| 221 |
- if (localStorage.getItem('username') && localStorage.getItem('password') && localStorage.getItem('server') ){
|
|
| 222 |
- var username=localStorage.getItem('username');
|
|
| 223 |
- var password=localStorage.getItem('password');
|
|
| 224 |
- var server=localStorage.getItem('server');
|
|
| 225 |
- var xhr = new XMLHttpRequest(); |
|
| 226 |
- |
|
| 227 |
- url = server + "/webapi/entry.cgi?api=SYNO.SurveillanceStation.HomeMode&version=1&method=GetInfo&_sid="+sid; |
|
| 228 |
- |
|
| 229 |
- xhr.open("GET", url,false);
|
|
| 230 |
- xhr.send(); |
|
| 231 |
- |
|
| 232 |
- if(xhr.status == 200) {
|
|
| 233 |
- response = JSON.parse(xhr.responseText); |
|
| 234 |
- if (response.success == true){
|
|
| 235 |
- status = response.data.on; |
|
| 236 |
- console.log('------ status:'+status);
|
|
| 237 |
- var message; |
|
| 238 |
- var dict; |
|
| 239 |
- if ( status != bool){
|
|
| 240 |
- console.log('---- switching home mode to '+ bool);
|
|
| 241 |
- url = server + "/webapi/entry.cgi?api=SYNO.SurveillanceStation.HomeMode&version=1&method=Switch&on="+bool+"&_sid="+sid; |
|
| 242 |
- |
|
| 243 |
- xhr.open("GET", url,false);
|
|
| 244 |
- xhr.send(); |
|
| 245 |
- |
|
| 246 |
- if(xhr.status == 200) {
|
|
| 247 |
- response = JSON.parse(xhr.responseText); |
|
| 248 |
- if (response.success == true){
|
|
| 249 |
- status=bool; |
|
| 250 |
- switch (status) {
|
|
| 251 |
- case true: |
|
| 252 |
- message = "You just set Home mode ON"; |
|
| 253 |
- break; |
|
| 254 |
- case false: |
|
| 255 |
- message = "You just set Home mode OFF"; |
|
| 256 |
- break; |
|
| 257 |
- default: |
|
| 258 |
- message = "something happened, try again !"; |
|
| 259 |
- } |
|
| 260 |
- // Build message |
|
| 261 |
- dict = {
|
|
| 262 |
- 'status': message, |
|
| 263 |
- }; |
|
| 264 |
- |
|
| 265 |
- // Send the message |
|
| 266 |
- Pebble.sendAppMessage(dict, function(e) {
|
|
| 267 |
- console.log('sent');
|
|
| 268 |
- }, function() {
|
|
| 269 |
- console.log('failed');
|
|
| 270 |
- }); |
|
| 271 |
- } |
|
| 272 |
- }else {
|
|
| 273 |
- console.log('------Request returned error code ' + xhr.status.toString());
|
|
| 274 |
- } |
|
| 275 |
- }else{
|
|
| 276 |
- console.log('---- nothing to do, status already '+status);
|
|
| 277 |
- switch (status) {
|
|
| 278 |
- case true: |
|
| 279 |
- message = "Your Home Mode is already ON"; |
|
| 280 |
- break; |
|
| 281 |
- case false: |
|
| 282 |
- message = "Your Home Mode is already OFF"; |
|
| 283 |
- break; |
|
| 284 |
- default: |
|
| 285 |
- message = "something happened, try again !"; |
|
| 286 |
- } |
|
| 287 |
- // Build message |
|
| 288 |
- dict = {
|
|
| 289 |
- 'status': message, |
|
| 290 |
- }; |
|
| 291 |
- |
|
| 292 |
- // Send the message |
|
| 293 |
- Pebble.sendAppMessage(dict, function(e) {
|
|
| 294 |
- console.log('sent');
|
|
| 295 |
- }, function() {
|
|
| 296 |
- console.log('failed');
|
|
| 297 |
- }); |
|
| 298 |
- } |
|
| 299 |
- } |
|
| 300 |
- }else {
|
|
| 301 |
- console.log('------Request returned error code ' + xhr.status.toString());
|
|
| 302 |
- } |
|
| 303 |
- }else{
|
|
| 304 |
- Pebble.showSimpleNotificationOnPebble("DSCam H-S", "You need to set your Synology account and server.");
|
|
| 305 |
- } |
|
| 306 |
- } |
|
| 307 |
- |
|
| 308 |
-}*/ |
|
| 309 |
- |
|
| 310 | 215 |
function init() {
|
| 311 | 216 |
// local storage init |
| 312 | 217 |
localStorage.clear(); |
| 313 | 218 |
// clear any other var to do |
| 314 |
- clearInterval(locationInterval); |
|
| 219 |
+ //clearInterval(locationInterval); |
|
| 220 |
+ |
|
| 315 | 221 |
|
| 316 |
- console.log('--- Starting regular getCurrentPosition loop using setInterval at 1 sec');
|
|
| 222 |
+ console.log('--- Starting regular getCurrentPosition loop using setInterval at 5 sec');
|
|
| 317 | 223 |
locationInterval = setInterval(function () {
|
| 318 | 224 |
navigator.geolocation.getCurrentPosition(locationSuccess, locationError, locationOptions); |
| 319 |
- }, 1000); |
|
| 225 |
+ }, 5000); |
|
| 320 | 226 |
|
| 321 | 227 |
|
| 322 | 228 |
} |
| ... | ... |
@@ -338,13 +244,7 @@ Pebble.addEventListener('appmessage', function (e) {
|
| 338 | 244 |
switch (dict[0]) {
|
| 339 | 245 |
case 'get': |
| 340 | 246 |
get_coordinate(); |
| 341 |
- break;/* |
|
| 342 |
- case 'home_on': |
|
| 343 |
- switch_home(true); |
|
| 344 | 247 |
break; |
| 345 |
- case 'home_off': |
|
| 346 |
- switch_home(false); |
|
| 347 |
- break;*/ |
|
| 348 | 248 |
default: |
| 349 | 249 |
console.log('Sorry. I don\'t understand your request :' + dict[0]);
|
| 350 | 250 |
} |