~foxtrotgps-team/foxtrotgps/trunk

« back to all changes in this revision

Viewing changes to src/hrm_functions.c

  • Committer: Paul Wise
  • Date: 2018-03-06 03:32:21 UTC
  • Revision ID: pabs3@bonedaddy.net-20180306033221-lzyia8y0cpw95j1b
Remove trailing whitespace

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 
24
24
static GIOChannel *hrm_io_channel = NULL;
25
25
 
26
 
static guint hrm_sid1,  hrm_sid3; 
 
26
static guint hrm_sid1,  hrm_sid3;
27
27
guint watchdog;
28
28
 
29
29
void * get_hrm_data_thread(void *ptr);
34
34
#ifdef HAVE_BLUEZ
35
35
        g_free(hrmdata);
36
36
        hrmdata = NULL;
37
 
        
 
37
 
38
38
        global_reconnect_hrm = TRUE;
39
39
        g_source_remove(watchdog);
40
40
 
41
 
        g_source_remove(hrm_sid1); 
42
 
        g_source_remove(hrm_sid3); 
43
 
        
 
41
        g_source_remove(hrm_sid1);
 
42
        g_source_remove(hrm_sid3);
 
43
 
44
44
        osd_hrm(TRUE);
45
45
#endif /* HAVE_BLUEZ */
46
 
        
47
 
        return FALSE;   
 
46
 
 
47
        return FALSE;
48
48
}
49
49
 
50
50
void
54
54
        PangoContext            *context = NULL;
55
55
        PangoLayout             *layout  = NULL;
56
56
        PangoFontDescription    *desc    = NULL;
57
 
        
 
57
 
58
58
        GdkColor color;
59
59
        GdkGC *gc;
60
 
        
 
60
 
61
61
        gchar *buffer;
62
62
        static int x = 10, y = 310;
63
63
        static int width = 0, height = 0;
69
69
                return;
70
70
 
71
71
 
72
 
        if(mouse_dx == 0 && mouse_dy == 0) 
 
72
        if(mouse_dx == 0 && mouse_dy == 0)
73
73
        {
74
 
                if(hrmdata) 
 
74
                if(hrmdata)
75
75
                        buffer = g_strdup_printf("%u", hrmdata->freq);
76
76
                else
77
77
                        buffer = g_strdup_printf("--");
78
 
                
79
 
                
 
78
 
 
79
 
80
80
                context = gtk_widget_get_pango_context (map_drawable);
81
81
                layout  = pango_layout_new (context);
82
82
                desc    = pango_font_description_new();
83
 
                
 
83
 
84
84
                pango_font_description_set_absolute_size (desc, 50 * PANGO_SCALE);
85
85
                pango_layout_set_font_description (layout, desc);
86
86
                pango_layout_set_text (layout, buffer, strlen(buffer));
87
 
        
88
 
        
 
87
 
 
88
 
89
89
                gc = gdk_gc_new (map_drawable->window);
90
 
        
91
 
                if(hrmdata) 
 
90
 
 
91
                if(hrmdata)
92
92
                        color.red = (hrmdata->freq > MAX_HEART_FREQ) ? 0xffff : 0;
93
93
                else
94
94
                        color.red = 0;
95
95
                color.green = 0;
96
96
                color.blue = 0;
97
 
                
 
97
 
98
98
                gdk_gc_set_rgb_fg_color (gc, &color);
99
 
                
 
99
 
100
100
                if(hrmdata)
101
101
                        hrm = hrmdata->freq;
102
102
                else
103
103
                        hrm = 0;
104
 
                
 
104
 
105
105
                if(hrm_tmp != hrm || force_redraw)
106
106
                {
107
 
                        
 
107
 
108
108
                        gdk_draw_drawable (
109
109
                                map_drawable->window,
110
110
                                map_drawable->style->fg_gc[GTK_WIDGET_STATE (map_drawable)],
112
112
                                0,300,
113
113
                                0, 300,
114
114
                                width+10,height+10);
115
 
                
116
 
                        
 
115
 
 
116
 
117
117
 
118
118
                                gdk_draw_layout(map_drawable->window,
119
119
                                                gc,
120
120
                                                x, y,
121
121
                                                layout);
122
 
                        
123
 
                        
 
122
 
 
123
 
124
124
                        pango_layout_get_pixel_size(layout, &width, &height);
125
125
                }
126
 
        
 
126
 
127
127
                hrm_tmp = hrm;
128
 
                
 
128
 
129
129
                g_free(buffer);
130
130
                pango_font_description_free (desc);
131
131
                g_object_unref (layout);
140
140
#ifdef HAVE_BLUEZ
141
141
        static GtkWidget *widget1=NULL, *widget2=NULL;
142
142
        static gchar buffer[128];
143
 
                                
 
143
 
144
144
        if(!widget1) {
145
145
                widget1 = lookup_widget(window1, "label206");
146
146
                widget2 = lookup_widget(window1, "label207");
147
147
        }
148
 
        
 
148
 
149
149
        g_snprintf (buffer, 128, _("<b><big>%d</big></b> <small>bpm</small>"),
150
150
                    hrmdata->freq);
151
151
        gtk_label_set_label(GTK_LABEL(widget1), buffer);
163
163
#ifdef HAVE_BLUEZ
164
164
        g_free(hrmdata);
165
165
        hrmdata = NULL;
166
 
        g_source_remove(hrm_sid1); 
167
 
        g_source_remove(hrm_sid3); 
 
166
        g_source_remove(hrm_sid1);
 
167
        g_source_remove(hrm_sid3);
168
168
#endif /* HAVE_BLUEZ */
169
 
        
170
 
        return FALSE; 
 
169
 
 
170
        return FALSE;
171
171
}
172
172
 
