Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

phh
Tuesday, February 2nd, 2010 at 1:36:47pm MST 

  1. #define _GNU_SOURCE
  2. #include "msm_mdp.h"
  3. #define __dev_t_defined
  4. #define __gid_t_defined
  5. #define __uid_t_defined
  6. #define __mode_t_defined
  7. #define __timer_t_defined
  8. #define __nlink_t_defined
  9. #define __blkcnt_t_defined
  10. #define __fd_set_defined
  11. #define _SYS_SELECT_H
  12. #include <sys/types.h>
  13. #include <sys/stat.h>
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <unistd.h>
  17. #include <string.h>
  18. #include <sys/mman.h>
  19. #include <sys/ioctl.h>
  20. #include <fcntl.h>
  21. #include <linux/fb.h>
  22. #include <linux/input.h>
  23. #include <dirent.h>
  24. //#include <linux/msm_mdp.h>
  25.  
  26. short *ptr;
  27. struct fb_var_screeninfo info;
  28. //considering screen is 2048x2048
  29. int points[5][2]= {
  30.         {  128, 128  },
  31.         { 1903, 129  },
  32.         { 1024, 1024 },
  33.         {  128, 1907 },
  34.         { 1903, 1907 },
  35. };
  36.  
  37.  
  38. void put_pixel(int rel_x, int rel_y, short rgb) {
  39.         int x,y;
  40.         x=rel_x*info.xres;
  41.         x/=2048;
  42.         y=rel_y*info.yres;
  43.         y/=2048;
  44.         ptr[x+info.xres_virtual*y]=rgb;
  45. }
  46.  
  47. int dev_id=-1;
  48. int open_input() {
  49.         /* scan all input drivers and look for "kionix-ksd9" */
  50.         int fd = -1;
  51.         const char *dirname = "/dev/input";
  52.         char devname[PATH_MAX];
  53.         char *filename;
  54.         DIR *dir;
  55.         struct dirent *de;
  56.         dir = opendir(dirname);
  57.         if(dir == NULL)
  58.                 return -1;
  59.         strcpy(devname, dirname);
  60.         filename = devname + strlen(devname);
  61.         *filename++ = '/';
  62.         while((de = readdir(dir))) {
  63.                 if(de->d_name[0] == '.' &&
  64.                                 (de->d_name[1] == '\0' ||
  65.                                  (de->d_name[1] == '.' && de->d_name[2] == '\0')))
  66.                         continue;
  67.                 strcpy(filename, de->d_name);
  68.                 fd = open(devname, O_RDONLY);
  69.                 if (fd>=0) {
  70.                         char name[80];
  71.                         if (ioctl(fd, EVIOCGNAME(sizeof(name) - 1), &name) < 1) {
  72.                                 name[0] = '\0';
  73.                         }
  74.                         if (!strcmp(name, "tssc-manager")) {
  75.                                 int i,id;
  76.                                 for(i=0;i<strlen(devname);++i)
  77.                                         if(isdigit(devname[i])) {
  78.                                                 dev_id=atoi(devname+i);
  79.                                                 break;
  80.                                         }
  81.                                 break;
  82.                         }
  83.                         close(fd);
  84.                         fd = -1;
  85.                 }
  86.         }
  87.         closedir(dir);
  88.         return fd;
  89. }
  90.  
  91. int main(int argc, char **argv) {
  92.         int fd=open("/dev/graphics/fb0", O_RDWR);
  93.         int i,x,y;
  94.         char *str;
  95.         int input_fd=open_input();
  96.         struct input_event ev_buf;
  97.         struct mdp_blit_req_list *req_list;
  98.         struct mdp_blit_req *req;
  99.  
  100.  
  101.         req_list = calloc(1,sizeof(struct mdp_blit_req_list) +
  102.                         sizeof(struct mdp_blit_req));
  103.         req_list->count = 1;
  104.         req = req_list->req;
  105.         req->src.format=MDP_RGB_565;
  106.         req->src.format=MDP_RGB_565;
  107.         req->src.offset=0;
  108.         req->dst.offset=0;
  109.         req->src.memory_id=fd;
  110.         req->dst.memory_id=fd;
  111.         req->alpha=MDP_ALPHA_NOP;
  112.         req->transp_mask=MDP_TRANSP_NOP;
  113.         req->flags=MDP_ROT_NOP;
  114.        
  115.         if(input_fd<0) {
  116.                 perror("Open input device");
  117.                 return -1;
  118.         }
  119.         if(fd<0) {
  120.                 perror("Open fb device");
  121.                 return -1;
  122.         }
  123.         ioctl(fd, FBIOGET_VSCREENINFO, &info);
  124.         ptr=mmap(0, info.xres_virtual*info.yres_virtual*info.bits_per_pixel/8, PROT_WRITE|PROT_READ, MAP_SHARED, fd, 0);
  125.         if(!ptr) {
  126.                 perror("mapping framebuffer");
  127.                 return -1;
  128.         }
  129.         req->src.width=info.xres;
  130.         req->src_rect.w=info.xres;
  131.         req->dst.width=info.xres;
  132.         req->dst_rect.w=info.xres;
  133.         req->src.height=info.yres;
  134.         req->src_rect.h=info.yres;
  135.         req->dst.height=info.yres;
  136.         req->dst_rect.h=info.yres;
  137.         req->src_rect.x=0;
  138.         req->dst_rect.x=0;
  139.         req->src_rect.y=0;
  140.         req->dst_rect.y=0;
  141.         info.yoffset=0;
  142.         char *path=0;
  143.         asprintf(&path, "/sys/class/input/input%d/calibration_screen", dev_id);
  144.         int calib_fd=open(path, O_WRONLY);
  145.         free(path);path=NULL;
  146.         if(calib_fd<0) {
  147.                 perror("opening calibration_screen");
  148.                 //return -2;
  149.         }
  150.         asprintf(&str, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",
  151.                         points[0][0], points[0][1],
  152.                         points[1][0], points[1][1],
  153.                         points[3][0], points[3][1],
  154.                         points[4][0], points[4][1],
  155.                         points[2][0], points[2][1]);
  156.         write(calib_fd, str, strlen(str));
  157.         free(str);
  158.         close(calib_fd);
  159.         str=NULL;
  160.         asprintf(&path, "/sys/class/input/input%d/calibration", dev_id);
  161.         for(i=1;i<6;++i) {
  162.                 calib_fd=open(path, O_WRONLY);
  163.                 for(x=points[i-1][0]-70;x<=points[i-1][0]+70;++x)
  164.                         for(y=points[i-1][1]-50;y<=points[i-1][1]+50;++y)
  165.                                 put_pixel(x, y, 0xffff);
  166.                 for(x=points[i-1][0]-70;x<=points[i-1][0]+70;++x)
  167.                         put_pixel(x, points[i-1][1], 0x0000);
  168.                 for(y=points[i-1][1]-70;y<=points[i-1][1]+70;++y)
  169.                         put_pixel(points[i-1][0], y, 0x0000);
  170.                 ioctl(fd, MSMFB_BLIT, req_list);
  171.                 ioctl(fd, FBIOPAN_DISPLAY, &info);
  172.                 asprintf(&str, "%d\n", i);
  173.                 write(calib_fd, str, strlen(str));
  174.                 close(calib_fd);
  175.                 free(str);
  176.                 str=NULL;
  177.                 while(1) {
  178.                         if(read(input_fd, &ev_buf, sizeof(ev_buf))<0)
  179.                                 return -1;
  180.                         if(ev_buf.type==EV_KEY && ev_buf.value!=0 && ev_buf.code==BTN_TOUCH)
  181.                                 break;
  182.                 }
  183.                 while(1) {
  184.                         if(read(input_fd, &ev_buf, sizeof(ev_buf))<0)
  185.                                 return -1;
  186.                         if(ev_buf.type==EV_KEY && ev_buf.value==0 && ev_buf.code==BTN_TOUCH)
  187.                                 break;
  188.                 }
  189.         }
  190.         calib_fd=open("/sys/class/input/input3/calibration", O_WRONLY);
  191.         write(calib_fd, "0\n", 2);
  192.         close(calib_fd);
  193.         return 0;
  194. }

advertising

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

worth-right
fantasy-obligation