Browse code

new workflows adn refactoring

Louis authored on28/04/2025 18:37:32
Showing1 changed files
... ...
@@ -9,8 +9,7 @@ const uint32_t inbox_size = 64;
9 9
 const uint32_t outbox_size = 64;
10 10
 
11 11
 
12
-static char s_auth[60];
13
-static char s_api[40];
12
+static char s_api[60];
14 13
 static char s_api_short[22];
15 14
 static char s_username[40];
16 15
 static char s_password[40];
... ...
@@ -206,7 +205,7 @@ static void update_time() {
206 205
 
207 206
 void comm_is_ready() {
208 207
 
209
-  // Authenticate to get token from syno
208
+  // Trigger timed home mode (15 min)
210 209
 
211 210
   // Declare the dictionary's iterator
212 211
   DictionaryIterator *out_iter;
... ...
@@ -216,15 +215,13 @@ void comm_is_ready() {
216 215
   
217 216
   if(result == APP_MSG_OK) {
218 217
     // Add an item to ask for weather data
219
-    msg = "auth";
218
+    msg = "timed";
220 219
     dict_write_cstring(out_iter, status, msg);
221 220
   
222 221
     // Send this message
223 222
     result = app_message_outbox_send();
224 223
     if(result != APP_MSG_OK) {
225 224
       APP_LOG(APP_LOG_LEVEL_ERROR, "Error sending the outbox: %d", (int)result);
226
-    }else{
227
-      text_layer_set_text(s_text_layer, "Authenticating...");
228 225
     }
229 226
   } else {
230 227
     // The outbox cannot be used right now
... ...
@@ -259,28 +256,14 @@ static void inbox_received_callback(DictionaryIterator *iter, void *context) {
259 256
     APP_LOG(APP_LOG_LEVEL_DEBUG, "received jsready message on watch... ");
260 257
   }
261 258
 
262
-  // Read Auth returns
263
-  Tuple *auth_tuple = dict_find(iter, MESSAGE_KEY_auth);
264
-
265
-  if(auth_tuple) {
266
-    strncpy(s_auth, auth_tuple->value->cstring, 60);
267
-    // Display in the TextLayer
268
-    text_layer_set_text(s_text_layer, s_auth);
269
-    if(strcmp(s_auth, "Authentication failed")==0){
270
-      vibes_long_pulse();
271
-    }
272
-    APP_LOG(APP_LOG_LEVEL_DEBUG, "Auth message received ... ");
273
-  }else{
274
-    APP_LOG(APP_LOG_LEVEL_DEBUG, "not auth message... ");
275
-  }
276
-
277 259
   // Read API returns
278 260
   Tuple *api_tuple = dict_find(iter, MESSAGE_KEY_status);
279 261
 
280 262
   if(api_tuple) {
281
-    strncpy(s_api, api_tuple->value->cstring, 40);
263
+    strncpy(s_api, api_tuple->value->cstring, 60);
282 264
     // Display in the TextLayer
283 265
     text_layer_set_text(s_text_layer, s_api);
266
+    // Vibrating depending of returns, not everytime
284 267
     strncpy(s_api_short, s_api, 22);
285 268
     if(strcmp(s_api_short, "Home mode is ON")==0){
286 269
       vibes_short_pulse();
Browse code

fix vibration

Louis Jonget authored on11/03/2024 17:26:51
Showing1 changed files
... ...
@@ -11,6 +11,7 @@ const uint32_t outbox_size = 64;
11 11
 
12 12
 static char s_auth[60];
13 13
 static char s_api[40];
14
+static char s_api_short[22];
14 15
 static char s_username[40];
15 16
 static char s_password[40];
16 17
 static char s_server[255];
... ...
@@ -280,11 +281,14 @@ static void inbox_received_callback(DictionaryIterator *iter, void *context) {
280 281
     strncpy(s_api, api_tuple->value->cstring, 40);
281 282
     // Display in the TextLayer
282 283
     text_layer_set_text(s_text_layer, s_api);
283
-    if(strcmp(s_api, "Home mode is ON (camera is off)")==0){
284
+    strncpy(s_api_short, s_api, 22);
285
+    if(strcmp(s_api_short, "Home mode is ON")==0){
284 286
       vibes_short_pulse();
285
-    }else if(strcmp(s_api, "Home mode is OFF (camera is on)")==0){
287
+    }else if(strcmp(s_api_short, "Home mode is OFF")==0){
286 288
       vibes_double_pulse();
287
-    }else if(strcmp(s_api,"Time out too many times, verify settings")==0){
289
+    }else if(strcmp(s_api_short, "Home mode is ON until ")==0){
290
+      vibes_double_pulse();
291
+    }else if(strcmp(s_api_short,"Timeout too many times")==0){
288 292
       vibes_long_pulse();
289 293
     }
290 294
     APP_LOG(APP_LOG_LEVEL_DEBUG, "status message received ... ");
Browse code

adding vibration

louis.jonget authored on24/03/2023 10:18:31
Showing1 changed files
... ...
@@ -265,6 +265,9 @@ static void inbox_received_callback(DictionaryIterator *iter, void *context) {
265 265
     strncpy(s_auth, auth_tuple->value->cstring, 60);
266 266
     // Display in the TextLayer
267 267
     text_layer_set_text(s_text_layer, s_auth);
268
+    if(strcmp(s_auth, "Authentication failed")==0){
269
+      vibes_long_pulse();
270
+    }
268 271
     APP_LOG(APP_LOG_LEVEL_DEBUG, "Auth message received ... ");
269 272
   }else{
270 273
     APP_LOG(APP_LOG_LEVEL_DEBUG, "not auth message... ");
... ...
@@ -277,6 +280,13 @@ static void inbox_received_callback(DictionaryIterator *iter, void *context) {
277 280
     strncpy(s_api, api_tuple->value->cstring, 40);
278 281
     // Display in the TextLayer
279 282
     text_layer_set_text(s_text_layer, s_api);
283
+    if(strcmp(s_api, "Home mode is ON (camera is off)")==0){
284
+      vibes_short_pulse();
285
+    }else if(strcmp(s_api, "Home mode is OFF (camera is on)")==0){
286
+      vibes_double_pulse();
287
+    }else if(strcmp(s_api,"Time out too many times, verify settings")==0){
288
+      vibes_long_pulse();
289
+    }
280 290
     APP_LOG(APP_LOG_LEVEL_DEBUG, "status message received ... ");
281 291
   }else{
282 292
     APP_LOG(APP_LOG_LEVEL_DEBUG, "not status message... ");
Browse code

fixed untracked files

louis.jonget authored on24/01/2023 10:30:34
Showing1 changed files
1 1
old mode 100755
2 2
new mode 100644
Browse code

modified authenticate function to have timeout and second retry on failed xhr

louis authored on22/06/2022 17:06:52
Showing1 changed files
... ...
@@ -9,7 +9,7 @@ const uint32_t inbox_size = 64;
9 9
 const uint32_t outbox_size = 64;
10 10
 
11 11
 
12
-static char s_auth[40];
12
+static char s_auth[60];
13 13
 static char s_api[40];
14 14
 static char s_username[40];
15 15
 static char s_password[40];
... ...
@@ -262,7 +262,7 @@ static void inbox_received_callback(DictionaryIterator *iter, void *context) {
262 262
   Tuple *auth_tuple = dict_find(iter, MESSAGE_KEY_auth);
263 263
 
264 264
   if(auth_tuple) {
265
-    strncpy(s_auth, auth_tuple->value->cstring, 40);
265
+    strncpy(s_auth, auth_tuple->value->cstring, 60);
266 266
     // Display in the TextLayer
267 267
     text_layer_set_text(s_text_layer, s_auth);
268 268
     APP_LOG(APP_LOG_LEVEL_DEBUG, "Auth message received ... ");
Browse code

adding logs

Louis authored on14/03/2019 23:33:45
Showing1 changed files
... ...
@@ -34,7 +34,6 @@ time_t current_time;
34 34
   
35 35
 typedef enum {
36 36
   status,
37
-  auth,
38 37
   username,
39 38
   password,
40 39
   server
... ...
@@ -217,7 +216,7 @@ void comm_is_ready() {
217 216
   if(result == APP_MSG_OK) {
218 217
     // Add an item to ask for weather data
219 218
     msg = "auth";
220
-    dict_write_cstring(out_iter, auth, msg);
219
+    dict_write_cstring(out_iter, status, msg);
221 220
   
222 221
     // Send this message
223 222
     result = app_message_outbox_send();
Browse code

adding logs

Louis authored on14/03/2019 23:31:59
Showing1 changed files
... ...
@@ -33,8 +33,8 @@ static uint32_t size ;
33 33
 time_t current_time;
34 34
   
35 35
 typedef enum {
36
-  auth,
37 36
   status,
37
+  auth,
38 38
   username,
39 39
   password,
40 40
   server
Browse code

adding logs

Louis authored on14/03/2019 23:02:31
Showing1 changed files
... ...
@@ -172,7 +172,7 @@ static void down_click_handler(ClickRecognizerRef recognizer, void *context) {
172 172
     if(result != APP_MSG_OK) {
173 173
       APP_LOG(APP_LOG_LEVEL_ERROR, "Error sending the outbox: %d", (int)result);
174 174
     }else{
175
-      APP_LOG(APP_LOG_LEVEL_INFO, "Sending to the outbox: %d", msg);
175
+      APP_LOG(APP_LOG_LEVEL_INFO, "Sending to the outbox: %s", msg);
176 176
       text_layer_set_text(s_text_layer, "Sent...");
177 177
     }
178 178
   } else {
Browse code

adding logs

Louis authored on14/03/2019 22:54:50
Showing1 changed files
... ...
@@ -172,6 +172,7 @@ static void down_click_handler(ClickRecognizerRef recognizer, void *context) {
172 172
     if(result != APP_MSG_OK) {
173 173
       APP_LOG(APP_LOG_LEVEL_ERROR, "Error sending the outbox: %d", (int)result);
174 174
     }else{
175
+      APP_LOG(APP_LOG_LEVEL_INFO, "Sending to the outbox: %d", msg);
175 176
       text_layer_set_text(s_text_layer, "Sent...");
176 177
     }
177 178
   } else {
Browse code

adding callback for auth

Louis authored on14/03/2019 22:43:30
Showing1 changed files
... ...
@@ -9,6 +9,7 @@ const uint32_t inbox_size = 64;
9 9
 const uint32_t outbox_size = 64;
10 10
 
11 11
 
12
+static char s_auth[40];
12 13
 static char s_api[40];
13 14
 static char s_username[40];
14 15
 static char s_password[40];
... ...
@@ -257,6 +258,18 @@ static void inbox_received_callback(DictionaryIterator *iter, void *context) {
257 258
     APP_LOG(APP_LOG_LEVEL_DEBUG, "received jsready message on watch... ");
258 259
   }
259 260
 
261
+  // Read Auth returns
262
+  Tuple *auth_tuple = dict_find(iter, MESSAGE_KEY_auth);
263
+
264
+  if(auth_tuple) {
265
+    strncpy(s_auth, auth_tuple->value->cstring, 40);
266
+    // Display in the TextLayer
267
+    text_layer_set_text(s_text_layer, s_auth);
268
+    APP_LOG(APP_LOG_LEVEL_DEBUG, "Auth message received ... ");
269
+  }else{
270
+    APP_LOG(APP_LOG_LEVEL_DEBUG, "not auth message... ");
271
+  }
272
+
260 273
   // Read API returns
261 274
   Tuple *api_tuple = dict_find(iter, MESSAGE_KEY_status);
262 275
 
Browse code

removed text from commsready

Louis authored on14/03/2019 22:37:29
Showing1 changed files
... ...
@@ -230,7 +230,7 @@ void comm_is_ready() {
230 230
   }
231 231
 
232 232
   // set the text
233
-  text_layer_set_text(s_text_layer, "Welcome to Syno Cam Switch ! ready");
233
+  //text_layer_set_text(s_text_layer, "Welcome to Syno Cam Switch ! ready");
234 234
 
235 235
   // click provider
236 236
   window_set_click_config_provider(s_window, click_config_provider);
Browse code

authenticate at app start

Louis authored on14/03/2019 22:27:39
Showing1 changed files
... ...
@@ -32,6 +32,7 @@ static uint32_t size ;
32 32
 time_t current_time;
33 33
   
34 34
 typedef enum {
35
+  auth,
35 36
   status,
36 37
   username,
37 38
   password,
... ...
@@ -202,27 +203,34 @@ static void update_time() {
202 203
 }
203 204
 
204 205
 void comm_is_ready() {
205
-  // Get information about the window
206
-  //Layer *window_layer = window_get_root_layer(s_window);
207
-  //GRect bounds = layer_get_bounds(window_layer);
208 206
 
209
-  // Create a text layer and set the text
210
-  //const GEdgeInsets label_insets = {.right = ACTION_BAR_WIDTH, .left = ACTION_BAR_WIDTH / 2};
211
-  //s_text_layer = text_layer_create(grect_inset(bounds, label_insets));
212
-  text_layer_set_text(s_text_layer, "Welcome to Syno Cam Switch ! ready");
213
-
214
-  // Set the font and text alignment
215
-  //text_layer_set_font(s_text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD));
216
-  //text_layer_set_text_alignment(s_text_layer, GTextAlignmentCenter);
207
+  // Authenticate to get token from syno
217 208
 
218
-  // Add the text layer to the window
219
-  //layer_add_child(window_get_root_layer(s_window), text_layer_get_layer(s_text_layer));
220
-
221
-  // Enable text flow and paging on the text layer, with a slight inset of 10, for round screens
222
-  //text_layer_enable_screen_text_flow_and_paging(s_text_layer, 10);
209
+  // Declare the dictionary's iterator
210
+  DictionaryIterator *out_iter;
211
+  
212
+  // Prepare the outbox buffer for this message
213
+  AppMessageResult result = app_message_outbox_begin(&out_iter);
214
+  
215
+  if(result == APP_MSG_OK) {
216
+    // Add an item to ask for weather data
217
+    msg = "auth";
218
+    dict_write_cstring(out_iter, auth, msg);
219
+  
220
+    // Send this message
221
+    result = app_message_outbox_send();
222
+    if(result != APP_MSG_OK) {
223
+      APP_LOG(APP_LOG_LEVEL_ERROR, "Error sending the outbox: %d", (int)result);
224
+    }else{
225
+      text_layer_set_text(s_text_layer, "Authenticating...");
226
+    }
227
+  } else {
228
+    // The outbox cannot be used right now
229
+    APP_LOG(APP_LOG_LEVEL_ERROR, "Error preparing the outbox: %d", (int)result);
230
+  }
223 231
 
224
-  // Push the window, setting the window animation to 'true'
225
-  //window_stack_push(s_window, true);
232
+  // set the text
233
+  text_layer_set_text(s_text_layer, "Welcome to Syno Cam Switch ! ready");
226 234
 
227 235
   // click provider
228 236
   window_set_click_config_provider(s_window, click_config_provider);
Browse code

gitignore

Louis authored on17/12/2018 22:59:29
Showing1 changed files
... ...
@@ -16,8 +16,7 @@ static char s_server[255];
16 16
 static bool s_js_ready;
17 17
 
18 18
 static Window *s_window;
19
-//static Layer *window_layer;
20
-//static GRect bounds;
19
+
21 20
 static TextLayer *s_text_layer,*s_statusbar;
22 21
 
23 22
 static ActionBarLayer *s_action_bar_layer;
... ...
@@ -30,6 +29,7 @@ bool is_home_on = false;
30 29
 
31 30
 static uint32_t size ;
32 31
   
32
+time_t current_time;
33 33
   
34 34
 typedef enum {
35 35
   status,
... ...
@@ -73,7 +73,7 @@ static GRect init_text_layer(Layer *parent_layer, TextLayer **text_layer, int16_
73 73
 }
74 74
 
75 75
 void init_statusbar_text_layer(Layer *parent, TextLayer **layer) {
76
-  init_text_layer(parent, layer, 0, 16, 0, FONT_KEY_GOTHIC_14);
76
+  init_text_layer(parent, layer, 0, 16, 0, FONT_KEY_GOTHIC_18_BOLD);
77 77
   GRect sb_bounds = layer_get_bounds(text_layer_get_layer(*layer));
78 78
   sb_bounds.origin.y -= 1;
79 79
   layer_set_bounds(text_layer_get_layer(*layer), sb_bounds);
... ...
@@ -337,7 +337,7 @@ static void init(void) {
337 337
   }
338 338
 
339 339
   init_statusbar_text_layer(window_layer, &s_statusbar);
340
-  text_layer_set_text(s_statusbar, "9:41 AM");
340
+  text_layer_set_text(s_statusbar, "");
341 341
 
342 342
 
343 343
   // Create a text layer and set the text
... ...
@@ -346,7 +346,7 @@ static void init(void) {
346 346
   text_layer_set_text(s_text_layer, "Welcome to Syno Cam Switch !");
347 347
   
348 348
   // Set the font and text alignment
349
-  text_layer_set_font(s_text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD));
349
+  text_layer_set_font(s_text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD));
350 350
   text_layer_set_text_alignment(s_text_layer, GTextAlignmentCenter);
351 351
 
352 352
   // Add the text layer to the window
... ...
@@ -359,7 +359,11 @@ static void init(void) {
359 359
   window_stack_push(s_window, true);
360 360
   
361 361
   // get the current time !
362
-  update_time();
362
+  //update_time();
363
+  //Kick the tick_handler for instant update
364
+  current_time = time(NULL);
365
+  tick_handler(localtime(&current_time),MINUTE_UNIT);
366
+  tick_timer_service_subscribe((MINUTE_UNIT), tick_handler);
363 367
 
364 368
   // App Logging!
365 369
   APP_LOG(APP_LOG_LEVEL_DEBUG, "Just pushed a window!");
Browse code

statusbar with time

Louis authored on27/11/2018 00:21:26
Showing1 changed files
... ...
@@ -3,6 +3,7 @@
3 3
 // Persistent storage key
4 4
 #define SETTINGS_KEY 1
5 5
 
6
+
6 7
 // Largest expected inbox and outbox message sizes
7 8
 const uint32_t inbox_size = 64;
8 9
 const uint32_t outbox_size = 64;
... ...
@@ -17,12 +18,13 @@ static bool s_js_ready;
17 18
 static Window *s_window;
18 19
 //static Layer *window_layer;
19 20
 //static GRect bounds;
20
-static TextLayer *s_text_layer;
21
+static TextLayer *s_text_layer,*s_statusbar;
21 22
 
22 23
 static ActionBarLayer *s_action_bar_layer;
24
+static StatusBarLayer *s_status_bar_layer;
23 25
 
24 26
 static GBitmap *s_h_on_bitmap, *s_h_off_bitmap, *s_q_mark_bitmap;
25
-
27
+static const int16_t MARGIN = 8;
26 28
 
27 29
 bool is_home_on = false;
28 30
 
... ...
@@ -55,6 +57,28 @@ static void prv_save_settings() {
55 57
   persist_write_data(SETTINGS_KEY, &settings, sizeof(settings));
56 58
 }
57 59
 
60
+//! helper to construct the various text layers as they appear in this app
61
+static GRect init_text_layer(Layer *parent_layer, TextLayer **text_layer, int16_t y, int16_t h, int16_t additional_right_margin, char *font_key) {
62
+  // why "-1" (and then "+2")? because for this font we need to compensate for weird white-spacing
63
+  const int16_t font_compensator = strcmp(font_key, FONT_KEY_LECO_38_BOLD_NUMBERS) == 0 ? 3 : 1;
64
+
65
+  const GRect frame = GRect(MARGIN - font_compensator, y, layer_get_bounds(parent_layer).size.w - 2 * MARGIN + 2 * font_compensator - additional_right_margin, h);
66
+
67
+  *text_layer = text_layer_create(frame);
68
+  text_layer_set_background_color(*text_layer, GColorClear);
69
+  text_layer_set_text_color(*text_layer, PBL_IF_COLOR_ELSE(GColorWhite, GColorBlack));
70
+  text_layer_set_font(*text_layer, fonts_get_system_font(font_key));
71
+  layer_add_child(parent_layer, text_layer_get_layer(*text_layer));
72
+  return frame;
73
+}
74
+
75
+void init_statusbar_text_layer(Layer *parent, TextLayer **layer) {
76
+  init_text_layer(parent, layer, 0, 16, 0, FONT_KEY_GOTHIC_14);
77
+  GRect sb_bounds = layer_get_bounds(text_layer_get_layer(*layer));
78
+  sb_bounds.origin.y -= 1;
79
+  layer_set_bounds(text_layer_get_layer(*layer), sb_bounds);
80
+  text_layer_set_text_alignment(*layer, GTextAlignmentCenter);
81
+}
58 82
 
59 83
 static void inbox_dropped_callback(AppMessageResult reason, void *context) {
60 84
   // A message was received, but had to be dropped
... ...
@@ -162,6 +186,21 @@ static void click_config_provider(void *context) {
162 186
   window_single_click_subscribe(BUTTON_ID_DOWN, down_click_handler);
163 187
 }
164 188
 
189
+static void update_time() {
190
+  // Get a tm structure
191
+  time_t temp = time(NULL);
192
+  struct tm *tick_time = localtime(&temp);
193
+
194
+  // Write the current hours and minutes into a buffer
195
+  static char s_buffer[8];
196
+  strftime(s_buffer, sizeof(s_buffer), clock_is_24h_style() ?
197
+                                          "%H:%M" : "%I:%M", tick_time);
198
+
199
+  // Display this time on the TextLayer
200
+  text_layer_set_text(s_statusbar, s_buffer);
201
+  
202
+}
203
+
165 204
 void comm_is_ready() {
166 205
   // Get information about the window
167 206
   //Layer *window_layer = window_get_root_layer(s_window);
... ...
@@ -190,6 +229,10 @@ void comm_is_ready() {
190 229
 
191 230
 }
192 231
 
232
+static void tick_handler(struct tm *tick_time, TimeUnits units_changed) {
233
+  update_time();  
234
+}
235
+
193 236
 static void inbox_received_callback(DictionaryIterator *iter, void *context) {
194 237
   // A new message has been successfully received
195 238
   APP_LOG(APP_LOG_LEVEL_DEBUG, "New message! ");
... ...
@@ -272,7 +315,31 @@ static void init(void) {
272 315
   action_bar_layer_set_icon(s_action_bar_layer, BUTTON_ID_DOWN, s_h_off_bitmap);
273 316
   action_bar_layer_add_to_window(s_action_bar_layer, s_window);
274 317
   
275
-  
318
+  s_status_bar_layer = status_bar_layer_create();
319
+
320
+  Layer *status_bar_base_layer = status_bar_layer_get_layer(s_status_bar_layer);
321
+  GRect status_frame = layer_get_frame(status_bar_base_layer);
322
+  status_frame.origin.y = -STATUS_BAR_LAYER_HEIGHT;
323
+  layer_set_frame(status_bar_base_layer, status_frame);
324
+
325
+  layer_add_child(window_layer, status_bar_base_layer);
326
+
327
+  if (bounds.origin.y == 0) {
328
+    bounds.origin.y = STATUS_BAR_LAYER_HEIGHT;
329
+    bounds.size.h -= STATUS_BAR_LAYER_HEIGHT;
330
+
331
+    GRect frame = layer_get_frame(window_layer);
332
+    frame.size.h = bounds.size.h;
333
+
334
+    layer_set_frame(window_layer, frame);
335
+    layer_set_bounds(window_layer, bounds);
336
+    layer_set_clips(window_layer, false);
337
+  }
338
+
339
+  init_statusbar_text_layer(window_layer, &s_statusbar);
340
+  text_layer_set_text(s_statusbar, "9:41 AM");
341
+
342
+
276 343
   // Create a text layer and set the text
277 344
   const GEdgeInsets label_insets = {.right = ACTION_BAR_WIDTH, .left = ACTION_BAR_WIDTH / 2};
278 345
   s_text_layer = text_layer_create(grect_inset(bounds, label_insets));
... ...
@@ -283,14 +350,17 @@ static void init(void) {
283 350
   text_layer_set_text_alignment(s_text_layer, GTextAlignmentCenter);
284 351
 
285 352
   // Add the text layer to the window
286
-  layer_add_child(window_get_root_layer(s_window), text_layer_get_layer(s_text_layer));
353
+  layer_add_child(window_layer, text_layer_get_layer(s_text_layer));
287 354
   
288
-  // Enable text flow and paging on the text layer, with a slight inset of 10, for round screens
289
-  text_layer_enable_screen_text_flow_and_paging(s_text_layer, 10);
355
+  // Enable text flow and paging on the text layer, with a slight inset of 5, for round screens
356
+  text_layer_enable_screen_text_flow_and_paging(s_text_layer, 5);
290 357
 
291 358
   // Push the window, setting the window animation to 'true'
292 359
   window_stack_push(s_window, true);
293 360
   
361
+  // get the current time !
362
+  update_time();
363
+
294 364
   // App Logging!
295 365
   APP_LOG(APP_LOG_LEVEL_DEBUG, "Just pushed a window!");
296 366
   
... ...
@@ -302,6 +372,9 @@ static void deinit(void) {
302 372
 
303 373
   // Destroy the action bar layer
304 374
   action_bar_layer_destroy(s_action_bar_layer);
375
+
376
+  // Destroy the status bar layer
377
+  status_bar_layer_destroy(s_status_bar_layer);
305 378
   
306 379
   // Destroy the window
307 380
   window_destroy(s_window);
Browse code

better handling sent message ?

Louis authored on29/09/2018 01:27:02
Showing1 changed files
... ...
@@ -89,6 +89,8 @@ static void select_click_handler(ClickRecognizerRef recognizer, void *context) {
89 89
     result = app_message_outbox_send();
90 90
     if(result != APP_MSG_OK) {
91 91
       APP_LOG(APP_LOG_LEVEL_ERROR, "Error sending the outbox: %d", (int)result);
92
+    }else{
93
+      text_layer_set_text(s_text_layer, "Sent...");
92 94
     }
93 95
   } else {
94 96
     // The outbox cannot be used right now
... ...
@@ -115,6 +117,8 @@ static void up_click_handler(ClickRecognizerRef recognizer, void *context) {
115 117
     result = app_message_outbox_send();
116 118
     if(result != APP_MSG_OK) {
117 119
       APP_LOG(APP_LOG_LEVEL_ERROR, "Error sending the outbox: %d", (int)result);
120
+    }else{
121
+      text_layer_set_text(s_text_layer, "Sent...");
118 122
     }
119 123
   } else {
120 124
     // The outbox cannot be used right now
... ...
@@ -141,6 +145,8 @@ static void down_click_handler(ClickRecognizerRef recognizer, void *context) {
141 145
     result = app_message_outbox_send();
142 146
     if(result != APP_MSG_OK) {
143 147
       APP_LOG(APP_LOG_LEVEL_ERROR, "Error sending the outbox: %d", (int)result);
148
+    }else{
149
+      text_layer_set_text(s_text_layer, "Sent...");
144 150
     }
145 151
   } else {
146 152
     // The outbox cannot be used right now
Browse code

sent message

Louis authored on22/09/2018 15:50:26
Showing1 changed files
... ...
@@ -164,7 +164,7 @@ void comm_is_ready() {
164 164
   // Create a text layer and set the text
165 165
   //const GEdgeInsets label_insets = {.right = ACTION_BAR_WIDTH, .left = ACTION_BAR_WIDTH / 2};
166 166
   //s_text_layer = text_layer_create(grect_inset(bounds, label_insets));
167
-  text_layer_set_text(s_text_layer, "Welcome to Syno Cam Switch ! ready to switch...");
167
+  text_layer_set_text(s_text_layer, "Welcome to Syno Cam Switch ! ready");
168 168
 
169 169
   // Set the font and text alignment
170 170
   //text_layer_set_font(s_text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD));
Browse code

click_handler uncommented

Louis authored on18/09/2018 23:36:08
Showing1 changed files
... ...
@@ -180,7 +180,7 @@ void comm_is_ready() {
180 180
   //window_stack_push(s_window, true);
181 181
 
182 182
   // click provider
183
-  //window_set_click_config_provider(s_window, click_config_provider);
183
+  window_set_click_config_provider(s_window, click_config_provider);
184 184
 
185 185
 }
186 186
 
... ...
@@ -197,16 +197,17 @@ static void inbox_received_callback(DictionaryIterator *iter, void *context) {
197 197
     //Pebblekit JS is ready ! Safe to send messages
198 198
     s_js_ready = true;
199 199
     comm_is_ready();
200
+    APP_LOG(APP_LOG_LEVEL_DEBUG, "received jsready message on watch... ");
200 201
   }
201 202
 
202 203
   // Read API returns
203
-  // Tuple *api_tuple = dict_read_first(iter);
204 204
   Tuple *api_tuple = dict_find(iter, MESSAGE_KEY_status);
205 205
 
206 206
   if(api_tuple) {
207 207
     strncpy(s_api, api_tuple->value->cstring, 40);
208 208
     // Display in the TextLayer
209 209
     text_layer_set_text(s_text_layer, s_api);
210
+    APP_LOG(APP_LOG_LEVEL_DEBUG, "status message received ... ");
210 211
   }else{
211 212
     APP_LOG(APP_LOG_LEVEL_DEBUG, "not status message... ");
212 213
   }
Browse code

commented unused code/corrected

Louis authored on18/09/2018 23:28:35
Showing1 changed files
... ...
@@ -164,7 +164,7 @@ void comm_is_ready() {
164 164
   // Create a text layer and set the text
165 165
   //const GEdgeInsets label_insets = {.right = ACTION_BAR_WIDTH, .left = ACTION_BAR_WIDTH / 2};
166 166
   //s_text_layer = text_layer_create(grect_inset(bounds, label_insets));
167
-  //text_layer_set_text(s_text_layer, "Welcome to Syno Cam Switch ! ready to switch...");
167
+  text_layer_set_text(s_text_layer, "Welcome to Syno Cam Switch ! ready to switch...");
168 168
 
169 169
   // Set the font and text alignment
170 170
   //text_layer_set_font(s_text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD));
... ...
@@ -174,15 +174,11 @@ void comm_is_ready() {
174 174
   //layer_add_child(window_get_root_layer(s_window), text_layer_get_layer(s_text_layer));
175 175
 
176 176
   // Enable text flow and paging on the text layer, with a slight inset of 10, for round screens
177
-  text_layer_enable_screen_text_flow_and_paging(s_text_layer, 10);
177
+  //text_layer_enable_screen_text_flow_and_paging(s_text_layer, 10);
178 178
 
179 179
   // Push the window, setting the window animation to 'true'
180 180
   //window_stack_push(s_window, true);
181 181
 
182
-  // App Logging!
183
-  APP_LOG(APP_LOG_LEVEL_DEBUG, "Just pushed a window!");
184
-
185
-  // waiting for BT comm ready 
186 182
   // click provider
187 183
   //window_set_click_config_provider(s_window, click_config_provider);
188 184
 
Browse code

commented unused code

Louis authored on18/09/2018 23:25:34
Showing1 changed files
... ...
@@ -180,7 +180,7 @@ void comm_is_ready() {
180 180
   //window_stack_push(s_window, true);
181 181
 
182 182
   // App Logging!
183
-  //APP_LOG(APP_LOG_LEVEL_DEBUG, "Just pushed a window!");
183
+  APP_LOG(APP_LOG_LEVEL_DEBUG, "Just pushed a window!");
184 184
 
185 185
   // waiting for BT comm ready 
186 186
   // click provider
Browse code

commented unused code

Louis authored on18/09/2018 23:22:14
Showing1 changed files
... ...
@@ -107,7 +107,7 @@ static void up_click_handler(ClickRecognizerRef recognizer, void *context) {
107 107
   AppMessageResult result = app_message_outbox_begin(&out_iter);
108 108
   
109 109
   if(result == APP_MSG_OK) {
110
-    // Add an item to ask for weather data
110
+    // Add an item to switch home mode on
111 111
     msg = "home_on";
112 112
     dict_write_cstring(out_iter, status, msg);
113 113
   
... ...
@@ -133,7 +133,7 @@ static void down_click_handler(ClickRecognizerRef recognizer, void *context) {
133 133
   AppMessageResult result = app_message_outbox_begin(&out_iter);
134 134
   
135 135
   if(result == APP_MSG_OK) {
136
-    // Add an item to ask for weather data
136
+    // Add an item to switch home mode off
137 137
     msg = "home_off";
138 138
     dict_write_cstring(out_iter, status, msg);
139 139
   
... ...
@@ -158,33 +158,33 @@ static void click_config_provider(void *context) {
158 158
 
159 159
 void comm_is_ready() {
160 160
   // Get information about the window
161
-  Layer *window_layer = window_get_root_layer(s_window);
162
-  GRect bounds = layer_get_bounds(window_layer);
161
+  //Layer *window_layer = window_get_root_layer(s_window);
162
+  //GRect bounds = layer_get_bounds(window_layer);
163 163
 
164 164
   // Create a text layer and set the text
165
-  const GEdgeInsets label_insets = {.right = ACTION_BAR_WIDTH, .left = ACTION_BAR_WIDTH / 2};
166
-  s_text_layer = text_layer_create(grect_inset(bounds, label_insets));
167
-  text_layer_set_text(s_text_layer, "Welcome to Syno Cam Switch ! ready to switch...");
165
+  //const GEdgeInsets label_insets = {.right = ACTION_BAR_WIDTH, .left = ACTION_BAR_WIDTH / 2};
166
+  //s_text_layer = text_layer_create(grect_inset(bounds, label_insets));
167
+  //text_layer_set_text(s_text_layer, "Welcome to Syno Cam Switch ! ready to switch...");
168 168
 
169 169
   // Set the font and text alignment
170
-  text_layer_set_font(s_text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD));
171
-  text_layer_set_text_alignment(s_text_layer, GTextAlignmentCenter);
170
+  //text_layer_set_font(s_text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD));
171
+  //text_layer_set_text_alignment(s_text_layer, GTextAlignmentCenter);
172 172
 
173 173
   // Add the text layer to the window
174
-  layer_add_child(window_get_root_layer(s_window), text_layer_get_layer(s_text_layer));
174
+  //layer_add_child(window_get_root_layer(s_window), text_layer_get_layer(s_text_layer));
175 175
 
176 176
   // Enable text flow and paging on the text layer, with a slight inset of 10, for round screens
177 177
   text_layer_enable_screen_text_flow_and_paging(s_text_layer, 10);
178 178
 
179 179
   // Push the window, setting the window animation to 'true'
180
-  window_stack_push(s_window, true);
180
+  //window_stack_push(s_window, true);
181 181
 
182 182
   // App Logging!
183
-  APP_LOG(APP_LOG_LEVEL_DEBUG, "Just pushed a window!");
183
+  //APP_LOG(APP_LOG_LEVEL_DEBUG, "Just pushed a window!");
184 184
 
185 185
   // waiting for BT comm ready 
186 186
   // click provider
187
-  window_set_click_config_provider(s_window, click_config_provider);
187
+  //window_set_click_config_provider(s_window, click_config_provider);
188 188
 
189 189
 }
190 190
 
Browse code

JSReady enabled

Louis authored on18/09/2018 23:08:46
Showing1 changed files
... ...
@@ -12,8 +12,11 @@ static char s_api[40];
12 12
 static char s_username[40];
13 13
 static char s_password[40];
14 14
 static char s_server[255];
15
+static bool s_js_ready;
15 16
 
16 17
 static Window *s_window;
18
+//static Layer *window_layer;
19
+//static GRect bounds;
17 20
 static TextLayer *s_text_layer;
18 21
 
19 22
 static ActionBarLayer *s_action_bar_layer;
... ...
@@ -53,49 +56,6 @@ static void prv_save_settings() {
53 56
 }
54 57
 
55 58
 
56
-static void inbox_received_callback(DictionaryIterator *iter, void *context) {
57
-  // A new message has been successfully received
58
-  APP_LOG(APP_LOG_LEVEL_DEBUG, "New message! ");
59
-  
60
-  size = dict_size(iter);
61
-  
62
-  // Read API returns
63
-  // Tuple *api_tuple = dict_read_first(iter);
64
-  Tuple *api_tuple = dict_find(iter, MESSAGE_KEY_status);
65
-  
66
-  if(api_tuple) {
67
-    strncpy(s_api, api_tuple->value->cstring, 40);
68
-    // Display in the TextLayer
69
-    text_layer_set_text(s_text_layer, s_api);
70
-  }else{
71
-    APP_LOG(APP_LOG_LEVEL_DEBUG, "not status message... ");
72
-  }
73
-  
74
-  
75
-  // Read String preferences
76
-  Tuple *username_t = dict_find(iter, MESSAGE_KEY_username);
77
-  if(username_t) {
78
-    strncpy(s_username, username_t->value->cstring, 40);
79
-    prv_save_settings();
80
-    APP_LOG(APP_LOG_LEVEL_DEBUG, "new username in settings... %s",s_username);
81
-  }
82
-
83
-  Tuple *password_t = dict_find(iter, MESSAGE_KEY_password);
84
-  if(password_t) {
85
-    strncpy(s_password, password_t->value->cstring, 40);
86
-    prv_save_settings();
87
-    APP_LOG(APP_LOG_LEVEL_DEBUG, "new password in settings... %s",s_password);
88
-  }
89
-  
90
-  Tuple *server_t = dict_find(iter, MESSAGE_KEY_server);
91
-  if(server_t) {
92
-    strncpy(s_server, server_t->value->cstring, 255);
93
-    prv_save_settings();
94
-    APP_LOG(APP_LOG_LEVEL_DEBUG, "new server in settings... %s",s_server);
95
-  }
96
-
97
-}
98
-
99 59
 static void inbox_dropped_callback(AppMessageResult reason, void *context) {
100 60
   // A message was received, but had to be dropped
101 61
   APP_LOG(APP_LOG_LEVEL_ERROR, "Message dropped. Reason: %d", (int)reason);
... ...
@@ -196,6 +156,89 @@ static void click_config_provider(void *context) {
196 156
   window_single_click_subscribe(BUTTON_ID_DOWN, down_click_handler);
197 157
 }
198 158
 
159
+void comm_is_ready() {
160
+  // Get information about the window
161
+  Layer *window_layer = window_get_root_layer(s_window);
162
+  GRect bounds = layer_get_bounds(window_layer);
163
+
164
+  // Create a text layer and set the text
165
+  const GEdgeInsets label_insets = {.right = ACTION_BAR_WIDTH, .left = ACTION_BAR_WIDTH / 2};
166
+  s_text_layer = text_layer_create(grect_inset(bounds, label_insets));
167
+  text_layer_set_text(s_text_layer, "Welcome to Syno Cam Switch ! ready to switch...");
168
+
169
+  // Set the font and text alignment
170
+  text_layer_set_font(s_text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD));
171
+  text_layer_set_text_alignment(s_text_layer, GTextAlignmentCenter);
172
+
173
+  // Add the text layer to the window
174
+  layer_add_child(window_get_root_layer(s_window), text_layer_get_layer(s_text_layer));
175
+
176
+  // Enable text flow and paging on the text layer, with a slight inset of 10, for round screens
177
+  text_layer_enable_screen_text_flow_and_paging(s_text_layer, 10);
178
+
179
+  // Push the window, setting the window animation to 'true'
180
+  window_stack_push(s_window, true);
181
+
182
+  // App Logging!
183
+  APP_LOG(APP_LOG_LEVEL_DEBUG, "Just pushed a window!");
184
+
185
+  // waiting for BT comm ready 
186
+  // click provider
187
+  window_set_click_config_provider(s_window, click_config_provider);
188
+
189
+}
190
+
191
+static void inbox_received_callback(DictionaryIterator *iter, void *context) {
192
+  // A new message has been successfully received
193
+  APP_LOG(APP_LOG_LEVEL_DEBUG, "New message! ");
194
+  
195
+  size = dict_size(iter);
196
+  
197
+  // JS readiness 
198
+  Tuple *ready_tuple = dict_find(iter, MESSAGE_KEY_JSReady);
199
+  
200
+  if(ready_tuple){
201
+    //Pebblekit JS is ready ! Safe to send messages
202
+    s_js_ready = true;
203
+    comm_is_ready();
204
+  }
205
+
206
+  // Read API returns
207
+  // Tuple *api_tuple = dict_read_first(iter);
208
+  Tuple *api_tuple = dict_find(iter, MESSAGE_KEY_status);
209
+
210
+  if(api_tuple) {
211
+    strncpy(s_api, api_tuple->value->cstring, 40);
212
+    // Display in the TextLayer
213
+    text_layer_set_text(s_text_layer, s_api);
214
+  }else{
215
+    APP_LOG(APP_LOG_LEVEL_DEBUG, "not status message... ");
216
+  }
217
+ 
218
+  // Read String preferences
219
+  Tuple *username_t = dict_find(iter, MESSAGE_KEY_username);
220
+  if(username_t) {
221
+    strncpy(s_username, username_t->value->cstring, 40);
222
+    prv_save_settings();
223
+    APP_LOG(APP_LOG_LEVEL_DEBUG, "new username in settings... %s",s_username);
224
+  }
225
+
226
+  Tuple *password_t = dict_find(iter, MESSAGE_KEY_password);
227
+  if(password_t) {
228
+    strncpy(s_password, password_t->value->cstring, 40);
229
+    prv_save_settings();
230
+    APP_LOG(APP_LOG_LEVEL_DEBUG, "new password in settings... %s",s_password);
231
+  }
232
+  
233
+  Tuple *server_t = dict_find(iter, MESSAGE_KEY_server);
234
+  if(server_t) {
235
+    strncpy(s_server, server_t->value->cstring, 255);
236
+    prv_save_settings();
237
+    APP_LOG(APP_LOG_LEVEL_DEBUG, "new server in settings... %s",s_server);
238
+  }
239
+
240
+}
241
+
199 242
 static void init(void) {
200 243
 
201 244
   // Open AppMessage
... ...
@@ -248,10 +291,6 @@ static void init(void) {
248 291
   // App Logging!
249 292
   APP_LOG(APP_LOG_LEVEL_DEBUG, "Just pushed a window!");
250 293
   
251
-  // click provider
252
-  window_set_click_config_provider(s_window, click_config_provider);
253
-
254
-  
255 294
 }
256 295
 
257 296
 static void deinit(void) {
Louis authored on10/07/2018 13:58:16
Showing1 changed files
1 1
new file mode 100755
... ...
@@ -0,0 +1,272 @@
1
+#include <pebble.h>
2
+
3
+// Persistent storage key
4
+#define SETTINGS_KEY 1
5
+
6
+// Largest expected inbox and outbox message sizes
7
+const uint32_t inbox_size = 64;
8
+const uint32_t outbox_size = 64;
9
+
10
+
11
+static char s_api[40];
12
+static char s_username[40];
13
+static char s_password[40];
14
+static char s_server[255];
15
+
16
+static Window *s_window;
17
+static TextLayer *s_text_layer;
18
+
19
+static ActionBarLayer *s_action_bar_layer;
20
+
21
+static GBitmap *s_h_on_bitmap, *s_h_off_bitmap, *s_q_mark_bitmap;
22
+
23
+
24
+bool is_home_on = false;
25
+
26
+static uint32_t size ;
27
+  
28
+  
29
+typedef enum {
30
+  status,
31
+  username,
32
+  password,
33
+  server
34
+} AppKey;
35
+
36
+
37
+static char * msg;
38
+
39
+
40
+// Define our settings struct
41
+typedef struct Settings {
42
+  char username;
43
+  char password;
44
+  char server;
45
+} Settings;
46
+
47
+// An instance of the struct
48
+static Settings settings;
49
+
50
+// Save the settings to persistent storage
51
+static void prv_save_settings() {
52
+  persist_write_data(SETTINGS_KEY, &settings, sizeof(settings));
53
+}
54
+
55
+
56
+static void inbox_received_callback(DictionaryIterator *iter, void *context) {
57
+  // A new message has been successfully received
58
+  APP_LOG(APP_LOG_LEVEL_DEBUG, "New message! ");
59
+  
60
+  size = dict_size(iter);
61
+  
62
+  // Read API returns
63
+  // Tuple *api_tuple = dict_read_first(iter);
64
+  Tuple *api_tuple = dict_find(iter, MESSAGE_KEY_status);
65
+  
66
+  if(api_tuple) {
67
+    strncpy(s_api, api_tuple->value->cstring, 40);
68
+    // Display in the TextLayer
69
+    text_layer_set_text(s_text_layer, s_api);
70
+  }else{
71
+    APP_LOG(APP_LOG_LEVEL_DEBUG, "not status message... ");
72
+  }
73
+  
74
+  
75
+  // Read String preferences
76
+  Tuple *username_t = dict_find(iter, MESSAGE_KEY_username);
77
+  if(username_t) {
78
+    strncpy(s_username, username_t->value->cstring, 40);
79
+    prv_save_settings();
80
+    APP_LOG(APP_LOG_LEVEL_DEBUG, "new username in settings... %s",s_username);
81
+  }
82
+
83
+  Tuple *password_t = dict_find(iter, MESSAGE_KEY_password);
84
+  if(password_t) {
85
+    strncpy(s_password, password_t->value->cstring, 40);
86
+    prv_save_settings();
87
+    APP_LOG(APP_LOG_LEVEL_DEBUG, "new password in settings... %s",s_password);
88
+  }
89
+  
90
+  Tuple *server_t = dict_find(iter, MESSAGE_KEY_server);
91
+  if(server_t) {
92
+    strncpy(s_server, server_t->value->cstring, 255);
93
+    prv_save_settings();
94
+    APP_LOG(APP_LOG_LEVEL_DEBUG, "new server in settings... %s",s_server);
95
+  }
96
+
97
+}
98
+
99
+static void inbox_dropped_callback(AppMessageResult reason, void *context) {
100
+  // A message was received, but had to be dropped
101
+  APP_LOG(APP_LOG_LEVEL_ERROR, "Message dropped. Reason: %d", (int)reason);
102
+}
103
+
104
+static void outbox_sent_callback(DictionaryIterator *iter, void *context) {
105
+  // The message just sent has been successfully delivered
106
+  APP_LOG(APP_LOG_LEVEL_INFO, "Message sent. ");
107
+}
108
+
109
+static void outbox_failed_callback(DictionaryIterator *iter, AppMessageResult reason, void *context) {
110
+  // The message just sent failed to be delivered
111
+  APP_LOG(APP_LOG_LEVEL_ERROR, "Message send failed. Reason: %d", (int)reason);
112
+}
113
+
114
+
115
+static void select_click_handler(ClickRecognizerRef recognizer, void *context) {
116
+
117
+  // Declare the dictionary's iterator
118
+  DictionaryIterator *out_iter;
119
+  
120
+  // Prepare the outbox buffer for this message
121
+  AppMessageResult result = app_message_outbox_begin(&out_iter);
122
+  
123
+  if(result == APP_MSG_OK) {
124
+    // Add an item to ask for weather data
125
+    msg = "get";
126
+    dict_write_cstring(out_iter, status, msg);
127
+  
128
+    // Send this message
129
+    result = app_message_outbox_send();
130
+    if(result != APP_MSG_OK) {
131
+      APP_LOG(APP_LOG_LEVEL_ERROR, "Error sending the outbox: %d", (int)result);
132
+    }
133
+  } else {
134
+    // The outbox cannot be used right now
135
+    APP_LOG(APP_LOG_LEVEL_ERROR, "Error preparing the outbox: %d", (int)result);
136
+  }
137
+  
138
+  
139
+}
140
+
141
+static void up_click_handler(ClickRecognizerRef recognizer, void *context) {
142
+
143
+  // Declare the dictionary's iterator
144
+  DictionaryIterator *out_iter;
145
+  
146
+  // Prepare the outbox buffer for this message
147
+  AppMessageResult result = app_message_outbox_begin(&out_iter);
148
+  
149
+  if(result == APP_MSG_OK) {
150
+    // Add an item to ask for weather data
151
+    msg = "home_on";
152
+    dict_write_cstring(out_iter, status, msg);
153
+  
154
+    // Send this message
155
+    result = app_message_outbox_send();
156
+    if(result != APP_MSG_OK) {
157
+      APP_LOG(APP_LOG_LEVEL_ERROR, "Error sending the outbox: %d", (int)result);
158
+    }
159
+  } else {
160
+    // The outbox cannot be used right now
161
+    APP_LOG(APP_LOG_LEVEL_ERROR, "Error preparing the outbox: %d", (int)result);
162
+  }
163
+  
164
+  
165
+}
166
+
167
+static void down_click_handler(ClickRecognizerRef recognizer, void *context) {
168
+
169
+  // Declare the dictionary's iterator
170
+  DictionaryIterator *out_iter;
171
+  
172
+  // Prepare the outbox buffer for this message
173
+  AppMessageResult result = app_message_outbox_begin(&out_iter);
174
+  
175
+  if(result == APP_MSG_OK) {
176
+    // Add an item to ask for weather data
177
+    msg = "home_off";
178
+    dict_write_cstring(out_iter, status, msg);
179
+  
180
+    // Send this message
181
+    result = app_message_outbox_send();
182
+    if(result != APP_MSG_OK) {
183
+      APP_LOG(APP_LOG_LEVEL_ERROR, "Error sending the outbox: %d", (int)result);
184
+    }
185
+  } else {
186
+    // The outbox cannot be used right now
187
+    APP_LOG(APP_LOG_LEVEL_ERROR, "Error preparing the outbox: %d", (int)result);
188
+  }
189
+  
190
+  
191
+}
192
+
193
+static void click_config_provider(void *context) {
194
+  window_single_click_subscribe(BUTTON_ID_SELECT, select_click_handler);
195
+  window_single_click_subscribe(BUTTON_ID_UP, up_click_handler);
196
+  window_single_click_subscribe(BUTTON_ID_DOWN, down_click_handler);
197
+}
198
+
199
+static void init(void) {
200
+
201
+  // Open AppMessage
202
+  app_message_open(inbox_size, outbox_size);
203
+  
204
+  // Register to be notified about inbox received events
205
+  app_message_register_inbox_received(inbox_received_callback);
206
+  // Register to be notified about inbox dropped events
207
+  app_message_register_inbox_dropped(inbox_dropped_callback);
208
+  // Register to be notified about outbox sent events
209
+  app_message_register_outbox_sent(outbox_sent_callback);
210
+  // Register to be notified about outbox failed events
211
+  app_message_register_outbox_failed(outbox_failed_callback);
212
+  
213
+  // Create a window and get information about the window
214
+  s_window = window_create();
215
+  Layer *window_layer = window_get_root_layer(s_window);
216
+  GRect bounds = layer_get_bounds(window_layer);
217
+  
218
+  //load buttons
219
+  s_h_on_bitmap = gbitmap_create_with_resource(RESOURCE_ID_HOME_ON);
220
+  s_q_mark_bitmap = gbitmap_create_with_resource(RESOURCE_ID_Q_MARK);
221
+  s_h_off_bitmap = gbitmap_create_with_resource(RESOURCE_ID_HOME_OFF);
222
+
223
+  s_action_bar_layer = action_bar_layer_create();
224
+  action_bar_layer_set_icon(s_action_bar_layer, BUTTON_ID_UP, s_h_on_bitmap);
225
+  action_bar_layer_set_icon(s_action_bar_layer, BUTTON_ID_SELECT, s_q_mark_bitmap);
226
+  action_bar_layer_set_icon(s_action_bar_layer, BUTTON_ID_DOWN, s_h_off_bitmap);
227
+  action_bar_layer_add_to_window(s_action_bar_layer, s_window);
228
+  
229
+  
230
+  // Create a text layer and set the text
231
+  const GEdgeInsets label_insets = {.right = ACTION_BAR_WIDTH, .left = ACTION_BAR_WIDTH / 2};
232
+  s_text_layer = text_layer_create(grect_inset(bounds, label_insets));
233
+  text_layer_set_text(s_text_layer, "Welcome to Syno Cam Switch !");
234
+  
235
+  // Set the font and text alignment
236
+  text_layer_set_font(s_text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD));
237
+  text_layer_set_text_alignment(s_text_layer, GTextAlignmentCenter);
238
+
239
+  // Add the text layer to the window
240
+  layer_add_child(window_get_root_layer(s_window), text_layer_get_layer(s_text_layer));
241
+  
242
+  // Enable text flow and paging on the text layer, with a slight inset of 10, for round screens
243
+  text_layer_enable_screen_text_flow_and_paging(s_text_layer, 10);
244
+
245
+  // Push the window, setting the window animation to 'true'
246
+  window_stack_push(s_window, true);
247
+  
248
+  // App Logging!
249
+  APP_LOG(APP_LOG_LEVEL_DEBUG, "Just pushed a window!");
250
+  
251
+  // click provider
252
+  window_set_click_config_provider(s_window, click_config_provider);
253
+
254
+  
255
+}
256
+
257
+static void deinit(void) {
258
+  // Destroy the text layer
259
+  text_layer_destroy(s_text_layer);
260
+
261
+  // Destroy the action bar layer
262
+  action_bar_layer_destroy(s_action_bar_layer);
263
+  
264
+  // Destroy the window
265
+  window_destroy(s_window);
266
+}
267
+
268
+int main(void) {
269
+  init();
270
+  app_event_loop();
271
+  deinit();
272
+}