173
173
 
176
176
{
177
177
#ifdef HAVE_BLUEZ
178
178
        static int hrm_status = 0;
179
 
        
 
179
 
180
180
        gsize bytes_read;
181
181
        GError *error = NULL;
182
182
        gchar buf[1024];
186
186
                                hrm_io_channel,
187
187
                                (char *) buf, sizeof(buf),
188
188
                                &bytes_read, &error);
189
 
                                
 
189
 
190
190
        if(status == G_IO_STATUS_NORMAL)
191
191
        {
192
192
 
193
 
                
 
193
 
194
194
                if(hrm_status == 0)
195
195
                {
196
196
                        if((bytes_read == 60) && (buf[0] == 2))
197
197
                                hrmdata->freq = buf[12];
198
 
                        
 
198
 
199
199
                        if((bytes_read == 1) && (buf[0] == 2))
200
200
                                hrm_status = 1;
201
201
                }
202
202
                else {
203
203
                        if(bytes_read == 59)
204
204
                                hrmdata->freq = buf[11];
205
 
                        
 
205
 
206
206
                        hrm_status = 0;
207
 
                }       
208
 
                
209
 
                
 
207
                }
 
208
 
 
209
 
210
210
                g_source_remove(watchdog);
211
211
                watchdog = g_timeout_add_seconds_full(G_PRIORITY_DEFAULT_IDLE,60,reset_hrm_io,NULL,NULL);
212
212
        }
214
214
        {
215
215
                if (error)
216
216
                        printf("gio: %s \n", error->message);
217
 
                        
 
217
 
218
218
        }
219
 
        
220
 
        
 
219
 
 
220
 
221
221
        if(hrmdata->freq < hrmdata->min && hrmdata->freq > 50)
222
222
                hrmdata->min = hrmdata->freq;
223
223
        if(hrmdata->freq > hrmdata->max && hrmdata->freq < 220)
229
229
 
230
230
 
231
231
 
232
 
void 
 
232
void
233
233
get_hrm_data()
234
234
{
235
235
#ifdef HAVE_BLUEZ
253
253
 
254
254
        if(!global_hrm_bt_addr)
255
255
                return NULL;
256
 
        
 
256
 
257
257
        if(!hrmdata  || global_reconnect_hrm)
258
258
        {
259
259
                if(cnt++ % 15 != 0)
260
260
                        return NULL;
261
 
                
 
261
 
262
262
                if (hrm_sock) hrm_sock = close(hrm_sock);
263
263
 
264
264
                hrm_sock = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
266
266
                        printf("error opening hrm socket\n");
267
267
                        return NULL;
268
268
                }
269
 
                
 
269
 
270
270
                str2ba(global_hrm_bt_addr, &addr.rc_bdaddr);
271
 
                
 
271
 
272
272
                addr.rc_family = AF_BLUETOOTH;
273
273
                addr.rc_channel = 1;
274
 
    
 
274
 
275
275
                conn = connect(hrm_sock, (struct sockaddr *)&addr, sizeof(addr));
276
276
                if(conn < 0) {
277
277
                        printf("error connecting %s\n", global_hrm_bt_addr);
278
 
                        
 
278
 
279
279
                        conn = 1;
280
280
                        shutdown(hrm_sock, SHUT_RDWR);
281
281
                }
282
282
                else {
283
283
                        global_reconnect_hrm = FALSE;
284
 
                        
 
284
 
285
285
                        if(!hrmdata) {
286
286
                                hrmdata = g_new0(hrm_data_t,1);
287
287
                                hrmdata->min = 999;
288
288
                        }
289
289
 
290
290
                        len = read(hrm_sock, buf, 500);
291
 
                        
 
291
 
292
292
                        fprintf(stderr, "HRM Rcvd %i bytes", len);
293
 
                        
294
 
                        
 
293
 
 
294
 
295
295
                        watchdog = g_timeout_add_seconds_full(G_PRIORITY_DEFAULT_IDLE,60,reset_hrm_io,NULL,NULL);
296
 
                        
 
296
 
297
297
                        hrm_io_channel = g_io_channel_unix_new(hrm_sock);
298
298
                        g_io_channel_set_encoding(hrm_io_channel, NULL, &error);
299
299
                        g_io_channel_set_flags(hrm_io_channel, G_IO_FLAG_NONBLOCK, NULL);
300
 
                        
 
300
 
301
301
                        hrm_sid1 = g_io_add_watch_full(hrm_io_channel, G_PRIORITY_HIGH_IDLE+200, G_IO_ERR | G_IO_HUP, cb_hrm_io_error, NULL, NULL);
302
302
                        hrm_sid3 = g_io_add_watch_full(hrm_io_channel, G_PRIORITY_HIGH_IDLE+200, G_IO_IN | G_IO_PRI, cb_hrm_data, NULL, NULL);
303
303
                }