summaryrefslogtreecommitdiff
path: root/cpukit/libmisc/fb/mw_print.c
blob: 1d226b7d0f437a0818e20437b42b22ad77685ba4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/**
 * @file
 *
 * @brief MicroWindows Print
 * @ingroup libmisc_fb_mw Input Devices for MicroWindows
 */

/*
 *  COPYRIGHT (c) 1989-2011.
 *  On-Line Applications Research Corporation (OAR).
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *  http://www.rtems.org/license/LICENSE.
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <stdio.h>

#include <rtems/mw_uid.h>
#include <rtems/printer.h>

static const char *uid_buttons(
  unsigned short  btns,
  char           *buffer,
  size_t          max
)
{
  snprintf(
    buffer,
    max,
    "LEFT=%s CENTER=%s RIGHT=%s",
    ((btns & MV_BUTTON_LEFT) ? "down" : "up"),
    ((btns & MV_BUTTON_CENTER) ? "down" : "up"),
    ((btns & MV_BUTTON_RIGHT) ? "down" : "up")
  );
  return buffer;
}

void uid_print_message(
  struct MW_UID_MESSAGE *uid
)
{
  rtems_printer printer;
  rtems_print_printer_printk(&printer);
  uid_print_message_with_plugin( &printer, uid );
}

void uid_print_message_with_plugin(
  const rtems_printer   *printer,
  struct MW_UID_MESSAGE *uid
)
{
  char buttons[80];

  switch (uid->type) {
    case MV_UID_INVALID:
      rtems_printf( printer, "MV_UID_INVALID\n" );
      break;
    case MV_UID_REL_POS:
      rtems_printf(
        printer,
        "MV_UID_REL_POS - %s x=%d y=%d z=%d\n",
        uid_buttons( uid->m.pos.btns, buttons, sizeof(buttons)),
        uid->m.pos.x,    /* x location */
        uid->m.pos.y,    /* y location */
        uid->m.pos.z     /* z location, 0 for 2D */
      );
      break;
    case MV_UID_ABS_POS:
      rtems_printf(
        printer,
        "MV_UID_ABS_POS - %s x=%d y=%d z=%d\n",
        uid_buttons( uid->m.pos.btns, buttons, sizeof(buttons)),
        uid->m.pos.x,    /* x location */
        uid->m.pos.y,    /* y location */
        uid->m.pos.z     /* z location, 0 for 2D */
      );
      break;
    case MV_UID_KBD:
      rtems_printf( printer,
        "MV_UID_KBD - code=0x%04x modifiers=0x%02x mode=0x%02x\n",
        uid->m.kbd.code,        /* keycode or scancode        */
        uid->m.kbd.modifiers,   /* key modifiers              */
        uid->m.kbd.mode         /* current Kbd mode           */
      );
      break;
   case MV_UID_TIMER:
      rtems_printf( printer, "MV_UID_TIMER\n" );
      break;
    default:
      rtems_printf( printer, "Invalid device type\n" );
      break;
  }

}