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

📄 input_rtems.c

📁 神龙卡开发原代码
💻 C
字号:
/*/////////////////////////////////////////////////////////////////////////////// $Header: /bigbig/dungeon/ndc/havana_project/havana/jasper_files/microwindows/src/drivers/input_rtems.c,v 1.1 2003/05/26 12:08:41 crinon Exp $//// Copyright (c) 2000 - Rosimildo da Silva//  // MODULE DESCRIPTION: // This module implements the Microwindows Drivers for systems that implements // the Micro Input Device interface. This driver is not specific in any way// to RTEMS. It could be used with any sustem that implements such interface.//// The skeleton of the drivers were based on standard Microwindows drivers.//// MODIFICATION/HISTORY://// $Log: input_rtems.c,v $// Revision 1.1  2003/05/26 12:08:41  crinon// add gui in havana application//// Revision 1.1  2003/03/20 18:30:55  crinon// jasper gui project//* * 1     5/29/02 1:13p Fabrice// Revision 1.1.1.1  2001/06/21 06:32:41  greg// Microwindows pre8 with patches//// Revision 1.1.1.1  2001/06/05 03:44:01  root// First import of 5/5/2001 Microwindows to CVS/////////////////////////////////////////////////////////////////////////////////*/#include <stdio.h>#include <stdlib.h>#include <fcntl.h>#include <sys/ioctl.h>#include <errno.h>#include <rtems/mw_uid.h>#include "device.h"#include "windef.h"   /* UCHAR */extern int close( int fd ); /* RTEMS does not include close() in stdio.h */#define    SCALE        3    /* default scaling factor for acceleration */#define    THRESH       5    /* default threshhold for acceleration *//* prototypes of the mouse driver */static int      MWMou_Open(MOUSEDEVICE *pmd);static void     MWMou_Close(void);static int      MWMou_GetButtonInfo(void);static void     MWMou_GetDefaultAccel(int *pscale,int *pthresh);static int      MWMou_Read(MWCOORD *dx, MWCOORD *dy, MWCOORD *dz, int *bp);/* prototypes of the Kbd driver */static int     MWKbd_Open(KBDDEVICE *pkd);static void    MWKbd_Close(void);static void    MWKbd_GetModifierInfo(int *modifiers);static int     MWKbd_Read(MWUCHAR *buf, int *modifiers);MOUSEDEVICE mousedev = {    MWMou_Open,    MWMou_Close,    MWMou_GetButtonInfo,    MWMou_GetDefaultAccel,    MWMou_Read,    NULL};KBDDEVICE kbddev = {    MWKbd_Open,    MWKbd_Close,    MWKbd_GetModifierInfo,    MWKbd_Read,    NULL};struct MW_UID_MESSAGE m_kbd = { 0 };struct MW_UID_MESSAGE m_mou = { 0 };static int mou_fd = -1;static int kbd_fd   = -1;static const char *Q_NAME        = "MWQ";#define            Q_MAX_MSGS      128#define            MOUSE_DEVICE    "/dev/mouse"/* Open and register driver */static int open_queue_and_register_driver( int fd ){   int rc;   rc = uid_open_queue( Q_NAME, O_CREAT | O_RDWR, Q_MAX_MSGS );   if( rc )    {      return rc;   }   return uid_register_device( fd, Q_NAME );}/* close and unregister device */static int close_queue_and_unregister_device( int fd ){    uid_unregister_device( fd );    return uid_close_queue();}  /* * Open up the mouse device. */static intMWMou_Open(MOUSEDEVICE *pmd){   int rc;   /* no valid event */   m_mou.type = MV_UID_INVALID;   mou_fd = open( MOUSE_DEVICE, O_NONBLOCK );   /* Open your mouse device here */   rc = open_queue_and_register_driver( mou_fd );   if( rc )      return -1;   return 2;}/* * Close the mouse device. */static voidMWMou_Close(void){   close_queue_and_unregister_device( mou_fd );   close( mou_fd );}/* * Get mouse buttons supported */static intMWMou_GetButtonInfo(void){   return 0;}/* * Get default mouse acceleration settings */static voidMWMou_GetDefaultAccel(int *pscale,int *pthresh){    *pscale = SCALE;    *pthresh = THRESH;}/* * Attempt to read bytes from the mouse and interpret them. * Returns -1 on error, 0 if either no bytes were read or not enough * was read for a complete state, or 1 if the new state was read. * When a new state is read, the current buttons and x and y deltas * are returned.  This routine does not block. */static intMWMou_Read(MWCOORD *dx, MWCOORD *dy, MWCOORD *dz, int *bp){   /* check if a new mouse event has been posted */   if( m_mou.type != MV_UID_INVALID )   {      /* check which return to send up ... */      int rc = ( m_mou.type == MV_UID_REL_POS ) ? 1 : 2;      *bp = m_mou.m.pos.btns;      *dx = m_mou.m.pos.x;      *dy = m_mou.m.pos.y;      *dz = m_mou.m.pos.z;      /* consume event */      m_mou.type = MV_UID_INVALID;      return rc;   }   return 0;}/* * Open the keyboard. */static intMWKbd_Open(KBDDEVICE *pkd){   int rc;   /* no valid event */   m_kbd.type = MV_UID_INVALID;  /* kbd it is already opened */   kbd_fd = fileno( stdin );   /* register kbd driver */   rc = open_queue_and_register_driver( kbd_fd );   if( rc )      return -1;   return 1;}/* * Close the keyboard. */static voidMWKbd_Close(void){}/* * Return the possible modifiers for the keyboard. */static  voidMWKbd_GetModifierInfo(int *modifiers){    *modifiers = 0;      /* no modifiers available */}/* * This reads one keystroke from the keyboard, and the current state of * the mode keys (ALT, SHIFT, CTRL).  Returns -1 on error, 0 if no data * is ready, and 1 if data was read.  This is a non-blocking call. */static intMWKbd_Read(MWUCHAR *buf, int *modifiers){   /* check if new KBD event has been posted */   if( m_kbd.type != MV_UID_INVALID )   {      *buf = (UCHAR)m_kbd.m.kbd.code;/*    *modifiers = m_kbd.m.kbd.modifiers;  */      *modifiers = 0;      /* consume event */      m_kbd.type = MV_UID_INVALID;      return 1;   }    return 0;}

⌨️ 快捷键说明

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