1 /* 2 * Common keypad client functionality for input event generation. 3 * 4 * (c) 2018 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA 20 */ 21 22 #pragma once 23 24 #include <l4/devices/keypad.h> 25 #include <l4/devices/keypad-client.h> 26 27 #include <pthread.h> 28 #include <pthread-l4.h> 29 30 #include <l4/re/event_enums.h> 31 32 #include <stdint.h> 33 34 /* Input event and handler. */ 35 36 typedef struct 37 { 38 enum L4Re_events_ev type; 39 int code; 40 int value; 41 } Input_event; 42 43 typedef void (*Input_handler)(Input_event, void *); 44 45 46 47 #ifdef __cplusplus 48 49 #include <l4/re/dataspace> 50 #include <l4/re/env> 51 52 /* Client object to provide input event access. */ 53 54 class Input_keypad_client 55 { 56 /* Memory and keypad access capabilities. */ 57 58 L4::Cap<L4Re::Dataspace> _mem; 59 L4::Cap<Keypad_device_interface> _keypad_server; 60 61 /* Keypad layout details. */ 62 63 Keypad *_keypad; 64 65 /* Keypad memory. */ 66 67 void *_keymem = 0, *_keymem_previous = 0; 68 69 /* Input framework integration. */ 70 71 Input_handler _handler = 0; 72 73 /* Thread details. */ 74 75 pthread_t _pthread; 76 void *_priv; 77 78 /* Initialisation functions. */ 79 80 void init_memory(); 81 void init_keypad(); 82 void init_keypad_data(); 83 void release_keypad_data(); 84 85 /* Activity methods. */ 86 87 static void *scan_mainloop(void *data); 88 void scan_keypad(); 89 90 public: 91 explicit Input_keypad_client(Keypad *keypad) : _keypad(keypad) 92 { 93 init_memory(); 94 init_keypad(); 95 init_keypad_data(); 96 } 97 98 ~Input_keypad_client() 99 { 100 release_keypad_data(); 101 } 102 103 /* Thread initialisation. */ 104 105 void attach(Input_handler handler, void *priv); 106 }; 107 108 #endif