|
|
1.1 root 1: /*
2: * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3: *
4: * @APPLE_LICENSE_HEADER_START@
5: *
6: * The contents of this file constitute Original Code as defined in and
7: * are subject to the Apple Public Source License Version 1.1 (the
8: * "License"). You may not use this file except in compliance with the
9: * License. Please obtain a copy of the License at
10: * http://www.apple.com/publicsource and read it before using this file.
11: *
12: * This Original Code and all software distributed under the License are
13: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17: * License for the specific language governing rights and limitations
18: * under the License.
19: *
20: * @APPLE_LICENSE_HEADER_END@
21: */
22: #include "AppleADBButtons.h"
23: #include <IOKit/IOLib.h>
24: #include <IOKit/pwr_mgt/IOPM.h>
25: #include <IOKit/hidsystem/IOHIDTypes.h>
26: #include <IOKit/hidsystem/IOHIDParameter.h>
27:
28: #define super IOHIKeyboard
29: OSDefineMetaClassAndStructors(AppleADBButtons,IOHIKeyboard)
30:
31: bool displayWranglerFound( OSObject *, void *, IOService * );
32: void button_data ( IOService * us, UInt8 adbCommand, IOByteCount length, UInt8 * data );
33: void asyncFunc ( void * );
34:
35: // **********************************************************************************
36: // start
37: //
38: // **********************************************************************************
39: bool AppleADBButtons::start ( IOService * theNub )
40: {
41: int i;
42:
43: for ( i = 0; i < kMax_registrations; i++ ) {
44: keycodes[i] = kNullKey;
45: downHandlers[i] = NULL;
46: }
47:
48: if( !super::start(theNub))
49: return false;
50:
51: adbDevice = (IOADBDevice *)theNub;
52: if( !adbDevice->seizeForClient(this, button_data) ) {
53: IOLog("%s: Seize failed\n", getName());
54: return false;
55: }
56: registerService();
57:
58: addNotification( gIOPublishNotification,serviceMatching("IODisplayWrangler"), // look for the display wrangler
59: (IOServiceNotificationHandler)displayWranglerFound, this, 0 );
60:
61: return true;
62: }
63:
64:
65: // **********************************************************************************
66: // displayWranglerFound
67: //
68: // The Display Wrangler has appeared. We will be calling its
69: // ActivityTickle method when there is user activity.
70: // **********************************************************************************
71: bool displayWranglerFound( OSObject * us, void * ref, IOService * yourDevice )
72: {
73: if ( yourDevice != NULL ) {
74: ((AppleADBButtons *)us)->displayManager = yourDevice;
75: }
76: return true;
77: }
78:
79: UInt32 AppleADBButtons::interfaceID()
80: {
81: return NX_EVS_DEVICE_INTERFACE_ADB;
82: }
83:
84: UInt32 AppleADBButtons::deviceType()
85: {
86: return adbDevice->handlerID();
87: }
88:
89: // **********************************************************************************
90: // registerForButton
91: //
92: // Clients call here, specifying a button and a routine to call when that
93: // button is pressed or released.
94: // **********************************************************************************
95: IOReturn AppleADBButtons::registerForButton ( unsigned int keycode, IOService * registrant, button_handler handler, bool down )
96: {
97: int i;
98:
99: for ( i = 0; i < kMax_registrations; i++ ) {
100: if ( keycodes[i] == kNullKey ) {
101: if ( down ) {
102: registrants[i] = registrant;
103: downHandlers[i] = handler;
104: keycodes[i] = keycode;
105: break;
106: }
107: }
108: }
109: return kIOReturnSuccess;
110: }
111:
112: // **********************************************************************************
113: // button_data
114: //
115: // **********************************************************************************
116: void button_data ( IOService * us, UInt8 adbCommand, IOByteCount length, UInt8 * data )
117: {
118: ((AppleADBButtons *)us)->packet(data,length,adbCommand);
119: }
120:
121:
122: // **********************************************************************************
123: // packet
124: //
125: // **********************************************************************************
126: IOReturn AppleADBButtons::packet (UInt8 * data, IOByteCount, UInt8 adbCommand )
127: {
128: unsigned int keycode;
129: bool down;
130:
131: keycode = *data;
132: down = ((keycode & 0x80) == 0);
133: keycode &= 0x7f;
134:
135: dispatchButtonEvent(keycode,down);
136:
137: keycode = *(data + 1);
138: if( keycode != 0xff ) {
139: down = ((keycode & 0x80) == 0);
140: keycode &= 0x7f;
141: dispatchButtonEvent(keycode,down);
142: }
143:
144: if ( displayManager != NULL ) { // if there is a display manager, tell
145: displayManager->activityTickle(kIOPMSuperclassPolicy1); // it there is user activity
146: }
147:
148: return kIOReturnSuccess;
149: }
150:
151:
152: // **********************************************************************************
153: // dispatchButtonEvent
154: //
155: // Look for any registered handlers for this button and notify them.
156: // **********************************************************************************
157: void AppleADBButtons::dispatchButtonEvent (unsigned int keycode, bool down )
158: {
159: int i;
160: AbsoluteTime now;
161:
162: clock_get_uptime(&now);
163:
164: for ( i = 0; i < kMax_registrations; i++ ) {
165: if ( keycodes[i] == keycode ) {
166: if ( down ) {
167: if (downHandlers[i] != NULL ) {
168: thread_call_func((thread_call_func_t)downHandlers[i],
169: (thread_call_param_t)registrants[i],
170: true);
171: }
172: }
173: }
174: }
175:
176: dispatchKeyboardEvent(keycode, down, now);
177: }
178:
179: const unsigned char *AppleADBButtons::defaultKeymapOfLength(UInt32 *length)
180: {
181: static const unsigned char appleADBButtonsKeyMap[] = {
182: 0x00, 0x00, // chars
183: 0x00, // no modifier keys
184: 0x00, // no defs
185: 0x00, // no seqs
186: 0x05, // 5 special keys
187: NX_KEYTYPE_SOUND_UP, kVolume_up,
188: NX_KEYTYPE_SOUND_DOWN, kVolume_down,
189: NX_KEYTYPE_MUTE, kMute,
190: NX_KEYTYPE_BRIGHTNESS_UP, kBrightness_up,
191: NX_KEYTYPE_BRIGHTNESS_DOWN, kBrightness_down
192: };
193:
194: *length = sizeof(appleADBButtonsKeyMap);
195:
196: return appleADBButtonsKeyMap;
197: }
198:
199: IOReturn AppleADBButtons::setParamProperties(OSDictionary *dict)
200: {
201: if (dict->getObject(kIOHIDKeyMappingKey)) {
202: dict->removeObject(kIOHIDKeyMappingKey);
203: // Do we also need to release this object? - hopefully not
204: }
205:
206: return super::setParamProperties(dict);
207: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.