| ... | ... |
@@ -4,11 +4,6 @@ var clay = new Clay(clayConfig, null, { autoHandleEvents: false });
|
| 4 | 4 |
var messageKeys = require('message_keys');
|
| 5 | 5 |
|
| 6 | 6 |
var message; |
| 7 |
-var locate_me |
|
| 8 |
- |
|
| 9 |
-var firstlocationInterval = false; |
|
| 10 |
-var locationInterval = false; |
|
| 11 |
-var instantLocationInterval = false; |
|
| 12 | 7 |
|
| 13 | 8 |
|
| 14 | 9 |
Pebble.addEventListener('showConfiguration', function(e) {
|
| ... | ... |
@@ -44,7 +39,34 @@ Pebble.addEventListener('webviewclosed', function(t) {
|
| 44 | 39 |
} |
| 45 | 40 |
}); |
| 46 | 41 |
|
| 47 |
-function PostToWeb(event) {
|
|
| 42 |
+function PostPosition(x,y,z){
|
|
| 43 |
+ console.log(localStorage.getItem('clay-settings'))
|
|
| 44 |
+ var url = JSON.parse(localStorage.getItem('clay-settings')).web_url + "?event=position&user="+JSON.parse(localStorage.getItem('clay-settings')).username+"&x="+x+"&y="+y+"&z="+z;
|
|
| 45 |
+ console.log(url) |
|
| 46 |
+ var xhr = new XMLHttpRequest(); |
|
| 47 |
+ xhr.timeout = 10000; // time in milliseconds |
|
| 48 |
+ xhr.open("GET", url, false);
|
|
| 49 |
+ //console.log('------ CSV / xhr opened')
|
|
| 50 |
+ xhr.onload = function() {
|
|
| 51 |
+ //console.log('------xhr onloaded')
|
|
| 52 |
+ if (xhr.readyState === 4) {
|
|
| 53 |
+ //console.log('------xhr request returned with ' + xhr.status);
|
|
| 54 |
+ //console.log(this.responseText); |
|
| 55 |
+ //localStorage.setItem("custom_uploaded", true);
|
|
| 56 |
+ if (xhr.status == 200) {
|
|
| 57 |
+ //console.log('--> HTTP 200');
|
|
| 58 |
+ return true; |
|
| 59 |
+ } else {
|
|
| 60 |
+ //console.log('--> HTTP ' + xhr.status);
|
|
| 61 |
+ return false; |
|
| 62 |
+ } |
|
| 63 |
+ } |
|
| 64 |
+ }; |
|
| 65 |
+ |
|
| 66 |
+ //send xhr without body (GET) |
|
| 67 |
+ xhr.send(); |
|
| 68 |
+} |
|
| 69 |
+function PostEvent(event) {
|
|
| 48 | 70 |
console.log(localStorage.getItem('clay-settings'))
|
| 49 | 71 |
var url = JSON.parse(localStorage.getItem('clay-settings')).web_url + "?event="+event+"&user="+JSON.parse(localStorage.getItem('clay-settings')).username;
|
| 50 | 72 |
var xhr = new XMLHttpRequest(); |
| ... | ... |
@@ -101,18 +123,24 @@ Pebble.addEventListener('ready', function(e) {
|
| 101 | 123 |
Pebble.addEventListener('appmessage', function (e) {
|
| 102 | 124 |
// Get the dictionary from the message |
| 103 | 125 |
var dict = e.payload; |
| 104 |
- //console.log(dict[0].toString()); |
|
| 126 |
+ for (var i in dict){
|
|
| 127 |
+ console.log(i +": "+dict[i].toString()); |
|
| 128 |
+ } |
|
| 129 |
+ |
|
| 105 | 130 |
switch (dict[0]) {
|
| 131 |
+ case 'position': |
|
| 132 |
+ PostPosition(dict[1],dict[2],dict[3]) |
|
| 133 |
+ break; |
|
| 106 | 134 |
case 'gotosleep': |
| 107 |
- PostToWeb("gotosleep")
|
|
| 135 |
+ PostEvent("gotosleep")
|
|
| 108 | 136 |
break; |
| 109 | 137 |
case 'awake': |
| 110 |
- PostToWeb("awake")
|
|
| 138 |
+ PostEvent("awake")
|
|
| 111 | 139 |
break; |
| 112 | 140 |
case 'wakeup': |
| 113 |
- PostToWeb("wakeup")
|
|
| 141 |
+ PostEvent("wakeup")
|
|
| 114 | 142 |
break; |
| 115 |
- default: |
|
| 143 |
+ default: |
|
| 116 | 144 |
console.log('Sorry. I don\'t understand your request :' + dict[0]);
|
| 117 | 145 |
} |
| 118 | 146 |
|
| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,119 @@ |
| 1 |
+var Clay = require('pebble-clay');
|
|
| 2 |
+var clayConfig = require('./config');
|
|
| 3 |
+var clay = new Clay(clayConfig, null, { autoHandleEvents: false });
|
|
| 4 |
+var messageKeys = require('message_keys');
|
|
| 5 |
+ |
|
| 6 |
+var message; |
|
| 7 |
+var locate_me |
|
| 8 |
+ |
|
| 9 |
+var firstlocationInterval = false; |
|
| 10 |
+var locationInterval = false; |
|
| 11 |
+var instantLocationInterval = false; |
|
| 12 |
+ |
|
| 13 |
+ |
|
| 14 |
+Pebble.addEventListener('showConfiguration', function(e) {
|
|
| 15 |
+ clay.config = clayConfig; |
|
| 16 |
+ console.log("Clay config is showing...")
|
|
| 17 |
+ Pebble.openURL(clay.generateUrl()); |
|
| 18 |
+}); |
|
| 19 |
+ |
|
| 20 |
+Pebble.addEventListener('webviewclosed', function(t) {
|
|
| 21 |
+ console.log("Clayview closed")
|
|
| 22 |
+ if (!t || t.response) {
|
|
| 23 |
+ console.log("Clay config is submitted : " + t.response)
|
|
| 24 |
+ try {
|
|
| 25 |
+ if (data = JSON.parse(t.response), data.code && data.scope == "read,activity:write") {
|
|
| 26 |
+ if (data.state == "agenda_sommeil" && data.scope == "read,activity:write") {
|
|
| 27 |
+ getTokens(data.code); |
|
| 28 |
+ } else {
|
|
| 29 |
+ console.log("Error on response returned : scope is " + grantcode.scope + " and state is " + grantcode.state);
|
|
| 30 |
+ } |
|
| 31 |
+ } else {
|
|
| 32 |
+ clay.getSettings(t.response); |
|
| 33 |
+ console.log("Clay settings in Localstorage looks like " + localStorage.getItem("clay-settings"));
|
|
| 34 |
+ } |
|
| 35 |
+ } catch (t) {
|
|
| 36 |
+ console.log("Oauth parsing error, continue on saving clay settings");
|
|
| 37 |
+ clay.getSettings(t.response); |
|
| 38 |
+ var claysettings = JSON.parse(localStorage.getItem('clay-settings'))
|
|
| 39 |
+ claysettings.strava_enabled = false; |
|
| 40 |
+ localStorage.setItem("clay-settings", JSON.stringify("claysettings"));
|
|
| 41 |
+ console.log("Clay settings in Localstorage looks like " + localStorage.getItem("clay-settings"));
|
|
| 42 |
+ } |
|
| 43 |
+ |
|
| 44 |
+ } |
|
| 45 |
+}); |
|
| 46 |
+ |
|
| 47 |
+function PostToWeb(event) {
|
|
| 48 |
+ console.log(localStorage.getItem('clay-settings'))
|
|
| 49 |
+ var url = JSON.parse(localStorage.getItem('clay-settings')).web_url + "?event="+event+"&user="+JSON.parse(localStorage.getItem('clay-settings')).username;
|
|
| 50 |
+ var xhr = new XMLHttpRequest(); |
|
| 51 |
+ xhr.timeout = 10000; // time in milliseconds |
|
| 52 |
+ xhr.open("GET", url, false);
|
|
| 53 |
+ //console.log('------ CSV / xhr opened')
|
|
| 54 |
+ xhr.onload = function() {
|
|
| 55 |
+ //console.log('------xhr onloaded')
|
|
| 56 |
+ if (xhr.readyState === 4) {
|
|
| 57 |
+ //console.log('------xhr request returned with ' + xhr.status);
|
|
| 58 |
+ //console.log(this.responseText); |
|
| 59 |
+ //localStorage.setItem("custom_uploaded", true);
|
|
| 60 |
+ if (xhr.status == 200) {
|
|
| 61 |
+ //console.log('--> HTTP 200');
|
|
| 62 |
+ return true; |
|
| 63 |
+ } else {
|
|
| 64 |
+ //console.log('--> HTTP ' + xhr.status);
|
|
| 65 |
+ return false; |
|
| 66 |
+ } |
|
| 67 |
+ } |
|
| 68 |
+ }; |
|
| 69 |
+ |
|
| 70 |
+ //send xhr without body (GET) |
|
| 71 |
+ xhr.send(); |
|
| 72 |
+} |
|
| 73 |
+ |
|
| 74 |
+function init() {
|
|
| 75 |
+ //init vars |
|
| 76 |
+ // get vars from clay: |
|
| 77 |
+ //var su = localStorage.getItem("strava_uploaded")
|
|
| 78 |
+ |
|
| 79 |
+ //debug : |
|
| 80 |
+ //console.log("Locate_me = " + locate_me);
|
|
| 81 |
+ |
|
| 82 |
+ //actions: |
|
| 83 |
+ //PostToWeb() |
|
| 84 |
+ |
|
| 85 |
+ |
|
| 86 |
+ //set var in clay : |
|
| 87 |
+ //localStorage.setItem("strava_uploaded", 0);
|
|
| 88 |
+ |
|
| 89 |
+} |
|
| 90 |
+ |
|
| 91 |
+// Get JS readiness events |
|
| 92 |
+Pebble.addEventListener('ready', function(e) {
|
|
| 93 |
+ console.log('PebbleKit JS is ready');
|
|
| 94 |
+ // Update Watch on this |
|
| 95 |
+ Pebble.sendAppMessage({ 'JSReady': 1 });
|
|
| 96 |
+ |
|
| 97 |
+ //init(); |
|
| 98 |
+}); |
|
| 99 |
+ |
|
| 100 |
+// Get AppMessage events |
|
| 101 |
+Pebble.addEventListener('appmessage', function (e) {
|
|
| 102 |
+ // Get the dictionary from the message |
|
| 103 |
+ var dict = e.payload; |
|
| 104 |
+ //console.log(dict[0].toString()); |
|
| 105 |
+ switch (dict[0]) {
|
|
| 106 |
+ case 'gotosleep': |
|
| 107 |
+ PostToWeb("gotosleep")
|
|
| 108 |
+ break; |
|
| 109 |
+ case 'awake': |
|
| 110 |
+ PostToWeb("awake")
|
|
| 111 |
+ break; |
|
| 112 |
+ case 'wakeup': |
|
| 113 |
+ PostToWeb("wakeup")
|
|
| 114 |
+ break; |
|
| 115 |
+ default: |
|
| 116 |
+ console.log('Sorry. I don\'t understand your request :' + dict[0]);
|
|
| 117 |
+ } |
|
| 118 |
+ |
|
| 119 |
+ }); |
|
| 0 | 120 |
\ No newline at end of file |