【C语言】在LCD(/dev/fb0)上点击触摸屏(/dev/input/event0)切换显示图片

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <strings.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>
#include <linux/input.h>    //输入子系统头文件

#define LCD_SIZE 800*480 //LCD分辨率800px*480x, aRGB像素,4字节,32位
#define IMG_COUNTS 10    //图片数量

/* ***************全局变量**************** */
int lcd_fd;    //LCD设备文件描述符
int ts_fd;    //触摸屏设备文件描述符
unsigned int* lcd_mmp;    //LCD设备文件映射的显存首地址


/* *******************函数声明********************* */
//打开LCD设备文件并映射显存,成功返回0
int open_lcd(void);

//关闭LCD设备文件、撤销显存映射,成功返回0
int close_lcd();

//打开触摸屏设备文件,成功返回0
int open_ts(void);

//关闭触摸屏设备文件,成功返回0
int close_ts(void);

//获取点击触摸屏的坐标(x,y),参数是存储坐标值的数组名,返回存储坐标值的数组首地址
unsigned int* get_position(unsigned int *pos);

//LCD显示某个颜色块,参数是起点的宽度、高度值,色块的宽度、高度,颜色数据
void show_color(int x_start, int y_start, int width, int height, unsigned int color);

//LCD显示图片
int show_pic_full(const char *img_path);

/* ******************主函数******************** */
int main(int argc, const char *argv[])
{
    //1、打开LCD、触摸屏文件
    open_lcd();
    open_ts();
    
    
    //2、获取点击触摸屏的坐标pos_x, pos_y
    unsigned int abs[2]={0};    //保存点击坐标位置,abs[0]是X轴的值,abs[0]是Y轴的值
    printf("abs=%p\n",abs);

    //3、判断坐标的pos_x,在LCD上刷图显示
    //点击左边,x值小于400,图片路径数组往前一个,点击右边,x值大于400,图片路径数组往后一个
    //图片路径数组
    const char *imgs_path[IMG_COUNTS]={"/zyb/1014/1.ebm",
                                "/zyb/1014/2.ebm",
                         

  • 7
    点赞
  • 46
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值