int test_gesture(short length, unsigned short tolerance) { int ipc_status; message msg; int receive; int validation = 1; sumOfX = 0; int irq_set = mouse_subscribe(); unsigned long clean; counter = 0; interrupts = 0; while (validation) { receive = driver_receive(ANY, &msg, &ipc_status); if (receive != 0) { printf("driver_receive failed with: %d", receive); continue; } if (is_ipc_notify(ipc_status)) { switch (_ENDPOINT_P(msg.m_source)) { case HARDWARE: if (msg.NOTIFY_ARG & irq_set) { validation = gesture_handler(length, tolerance); } break; default: break; } } else { } } mouse_unsubscribe(); printf("\n\tpress ANY KEY to continue\n"); mouse_read(&clean); //Clean the buffer return 0; }
int test_config(void) { printf("\n\tTouch in the mouse\n\n"); unsigned long data, res; unsigned char a[3]; mouse_subscribe(); mouse_write(MOUSE_STATUS); mouse_read(&data); while (1) { mouse_read(&data); if ((BIT(7) & data) && (BIT(3) & res)) break; } a[0] = data; while (1) { mouse_read(&data); if (data <= 3) break; } a[1] = data; tickdelay(micros_to_ticks(DELAY_US)); if (mouse_read(&data) != 0) return -1; a[2] = data; printf("\n\tCONFIGURATION\n"); printf( "\tMode: %s\n\tEnable: %d\n\tScaling: %s\n\tLB: %d\n\tMB: %d\n\tRB: %d\n\tResolution: %d count/mm\n\tSample Rate: %d\n", MODE(a[0]) ? "Remote" : "Stream", ENABLE(a[0]), SCALING(a[0]) ? "1:1" : "2:1", LEFT(a[0]), MIDDLE(a[0]), RIGHT(a[0]), RESOLUTION(a[1]), RATE(a[2])); mouse_unsubscribe(); printf("\n\tpress ANY KEY to continue\n"); mouse_read(&res); /* clear out buffer */ }
int test_packet(unsigned short cnt) { int i = 0; int ipc_status; message msg; int receive; int irq_set = mouse_subscribe(); unsigned long clean; counter = 0; interrupts = 0; while (i < cnt * 3) { receive = driver_receive(ANY, &msg, &ipc_status); if (receive != 0) { printf("driver_receive failed with: %d", receive); continue; } if (is_ipc_notify(ipc_status)) { switch (_ENDPOINT_P(msg.m_source)) { case HARDWARE: if (msg.NOTIFY_ARG & irq_set) { mouse_handler(); i++; } break; default: break; } } else { } } mouse_unsubscribe(); printf("\n\tpress ANY KEY to continue\n"); mouse_read(&clean); //Clean the buffer return 0; }
int test_packet(unsigned short cnt) { int conta = 0, ind = 0, r, ipc_status; unsigned long irq_set, data; char cmd; message msg; if ((irq_set = mouse_subscribe()) == -1) { printf("Unable to subscribe mouse!\n"); return 1; } if (sys_outb(STAT_REG, ENABLE_MOUSE) != OK) //rato enable printf("Error\n"); if (sys_outb(STAT_REG, W_TO_MOUSE) != OK) //MOUSE printf("Error-MC\n"); if (sys_outb(OUT_BUF, ENABLE_SEND) != OK) //Ativar o envio printf("Error-SEND\n"); while (cnt > conta) { if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) { printf("driver_receive failed with: %d", r); continue; } if (is_ipc_notify(ipc_status)) { switch (_ENDPOINT_P(msg.m_source)) { case HARDWARE: if (msg.NOTIFY_ARG & irq_set) { get_packet(); mouse_print(); } break; default: break; } } else { } } printf("Terminou!\n"); if (sys_outb(STAT_REG, W_TO_MOUSE) != OK) printf("ERROR-MC"); if (sys_outb(OUT_BUF, DISABLE_STREAM) != OK) printf("ERROR-DISABLE_STREAM"); if (sys_inb(OUT_BUF, &data) != OK) printf("OUT_BUF not full!\n"); if (data != ACK) printf("Not ACK!\n"); if (mouse_unsubscribe() == -1) printf("falhou unsubscribe mouse!\n"); return 0; }
int test_async(unsigned short idle_time) { int ipc_status; message msg; int time = 0; int receive; unsigned long clean; int irq_set_mouse = mouse_subscribe(); int irq_set_timer = timer_subscribe_int(); counter = 0; interrupts = 0; while (time < idle_time * 60) { receive = driver_receive(ANY, &msg, &ipc_status); if (receive != 0) { printf("driver_receive failed with: %d", receive); continue; } if (is_ipc_notify(ipc_status)) { switch (_ENDPOINT_P(msg.m_source)) { case HARDWARE: if (msg.NOTIFY_ARG & irq_set_mouse) { mouse_handler(); time = 0; } if (msg.NOTIFY_ARG & irq_set_timer) { time++; } break; default: break; } } else { } } mouse_unsubscribe(); timer_unsubscribe_int(); printf("\n\tpress ANY KEY to continue\n"); mouse_read(&clean); return 0; }
int test_async(unsigned short idle_time) { int conta = 0, ind = 0, r, ipc_status, conta_timer = 0, fim = 0; unsigned long irq_set_mouse, irq_set_timer; char cmd, packet[3]; int tmp = 60 * idle_time; message msg; if ((irq_set_timer = timer_subscribe_int()) == -1) { printf("Unable to subscribe timer!\n"); return 1; } if ((irq_set_mouse = mouse_subscribe()) == -1) { printf("Unable to subscribe mouse!\n"); return 1; } if (sys_outb(STAT_REG, 0xA8) != OK) //rato enable printf("Error\n"); if (sys_outb(STAT_REG, W_TO_MOUSE) != OK) printf("Error-MC\n"); if (sys_outb(OUT_BUF, ENABLE_SEND) != OK) printf("Error-SEND\n"); // Enable Sending Data Packets while (fim == 0) { if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) { printf("driver_receive failed with: %d", r); continue; } if (is_ipc_notify(ipc_status)) { switch (_ENDPOINT_P(msg.m_source)) { case HARDWARE: if (msg.NOTIFY_ARG & irq_set_mouse) { conta_timer = 0; cmd = mouse_read(); switch (ind) { case 0: if (cmd & BIT(3)) packet[0] = cmd; ind++; break; case 1: packet[1] = cmd; ind++; break; case 2: packet[2] = cmd; conta++; ind = 0; mouse_print(packet); break; } } if (msg.NOTIFY_ARG & irq_set_timer) { conta_timer++; if (conta_timer >= tmp) { fim = 1; } } break; default: break; } } else { } } printf("Acabou o tempo de espera!\n"); if (sys_outb(STAT_REG, W_TO_MOUSE) != OK) printf("ERROR-MC"); if (sys_outb(OUT_BUF, DISABLE_STREAM) != OK) printf("ERROR-DISABLE_STREAM"); if (mouse_unsubscribe() == -1) printf("falhou unsubscribe mouse!\n"); if (timer_unsubscribe_int() == -1) printf("Falhou unsubscribe timer!\n"); return 0; }
int test_config(void) { unsigned long data; char packet[3]; int counter = 0; int ipc_status; message msg; unsigned long irq_set = mouse_subscribe(); if (irq_set == -1) { printf("Error Subscribing mouse"); return 0; } //Ativar o rato if (sys_outb(STAT_REG, ENABLE_MOUSE) != OK) { printf("Error enabling mourse."); return 0; } sys_inb(OUT_BUF, &data); if (sys_outb(STAT_REG, W_TO_MOUSE) != OK) { printf("Error writing byte to mouse."); return 0; } sys_inb(OUT_BUF, &data); if (sys_outb(OUT_BUF, DISABLE_STREAM) != OK) { printf("Error disabling stream mode."); return 0; } sys_inb(OUT_BUF, &data); if (sys_outb(STAT_REG, W_TO_MOUSE) != OK) { printf("Error writing byte to mouse."); return 0; } sys_inb(OUT_BUF, &data); if (sys_outb(OUT_BUF, STATUS_REQUEST) != OK) //GET MOUSE CONFIGURATION { printf("Error writing byte to mouse."); return 0; } sys_inb(OUT_BUF, &data); while (counter < 3) { int b = driver_receive(ANY, &msg, &ipc_status); if (b != 0) { printf("driver_receive failed with: %d", b); continue; } if (is_ipc_notify(ipc_status)) { switch (_ENDPOINT_P(msg.m_source)) { case HARDWARE: if (msg.NOTIFY_ARG & irq_set) { //unsigned long p = (unsigned long) packet[counter]; sys_inb(OUT_BUF, &packet[counter]); counter++; } break; default: break; } } } if ((packet[0] & BIT(6)) == BIT(6)) { printf("Remote (poled) mode\n"); } else { printf("Stream mode\n"); } if ((packet[0] & BIT(5)) == BIT(5)) { printf("Data reporting enabled\n"); } else { printf("Data reporting disabled\n"); } if ((packet[0] & BIT(4)) == BIT(4)) { printf("Scaling is 2:1\n"); } else { printf("Scaling is 1:1\n"); } if ((packet[0] & BIT(2)) == BIT(2)) { printf("Middle button pressed\n"); } else { printf("Middle button released\n"); } if ((packet[0] & BIT(1)) == BIT(1)) { printf("Right button pressed\n"); } else { printf("Right button released\n"); } if ((packet[0] & BIT(0)) == BIT(0)) { printf("Left button pressed\n"); } else { printf("Left button released\n"); } int x; if (packet[1] == 0) x = 0; if (packet[1] == 1) x = 2; if (packet[1] == 2) x = 4; if (packet[1] == 3) x = 8; printf("Resolution : %d\n", x); printf("Sample Rate : %d\n", packet[2]); mouse_unsubscribe(); return 0; }