OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [MW_0_8_9PRE7/] [mw/] [src/] [rtems/] [mw_uid_test.cc] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 673 markom
/*
2
*/
3
 
4
#include <stdio.h>
5
#include <stdlib.h>
6
#include <errno.h>
7
#include <sys/ioctl.h>
8
#include <fcntl.h>
9
 
10
#include <rtems/mw_uid.h>
11
#include <rtems/kd.h>
12
 
13
static const char *Q_NAME       = "MWQ";
14
#define            Q_MAX_MSGS   128
15
 
16
 
17
/*
18
 * "Select() routine called by the MicroWindows framework to receive events
19
 * from the input devices.
20
 */
21
void GsSelect(void)
22
{
23
  struct MW_UID_MESSAGE m;
24
  int rc;
25
 
26
  /* let's make sure that the type is invalid */
27
  m.type = MV_UID_INVALID;
28
 
29
  /* wait up to 100 milisecons for events */
30
  rc = uid_read_message( &m, 100 );
31
 
32
  /* return if timed-out or something went wrong */
33
  if( rc < 0 )
34
  {
35
     if( errno != ETIMEDOUT )
36
        printf( " rc= %d, errno=%d\n", rc, errno );
37
     return;
38
  }
39
  /* let's pass the event up to microwindows */
40
  switch( m.type )
41
  {
42
    /* Mouse or Touch Screen event */
43
    case MV_UID_REL_POS:
44
    case MV_UID_ABS_POS:
45
        printf( "Mouse: btns=%X, dx=%d, dy=%d, dz=%d\n",
46
                  m.m.pos.btns, m.m.pos.x, m.m.pos.y, m.m.pos.z );
47
        break;
48
 
49
 
50
    /* KBD event */
51
    case MV_UID_KBD:
52
        printf( "Kbd: code=%X, modifiers=%X, mode=%d\n",
53
                 (unsigned char )m.m.kbd.code, m.m.kbd.modifiers, m.m.kbd.mode );
54
        break;
55
 
56
    /* micro-windows does nothing with those.. */
57
    case MV_UID_TIMER:
58
    case MV_UID_INVALID:
59
    default:
60
       ;
61
  }
62
}
63
 
64
extern "C" int close( int );
65
extern "C" int rtems_main(int argc, char **argv)
66
{
67
  int status;
68
  printf( "Starting untar file.\n" );
69
  struct MW_UID_MESSAGE m;
70
 
71
  int rc;
72
  /* if this is the first time around, create the message queue */
73
  rc = uid_open_queue( Q_NAME, O_CREAT | O_RDWR, Q_MAX_MSGS );
74
 
75
  printf( "Open QUEUE=%X\n", rc );
76
 
77
  int mouse_fd = open( "/dev/mouse", O_NONBLOCK );
78
  uid_register_device( mouse_fd, Q_NAME );
79
 
80
  /* kbd it is already opened */
81
  int kbd_fd = fileno( stdin );
82
  uid_register_device( kbd_fd, Q_NAME );
83
 
84
  int old_mode = 0;
85
  /* set keyboard to scanmode */
86
  rc = uid_set_kbd_mode( kbd_fd, MV_KEY_MODE_SCANCODE, &old_mode );
87
  printf( "Kbd OldMode=%X, rc=%d\n", old_mode, rc );
88
  while( TRUE )
89
  {
90
     GsSelect();
91
  }
92
  uid_unregister_device( kbd_fd  );
93
  uid_unregister_device( mouse_fd );
94
  rc = uid_close_queue();
95
  printf( "Close QUEUE=%X\n", rc );
96
 
97
  close( mouse_fd );
98
 
99
  fprintf(stdout, "About to leave main()\n" );
100
  return 0;
101
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.