Browse code

agenda sommeil with position and compiling OK

Louis Jonget authored on17/05/2024 11:54:43
Showing5 changed files
... ...
@@ -1,4 +1,4 @@
1
-wscript
1
+# removed ignoring of wscript as needed to compile
2 2
 
3 3
 # Ignore swap files
4 4
 *.swp
5 5
Binary files a/build/agenda_sommeil.pbw and b/build/agenda_sommeil.pbw differ
... ...
@@ -1,13 +1,14 @@
1 1
 #include <pebble.h>
2
+#define ACCEL_STEP_MS 300000
2 3
 
3 4
 static Window *s_window;
4
-static StatusBarLayer *s_status_text_layer;
5
+static TextLayer *s_main_text_layer;
6
+/*static StatusBarLayer *s_status_text_layer;
5 7
 static TextLayer *s_upperleft_text_layer;
6 8
 static TextLayer *s_upperright_text_layer;
7
-static TextLayer *s_main_text_layer;
8 9
 static TextLayer *s_lowerleft_text_layer;
9 10
 static TextLayer *s_lowerright_text_layer;
10
-static TextLayer *s_lower_text_layer;
11
+static TextLayer *s_lower_text_layer;*/
11 12
 
12 13
 // Largest expected inbox and outbox message sizes
13 14
 const uint32_t inbox_size = 150;
... ...
@@ -15,16 +16,49 @@ const uint32_t outbox_size = 64;
15 16
 
16 17
 static uint32_t size ;
17 18
 static char s_status[4];
18
-static char s_msg[50];
19
+//static char s_msg[50];
19 20
 
20 21
 static bool s_js_ready;
21 22
 
22 23
 typedef enum {
23 24
   status,
24
-  event
25
+  x,
26
+  y,
27
+  z
25 28
 } AppKey;
26 29
 
27 30
 
31
+static void accel_data_handler(void *data) {
32
+  AccelData accel = (AccelData) { .x = 0, .y = 0, .z = 0 };
33
+  accel_service_peek(&accel);
34
+  APP_LOG(APP_LOG_LEVEL_INFO, "t: %llu, x: %d, y: %d, z: %d",accel.timestamp, accel.x , accel.y, accel.z);
35
+  
36
+  APP_LOG(APP_LOG_LEVEL_INFO, "size of timestamp : %u",sizeof(accel.timestamp));
37
+  
38
+  // Declare the dictionary's iterator
39
+  DictionaryIterator *out_iter;
40
+
41
+  // Prepare the outbox buffer for this message
42
+  AppMessageResult result = app_message_outbox_begin(&out_iter);
43
+
44
+  if(result == APP_MSG_OK) {
45
+    dict_write_cstring(out_iter, status, "position");
46
+    dict_write_int16(out_iter, x, accel.x);
47
+    dict_write_int16(out_iter, y, accel.y);
48
+    dict_write_int16(out_iter, z, accel.z);
49
+
50
+  // Send this message
51
+    result = app_message_outbox_send();
52
+    if(result != APP_MSG_OK) {
53
+      APP_LOG(APP_LOG_LEVEL_ERROR, "Error sending the outbox: %d", (int)result);
54
+    }
55
+  } else {
56
+    // The outbox cannot be used right now
57
+    APP_LOG(APP_LOG_LEVEL_ERROR, "Error preparing the outbox: %d", (int)result);
58
+  }
59
+  app_timer_register(ACCEL_STEP_MS, accel_data_handler, NULL);
60
+}
61
+
28 62
 static void send_message(char * msg){
29 63
 
30 64
   // Declare the dictionary's iterator
... ...
@@ -187,6 +221,11 @@ static void prv_init(void) {
187 221
   app_message_register_outbox_sent(outbox_sent_callback);
188 222
   // Register to be notified about outbox failed events
189 223
   app_message_register_outbox_failed(outbox_failed_callback);
224
+  
225
+  accel_data_service_subscribe(0, NULL);
226
+
227
+  app_timer_register(1000, accel_data_handler, NULL);
228
+
190 229
 
191 230
 
192 231
   s_window = window_create();
... ...
@@ -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
   
119 147
new file mode 100644
... ...
@@ -0,0 +1,54 @@
1
+#
2
+# This file is the default set of rules to compile a Pebble application.
3
+#
4
+# Feel free to customize this to your needs.
5
+#
6
+import os.path
7
+
8
+top = '.'
9
+out = 'build'
10
+
11
+
12
+def options(ctx):
13
+    ctx.load('pebble_sdk')
14
+
15
+
16
+def configure(ctx):
17
+    """
18
+    This method is used to configure your build. ctx.load(`pebble_sdk`) automatically configures
19
+    a build for each valid platform in `targetPlatforms`. Platform-specific configuration: add your
20
+    change after calling ctx.load('pebble_sdk') and make sure to set the correct environment first.
21
+    Universal configuration: add your change prior to calling ctx.load('pebble_sdk').
22
+    """
23
+    ctx.load('pebble_sdk')
24
+
25
+
26
+def build(ctx):
27
+    ctx.load('pebble_sdk')
28
+
29
+    build_worker = os.path.exists('worker_src')
30
+    binaries = []
31
+
32
+    cached_env = ctx.env
33
+    for platform in ctx.env.TARGET_PLATFORMS:
34
+        ctx.env = ctx.all_envs[platform]
35
+        ctx.set_group(ctx.env.PLATFORM_NAME)
36
+        app_elf = '{}/pebble-app.elf'.format(ctx.env.BUILD_DIR)
37
+        ctx.pbl_build(source=ctx.path.ant_glob('src/c/**/*.c'), target=app_elf, bin_type='app')
38
+
39
+        if build_worker:
40
+            worker_elf = '{}/pebble-worker.elf'.format(ctx.env.BUILD_DIR)
41
+            binaries.append({'platform': platform, 'app_elf': app_elf, 'worker_elf': worker_elf})
42
+            ctx.pbl_build(source=ctx.path.ant_glob('worker_src/c/**/*.c'),
43
+                          target=worker_elf,
44
+                          bin_type='worker')
45
+        else:
46
+            binaries.append({'platform': platform, 'app_elf': app_elf})
47
+    ctx.env = cached_env
48
+
49
+    ctx.set_group('bundle')
50
+    ctx.pbl_bundle(binaries=binaries,
51
+                   js=ctx.path.ant_glob(['src/pkjs/**/*.js',
52
+                                         'src/pkjs/**/*.json',
53
+                                         'src/common/**/*.js']),
54
+                   js_entry_file='src/pkjs/index.js')