Skip to content

Commit 430da89

Browse files
committed
Fixing whitespace.
1 parent df04d77 commit 430da89

File tree

1 file changed

+115
-115
lines changed

1 file changed

+115
-115
lines changed

main.c

+115-115
Original file line numberDiff line numberDiff line change
@@ -71,122 +71,122 @@
7171
// ----------------------------------------------------
7272
// function to create a matching dictionary for usage page & usage
7373
static CFMutableDictionaryRef hu_CreateMatchingDictionaryUsagePageUsage( Boolean isDeviceNotElement,
74-
UInt32 inUsagePage,
75-
UInt32 inUsage )
74+
UInt32 inUsagePage,
75+
UInt32 inUsage )
7676
{
77-
// create a dictionary to add usage page / usages to
78-
CFMutableDictionaryRef result = CFDictionaryCreateMutable( kCFAllocatorDefault,
79-
0,
80-
&kCFTypeDictionaryKeyCallBacks,
81-
&kCFTypeDictionaryValueCallBacks );
82-
83-
if ( result ) {
84-
if ( inUsagePage ) {
85-
// Add key for device type to refine the matching dictionary.
86-
CFNumberRef pageCFNumberRef = CFNumberCreate( kCFAllocatorDefault, kCFNumberIntType, &inUsagePage );
87-
88-
if ( pageCFNumberRef ) {
89-
if ( isDeviceNotElement ) {
90-
CFDictionarySetValue( result, CFSTR( kIOHIDDeviceUsagePageKey ), pageCFNumberRef );
91-
} else {
92-
CFDictionarySetValue( result, CFSTR( kIOHIDElementUsagePageKey ), pageCFNumberRef );
93-
}
94-
CFRelease( pageCFNumberRef );
95-
96-
// note: the usage is only valid if the usage page is also defined
97-
if ( inUsage ) {
98-
CFNumberRef usageCFNumberRef = CFNumberCreate( kCFAllocatorDefault, kCFNumberIntType, &inUsage );
99-
100-
if ( usageCFNumberRef ) {
101-
if ( isDeviceNotElement ) {
102-
CFDictionarySetValue( result, CFSTR( kIOHIDDeviceUsageKey ), usageCFNumberRef );
103-
} else {
104-
CFDictionarySetValue( result, CFSTR( kIOHIDElementUsageKey ), usageCFNumberRef );
105-
}
106-
CFRelease( usageCFNumberRef );
107-
} else {
108-
fprintf( stderr, "%s: CFNumberCreate( usage ) failed.", __PRETTY_FUNCTION__ );
109-
}
110-
}
111-
} else {
112-
fprintf( stderr, "%s: CFNumberCreate( usage page ) failed.", __PRETTY_FUNCTION__ );
113-
}
114-
}
115-
} else {
116-
fprintf( stderr, "%s: CFDictionaryCreateMutable failed.", __PRETTY_FUNCTION__ );
117-
}
118-
return result;
119-
} // hu_CreateMatchingDictionaryUsagePageUsage
77+
// create a dictionary to add usage page / usages to
78+
CFMutableDictionaryRef result = CFDictionaryCreateMutable( kCFAllocatorDefault,
79+
0,
80+
&kCFTypeDictionaryKeyCallBacks,
81+
&kCFTypeDictionaryValueCallBacks );
82+
83+
if ( result ) {
84+
if ( inUsagePage ) {
85+
// Add key for device type to refine the matching dictionary.
86+
CFNumberRef pageCFNumberRef = CFNumberCreate( kCFAllocatorDefault, kCFNumberIntType, &inUsagePage );
87+
88+
if ( pageCFNumberRef ) {
89+
if ( isDeviceNotElement ) {
90+
CFDictionarySetValue( result, CFSTR( kIOHIDDeviceUsagePageKey ), pageCFNumberRef );
91+
} else {
92+
CFDictionarySetValue( result, CFSTR( kIOHIDElementUsagePageKey ), pageCFNumberRef );
93+
}
94+
CFRelease( pageCFNumberRef );
95+
96+
// note: the usage is only valid if the usage page is also defined
97+
if ( inUsage ) {
98+
CFNumberRef usageCFNumberRef = CFNumberCreate( kCFAllocatorDefault, kCFNumberIntType, &inUsage );
99+
100+
if ( usageCFNumberRef ) {
101+
if ( isDeviceNotElement ) {
102+
CFDictionarySetValue( result, CFSTR( kIOHIDDeviceUsageKey ), usageCFNumberRef );
103+
} else {
104+
CFDictionarySetValue( result, CFSTR( kIOHIDElementUsageKey ), usageCFNumberRef );
105+
}
106+
CFRelease( usageCFNumberRef );
107+
} else {
108+
fprintf( stderr, "%s: CFNumberCreate( usage ) failed.", __PRETTY_FUNCTION__ );
109+
}
110+
}
111+
} else {
112+
fprintf( stderr, "%s: CFNumberCreate( usage page ) failed.", __PRETTY_FUNCTION__ );
113+
}
114+
}
115+
} else {
116+
fprintf( stderr, "%s: CFDictionaryCreateMutable failed.", __PRETTY_FUNCTION__ );
117+
}
118+
return result;
119+
} // hu_CreateMatchingDictionaryUsagePageUsage
120120

