Browse code

2 differents layers for speed and altitude

Louis authored on01/10/2022 17:14:31
Showing2 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,3 @@
1
+{
2
+    "C_Cpp.errorSquiggles": "Disabled"
3
+}
0 4
\ No newline at end of file
... ...
@@ -1,7 +1,7 @@
1 1
 #include <pebble.h>
2 2
 
3 3
 static Window *s_window;
4
-static TextLayer *s_text_layer;
4
+static TextLayer *s_speed_text_layer,*s_altitude_text_layer;
5 5
 
6 6
 // Largest expected inbox and outbox message sizes
7 7
 const uint32_t inbox_size = 64;
... ...
@@ -40,15 +40,15 @@ typedef enum {
40 40
 
41 41
 
42 42
 static void prv_select_click_handler(ClickRecognizerRef recognizer, void *context) {
43
-  text_layer_set_text(s_text_layer, "Select");
43
+  text_layer_set_text(s_speed_text_layer, "Select");
44 44
 }
45 45
 
46 46
 static void prv_up_click_handler(ClickRecognizerRef recognizer, void *context) {
47
-  text_layer_set_text(s_text_layer, "Up");
47
+  text_layer_set_text(s_speed_text_layer, "Up");
48 48
 }
49 49
 
50 50
 static void prv_down_click_handler(ClickRecognizerRef recognizer, void *context) {
51
-  text_layer_set_text(s_text_layer, "Down");
51
+  text_layer_set_text(s_speed_text_layer, "Down");
52 52
 }
53 53
 
54 54
 static void prv_click_config_provider(void *context) {
... ...
@@ -61,20 +61,35 @@ static void prv_window_load(Window *window) {
61 61
   Layer *window_layer = window_get_root_layer(window);
62 62
   GRect bounds = layer_get_bounds(window_layer);
63 63
 
64
-  s_text_layer = text_layer_create(GRect(0, 72, bounds.size.w, bounds.size.h));
65
-  text_layer_set_text(s_text_layer, "Press a button");
66
-  text_layer_set_text_alignment(s_text_layer, GTextAlignmentCenter);
67
-  layer_add_child(window_layer, text_layer_get_layer(s_text_layer));
64
+  // Create the speed text layer and set the text
65
+  s_speed_text_layer = text_layer_create(GRect(0, 0, bounds.size.w/2, bounds.size.h/2));
66
+  //text_layer_set_text(s_speed_text_layer, "Press a button");
67
+  // Set the font and text alignment
68
+  text_layer_set_font(s_speed_text_layer, fonts_get_system_font(FONT_KEY_ROBOTO_BOLD_SUBSET_49));
69
+  text_layer_set_text_alignment(s_speed_text_layer, GTextAlignmentRight);
70
+  //add layer to window
71
+  layer_add_child(window_layer, text_layer_get_layer(s_speed_text_layer));
72
+
73
+  
74
+  // Create the altitude text layer and set the text
75
+  s_altitude_text_layer = text_layer_create(GRect(bounds.size.w/2, bounds.size.h/2,bounds.size.w/2, bounds.size.h/2));
76
+  text_layer_set_text(s_altitude_text_layer, "Press a button");
77
+  // Set the font and text alignment
78
+  text_layer_set_font(s_altitude_text_layer, fonts_get_system_font(FONT_KEY_ROBOTO_BOLD_SUBSET_49));
79
+  text_layer_set_text_alignment(s_altitude_text_layer, GTextAlignmentRight);
80
+  //add layer to window
81
+  layer_add_child(window_layer, text_layer_get_layer(s_speed_text_layer));
68 82
 }
69 83
 
70 84
 static void prv_window_unload(Window *window) {
71
-  text_layer_destroy(s_text_layer);
85
+  text_layer_destroy(s_speed_text_layer);
86
+  text_layer_destroy(s_altitude_text_layer);
72 87
 }
73 88
 
74 89
 void comm_is_ready() {
75 90
 
76 91
   // set the text
77
-  text_layer_set_text(s_text_layer, "Welcome to Bike Companion ! JSready");
92
+  text_layer_set_text(s_altitude_text_layer, "Welcome to Bike Companion ! JSready");
78 93
 
79 94
   // Declare the dictionary's iterator
80 95
   DictionaryIterator *out_iter;
... ...
@@ -125,7 +140,7 @@ static void inbox_received_callback(DictionaryIterator *iter, void *context) {
125 140
     strncpy(s_latitude, latitude_tuple->value->cstring, 12);
126 141
 
127 142
     // Display in the TextLayer
128
-    //text_layer_set_text(s_text_layer, lf_latitude);
143
+    //text_layer_set_text(s_altitude_text_layer, lf_latitude);
129 144
     APP_LOG(APP_LOG_LEVEL_DEBUG, "latitude message received : %s",s_latitude);
130 145
   }else{
131 146
     //APP_LOG(APP_LOG_LEVEL_DEBUG, "not latitude message... ");
... ...
@@ -139,7 +154,7 @@ static void inbox_received_callback(DictionaryIterator *iter, void *context) {
139 154
     strncpy(s_longitude, longitude_tuple->value->cstring, 12);
140 155
 
141 156
     // Display in the TextLayer
142
-    //text_layer_set_text(s_text_layer, lf_longitude);
157
+    //text_layer_set_text(s_altitude_text_layer, lf_longitude);
143 158
     APP_LOG(APP_LOG_LEVEL_DEBUG, "longitude message received : %s",s_longitude);
144 159
   }else{
145 160
     //APP_LOG(APP_LOG_LEVEL_DEBUG, "not longitude message... ");
... ...
@@ -153,7 +168,7 @@ static void inbox_received_callback(DictionaryIterator *iter, void *context) {
153 168
     strncpy(s_accuracy, accuracy_tuple->value->cstring, 4);
154 169
 
155 170
     // Display in the TextLayer
156
-    //text_layer_set_text(s_text_layer, lf_accuracy);
171
+    //text_layer_set_text(s_altitude_text_layer, lf_accuracy);
157 172
     APP_LOG(APP_LOG_LEVEL_DEBUG, "accuracy message received : %s",s_accuracy);
158 173
   }else{
159 174
     //APP_LOG(APP_LOG_LEVEL_DEBUG, "not accuracy message... ");
... ...
@@ -167,7 +182,7 @@ static void inbox_received_callback(DictionaryIterator *iter, void *context) {
167 182
     strncpy(s_altitude, altitude_tuple->value->cstring, 5);
168 183
 
169 184
     // Display in the TextLayer
170
-    //text_layer_set_text(s_text_layer, lf_altitude);
185
+    //text_layer_set_text(s_altitude_text_layer, lf_altitude);
171 186
     APP_LOG(APP_LOG_LEVEL_DEBUG, "altitude message received : %s",altitude_tuple->value->cstring);
172 187
   }else{
173 188
     //APP_LOG(APP_LOG_LEVEL_DEBUG, "not altitude message... ");
... ...
@@ -181,7 +196,7 @@ static void inbox_received_callback(DictionaryIterator *iter, void *context) {
181 196
     strncpy(s_altitude_accuracy, altitude_accuracy_tuple->value->cstring, 3);
182 197
 
183 198
     // Display in the TextLayer
184
-    //text_layer_set_text(s_text_layer, lf_altitude_accuracy);
199
+    //text_layer_set_text(s_altitude_text_layer, lf_altitude_accuracy);
185 200
     APP_LOG(APP_LOG_LEVEL_DEBUG, "altitude_accuracy message received : %s",s_altitude_accuracy);
186 201
   }else{
187 202
     //APP_LOG(APP_LOG_LEVEL_DEBUG, "not altitude_accuracy message... ");
... ...
@@ -195,7 +210,7 @@ static void inbox_received_callback(DictionaryIterator *iter, void *context) {
195 210
     strncpy(s_timestamp, timestamp_tuple->value->cstring, 13);
196 211
 
197 212
     // Display in the TextLayer
198
-    //text_layer_set_text(s_text_layer, lf_timestamp);
213
+    //text_layer_set_text(s_altitude_text_layer, lf_timestamp);
199 214
     APP_LOG(APP_LOG_LEVEL_DEBUG, "timestamp message received : %s",s_timestamp);
200 215
   }else{
201 216
     //APP_LOG(APP_LOG_LEVEL_DEBUG, "not timestamp message... ");
... ...
@@ -210,7 +225,7 @@ static void inbox_received_callback(DictionaryIterator *iter, void *context) {
210 225
     strncpy(s_speed, speed_tuple->value->cstring, 5);
211 226
 
212 227
     // Display in the TextLayer
213
-    //text_layer_set_text(s_text_layer, lf_speed);
228
+    text_layer_set_text(s_speed_text_layer, s_speed);
214 229
     APP_LOG(APP_LOG_LEVEL_DEBUG, "speed message received : %s",s_speed);
215 230
   }else{
216 231
     //APP_LOG(APP_LOG_LEVEL_DEBUG, "not speed message... ");
... ...
@@ -233,17 +248,17 @@ static void inbox_received_callback(DictionaryIterator *iter, void *context) {
233 248
     strcat(s_msg, "\n Long. ");
234 249
     strcat(s_msg, s_longitude);
235 250
     strcat(s_msg, "\n Acc. ");
236
-    strcat(s_msg, s_accuracy);*/
251
+    strcat(s_msg, s_accuracy);
237 252
     strcat(s_msg, "\n Alt. ");
238 253
     strcat(s_msg, s_altitude);
239 254
     strcat(s_msg, "\n Speed. ");
240 255
     strcat(s_msg, s_speed);
241
-    /*strcat(s_msg, "\n Time. ");
256
+    strcat(s_msg, "\n Time. ");
242 257
     strcat(s_msg, s_timestamp);*/
243 258
 
244 259
     APP_LOG(APP_LOG_LEVEL_DEBUG, "to display : %s ",s_msg);
245 260
     // DEBUG Display in the TextLayer
246
-    text_layer_set_text(s_text_layer, s_msg);
261
+    //text_layer_set_text(s_altitude_text_layer, s_msg);
247 262
   }else{
248 263
     //APP_LOG(APP_LOG_LEVEL_DEBUG, "not status message... ");
249 264
   }