Home | History | Annotate | Download | only in android
      1 /* Copyright (C) 2010 The Android Open Source Project
      2 **
      3 ** This software is licensed under the terms of the GNU General Public
      4 ** License version 2, as published by the Free Software Foundation, and
      5 ** may be copied, distributed, and modified under those terms.
      6 **
      7 ** This program is distributed in the hope that it will be useful,
      8 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
      9 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     10 ** GNU General Public License for more details.
     11 */
     12 
     13 #include <stdio.h>
     14 #include "android/utils/debug.h"
     15 #include "android/keycode-array.h"
     16 #include "user-events.h"
     17 
     18 void
     19 android_keycodes_add_key_event( AKeycodeBuffer* keycodes,
     20                                 unsigned       code,
     21                                 unsigned       down )
     22 {
     23     if (code != 0 && keycodes->keycode_count < MAX_KEYCODES) {
     24         keycodes->keycodes[(int)keycodes->keycode_count++] =
     25                 ( (code & 0x1ff) | (down ? 0x200 : 0) );
     26     }
     27 }
     28 
     29 void
     30 android_keycodes_flush(AKeycodeBuffer* keycodes)
     31 {
     32     if (keycodes->keycode_count > 0) {
     33         if (VERBOSE_CHECK(keys)) {
     34             int  nn;
     35             printf(">> KEY" );
     36             for (nn = 0; nn < keycodes->keycode_count; nn++) {
     37                 int  code = keycodes->keycodes[nn];
     38                 printf(" [0x%03x,%s]", (code & 0x1ff), (code & 0x200) ? "down" : " up " );
     39             }
     40             printf( "\n" );
     41         }
     42         user_event_keycodes(keycodes->keycodes, keycodes->keycode_count);
     43         keycodes->keycode_count = 0;
     44     }
     45 }
     46