Index: lab3/i8042.h
===================================================================
--- lab3/i8042.h	(revision 10)
+++ lab3/i8042.h	(revision 11)
@@ -24,14 +24,17 @@
 #define STAT_REG_IBF	   	BIT(1)  /* Input Buffer Full */
 #define STAT_REG_OBF		  BIT(0)  /* Output Buffer Full */
 
+#define READ_COMMAND        0x20   /* Returns Command Byte */
+
 #define OUTPUT_BUF         0x60    /* Output Buffer */
 #define INPUT_BUF          0x60    /* Input Buffer */
-#define STATUS_REG        0x64    /* Status Register */
-#define KBC_CMD_REG     0x64    /* Command Register */
-#define KBC_CMD_ARG     0x60    /* Command Arguments Adress */
+#define STATUS_REG         0x64    /* Status Register */
+#define KBC_CMD_REG        0x64    /* Command Register */
+#define INT_ENABLE         BIT(0) /*enable interrupt on OBF, from keyboard*/
+#define KBC_CMD_ARG        0x60    /* Command Arguments Adress */
 
-#define ESC_BREAK      0x81
+#define ESC_BREAK           0x81
 #define TWO_BYTE_SCANCODE   0xE0  /* Two-byte long scancodes use 0xE0 as their first byte */
-#define MAKE_CODE            BIT(7)
+#define MAKE_CODE           BIT(7)
 
 #endif /* _LCOM_I8042_H */
Index: lab3/keyboard.c
===================================================================
--- lab3/keyboard.c	(revision 10)
+++ lab3/keyboard.c	(revision 11)
@@ -26,7 +26,7 @@
   if(util_sys_inb(STATUS_REG,&status_reg)!=0){ //checks if there is an error
     return;
   }
-  if(((status_reg & STAT_REG_OBF)==0) ||((status_reg&(STAT_REG_PAR|STAT_REG_TIMEOUT))!=0)){ //checks if there is a parity or timeout error (mask -> 0xC0, bit 7 and 6 set) and checks if output buffer is empty
+  if(((status_reg & STAT_REG_OBF)==0) ||((status_reg&(STAT_REG_PAR|STAT_REG_TIMEOUT))!=0)|| ((status_reg&STAT_REG_AUX)!=0)){ //checks if there is a parity or timeout error (mask -> 0xC0, bit 7 and 6 set), checks if output buffer is empty and checks if there is data coming from the mouse
     return;
   }
   util_sys_inb(OUTPUT_BUF,&scan_code);
@@ -33,6 +33,7 @@
 
 }
 
+
 int (kbc_subscribe_int)(uint8_t *bit_no) {    //similar function to that of timer_subscribe_int
     *bit_no = BIT(keyboard_id);
     if(sys_irqsetpolicy(KEYBOARD_IRQ,(IRQ_REENABLE|IRQ_EXCLUSIVE),&keyboard_id)==1){      //operation to subscribe int
@@ -49,3 +50,32 @@
   }
   return 0;
 }
+
+int (enable_interrupt)()
+{
+  uint8_t command;
+
+  if(sys_outb(STATUS_REG,READ_COMMAND)!=0){
+    printf("Error writing read-command\n");
+    return 1;
+  }
+
+  if(util_sys_inb(OUTPUT_BUF, &command)!=0){
+    printf("Error reading output buffer\n");
+    return 1;
+  }
+
+  command = command | INT_ENABLE;
+
+  if(sys_outb(STATUS_REG,OUTPUT_BUF)!=0){
+    printf("Error writing output buffer\n");
+    return 1;
+  }
+
+  if(sys_outb(OUTPUT_BUF,command)!=0){
+    printf("Error writing new buffer status\n");
+    return 1;
+  }
+
+  return 0;
+}
Index: lab3/keyboard.h
===================================================================
--- lab3/keyboard.h	(revision 10)
+++ lab3/keyboard.h	(revision 11)
@@ -5,15 +5,17 @@
 #include <lcom/lcf.h>
 #include <stdbool.h>
 #include <stdint.h>
+#include <minix/syslib.h>
+#include <minix/sysutil.h>
 
 #include "i8042.h"
 /**
-* @brief Handles keyboard interrupts (C implementation)
+* @brief Handles keyboard interrupts
 *
-* Reads the status register and the output buffer (OB).
-* If there was some error, the byte read from the OB should be discarded.
+* Reads the status register, the output buffer and the mouse data
+* If there was some error, the byte read from the OB should be discarded
 *
-* All communication with other code must be done via global variables, static if possible.
+* All communication with other code must be done via global variables, static if possible
 *
 * Must be defined using parenthesis around the function name:
 */
