From dca7d8ddffb6470133b88390fbba77fce3de05af Mon Sep 17 00:00:00 2001 From: Steve Illichevsky Date: Mon, 9 Jul 2012 09:45:50 +0400 Subject: [PATCH 1/2] Change function. Need testing. --- workHours.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/workHours.js b/workHours.js index e27565b..269829b 100644 --- a/workHours.js +++ b/workHours.js @@ -19,14 +19,14 @@ var dailyWorkplaceCounter = 0; var workplaceEntry = new Date(0); -workplace.on("enter", function(signal) { +device.regions.on("enter", function(signal) { dailyWorkplaceCounter += 1; workplaceEntry = new Date(); var notification = device.notifications.createNotification("Entering workplace for the " + dailyWorkplaceCounter + ". time today. Enjoy!"); notification.show(); }); -workplace.on("exit", function(signal) { +device.regions.on("exit", function(signal) { var now = new Date(); var remainingSeconds = (now.getTime() - workplaceEntry.getTime())/1000; var hours = remainingSeconds / (60*60) >> 0; From cb6d200b611aaad1c2d7e223bfcc4e7c7da506d8 Mon Sep 17 00:00:00 2001 From: Steve Illichevsky Date: Tue, 10 Jul 2012 09:27:13 +0400 Subject: [PATCH 2/2] Some fixes. --- workHours.js | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/workHours.js b/workHours.js index 269829b..24145e4 100644 --- a/workHours.js +++ b/workHours.js @@ -1,32 +1,34 @@ /* * Script to track my work hours automatically. - * Set up a 500m radius border around my workplace, and measuring the time spent within the area. + * Set up a 200m radius border around my workplace, and measuring the time spent within the area. * * Testing on my way to work tomorrow :-) */ -var myEmail = "mail@example.com"; +var location = { name : "Work",latitude : "55.7297654",longitude : "37.6790519" } ; +var myEmail = "you_mail@gmail.com"; // shuld be your email -var workplace = device.regions.createRegion({ - name:"Rotvoll", - latitude: 63.43915607186877, - longitude: 10.480849756066846, - radius: 500 -}); +var work = device.regions.createRegion({ + latitude: parseFloat(location.latitude, 10), + longitude: parseFloat(location.longitude, 10), + name: location.name, + radius: 200 + }); + var dailyWorkplaceCounter = 0; var workplaceEntry = new Date(0); - -device.regions.on("enter", function(signal) { - dailyWorkplaceCounter += 1; +// register a callback which sends a message when entering/exiting the region (depends on action) + work.on("enter", function(signal) { + dailyWorkplaceCounter += 1; workplaceEntry = new Date(); var notification = device.notifications.createNotification("Entering workplace for the " + dailyWorkplaceCounter + ". time today. Enjoy!"); notification.show(); }); -device.regions.on("exit", function(signal) { +work.on("exit", function(signal) { var now = new Date(); var remainingSeconds = (now.getTime() - workplaceEntry.getTime())/1000; var hours = remainingSeconds / (60*60) >> 0; @@ -69,4 +71,5 @@ device.scheduler.setTimer( }, timerAction); -device.regions.startMonitoring(workplace); \ No newline at end of file +console.info('Start monitoring...'); +device.regions.startMonitoring(work); \ No newline at end of file