#include <stdio.h>

#include <stdlib.h>

#include <unistd.h>

#include <fcntl.h>

 #include <sys/ioctl.h> /* for ioctl */

 #include <sys/types.h>

 #include <linux/fb.h> /* for fb_var_screeninfo, FBIOGET_VSCREENINFO */

int main(void) {

  int fd, fbfd;

  short buf[4];

     int xpos1, xpos2, ypos1, ypos2;

     int ret, t;

     struct fb_var_screeninfo fbvar;

     int rpixel;

     fbfd = open("/dev/fb0", O_RDWR);

     if(fbfd < 0)  {

   perror("fbdev open");

   exit(1);

     }

     ret = ioctl(fbfd, FBIOGET_VSCREENINFO, &fbvar);

     if(ret < 0) {

  perror("fbdev ioctl");

  exit(1);

     }

     if(fbvar.bits_per_pixel != 16) {

   fprintf(stderr, "bpp is not 16\n");

   exit(1);

     }

  fd = open(“/dev/ts”, O_RDWR);

  if(fd<0) return -1;

  read(fd, buf, sizeof(buf));

  printf(“x = %d, y= %d\n”, buf[1], buf[2]);

     xpos1 = buf[1];

     ypos1 = buf[2];

/* TODO – get xpos2 & ypos2 */

// YOUR CODES HERE

//

//

    if(xpos1 > xpos2) {

   t = xpos1;

   xpos1 = xpos2;

   xpos2 = t;

     }

     if(ypos1 > ypos2) {

   t = ypos1;

   ypos1 = ypos2;

   ypos2 = t;

     }

     /* random number between 0 and 65535(2^16-1) */

     rpixel = (int)(65536.0*rand()/(RAND_MAX+1.0));

    /* TODO – draw a rectangle with (xpos1, ypos1) and (xpos2, ypos2) */

    // Color is rpixel

    // YOUR CODES HERE

    //

  close(fd);

     close(fbfd);

  return 0;

} // end of main