⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcd16207.c

📁 uclinux 的lcd16207_example
💻 C
字号:
/*
 *  ioctl.c - the process to use ioctl's to control the kernel module
 *
 *  Until now we could have used cat for input and output.  But now
 *  we need to do ioctl's, which require writing our own process.
 */

/* 
 * device specifics, such as ioctl numbers and the
 * major device file. 
 */
#include "lcd_16207.h"

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>		/* open */
#include <unistd.h>		/* exit */
#include <sys/ioctl.h>		/* ioctl */

void lcd_delay(int delay);

/* 
 * Functions for the ioctl calls 
 */

//set message to display
ioctl_set_msg(int file_desc, char *message)
{
  int ret_val;
  
  ret_val = ioctl(file_desc, IOCTL_SET_MSG, message);
  
  if (ret_val < 0) {
    printf("ioctl_set_msg failed:%d\n", ret_val);
    exit(-1);
  }
}
// get message of display
ioctl_get_msg(int file_desc, char *message)
{
  int ret_val;
  
  /* 
   * Warning - this is dangerous because we don't tell
   * the kernel how far it's allowed to write, so it
   * might overflow the buffer. In a real production
   * program, we would have used two ioctls - one to tell
   * the kernel the buffer length and another to give
   * it the buffer to fill
   */
  ret_val = ioctl(file_desc, IOCTL_GET_MSG, message);
  
  if (ret_val < 0) {
    printf("ioctl_get_msg failed:%d\n", ret_val);
    exit(-1);
  }
  //printf("get_msg message:%s\n", message);
}

//not tested - todo
ioctl_get_nth_byte(int file_desc)
{
  int i;
  char c;
  
  printf("get_nth_byte message:");
  
  i = 0;
  do {
    c = ioctl(file_desc, IOCTL_GET_NTH_BYTE, i++);
    
    if (c < 0) {
      printf
	("ioctl_get_nth_byte failed at the %d'th byte:\n",
	 i);
      exit(-1);
    }
    
    putchar(c);
  } while (c != 0);
  putchar('\n');
}

/* 
 * Main - Call the ioctl functions 
 */
int main(int argc, char **argv, char **envp)
{
  int i, j, file_desc, ret_val, info;
  char *msg = argv[1];
  
  info = 1;

  file_desc = open(DEVICE_FILE_NAME, 0);
  if (file_desc < 0) {
    printf("Can't open device file: %s\n", DEVICE_FILE_NAME);
    exit(-1);
  }

  char msg32[33];
  if (strlen(argv[1]) > 1 && strlen(argv[1]) < 32) 
    {
      strcpy(msg32, argv[1]);
        for(i=strlen(argv[1]);i<32;i++)
	{
	  msg32[i]=(char)0x20;
	}
   }
  else
    {
      strncpy(msg32, argv[1], 32);
    }
  msg32[32]='\0';
  //printf("Input string:%s\n", msg32);

  //	ioctl_get_nth_byte(file_desc);
  if (info)
    printf("msg32:%s:\n", "12345678901234567890123456789012");
  
  if (info)
    printf("msg32:%s:\n", msg32);
  ioctl_set_msg(file_desc, msg32);
  lcd_delay(50);

  char msg32R[33];
  char mRead[33];
  msg32R[32]='\0';
  strncpy(msg32R,msg32,32);

  for(i=0;i<32;i++)
    {
      strncpy(msg32,msg32R+1,31);
      strncpy(msg32+31,msg32R,1);
      strncpy(msg32R,msg32,32);
      if (info) 
	printf("msg32:%s:\n", msg32);
      ioctl_set_msg(file_desc, msg32);
      ioctl_get_msg(file_desc, mRead);
      if (info) 
	printf("mRead:%s:\n", mRead);
      lcd_delay(50);
    }
  
  close(file_desc);
  return 0;
}

  //delay of display
void lcd_delay(int delay)
{
  int j;  
  for (j=0;j<delay;j++)
    {
      usleep(1000);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -