Project

General

Profile

Revision 77

fixed test_packets

View differences:

lab4/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
}
lab4/mouse.c
61 61
}
62 62

  
63 63
int (mouse_set_data_report)(int on){
64
    if(on) return mouse_issue_cmd(ENABLE_DATA_REP);
65
    else   return mouse_issue_cmd(   DIS_DATA_REP);
64
    int ret = 0;
65
    if(on){
66
        if((ret = mouse_issue_cmd(ENABLE_DATA_REP))) return ret;
67
    }
68
    else{
69
        if((ret = mouse_issue_cmd(   DIS_DATA_REP))) return ret;
70
    }
71
    return ret;
66 72
}
67 73

  
68 74
int (mouse_read_data)(uint8_t *data) {
......
75 81
int (mouse_issue_cmd)(uint32_t cmd) {
76 82
    int ret;
77 83
    uint8_t ack = 0;
78
    for(unsigned i = 0; i < KBC_NUM_TRIES; ++i) {
79
        if ((ret = kbc_issue_cmd(MOUSE_WRITE_B))) return ret;
80
        if ((ret = kbc_issue_arg(cmd))) return ret;
81
        if ((ret = mouse_read_byte(&ack))) return ret;
82
        if (ack == ACK_OK) return SUCCESS;
83
        if (ack == ACK_ERROR) return INVALID_COMMAND;
84
        tickdelay(micros_to_ticks(DELAY));
85
    }
86
    return TIMEOUT_ERROR;
84
    if ((ret = kbc_issue_cmd(MOUSE_WRITE_B))) return ret;
85
    if ((ret = kbc_issue_arg(cmd))) return ret;
86
    if ((ret = mouse_read_ack(&ack))) return ret;
87
    if (ack == ACK_OK) return SUCCESS;
88
    if (ack == ACK_ERROR) return INVALID_COMMAND;
89
    return OTHER_ERROR;
87 90
}
88 91

  
89 92
int (mouse_read_byte)(uint8_t *byte) {
......
101 104
    return TIMEOUT_ERROR;
102 105
}
103 106

  
107
int (mouse_read_ack)(uint8_t *byte) {
108
    int ret = 0;
109
    uint8_t stat;
110
    //for(int i = 0; i < KBC_NUM_TRIES; ++i){
111
        if((ret = util_sys_inb(STATUS_REG, &stat))) return ret;
112
        //if((stat&OUT_BUF_FUL) && (stat&AUX_MOUSE)) {
113
            if(stat & (PARITY_ERROR | TIME_OUT_REC)) return OTHER_ERROR;
114
            if((ret = util_sys_inb(OUTPUT_BUF, byte))) return ret;
115
            else return SUCCESS;
116
        //}
117
        //tickdelay(micros_to_ticks(DELAY));
118
    //}
119
    //return TIMEOUT_ERROR;
120
}
121

  
104 122
int16_t (sign_extend_byte)(uint8_t sign_bit, uint8_t byte) {
105 123
    return (int16_t)(((0xFF * sign_bit)<<8) | byte);
106 124
}
lab4/mouse.h
49 49
 */
50 50
int (mouse_read_byte)(uint8_t *byte);
51 51

  
52
int (mouse_read_ack)(uint8_t *byte);
53

  
52 54
/**
53 55
 * @brief Converts 9-bit number to 16-bit with sign extension
54 56
 * @param sign_bit  Sign bit identifiying the signal of the number

Also available in: Unified diff