121121
int main( int argc, const char * argv[] )
122122
{
123-
#pragma unused ( argc, argv )
124-
IOHIDDeviceRef * tIOHIDDeviceRefs = nil;
123+
#pragma unused ( argv )
124+
IOHIDDeviceRef * tIOHIDDeviceRefs = nil;
125125

126-
// create a IO HID Manager reference
127-
IOHIDManagerRef tIOHIDManagerRef = IOHIDManagerCreate( kCFAllocatorDefault, kIOHIDOptionsTypeNone );
128-
require( tIOHIDManagerRef, Oops );
129-
130-
// Create a device matching dictionary
131-
CFDictionaryRef matchingCFDictRef = hu_CreateMatchingDictionaryUsagePageUsage( TRUE,
132-
kHIDPage_GenericDesktop,
133-
kHIDUsage_GD_Keyboard );
134-
require( matchingCFDictRef, Oops );
135-
136-
// set the HID device matching dictionary
137-
IOHIDManagerSetDeviceMatching( tIOHIDManagerRef, matchingCFDictRef );
138-
139-
if ( matchingCFDictRef ) {
140-
CFRelease( matchingCFDictRef );
141-
}
142-
143-
// Now open the IO HID Manager reference
144-
IOReturn tIOReturn = IOHIDManagerOpen( tIOHIDManagerRef, kIOHIDOptionsTypeNone );
145-
require_noerr( tIOReturn, Oops );
146-
147-
// and copy out its devices
148-
CFSetRef deviceCFSetRef = IOHIDManagerCopyDevices( tIOHIDManagerRef );
149-
require( deviceCFSetRef, Oops );
150-
151-
// how many devices in the set?
152-
CFIndex deviceIndex, deviceCount = CFSetGetCount( deviceCFSetRef );
153-
154-
// allocate a block of memory to extact the device ref's from the set into
155-
tIOHIDDeviceRefs = malloc( sizeof( IOHIDDeviceRef ) * deviceCount );
156-
if (!tIOHIDDeviceRefs) {
157-
CFRelease(deviceCFSetRef);
158-
deviceCFSetRef = NULL;
159-
goto Oops;
160-
}
161-
162-
// now extract the device ref's from the set
163-
CFSetGetValues( deviceCFSetRef, (const void **) tIOHIDDeviceRefs );
164-
CFRelease(deviceCFSetRef);
165-
deviceCFSetRef = NULL;
166-
167-
// before we get into the device loop we'll setup our element matching dictionary
168-
matchingCFDictRef = hu_CreateMatchingDictionaryUsagePageUsage( FALSE, kHIDPage_LEDs, 0 );
169-
require( matchingCFDictRef, Oops );
170-
171-
int led_mask = 5; // no arguments turn on scrlk and numlk
126+
// create a IO HID Manager reference
127+
IOHIDManagerRef tIOHIDManagerRef = IOHIDManagerCreate( kCFAllocatorDefault, kIOHIDOptionsTypeNone );
128+
require( tIOHIDManagerRef, Oops );
129+
130+
// Create a device matching dictionary
131+
CFDictionaryRef matchingCFDictRef = hu_CreateMatchingDictionaryUsagePageUsage( TRUE,
132+
kHIDPage_GenericDesktop,
133+
kHIDUsage_GD_Keyboard );
134+
require( matchingCFDictRef, Oops );
135+
136+
// set the HID device matching dictionary
137+
IOHIDManagerSetDeviceMatching( tIOHIDManagerRef, matchingCFDictRef );
138+
139+
if ( matchingCFDictRef ) {
140+
CFRelease( matchingCFDictRef );
141+
}
142+
143+
// Now open the IO HID Manager reference
144+
IOReturn tIOReturn = IOHIDManagerOpen( tIOHIDManagerRef, kIOHIDOptionsTypeNone );
145+
require_noerr( tIOReturn, Oops );
146+
147+
// and copy out its devices
148+
CFSetRef deviceCFSetRef = IOHIDManagerCopyDevices( tIOHIDManagerRef );
149+
require( deviceCFSetRef, Oops );
150+
151+
// how many devices in the set?
152+
CFIndex deviceIndex, deviceCount = CFSetGetCount( deviceCFSetRef );
153+
154+
// allocate a block of memory to extact the device ref's from the set into
155+
tIOHIDDeviceRefs = malloc( sizeof( IOHIDDeviceRef ) * deviceCount );
156+
if (!tIOHIDDeviceRefs) {
157+
CFRelease(deviceCFSetRef);
158+
deviceCFSetRef = NULL;
159+
goto Oops;
160+
}
161+
162+
// now extract the device ref's from the set
163+
CFSetGetValues( deviceCFSetRef, (const void **) tIOHIDDeviceRefs );
164+
CFRelease(deviceCFSetRef);
165+
deviceCFSetRef = NULL;
166+
167+
// before we get into the device loop we'll setup our element matching dictionary
168+
matchingCFDictRef = hu_CreateMatchingDictionaryUsagePageUsage( FALSE, kHIDPage_LEDs, 0 );
169+
require( matchingCFDictRef, Oops );
170+
171+
int led_mask = 5; // no arguments turn on scrlk and numlk
172172
if (argc > 1) {
173173
led_mask = 1; // any argument tun on only numlk (and the rest off)
174174
printf("Turning off all but numlk\n");
175175
} else {
176176
printf("Turning on numlk and scrlk\n");
177177
}
178178

179-
Boolean delayFlag = FALSE; // if we find an LED element we'll set this to TRUE
179+
Boolean delayFlag = FALSE; // if we find an LED element we'll set this to TRUE
180180

181181
// printf( "pass = %d.\n", pass );
182182
for ( deviceIndex = 0; deviceIndex < deviceCount; deviceIndex++ ) {
183183

184184
// if this isn't a keyboard device...
185185
if ( !IOHIDDeviceConformsTo( tIOHIDDeviceRefs[deviceIndex], kHIDPage_GenericDesktop, kHIDUsage_GD_Keyboard ) ) {
186-
continue; // ...skip it
186+
continue; // ...skip it
187187
}
188188

189-
// printf( " device = %p.\n", tIOHIDDeviceRefs[deviceIndex] );
189+
// printf( " device = %p.\n", tIOHIDDeviceRefs[deviceIndex] );
190190

191191
// copy all the elements
192192
CFArrayRef elementCFArrayRef = IOHIDDeviceCopyMatchingElements( tIOHIDDeviceRefs[deviceIndex],
@@ -209,14 +209,14 @@ int main( int argc, const char * argv[] )
209209

210210
// if this isn't an LED element...
211211
if ( kHIDPage_LEDs != usagePage ) {
212-
continue; // ...skip it
212+
continue; // ...skip it
213213
}
214214

215215
uint32_t usage = IOHIDElementGetUsage( tIOHIDElementRef );
216216
IOHIDElementType tIOHIDElementType = IOHIDElementGetType( tIOHIDElementRef );
217217

218218
/*
219-
printf( " element = %p (page: %d, usage: %d, type: %d ).\n",
219+
printf( " element = %p (page: %d, usage: %d, type: %d ).\n",
220220
tIOHIDElementRef, usagePage, usage, tIOHIDElementType );
221221
*/
222222

@@ -232,7 +232,7 @@ int main( int argc, const char * argv[] )
232232
device_value /= modCFIndex;
233233

234234
/*
235-
printf( " value = 0x%08lX.\n", tCFIndex );
235+
printf( " value = 0x%08lX.\n", tCFIndex );
236236
*/
237237

238238
uint64_t timestamp = 0; // create the IO HID Value to be sent to this LED element
@@ -242,27 +242,27 @@ int main( int argc, const char * argv[] )
242242
tIOReturn = IOHIDDeviceSetValue( tIOHIDDeviceRefs[deviceIndex], tIOHIDElementRef, tIOHIDValueRef );
243243
CFRelease( tIOHIDValueRef );
244244
require_noerr( tIOReturn, next_element );
245-
delayFlag = TRUE; // set this TRUE so we'll delay before changing our LED values again
245+
delayFlag = TRUE; // set this TRUE so we'll delay before changing our LED values again
246246
}
247-
next_element: ;
247+
next_element: ;
248248
continue;
249249
}
250250
CFRelease( elementCFArrayRef );
251251
next_device: ;
252252
continue;
253253
}
254-
255-
256-
if ( matchingCFDictRef ) {
257-
CFRelease( matchingCFDictRef );
258-
}
259-
Oops: ;
260-
if ( tIOHIDDeviceRefs ) {
261-
free(tIOHIDDeviceRefs);
262-
}
263-
264-
if ( tIOHIDManagerRef ) {
265-
CFRelease( tIOHIDManagerRef );
266-
}
267-
return 0;
254+
255+
256+
if ( matchingCFDictRef ) {
257+
CFRelease( matchingCFDictRef );
258+
}
259+
Oops: ;
260+
if ( tIOHIDDeviceRefs ) {
261+
free(tIOHIDDeviceRefs);
262+
}
263+
264+
if ( tIOHIDManagerRef ) {
265+
CFRelease( tIOHIDManagerRef );
266+
}
267+
return 0;
268268
} /* main */

0 commit comments

Comments
 (0)