Gm,
Ik heb het volgende issue. Via een JS haal ik een waarde op uit een API. Middels een KEY dictionary schrijf ik deze code weg. Nu wil ik in C de waarde weer ophalen en er vervolgens mee aan de slag.
Ik heb op allerlei forums gezocht welke code ik dan in C zou kunnen gebruiken, maar kom er niet uit. Daarnaast weet ik niet waar ik de code dan in de C zou moeten schrijven om te gebruiken, daarom ook die code.
Zou volgens mij met een vrij simpel commando moeten, maar zoals gezegd geen idee welke dat is....
Hoop dat iemand me op weg kan helpen! Thx!
Zo schrijf ik de code weg in JS:
In deze code wil ik de waarde terug laten komen als s_num_drinks
Ik heb het volgende issue. Via een JS haal ik een waarde op uit een API. Middels een KEY dictionary schrijf ik deze code weg. Nu wil ik in C de waarde weer ophalen en er vervolgens mee aan de slag.
Ik heb op allerlei forums gezocht welke code ik dan in C zou kunnen gebruiken, maar kom er niet uit. Daarnaast weet ik niet waar ik de code dan in de C zou moeten schrijven om te gebruiken, daarom ook die code.
Zou volgens mij met een vrij simpel commando moeten, maar zoals gezegd geen idee welke dat is....
Hoop dat iemand me op weg kan helpen! Thx!
Zo schrijf ik de code weg in JS:
JavaScript:
;1
2
3
4
5
| //Construct a key-value dictionary var dict = {"KEY_LOCATION" : location, "KEY_TEMPERATURE": temperature}; //Send data to watch for display Pebble.sendAppMessage(dict); |
In deze code wil ik de waarde terug laten komen als s_num_drinks
C:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
| #include "pebble.h" #define REPEAT_INTERVAL_MS 50 // This is a custom defined key for saving our count field #define NUM_DRINKS_PKEY 1 // You can define defaults for values in persistent storage #define NUM_DRINKS_DEFAULT 0 static Window *s_main_window; static ActionBarLayer *s_action_bar; static TextLayer *s_header_layer, *s_body_layer, *s_label_layer; static GBitmap *s_icon_plus, *s_icon_minus; static int s_num_drinks = NUM_DRINKS_DEFAULT; static void update_text() { static char s_body_text[18]; snprintf(s_body_text, sizeof(s_body_text), "%u Bottles", s_num_drinks); text_layer_set_text(s_body_layer, s_body_text); } static void increment_click_handler(ClickRecognizerRef recognizer, void *context) { s_num_drinks++; update_text(); } static void decrement_click_handler(ClickRecognizerRef recognizer, void *context) { if (s_num_drinks <= 0) { // Keep the counter at zero return; } s_num_drinks--; update_text(); } static void click_config_provider(void *context) { window_single_repeating_click_subscribe(BUTTON_ID_UP, REPEAT_INTERVAL_MS, increment_click_handler); window_single_repeating_click_subscribe(BUTTON_ID_DOWN, REPEAT_INTERVAL_MS, decrement_click_handler); } static void main_window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); s_action_bar = action_bar_layer_create(); action_bar_layer_add_to_window(s_action_bar, window); action_bar_layer_set_click_config_provider(s_action_bar, click_config_provider); action_bar_layer_set_icon(s_action_bar, BUTTON_ID_UP, s_icon_plus); action_bar_layer_set_icon(s_action_bar, BUTTON_ID_DOWN, s_icon_minus); int width = layer_get_frame(window_layer).size.w - ACTION_BAR_WIDTH - 3; s_header_layer = text_layer_create(GRect(4, 0, width, 60)); text_layer_set_font(s_header_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24)); text_layer_set_background_color(s_header_layer, GColorClear); text_layer_set_text(s_header_layer, "Drink Counter"); layer_add_child(window_layer, text_layer_get_layer(s_header_layer)); s_body_layer = text_layer_create(GRect(4, 44, width, 60)); text_layer_set_font(s_body_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD)); text_layer_set_background_color(s_body_layer, GColorClear); layer_add_child(window_layer, text_layer_get_layer(s_body_layer)); s_label_layer = text_layer_create(GRect(4, 44 + 28, width, 60)); text_layer_set_font(s_label_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18)); text_layer_set_background_color(s_label_layer, GColorClear); text_layer_set_text(s_label_layer, "of drinks on the wall"); layer_add_child(window_layer, text_layer_get_layer(s_label_layer)); update_text(); } static void main_window_unload(Window *window) { text_layer_destroy(s_header_layer); text_layer_destroy(s_body_layer); text_layer_destroy(s_label_layer); action_bar_layer_destroy(s_action_bar); } static void init() { s_icon_plus = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_ACTION_ICON_PLUS); s_icon_minus = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_ACTION_ICON_MINUS); // Get the count from persistent storage for use if it exists, otherwise use the default s_num_drinks = persist_exists(NUM_DRINKS_PKEY) ? persist_read_int(NUM_DRINKS_PKEY) : NUM_DRINKS_DEFAULT; s_main_window = window_create(); window_set_window_handlers(s_main_window, (WindowHandlers) { .load = main_window_load, .unload = main_window_unload, }); window_stack_push(s_main_window, true); } static void deinit() { // Save the count into persistent storage on app exit persist_write_int(NUM_DRINKS_PKEY, s_num_drinks); window_destroy(s_main_window); gbitmap_destroy(s_icon_plus); gbitmap_destroy(s_icon_minus); } int main(void) { init(); app_event_loop(); deinit(); } |
[ Voor 0% gewijzigd door RobIII op 24-06-2015 14:54 ]