1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23/*
24cc -g -o /tmp/evstest EVSTests.c -framework IOKit
25*/
26
27#include <drivers/event_status_driver.h>
28#include <mach/thread_switch.h>
29#include <assert.h>
30
31int
32main(int argc, char **argv)
33{
34	NXEventHandle		hdl;
35        NXEventSystemDevice	info[ 20 ];
36	unsigned int		size;
37	double			dbl1, dbl2;
38	int			i, j;
39	NXKeyMapping		mapping;
40	int			mapSize;
41	char *			map;
42	unsigned int *		pmap;
43	NXMouseScaling		scaling;
44
45	hdl = NXOpenEventStatus();
46	assert( hdl );
47
48	size = sizeof( info) / sizeof( int);
49	assert( NXEventSystemInfo(hdl, NX_EVS_DEVICE_INFO, info, &size ));
50	size = size * sizeof( int) / sizeof( info[0]);
51	printf("%d devices\n", size);
52	for( i = 0; i < size; i++) {
53		printf("%d : dev_type = %d, interface = %d, "
54			"id = %d, interface_addr = %d\n", i,
55		info[ i ].dev_type, info[ i ].interface,
56		info[ i ].id, info[ i ].interface_addr );
57	}
58
59	dbl1 = NXKeyRepeatInterval(hdl);
60	printf("NXKeyRepeatInterval = %f\n", dbl1);
61	NXSetKeyRepeatInterval( hdl, 1.0 / 4 );
62	dbl2 = NXKeyRepeatInterval(hdl);
63	printf("now NXKeyRepeatInterval = %f\n", dbl2);
64
65	dbl1 = NXKeyRepeatThreshold(hdl);
66	printf("NXKeyRepeatThreshold = %f\n", dbl1);
67	NXSetKeyRepeatThreshold( hdl, 1.0 );
68	dbl2 = NXKeyRepeatThreshold(hdl);
69	printf("now NXKeyRepeatThreshold = %f\n", dbl2);
70
71	assert( KERN_SUCCESS == IOHIDGetMouseAcceleration(hdl, &dbl1));
72	printf("IOHIDGetMouseAcceleration = %f\n", dbl1);
73
74	assert( KERN_SUCCESS == IOHIDSetMouseAcceleration(hdl, 1.0));
75	assert( KERN_SUCCESS == IOHIDGetMouseAcceleration(hdl, &dbl1));
76	printf("now IOHIDGetMouseAcceleration = %f\n", dbl1);
77
78	NXGetMouseScaling(hdl, &scaling);
79	printf("Scaling[ %d ]: ", scaling.numScaleLevels);
80	for( i = 0; i < scaling.numScaleLevels; i++)
81	    printf("(%d,%d), ",
82		scaling.scaleThresholds[i], scaling.scaleFactors[i]);
83	printf("\n");
84	assert( KERN_SUCCESS == IOHIDSetMouseAcceleration(hdl, 0.3));
85	NXSetMouseScaling(hdl, &scaling);
86	printf("Scaling[ %d ]: ", scaling.numScaleLevels);
87	for( i = 0; i < scaling.numScaleLevels; i++)
88	    printf("(%d,%d), ",
89		scaling.scaleThresholds[i], scaling.scaleFactors[i]);
90	printf("\n");
91	assert( KERN_SUCCESS == IOHIDGetMouseAcceleration(hdl, &dbl1));
92	printf("now IOHIDGetMouseAcceleration = %f\n", dbl1);
93
94
95	printf("NXKeyRepeatThreshold = %f\n", dbl1);
96
97	printf("NXAutoDimThreshold = %f\n", NXAutoDimThreshold(hdl));
98	printf("NXAutoDimTime = %f\n", NXAutoDimTime(hdl));
99	printf("NXIdleTime = %f\n", NXIdleTime(hdl));
100	printf("NXAutoDimState = %d\n", NXAutoDimState(hdl));
101	printf("NXAutoDimBrightness = %f\n", NXAutoDimBrightness(hdl));
102	printf("NXScreenBrightness = %f\n", NXScreenBrightness(hdl));
103
104	NXSetAutoDimThreshold( hdl, 200.0 );
105//        NXSetAutoDimState( hdl, 1 );
106        NXSetAutoDimBrightness( hdl, 0.5 );
107        NXSetScreenBrightness( hdl, 0.7 );
108
109	printf("now NXAutoDimThreshold = %f\n", NXAutoDimThreshold(hdl));
110	printf("NXAutoDimTime = %f\n", NXAutoDimTime(hdl));
111	printf("NXIdleTime = %f\n", NXIdleTime(hdl));
112	printf("NXAutoDimState = %d\n", NXAutoDimState(hdl));
113	printf("NXAutoDimBrightness = %f\n", NXAutoDimBrightness(hdl));
114	printf("NXScreenBrightness = %f\n", NXScreenBrightness(hdl));
115
116	mapSize = NXKeyMappingLength(hdl);
117	map = (char *) malloc( mapSize );
118	mapping.mapping = map;
119	mapping.size = mapSize;
120	assert( &mapping == NXGetKeyMapping(hdl, &mapping));
121
122	pmap = (unsigned int *) map;
123if(0)	while ((((char *)pmap) - map) < mapSize) {
124	    printf("%04x: ", ((char *)pmap) - map);
125	    for( j = 0; j < 8; j++ ) {
126		printf("%08x ", *pmap++);
127		if( (((char *)pmap) - map) >= mapSize)
128		    break;
129	    }
130	    printf("\n");
131	}
132
133	map[ 0x32 ] = 0x62;	// a == b
134	assert( &mapping == NXSetKeyMapping(hdl, &mapping));
135
136	printf("sleeping...\n");
137	thread_switch( 0, SWITCH_OPTION_WAIT, 10 * 1000 );
138
139	NXResetKeyboard(hdl);
140	NXResetMouse(hdl);
141
142	return( 0 );
143}
144