## 页首HTML代码 ```html

开发板登录返回以及退出设计

IO编程

开发板登录返回以及退出设计

image

/****************************************************************************
 *
 * file name: 2024-05-14_main.c
 * author   : tongyaqi1110@163.com
 * date     : 2024-05-14
 * function : 在LCD上显示并触摸开发板登录返回以及退出设计
 * note     : None
 * CopyRight (c)   2024  tongyaqi1110@163.com   Right Reseverd
 *
 ****************************************************************************/
下面是“基操”代码
    打开LCD屏显示图片和动图/视频
    以及打开触摸屏

int main(int argc, char const *argv[])
{
  // 1.打开LCD   open
  int lcd_fd = open("/dev/fb0", O_RDWR);

  // 2.对LCD进行内存映射  mmap
  lcd_mp = (int *)mmap(NULL, 800 * 480 * 4, PROT_READ | PROT_WRITE, MAP_SHARED, lcd_fd, 0);

  // 3.显示开机动画
  char gif_path[128] = {0};
  for (int i = 0; i < 82; ++i)
  {
    sprintf(gif_path, "./gif/Frame%d.jpg", i); // 构造jpg图片的路径
    read_JPEG_file(gif_path, 0, 0);            // 在LCD上显示
    usleep(1000 * 10);                         // FPS = 50HZ
  }

  read_JPEG_file("hzw.jpg", 0, 0);
  printf("hhh\n");

  // 1.打开触摸屏
  int ts_fd = open("/dev/input/event0", O_RDWR);

  // 2.读取输入设备的信息
  struct input_event ts_event;
  // printf("hello\n");  测试用的
  // int cnt = 0;

  while (1)
  {
    read(ts_fd, &ts_event, sizeof(ts_event));

    // 获取的坐标是等比例缩小过的
    // 3.分析读取的设备信息 (type + code + value)
    if (ts_event.type == EV_ABS) // 说明是触摸屏
    {
      printf("2\n");
      if (ts_event.code == ABS_X) // 说明是X轴
      {
        // cnt++;
        x = ts_event.value * 800 / 1024;
      }
      if (ts_event.code == ABS_Y) // 说明是Y轴
      {
        // cnt++;
        y = ts_event.value * 480 / 600;
      }
     // printf("55\n");  测试用
    }
   // printf("d\n");  测试用
    return 0;
  }

下面为三个"按钮界面"代码

// 登录按钮
    if (x > 194 && x < 283 && y > 371 && y < 419)
    {
      printf("dd\n");

      read_JPEG_file("bird.jpg", 0, 0);
    }
    // 返回按钮
    else if (x > 674 && x < 768 && y > 22 && y < 70)
    {
      read_JPEG_file("hzw.jpg", 0, 0);
      cnt = 0;
    }
    // 退出按钮
    else if (x > 502 && x < 588 && y > 371 && y < 418)
    {
      // 8.关闭LCD
      read_JPEG_file("black.jpg", 0, 0);
      munmap(lcd_mp, 800 * 480 * 4);
      close(lcd_fd);
      close(ts_fd);

      return 0;
    }

posted @ 2024-05-14 22:05  一面小镜子  阅读(13)  评论(0编辑  收藏  举报