@@ -41,5 +43,11 @@
  * @return Return 0 upon success and non-zero otherwise
  */
 int(kbc_unsubscribe_int)();
+/**
+ * @brief Enables interrupts (used when polling function ends)
+ *
+ * @return Return 0 upon success and non-zero otherwise
+ */
+int (enable_interrupt)();
 
 #endif /*_KEYBOARD_H */
Index: lab3/lab3.c
===================================================================
--- lab3/lab3.c	(revision 10)
+++ lab3/lab3.c	(revision 11)
@@ -45,7 +45,7 @@
     return 1;
   }
 
-  while(scan_code!=ESC_BREAK){      //looping until scann_code is the breakcode of ESC key
+  while(scan_code!=ESC_BREAK){      //looping until scan_code is the breakcode of ESC key
     if ((r = driver_receive(ANY, &msg, &ipc_status))==1){ 
       printf("driver_receive failed with: %d",r);
       continue;
@@ -52,7 +52,7 @@
     }
     if (is_ipc_notify(ipc_status)){                             //received notification
       switch (_ENDPOINT_P(msg.m_source)){
-        case HARDWARE:                                          //hardware interrupt notification				
+        case HARDWARE:                                          //hardware interrupt notification
                 if (msg.m_notify.interrupts &keyboard_irq){          // subscribed interrupt
                   
                   kbc_ih();
@@ -72,7 +72,11 @@
                   else {
                     make = true;  //make code
                   }
-                  kbd_print_scancode(make, size, bytes); //prints the code
+
+                  if(kbd_print_scancode(make, size, bytes)!=0){ //prints the code
+                    printf("Error printing scan code\n");
+                    return 1;
+                  }
                       }
                break;
         default:
@@ -89,16 +93,76 @@
 		return 1;
 	}
 
-  kbd_print_no_sysinb(cnt);
+  if(kbd_print_no_sysinb(cnt)!=0){
+    printf("Error printing number of sys used\n");
+    return 1;
+  }
 
+  cnt=0;
+  scan_code=0;
+
   return 0;
 }
 
 int(kbd_test_poll)() {
-  /* To be completed by the students */
-  printf("%s is not yet implemented!\n", __func__);
+  uint8_t status, size, bytes[2]; //size of scancode can be 2 byte long
+  bool make=false; //to check if code is make or break
 
-  return 1;
+  while(scan_code!=ESC_BREAK){      //looping until scan_code is the breakcode of ESC key, can't do interruptions
+    if(util_sys_inb(STATUS_REG, &status)!=0){     //checks the status register
+      printf("Error reading status register\n");
+      return 1;
+    }					
+
+		if ((status & STAT_REG_OBF) && !(status & STAT_REG_AUX) && !(status & STAT_REG_PAR || status & STAT_REG_TIMEOUT)) {      //checks if there is no parity ot timeout error, if the output buffer is full and if there is mouse data
+
+			if(util_sys_inb(OUTPUT_BUF, &scan_code)!=0){
+        printf("Error reading output buffer\n");
+      return 1;
+      }
+
+			bytes[0]=scan_code;
+      bytes[1]=scan_code;
+
+      if(bytes[0]==TWO_BYTE_SCANCODE){
+        size=2;
+      }
+      else{
+        size=1;
+      }
+
+      if (scan_code & MAKE_CODE){	           //checks if code is make or break
+          make = false;	                     //break code
+        }
+      else {
+        make = true;                         //make code
+      }
+
+      if(kbd_print_scancode(make, size, bytes)!=0){ //prints the code
+        printf("Error printing scan code\n");
+        return 1;
+      }
+	
+		}
+		else { 																		//if the output buffer is not full wait
+			tickdelay(micros_to_ticks(DELAY_US));		//makes keyboard respond to a command in 20 ms
+		}
+  }
+
+  if(kbd_print_no_sysinb(cnt)!=0){
+    printf("Error printing number of sys used\n");
+    return 1;
+  }
+
+  if(enable_interrupt()!=0){
+    printf("Coulnd re-enable the interruptions\n");
+    return 1;
+
+  }
+  cnt=0;
+  scan_code=0;
+
+   return 0;
 }
 
 int(kbd_test_timed_scan)(uint8_t n) {
