forked from EMlyDinEsHMG/AsusNBFnKeys
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FnKeysHIKeyboardDevice.cpp
105 lines (84 loc) · 2.51 KB
/
FnKeysHIKeyboardDevice.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
* Copyright (c) 2012 - 2013 EMlyDinEsH(OSXLatitude). All rights reserved.
*
*
* FnKeysHIKeyboardDevice.cpp
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "FnKeysHIKeyboardDevice.h"
#include "AsusNBFnKeys.h"
#define DEBUG_START 0
#if DEBUG_START
#define DEBUG_LOG(fmt, args...) IOLog(fmt, ## args)
#else
#define DEBUG_LOG(fmt, args...)
#endif
#define super IOService
OSDefineMetaClassAndStructors(FnKeysHIKeyboardDevice, IOService);
bool FnKeysHIKeyboardDevice::attach( IOService * provider )
{
if( !super::attach(provider) ) return false;
FnKeys = OSDynamicCast(AsusNBFnKeys ,provider);
if (NULL == FnKeys)
return false;
FnKeys->retain();
return true;
}
void FnKeysHIKeyboardDevice::detach( IOService * provider )
{
FnKeys->release();
FnKeys = 0;
super::detach(provider);
}
void FnKeysHIKeyboardDevice::keyPressed(int code)
{
int i = 0, out;
do
{
if (keyMap[i].description == NULL && keyMap[i].in == 0 && keyMap[i].out == 0xFF)
{
DEBUG_LOG("%s: Unknown key %02X i=%d\n",this->getName(), code, i);
break;
}
if (keyMap[i].in == code)
{
DEBUG_LOG("%s: Key Pressed %02X i=%d\n",this->getName(), code, i);
out = keyMap[i].out;
messageClients(kIOACPIMessageDeviceNotification, &out);
break;
}
i++;
}
while (true);
}
void FnKeysHIKeyboardDevice::setKeyMap(const FnKeysKeyMap *_keyMap)
{
int i = 0;
keyMap = _keyMap;
OSDictionary *dict = OSDictionary::withCapacity(10);
DEBUG_LOG("%s: Setting key %02X i=%d\n",this->getName(), keyMap[i].in, i);
do
{
if (keyMap[i].description == NULL && keyMap[i].in == 0 && keyMap[i].out == 0xFF)
break;
DEBUG_LOG("%s: Setting key %02X i=%d\n",this->getName(), keyMap[i].in, i);
dict->setObject(keyMap[i].description, OSNumber::withNumber(keyMap[i].in,8));
i++;
}
while (true);
setProperty("KeyMap", dict);
}