|
1 /* |
|
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Declares main application class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef __KEYBOARD_H |
|
20 #define __KEYBOARD_H |
|
21 |
|
22 #include <e32std.h> |
|
23 #include <w32std.h> |
|
24 #include <e32event.h> |
|
25 |
|
26 #include "hidinterfaces.h" |
|
27 #include "hidkeys.h" |
|
28 #include "layoutmgr.h" |
|
29 #include "timeoutnotifier.h" |
|
30 #include <e32msgqueue.h> |
|
31 #include <e32cmn.h> |
|
32 #include "pointmsgqueue.h" |
|
33 #include "bthidsettings.h" |
|
34 |
|
35 class CField; |
|
36 class CHidKeyboardDriver; |
|
37 class CTimeOutTimer; |
|
38 /*! |
|
39 HID keyboard driver class |
|
40 */ |
|
41 class CHidKeyboardDriver : public CHidDriver, public MTimeOutNotifier |
|
42 { |
|
43 |
|
44 private: |
|
45 /*! Initialisation states */ |
|
46 enum TKeyboardDriverState |
|
47 { |
|
48 EUninitialised, /*!< Driver has not been initialised */ |
|
49 EInitialised, /*!< Driver is initialised */ |
|
50 EDisabled |
|
51 /*!< The driver will not respond to interrupt data */ |
|
52 }; |
|
53 |
|
54 // Flags indicating which locking keys are active |
|
55 enum TLockVals |
|
56 { |
|
57 ENumLock = 1, ECapsLock = 2, EScrollLock = 4 |
|
58 }; |
|
59 |
|
60 // The types of keyboard input report fields that we handle: |
|
61 enum TKeyFieldType |
|
62 { |
|
63 EStandardKeys = 0, |
|
64 EModifierKeys = 1, |
|
65 EMediaKeys = 2, |
|
66 EPowerKeys = 3, |
|
67 KNumInputFieldTypes |
|
68 }; |
|
69 |
|
70 // The types of keyboard input report fields that we handle: |
|
71 enum TMouseFieldType |
|
72 { |
|
73 EMouseButtons = 0, |
|
74 EMouseXY = 1, |
|
75 EMouseWheel = 2, |
|
76 EMouseMediaKeys = 3, |
|
77 EMousePowerKeys = 4, |
|
78 KMouseInputFieldTypes |
|
79 }; |
|
80 public: |
|
81 // Constructors and destructor |
|
82 /*! |
|
83 Creates an instantiated CHidKeyboardDriver object. |
|
84 @param aHid The generic HID layer that requested the driver |
|
85 @param aFactory aFactory The factory that created the driver |
|
86 @result A pointer to the instantiated keyboard driver |
|
87 */ |
|
88 static CHidKeyboardDriver* NewL(MDriverAccess* aHid); |
|
89 /*! |
|
90 Creates an instantiated CHidKeyboardDriver object and leaves it on the |
|
91 cleanup stack. |
|
92 @param aHid The generic HID layer that requested the driver |
|
93 @param aFactory aFactory The factory that created the driver |
|
94 @result A pointer to the instantiated keyboard driver |
|
95 */ |
|
96 static CHidKeyboardDriver* NewLC(MDriverAccess* aHid); |
|
97 |
|
98 /*! |
|
99 Stops driver activity, deletes the key repeat and decode objects and closes |
|
100 the window server session before the driver is deleted |
|
101 */ |
|
102 virtual ~CHidKeyboardDriver(); |
|
103 |
|
104 public: |
|
105 // new functions |
|
106 /*! |
|
107 Called by the Generic HID layer to see if the driver can is able to use |
|
108 reports from a newly-connected device |
|
109 @result ETrue The driver can handle the reports |
|
110 @result EFalse The driver cannot handle the reports |
|
111 */ |
|
112 virtual TInt CanHandleReportL(CReportRoot* aReportRoot); |
|
113 |
|
114 /*! |
|
115 Called by the Generic HID layer when a device has been removed, prior to the |
|
116 driver being removed. This allows the driver to notify any applications of |
|
117 disconnection, if required |
|
118 @param aReason The reason for device disconnection |
|
119 */ |
|
120 virtual void Disconnected(TInt aReason); |
|
121 |
|
122 /*! |
|
123 Called by the Generic HID layer when data has been received from the device |
|
124 handled by this driver. |
|
125 @param aChannel The channel on which the data was received (as defined by the |
|
126 transport layer |
|
127 @param aPayload A pointer to the data buffer |
|
128 */ |
|
129 virtual TInt DataIn(CHidTransport::THidChannelType aChannel, |
|
130 const TDesC8& aPayload); |
|
131 |
|
132 /*! |
|
133 Called by the transport layers to inform the generic HID of the success of |
|
134 the last Set... command. |
|
135 @param aConnectionId ID of the device |
|
136 @param aCmdAck Status of the last Set... command |
|
137 */ |
|
138 virtual void CommandResult(TInt aCmdAck); |
|
139 |
|
140 /*! |
|
141 Called after a driver is sucessfully created by the Generic HID, when a |
|
142 device is connected |
|
143 */ |
|
144 virtual void InitialiseL(TInt aConnectionId); |
|
145 |
|
146 /*! |
|
147 Resets the internal state of the driver (any pressed keys are released) and |
|
148 enables the driver |
|
149 */ |
|
150 virtual void StartL(TInt aConnectionId); |
|
151 /*! |
|
152 Cancels all pressed keys and disables the driver (so it will not |
|
153 process interrupt data) |
|
154 */ |
|
155 virtual void Stop(); |
|
156 |
|
157 /** |
|
158 * Return count of supported fields |
|
159 * |
|
160 * @since S60 v5.0 |
|
161 * @return Number of supported fields. |
|
162 */ |
|
163 virtual TInt SupportedFieldCount(); |
|
164 |
|
165 /** |
|
166 * Set input handling registy |
|
167 * |
|
168 * @since S60 v5.0 |
|
169 * @param aHandlingReg a Input handling registry |
|
170 */ |
|
171 virtual void SetInputHandlingReg(CHidInputDataHandlingReg* aHandlingReg); |
|
172 |
|
173 // ---------------------------------------- |
|
174 // Repeat key timer interface: |
|
175 |
|
176 /*! |
|
177 Callback function for the key repeat timer to trigger a repeat key event. |
|
178 */ |
|
179 TInt OnKeyRepeat(); |
|
180 |
|
181 static TInt TimerFiredOnKeyRepeat(TAny* aThis); |
|
182 |
|
183 private: |
|
184 // Constructors |
|
185 |
|
186 // Constructor taking a pointer to the HID layer requesting the driver |
|
187 // instance |
|
188 CHidKeyboardDriver(MDriverAccess* aHid); |
|
189 |
|
190 void ConstructL(); |
|
191 |
|
192 private: |
|
193 // Functions from base classes |
|
194 |
|
195 /** |
|
196 * From MTimeoutNotifier |
|
197 */ |
|
198 void TimerExpired(); |
|
199 private: |
|
200 // New Functions |
|
201 |
|
202 // Called from within DataIn to handle interrupt and control channel data |
|
203 void InterruptData(const TDesC8& aPayload); |
|
204 |
|
205 // Send key down / key up events to the window server: |
|
206 void KeyEvent(TBool aIsKeyDown, TInt aHidKey, TInt aUsagePage); |
|
207 TKeyEvent TKeyEventFromScanCode(TInt aScanCode) const; |
|
208 inline void KeyUp(TInt aHidKey, TInt aUsagePage); |
|
209 inline void KeyDown(TInt aHidKey, TInt aUsagePage); |
|
210 |
|
211 // Handles the states of the modifier keys |
|
212 void UpdateModifiers(TInt aFieldIndex, const TDesC8& aReport); |
|
213 // Handles the states of the XY (mouse up, down, left, right) |
|
214 void UpdateXY(TInt aFieldIndex, const TDesC8& aReport); |
|
215 |
|
216 // Handles the states of the Buttons (left & right button) |
|
217 void UpdateButtons(TInt aFieldIndex, const TDesC8& aReport); |
|
218 |
|
219 // Handles the states of the wheel |
|
220 void UpdateWheel(TInt aFieldIndex, const TDesC8& aReport); |
|
221 |
|
222 // Handle key presses |
|
223 void ProcessKeys(TInt aFieldIndex, const TDesC8& aReport); |
|
224 |
|
225 // Determines whether too many keys have been pressed on the device |
|
226 TBool IsRollover(TInt aFieldIndex, const TDesC8& aReport) const; |
|
227 |
|
228 // Get current modifier state in the format used by TKeyEvent |
|
229 TUint32 KeyEventModifiers() const; |
|
230 |
|
231 // Resets the internal keypress states and sends keyup events if required |
|
232 void CancelKeysForField(TInt aFieldIndex); |
|
233 void CancelAllKeys(); |
|
234 |
|
235 // Determines whether any lock (Caps,Num,scroll) keys are pressed |
|
236 void UpdateLockState(TInt aKey); |
|
237 |
|
238 // Sets the LEDs on the keyboard according to the keyboard state |
|
239 // (Not implemented) |
|
240 void SetKeyboardLeds() const; |
|
241 |
|
242 // Send a key event to the system |
|
243 void SendKeyPress(TUint16 aUnicode, TInt aUsagePage, TInt aScanCode, |
|
244 TBool aIsRepeatingKey); |
|
245 |
|
246 void SendToWindowGroup(const TKeyEvent& aKeyEvent, TEventCode aType); |
|
247 void SendToWindowServer(TKeyEvent aKeyEvent); |
|
248 |
|
249 // Determine which window group a key event should be sent to. |
|
250 // Except for special cases this is the window group with the focus. |
|
251 TInt WindowGroupForKeyEvent(const TKeyEvent& aKeyEvent, TEventCode aType); |
|
252 |
|
253 // Handles the sending of raw events to the phone application instead of key events. |
|
254 void HandleTelephoneAppKeys(TInt aScanCode, TInt aUniCode, |
|
255 TBool aIsKeyDown); |
|
256 |
|
257 // Checks if application launching key combination and launch a corresponding application |
|
258 void HandleApplicationLaunchKeysL(TUint16 aScancodeKey, TBool aIsKeyDown, |
|
259 TUint8 aModifiers); |
|
260 |
|
261 /** |
|
262 * CHidKeyboardDriver::LaunchApplicationL |
|
263 * @param aAppUid Application UID |
|
264 */ |
|
265 void LaunchApplicationL(TInt aAppUid); |
|
266 |
|
267 // Checks if multimedia-key (play,stop,..) and sends to RemCon |
|
268 TBool HandleMultimediaKeys(TUint16 aScancodeKey, TBool aIsKeyDown, |
|
269 TUint8 aModifiers); |
|
270 TBool HandleMultimediaKeysForNokia(TUint16 aScancodeKey, |
|
271 TBool aIsKeyDown, TUint8 aModifiers); |
|
272 TBool HandleMultimediaKeysForStandard(TUint16 aScancodeKey, |
|
273 TBool aIsKeyDown, TUint8 aModifiers); |
|
274 |
|
275 TInt AppMenuId(); |
|
276 TInt PhoneAppId(); |
|
277 TInt IdleAppId(); |
|
278 TBool IsApplicationMenuTopMost(); |
|
279 TBool IsPhoneAppTopMost(); |
|
280 |
|
281 // bitmap for Multimedia key states |
|
282 enum TMmKeyDown |
|
283 { |
|
284 EVolUp = 1, |
|
285 EVolDown = 2, |
|
286 EPlay = 4, |
|
287 EStop = 8, |
|
288 ENext = 16, |
|
289 EPrev = 32 |
|
290 }; |
|
291 |
|
292 void ResetBitmap(TBool aIsKeyDown, TMmKeyDown aBitmapToReset); |
|
293 |
|
294 /** |
|
295 * Send raw key event to window server |
|
296 * @param aScancode key scancode |
|
297 * @param aModifiers modifier |
|
298 * @return Error code |
|
299 */ |
|
300 TInt SendRawEvent(TInt aScancode, TBool aIsKeyDown, TUint aModifier); |
|
301 |
|
302 // ---------------------------------------- |
|
303 |
|
304 static TInt ResetArrayToSize(RArray<TInt>& aArray, TInt aSize); |
|
305 void MoveCursor(const TPoint& aPoint); |
|
306 TInt PostPointer(const TPoint& aPoint); |
|
307 TInt SendButtonEvent(TBool aButtonDown); |
|
308 |
|
309 TBool IsDigitKey(TInt aScanCode); |
|
310 TBool IsSpecialHandleKey(TInt aUniCode); |
|
311 |
|
312 void LaunchApplicationL(const TDesC& aName); |
|
313 private: |
|
314 |
|
315 TKeyboardDriverState iDriverState; |
|
316 |
|
317 // Application UIDs |
|
318 TInt iConnectionId; |
|
319 TInt iAppMenuId; |
|
320 TInt iPhoneAppId; |
|
321 TInt iIdleAppId; |
|
322 |
|
323 // The Generic HID layer |
|
324 MDriverAccess *iGenericHid; |
|
325 |
|
326 // Arrays of keys currently pressed for each field: |
|
327 RArray<TInt> iKeys[KNumInputFieldTypes]; |
|
328 |
|
329 // Pointers to the fields in the report descriptor containing the |
|
330 // various types of key: |
|
331 const CField* iField[KNumInputFieldTypes]; |
|
332 |
|
333 // Pointers to the fields in the report descriptor containing the |
|
334 // various types of key: |
|
335 const CField* iMouseField[KMouseInputFieldTypes]; |
|
336 // Pointer to the field in the report descriptor containing the LEDs: |
|
337 const CField* iLedField; |
|
338 |
|
339 // The current modifier state |
|
340 TUint8 iModifiers; |
|
341 // The current locking key states |
|
342 TUint8 iLockState; |
|
343 //Supported field types count |
|
344 TInt iSupportedFieldCount; |
|
345 |
|
346 // A window server session, so keypresses can be sent to applications: |
|
347 RWsSession iWsSession; |
|
348 |
|
349 // Timer object so the driver can generate repeat keypresses: |
|
350 CPeriodic *iRepeatTimer; |
|
351 |
|
352 // The last keypress event sent to the window server (allows key repeat) |
|
353 TKeyEvent iLastKey; |
|
354 |
|
355 // Layout manager session: |
|
356 RLayoutManager iLayoutMgr; |
|
357 |
|
358 // Settings handler class |
|
359 CBtHidSettings* iSettings; |
|
360 |
|
361 /*! The last keyboard layout selected by the user */ |
|
362 THidKeyboardLayoutId iLastSelectedLayout; |
|
363 |
|
364 // Flag for Multimedia key state |
|
365 TUint8 iMmKeyDown; |
|
366 |
|
367 CHidInputDataHandlingReg* iInputHandlingReg; |
|
368 |
|
369 // This timer stops key repeating after defined time to prevent endless key repeats in error cases. Fix for EMKD-7FBB9H |
|
370 CTimeOutTimer* iRepeatEndTimer; |
|
371 |
|
372 TBool iComboDevice; |
|
373 |
|
374 RMsgQueue<TPointBuffer> iPointBufQueue; |
|
375 TPointBuffer iPointerBuffer; |
|
376 TBool iButtonDown; |
|
377 TBool iButton2Down; |
|
378 }; |
|
379 |
|
380 // ---------------------------------------------------------------------- |
|
381 // Helpers for sending key events: |
|
382 |
|
383 inline void CHidKeyboardDriver::KeyUp(TInt aHidKey, TInt aUsagePage) |
|
384 { |
|
385 KeyEvent(EFalse, aHidKey, aUsagePage); |
|
386 } |
|
387 |
|
388 inline void CHidKeyboardDriver::KeyDown(TInt aHidKey, TInt aUsagePage) |
|
389 { |
|
390 KeyEvent(ETrue, aHidKey, aUsagePage); |
|
391 } |
|
392 |
|
393 // ---------------------------------------------------------------------- |
|
394 |
|
395 #endif |