-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPebble_Code
163 lines (125 loc) · 3.59 KB
/
Pebble_Code
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#include <pebble.h>
#include <math.h>
#include <stdio.h>
#define TAP_NOT_DATA false
int a[15];
int i;
int sum = 0 ;
int avg;
int count =1;
static Window *s_main_window;
static TextLayer *s_output_layer;
static void data_handler(AccelData *data, uint32_t num_samples) {
// Long lived buffer
static char s_buffer[128];
// Compose string of all data
if(count == 1) {
for ( i=0;i<15;i++)
{
a[i]=abs(data[0].x);
psleep(1000);
sum = sum +a[i];
}
count ++;
}
avg = sum /15;
snprintf(s_buffer, sizeof(s_buffer),
"%d",avg);
text_layer_set_text(s_output_layer, s_buffer);
if(avg>=70 && avg<=125 ){
snprintf(s_buffer, sizeof(s_buffer),
"\n \n LEVODOPA \n DOSAGE : ~25 mg \n :-!");
}
else if(avg>125 && avg <=175){
snprintf(s_buffer, sizeof(s_buffer),
"\n \n LEVODOPA \n DOSAGE : ~50 mg \n :-|");
}
else if(avg>=176 && avg <=250){
snprintf(s_buffer, sizeof(s_buffer),
"\n \n LEVODOPA \n DOSAGE : ~150 mg \n :-( ");
}
else if(avg>250 && avg <=4000){
snprintf(s_buffer, sizeof(s_buffer),
"\n \n LEVODOPA \n DOSAGE : ~200 mg \n :-( ");
}
else
{
snprintf(s_buffer, sizeof(s_buffer),
"\n\n You are OK. :-) ");
}
//Show the data
text_layer_set_text(s_output_layer, s_buffer);
}
static void tap_handler(AccelAxisType axis, int32_t direction) {
switch (axis) {
case ACCEL_AXIS_X:
if (direction > 0) {
text_layer_set_text(s_output_layer, "X axis positive.");
} else {
text_layer_set_text(s_output_layer, "X axis negative.");
}
break;
case ACCEL_AXIS_Y:
if (direction > 0) {
text_layer_set_text(s_output_layer, "Y axis positive.");
} else {
text_layer_set_text(s_output_layer, "Y axis negative.");
}
break;
case ACCEL_AXIS_Z:
if (direction > 0) {
text_layer_set_text(s_output_layer, "Z axis positive.");
} else {
text_layer_set_text(s_output_layer, "Z axis negative.");
}
break;
}
}
static void main_window_load(Window *window) {
Layer *window_layer = window_get_root_layer(window);
GRect window_bounds = layer_get_bounds(window_layer);
// Create output TextLayer
s_output_layer = text_layer_create(GRect(5, 0, window_bounds.size.w - 10, window_bounds.size.h));
text_layer_set_font(s_output_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24));
text_layer_set_text(s_output_layer, " ^_^ \n ANALYSING.... \n \n \n HEALTHSHAKE");
text_layer_set_overflow_mode(s_output_layer, GTextOverflowModeWordWrap);
layer_add_child(window_layer, text_layer_get_layer(s_output_layer));
}
static void main_window_unload(Window *window) {
// Destroy output TextLayer
text_layer_destroy(s_output_layer);
}
static void init() {
// Create main Window
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);
// Use tap service? If not, use data service
if (TAP_NOT_DATA) {
// Subscribe to the accelerometer tap service
accel_tap_service_subscribe(tap_handler);
} else {
// Subscribe to the accelerometer data service
int num_samples = 1;
accel_data_service_subscribe(num_samples, data_handler);
// Choose update rate
accel_service_set_sampling_rate(ACCEL_SAMPLING_10HZ);
}
}
static void deinit() {
// Destroy main Window
window_destroy(s_main_window);
if (TAP_NOT_DATA) {
accel_tap_service_unsubscribe();
} else {
accel_data_service_unsubscribe();
}
}
int main(void) {
init();
app_event_loop();
deinit();
}