| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1660 人关注过本帖
标题:linux平台在开发板上制作一个简单的登录界面,,loin_in()中当我按下按键1时 ...
取消只看楼主 加入收藏
淡定d淡定d
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2017-6-1
收藏
 问题点数:0 回复次数:0 
linux平台在开发板上制作一个简单的登录界面,,loin_in()中当我按下按键1时,程序一直停留在addpwd('1');中无法按下2了,,怎么修改程序呢?
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <linux/input.h>
#include <pthread.h>

unsigned int *lcd;
int tsfd;
struct input_event buf;
int myx=0,myy=0;
//账号密码
int pwdlenth=0;
char pwdworld[6]={0};

char nub[2][50]={
    "mima.bmp",
    "xing.bmp",
   
};
//画点函数
void poin(int px,int py,int x,int y,int color)
{
    //把lcd指针偏移到固定的位置再画点
    unsigned int * newlcd  = lcd  + px + py*800;
     
    *(newlcd+ x + y*800)=color;
   
}

//显示图片函数
void show_bmp(char *picname,int x,int y)
{
   
         
        //打开图片文件
        int bmpfd=open(picname,O_RDWR);
            if(bmpfd <0 )
            {
                printf("open bmp fail\n");
               
            }
        //去除头54个字节  lseek
        //lseek(bmpfd,54,SEEK_SET);
        char buf[54]={0};
        read(bmpfd,buf,54);
        
        //获取图片的长和宽
        int w = buf[18];
            w = w | buf[19]<<8;

        int h = buf[22];
            h = h | buf[23]<<8;
        
        //根据图片的长和宽确定BUF的大小
        char oldbmpbuf[w*h*3];
        //char newbmpbuf[800*480*4];
        int newbmpbuf[h][w];        
        
        //读取图片中的数据到colorbuf中   
        read(bmpfd,oldbmpbuf,sizeof(oldbmpbuf));
        
        char *p=oldbmpbuf;
        int color;
        char red;
        char  green;
        char  blue;
        //开始转码
        int i,j;
        for(i=0;i<h;i++)
        {
            for(j=0;j<w;j++)
            {
                blue=*p++;
                green=*p++;
                red=*p++;
                color  =   red << 16 | green << 8 | blue;
                newbmpbuf[i][j]=  color;
            }
            
        }
        
        //图片翻转算法
        int daoxubuf[h][w];
        
        for(i=0;i<h;i++)
        {
            for(j=0;j<w;j++)
            {
                daoxubuf[i][j] = newbmpbuf[h-1-i][j];
               
            }
            
        }
        
   
        
            for(i=0;i<h;i++)
        {
            for(j=0;j<w;j++)
            {
                //显示像素点函数
                poin(x,y,j,i,daoxubuf[i][j]);
               
            }
            
        }
            
}
void show_loin()
{
   
        printf("123456\n");
          show_bmp(nub[0],0,0);

                        
}
//添加密码函数
void addpwd(char i)
{
     pwdworld[pwdlenth]=i;
   
     printf("pwdworld=%s\n",pwdworld);
      //显示****星号
     show_bmp(nub[1],200+50*pwdlenth,50);
     pwdlenth++;
   
   
}
//触摸屏线程
void *my_ts(void *arg)
{
   
       //读取触摸屏事件值
       while(1)
       {
               while(1)
               {
                    read(tsfd,&buf,sizeof(buf));
                    //判断是否为触摸屏事件
                    if(buf.type == EV_ABS)
                    {
                        //判断他是事件类型
                        if(buf.code == ABS_X)
                        {
                           
                            myx=buf.value;
                           
                        }
                        if(buf.code == ABS_Y)
                        {
                            printf("Y=%d\n",buf.value);
                            myy=buf.value;
                           
                        }
                        
                            if(buf.code == ABS_PRESSURE)
                        {
                            printf("pre=%d\n",buf.value);
                            if(buf.value == 0)
                            {
                                break;
                            }
                        }
                           
                    }
               }
                printf("x=%d--y=%d\n",myx,myy);
                    
       }
   
   
}
//账号密码匹配
void loin_in()
{
   
        while(1)
        {        //点击1按钮
                if(myx<300&&myx>240 &&myy<210&&myy>150)
                {
                    addpwd(1);
                }
                 //点击2按钮
                if(myx<410&&myx>350 &&myy<210&&myy>150)
                {
                    addpwd(2);
                }
                if(myx<520&&myx>460 &&myy<210&&myy>150)
                {
                    addpwd(3);
                }
               

                if(myx<300&&myx>240 &&myy<290&&myy>230)
                {
                    addpwd(4);
                }
                if(myx<410&&myx>350 &&myy<290&&myy>230)
                {
                    addpwd(5);
                }
                if(myx<520&&myx>460 &&myy<290&&myy>230)
                {
                    addpwd(6);
                }
               
                //点击ent建
                if(myx<300&&myx>240 &&myy<450&&myy>390)
                {
                    if(strcmp(pwdworld,"123456")==0)
                    {
                        
                        break;
                        
                    }
                }
            
            
            
            
        }
   
   
   
   
   
}

void *play_vedio(void *mvname)
{
   
    //播放buf  
    char buf[100]={"mplayer -slave -quiet -input  file=/pipe  -geometry  0:0 -zoom -x 800 -y 480 "};
    //字符串拼接函数
    //char newbuf=buf+mvname
   
    system("mplayer -slave -quiet -input  file=/pipe  -geometry  0:0 -zoom -x 800 -y 480 mv.avi &");
   
}


int main()
{
        //打开显卡设备   /dev/fb0  
        int fd = open("/dev/fb0",O_RDWR);
            if(fd<0)
            {
                printf("open lcd fail\n");
               
            }
        //打开触摸屏设备   
        tsfd = open("/dev/event0",O_RDWR);
        if(tsfd<0)
        {
            printf("open fail\n");
        }
        
        
           //映射显卡设备
           lcd = mmap(NULL,800*480*4,PROT_READ|PROT_WRITE,MAP_SHARED,fd,0);
      
          //显示主界面
          show_loin();
         
          //获取坐标点
         
        pthread_t pid;
       int pid1=pthread_create(&pid,NULL,my_ts,NULL);
        if(pid1<0)
        {
            printf("pthread_create fail\n");
            
        }
          //匹配账号密码
        loin_in();
         
         //主程序窗口
        show_bmp("home.bmp",0,0);
        int biaozhi=0;
          while(1)
          {  
                if(biaozhi==1)
                {
                    show_bmp("home.bmp",0,0);
                    biaozhi=0;
                }
                  // 130  180   270  290
                if(myx>130 && myx < 270  && myy>180 && myy <290)
                {
                    myx=0;
                    myy=0;
                pthread_t pid2;
                int pid3=pthread_create(&pid,NULL,play_vedio,NULL);
                if(pid1<0)
                {
                    printf("pthread_create fail\n");
                    
                }
                    
                }
                //结束播放
                if(myx>700 && myx < 800  && myy>400 && myy <480)
                {
               
                    myx=0;
                    myy=0;
                    system("killall mplayer");
                    biaozhi=1;
                }
              
              
              
              
              
              
          }
         
         
         
            
         
   
        close(fd);
   
}
搜索更多相关主题的帖子: include linux color 开发 
2017-06-01 22:24
快速回复:linux平台在开发板上制作一个简单的登录界面,,loin_in()中当我按下按 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020387 second(s), 11 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved