Project

General

Profile

Revision 77

fixed test_packets

View differences:

lab4.c
37 37
extern int counter;
38 38

  
39 39
int (mouse_test_packet)(uint32_t cnt) {
40
    int ret = 0;
40 41
    /// loop stuff
41 42
    int ipc_status, r;
42 43
    message msg;
......
44 45
    uint8_t mouse_irq_bit = 12;
45 46
    int mouse_id = 0;
46 47
    int mouse_irq = BIT(mouse_irq_bit);
47
    if (mouse_set_data_report(true)) return 1;
48
    if ((ret = mouse_set_data_report(true))) return ret;
49
    //if ((ret = mouse_enable_data_reporting())) return ret;
48 50

  
49 51
    if (subscribe_mouse_interrupt(mouse_irq_bit, &mouse_id)) return 1;
50 52
    /// cycle
......
78 80
    }
79 81
    if (unsubscribe_interrupt(&mouse_id)) return 1;
80 82
    if (mouse_set_data_report(false)) return 1;
81

  
82 83
    return 0;
83 84
}
84 85

  
......
187 188
    return 0;
188 189
}
189 190

  
191
enum state{
192
    STATE_NEUTRAL,
193
    STATE_FIRST,
194
    STATE_MID,
195
    STATE_SECOND
196
};
197

  
190 198
int (mouse_test_gesture)(uint8_t x_len, uint8_t tolerance) {
191
    /* To be completed */
192
    printf("%s: under construction\n", __func__);
193
    return 1;
199
    int ret = 0;
200
    /// loop stuff
201
    int ipc_status, r;
202
    message msg;
203
    /// Mouse interrupt handling
204
    uint8_t mouse_irq_bit = 12;
205
    int mouse_id = 0;
206
    int mouse_irq = BIT(mouse_irq_bit);
207
    //if ((ret = mouse_set_data_report(true))) return ret;
208
    if ((ret = mouse_enable_data_reporting())) return ret;
209

  
210
    if (subscribe_mouse_interrupt(mouse_irq_bit, &mouse_id)) return 1;
211
    /// cycle
212
    int good = 1;
213
    //int st = STATE_NEUTRAL;
214
    //int16_t dx, dy;
215
    while (good) {
216
        /* Get a request message. */
217
        if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) {
218
            printf("driver_receive failed with %d", r);
219
            continue;
220
        }
221
        if (is_ipc_notify(ipc_status)) { /* received notification */
222
            switch (_ENDPOINT_P(msg.m_source)) {
223
                case HARDWARE: /* hardware interrupt notification */
224
                    if (msg.m_notify.interrupts & mouse_irq) { /* subscribed interrupt */
225
                        mouse_ih();
226
                        if(counter >= 3){
227
                            struct packet pp = mouse_parse_packet(packet);
228
                            mouse_print_packet(&pp);/*
229
                            switch(st){
230
                                case STATE_NEUTRAL:
231
                                    if(pp.lb == 1 && pp.mb == 0 && pp.rb == 0){
232
                                        st = STATE_FIRST;
233
                                        dx = 0;
234
                                        dy = 0;
235
                                    }
236
                                    break;
237
                                case STATE_FIRST:
238
                                    if(pp.lb == 1){
239
                                        if(pp.delta_x >= -tolerance && pp.delta_y >= -tolerance){
240
                                            dx += pp.delta_x;
241
                                            dy += pp.delta_y;
242
                                        }else{
243
                                            st = STATE_NEUTRAL;
244
                                        }
245
                                    }else{
246
                                        if(abs(dx) < abs(dy) && dx > 0 && dy > 0){
247
                                            st = STATE_MID;
248
                                        }else{
249
                                            st = STATE_NEUTRAL;
250
                                        }
251
                                    }
252
                                    break;
253
                                case STATE_MID:
254
                                    if(pp.lb == 0 && pp.mb == 0 && pp.rb == 1){
255
                                        st = STATE_SECOND;
256
                                        dx = 0;
257
                                        dy = 0;
258
                                    }else{
259
                                        st = STATE_NEUTRAL;
260
                                    }
261
                                    break;
262
                                case STATE_SECOND:
263
                                    if(pp.rb == 1){
264
                                        if(pp.delta_x >= -tolerance && pp.delta_y <= tolerance){
265
                                            dx += pp.delta_x;
266
                                            dy += pp.delta_y;
267
                                        }else{
268
                                            st = STATE_NEUTRAL;
269
                                        }
270
                                    }else{
271
                                        if(abs(dx) < abs(dy) && dx > 0 && dy < 0){
272
                                            st = STATE_NEUTRAL;
273
                                            good = false;
274
                                        }else{
275
                                            st = STATE_NEUTRAL;
276
                                        }
277
                                    }
278
                                    break;
279
                                default:
280
                                    return OTHER_ERROR;
281
                                    break;
282
                            }*/
283
                        }
284
                    }
285
                    break;
286
                default:
287
                    break; /* no other notifications expected: do nothing */
288
            }
289
        } else { /* received standart message, not a notification */
290
            /* no standart message expected: do nothing */
291
        }
292
    }
293
    if (unsubscribe_interrupt(&mouse_id)) return 1;
294
    if (mouse_set_data_report(false)) return 1;
295

  
296
    return 0;
194 297
}

Also available in: Unified diff