From 031a0af4993e8fad33d49d9c3cfa936a205b7c79 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 27 Oct 2018 06:19:28 +0200 Subject: HeadphoneKey: Only print `NSLog`s in a debug mode Add a new `LogDebug` macro that `NSLog`s when a `DOME_KEY_DEBUG` environment variable is set to "1". This gets rid of the verbose output every time a headphone key is pressed. But it enables you to see it if needed for debugging purposes. --- DomeKey/HeadphoneKey.h | 1 + DomeKey/HeadphoneKey.m | 8 ++++---- DomeKey/log.h | 10 ++++++++++ 3 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 DomeKey/log.h diff --git a/DomeKey/HeadphoneKey.h b/DomeKey/HeadphoneKey.h index be0e62c..618bdd2 100644 --- a/DomeKey/HeadphoneKey.h +++ b/DomeKey/HeadphoneKey.h @@ -10,6 +10,7 @@ #import #import "dome_key_map.h" +#import "log.h" typedef enum KeyPress : BOOL { KeyPressDown = YES, diff --git a/DomeKey/HeadphoneKey.m b/DomeKey/HeadphoneKey.m index 5cf0806..df31fec 100644 --- a/DomeKey/HeadphoneKey.m +++ b/DomeKey/HeadphoneKey.m @@ -56,15 +56,15 @@ if (upOrDown == KeyPressUp) { switch (usageId) { case kHIDUsage_Csmr_PlayOrPause: - NSLog(@"Middle"); + LogDebug(@"Middle"); [self handleDeadKey:HeadphoneButton_Play]; break; case kHIDUsage_Csmr_VolumeIncrement: - NSLog(@"Top"); + LogDebug(@"Top"); [self handleDeadKey:HeadphoneButton_Up]; break; case kHIDUsage_Csmr_VolumeDecrement: - NSLog(@"Bottom"); + LogDebug(@"Bottom"); [self handleDeadKey:HeadphoneButton_Down]; break; } @@ -88,7 +88,7 @@ - (void)runAction { - NSLog(@"%@", _key_buffer); + LogDebug(@"%@", _key_buffer); NSUInteger count = [_key_buffer count]; HeadphoneButton buttons[count]; diff --git a/DomeKey/log.h b/DomeKey/log.h new file mode 100644 index 0000000..7684143 --- /dev/null +++ b/DomeKey/log.h @@ -0,0 +1,10 @@ +#ifndef LOG_H +#define LOG_H + +#define LogDebug(...) \ + if ([[[[NSProcessInfo processInfo] environment] \ + objectForKey:@"DOME_KEY_DEBUG"] isEqualToString:@"1"]) { \ + NSLog(__VA_ARGS__); \ + } + +#endif /* LOG_H */ -- cgit v1.2.3