171bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine/* Copyright (C) 2010 The Android Open Source Project 271bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine** 371bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine** This software is licensed under the terms of the GNU General Public 471bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine** License version 2, as published by the Free Software Foundation, and 571bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine** may be copied, distributed, and modified under those terms. 671bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine** 771bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine** This program is distributed in the hope that it will be useful, 871bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine** but WITHOUT ANY WARRANTY; without even the implied warranty of 971bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1071bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine** GNU General Public License for more details. 1171bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine*/ 1271bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine 1371bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine#include <stdio.h> 1471bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine#include "android/utils/debug.h" 1571bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine#include "android/keycode-array.h" 1671bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine#include "user-events.h" 1771bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine 1871bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkinevoid 1971bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkineandroid_keycodes_add_key_event( AKeycodeBuffer* keycodes, 2071bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine unsigned code, 2171bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine unsigned down ) 2271bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine{ 2371bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine if (code != 0 && keycodes->keycode_count < MAX_KEYCODES) { 2471bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine keycodes->keycodes[(int)keycodes->keycode_count++] = 2571bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine ( (code & 0x1ff) | (down ? 0x200 : 0) ); 2671bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine } 2771bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine} 2871bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine 2971bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkinevoid 3071bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkineandroid_keycodes_flush(AKeycodeBuffer* keycodes) 3171bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine{ 3271bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine if (keycodes->keycode_count > 0) { 3371bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine if (VERBOSE_CHECK(keys)) { 3471bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine int nn; 3571bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine printf(">> KEY" ); 3671bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine for (nn = 0; nn < keycodes->keycode_count; nn++) { 3771bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine int code = keycodes->keycodes[nn]; 3871bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine printf(" [0x%03x,%s]", (code & 0x1ff), (code & 0x200) ? "down" : " up " ); 3971bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine } 4071bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine printf( "\n" ); 4171bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine } 4271bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine user_event_keycodes(keycodes->keycodes, keycodes->keycode_count); 4371bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine keycodes->keycode_count = 0; 4471bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine } 4571bb14f826775867d16e7d382cfdc48e6ca46ccbVladimir Chtchetkine} 46