From: Joe Wreschnig Date: Sun, 3 Mar 2013 20:42:59 +0000 (+0100) Subject: Big rename part 1: 'action' to 'input'. X-Git-Tag: version-1.0~51 X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=commitdiff_plain;h=f864d363128de19fc6591b77ae9226b34166d715 Big rename part 1: 'action' to 'input'. --- diff --git a/ApplicationController.h b/ApplicationController.h index dc513ae..5dae0cc 100644 --- a/ApplicationController.h +++ b/ApplicationController.h @@ -6,7 +6,7 @@ // Copyright 2009 University of Otago. All rights reserved. // -@class JoystickController; +@class NJInputController; @class TargetController; @class ConfigsController; @@ -18,7 +18,7 @@ IBOutlet NSMenu *dockMenuBase; } -@property (nonatomic, strong) IBOutlet JoystickController *jsController; +@property (nonatomic, strong) IBOutlet NJInputController *jsController; @property (nonatomic, strong) IBOutlet TargetController *targetController; @property (nonatomic, strong) IBOutlet ConfigsController *configsController; diff --git a/ApplicationController.m b/ApplicationController.m index 1acc692..bc7c468 100644 --- a/ApplicationController.m +++ b/ApplicationController.m @@ -9,7 +9,7 @@ #import "Config.h" #import "ConfigsController.h" -#import "JoystickController.h" +#import "NJInputController.h" #import "TargetController.h" #import "NJEvents.h" diff --git a/Config.h b/Config.h index 606529d..a2ba55b 100644 --- a/Config.h +++ b/Config.h @@ -7,7 +7,7 @@ // @class Target; -@class JSAction; +@class NJInput; @interface Config : NSObject @@ -15,8 +15,8 @@ @property (nonatomic, readonly) NSMutableDictionary *entries; - (id)initWithName:(NSString *)name; -- (Target *)objectForKeyedSubscript:(JSAction *)action; -- (void)setObject:(Target *)target forKeyedSubscript:(JSAction *)action; +- (Target *)objectForKeyedSubscript:(NJInput *)input; +- (void)setObject:(Target *)target forKeyedSubscript:(NJInput *)input; - (NSDictionary *)serialize; @end diff --git a/Config.m b/Config.m index 046ccc2..1897734 100644 --- a/Config.m +++ b/Config.m @@ -7,7 +7,7 @@ #import "Config.h" -#import "JSAction.h" +#import "NJInput.h" @implementation Config @@ -19,16 +19,16 @@ return self; } -- (Target *)objectForKeyedSubscript:(JSAction *)action { - return action ? _entries[action.uid] : nil; +- (Target *)objectForKeyedSubscript:(NJInput *)input { + return input ? _entries[input.uid] : nil; } -- (void)setObject:(Target *)target forKeyedSubscript:(JSAction *)action { - if (action) { +- (void)setObject:(Target *)target forKeyedSubscript:(NJInput *)input { + if (input) { if (target) - _entries[action.uid] = target; + _entries[input.uid] = target; else - [_entries removeObjectForKey:action.uid]; + [_entries removeObjectForKey:input.uid]; } } diff --git a/English.lproj/MainMenu.xib b/English.lproj/MainMenu.xib index 6e87fb0..e1e7aa1 100644 --- a/English.lproj/MainMenu.xib +++ b/English.lproj/MainMenu.xib @@ -409,7 +409,7 @@ {640, 300} - + 256 @@ -433,8 +433,7 @@ 256 {200, 298} - - + YES NO YES @@ -533,7 +532,6 @@ {{1, 1}, {200, 298}} - @@ -544,7 +542,6 @@ -2147483392 {{1, 1}, {8, 298}} - NO @@ -556,7 +553,6 @@ -2147483392 {{-100, -100}, {473, 15}} - NO 1 @@ -567,8 +563,7 @@ {202, 300} - - + 150034 @@ -581,7 +576,6 @@ {202, 300} - NSView @@ -594,7 +588,6 @@ 265 {{227, 123}, {180, 24}} - _NS:9 YES @@ -631,7 +624,6 @@ 265 {{227, 55}, {180, 24}} - _NS:9 YES @@ -663,7 +655,6 @@ 265 {{227, 89}, {180, 24}} - _NS:9 YES @@ -696,7 +687,6 @@ 265 {{229, 190}, {176, 24}} - _NS:9 NJKeyInputField @@ -706,7 +696,6 @@ 265 {{226, 156}, {182, 26}} - YES @@ -739,7 +728,6 @@ 268 {{20, 16}, {201, 236}} - NO 7 @@ -884,7 +872,6 @@ 266 {{0, 269}, {429, 17}} - YES @@ -908,7 +895,6 @@ 10 {{12, 258}, {405, 5}} - {0, 0} @@ -935,21 +921,17 @@ {{211, 0}, {429, 300}} - NSView {640, 300} - YES {640, 300} - - {{0, 0}, {1440, 878}} @@ -959,7 +941,7 @@ YES - + 256 @@ -975,7 +957,6 @@ 256 {320, 418} - YES NO @@ -1035,7 +1016,6 @@ {{1, 1}, {320, 418}} - @@ -1046,7 +1026,6 @@ -2147483392 {{306, 1}, {15, 403}} - NO @@ -1058,7 +1037,6 @@ -2147483392 {{1, 404}, {305, 15}} - NO 1 @@ -1069,7 +1047,6 @@ {{0, 34}, {322, 420}} - 133682 @@ -1085,7 +1062,6 @@ 260 {{10, 4}, {39, 28}} - YES @@ -1112,7 +1088,6 @@ 260 {{57, 4}, {39, 28}} - YES 603979776 @@ -1135,8 +1110,6 @@ {322, 454} - - NSView @@ -1158,7 +1131,7 @@ ConfigsController - JoystickController + NJInputController TargetController diff --git a/Enjoyable.xcodeproj/project.pbxproj b/Enjoyable.xcodeproj/project.pbxproj index e75f56c..5b21e99 100644 --- a/Enjoyable.xcodeproj/project.pbxproj +++ b/Enjoyable.xcodeproj/project.pbxproj @@ -18,16 +18,16 @@ D549CA4C0FBB441B00BC8203 /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = D549CA4B0FBB441B00BC8203 /* Credits.rtf */; }; D5617A360FAEB74000928B3A /* ConfigsController.m in Sources */ = {isa = PBXBuildFile; fileRef = D5617A350FAEB74000928B3A /* ConfigsController.m */; }; D5617A390FAEBA1800928B3A /* Config.m in Sources */ = {isa = PBXBuildFile; fileRef = D5617A380FAEBA1800928B3A /* Config.m */; }; - D5617D1A0FAF568100928B3A /* JSActionButton.m in Sources */ = {isa = PBXBuildFile; fileRef = D5617D190FAF568100928B3A /* JSActionButton.m */; }; - D5617D260FAF579300928B3A /* JSActionHat.m in Sources */ = {isa = PBXBuildFile; fileRef = D5617D250FAF579300928B3A /* JSActionHat.m */; }; - D5617D2B0FAF579A00928B3A /* JSActionAnalog.m in Sources */ = {isa = PBXBuildFile; fileRef = D5617D2A0FAF579A00928B3A /* JSActionAnalog.m */; }; + D5617D1A0FAF568100928B3A /* NJInputButton.m in Sources */ = {isa = PBXBuildFile; fileRef = D5617D190FAF568100928B3A /* NJInputButton.m */; }; + D5617D260FAF579300928B3A /* NJInputHat.m in Sources */ = {isa = PBXBuildFile; fileRef = D5617D250FAF579300928B3A /* NJInputHat.m */; }; + D5617D2B0FAF579A00928B3A /* NJInputAnalog.m in Sources */ = {isa = PBXBuildFile; fileRef = D5617D2A0FAF579A00928B3A /* NJInputAnalog.m */; }; D5617FD60FAFD06000928B3A /* Target.m in Sources */ = {isa = PBXBuildFile; fileRef = D5617FD50FAFD06000928B3A /* Target.m */; }; D5617FD90FAFD1E600928B3A /* TargetKeyboard.m in Sources */ = {isa = PBXBuildFile; fileRef = D5617FD80FAFD1E600928B3A /* TargetKeyboard.m */; }; D5617FE40FAFD7B000928B3A /* TargetController.m in Sources */ = {isa = PBXBuildFile; fileRef = D5617FE30FAFD7B000928B3A /* TargetController.m */; }; D5617FE70FAFDB5800928B3A /* NJKeyInputField.m in Sources */ = {isa = PBXBuildFile; fileRef = D5617FE60FAFDB5800928B3A /* NJKeyInputField.m */; }; - D594BE860FAE6219007A85F2 /* Joystick.m in Sources */ = {isa = PBXBuildFile; fileRef = D594BE850FAE6219007A85F2 /* Joystick.m */; }; - D594BE8A0FAE64AD007A85F2 /* JSAction.m in Sources */ = {isa = PBXBuildFile; fileRef = D594BE890FAE64AD007A85F2 /* JSAction.m */; }; - D594BEF90FAE6FF2007A85F2 /* JoystickController.m in Sources */ = {isa = PBXBuildFile; fileRef = D594BEF80FAE6FF2007A85F2 /* JoystickController.m */; }; + D594BE860FAE6219007A85F2 /* NJDevice.m in Sources */ = {isa = PBXBuildFile; fileRef = D594BE850FAE6219007A85F2 /* NJDevice.m */; }; + D594BE8A0FAE64AD007A85F2 /* NJInput.m in Sources */ = {isa = PBXBuildFile; fileRef = D594BE890FAE64AD007A85F2 /* NJInput.m */; }; + D594BEF90FAE6FF2007A85F2 /* NJInputController.m in Sources */ = {isa = PBXBuildFile; fileRef = D594BEF80FAE6FF2007A85F2 /* NJInputController.m */; }; D594BF000FAE7397007A85F2 /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D594BEFF0FAE7397007A85F2 /* IOKit.framework */; }; D594BF830FAE9661007A85F2 /* ApplicationController.m in Sources */ = {isa = PBXBuildFile; fileRef = D594BF820FAE9661007A85F2 /* ApplicationController.m */; }; D5F809710FB093400006A4DE /* TargetConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = D5F809700FB093400006A4DE /* TargetConfig.m */; }; @@ -60,12 +60,12 @@ D5617A350FAEB74000928B3A /* ConfigsController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ConfigsController.m; sourceTree = ""; }; D5617A370FAEBA1800928B3A /* Config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Config.h; sourceTree = ""; }; D5617A380FAEBA1800928B3A /* Config.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Config.m; sourceTree = ""; }; - D5617D180FAF568100928B3A /* JSActionButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSActionButton.h; sourceTree = ""; }; - D5617D190FAF568100928B3A /* JSActionButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JSActionButton.m; sourceTree = ""; }; - D5617D240FAF579300928B3A /* JSActionHat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSActionHat.h; sourceTree = ""; }; - D5617D250FAF579300928B3A /* JSActionHat.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JSActionHat.m; sourceTree = ""; }; - D5617D290FAF579A00928B3A /* JSActionAnalog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSActionAnalog.h; sourceTree = ""; }; - D5617D2A0FAF579A00928B3A /* JSActionAnalog.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JSActionAnalog.m; sourceTree = ""; }; + D5617D180FAF568100928B3A /* NJInputButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NJInputButton.h; sourceTree = ""; }; + D5617D190FAF568100928B3A /* NJInputButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NJInputButton.m; sourceTree = ""; }; + D5617D240FAF579300928B3A /* NJInputHat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NJInputHat.h; sourceTree = ""; }; + D5617D250FAF579300928B3A /* NJInputHat.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NJInputHat.m; sourceTree = ""; }; + D5617D290FAF579A00928B3A /* NJInputAnalog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NJInputAnalog.h; sourceTree = ""; }; + D5617D2A0FAF579A00928B3A /* NJInputAnalog.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NJInputAnalog.m; sourceTree = ""; }; D5617FD40FAFD06000928B3A /* Target.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Target.h; sourceTree = ""; }; D5617FD50FAFD06000928B3A /* Target.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Target.m; sourceTree = ""; }; D5617FD70FAFD1E600928B3A /* TargetKeyboard.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TargetKeyboard.h; sourceTree = ""; }; @@ -74,12 +74,12 @@ D5617FE30FAFD7B000928B3A /* TargetController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TargetController.m; sourceTree = ""; }; D5617FE50FAFDB5800928B3A /* NJKeyInputField.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NJKeyInputField.h; sourceTree = ""; }; D5617FE60FAFDB5800928B3A /* NJKeyInputField.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NJKeyInputField.m; sourceTree = ""; }; - D594BE840FAE6219007A85F2 /* Joystick.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Joystick.h; sourceTree = ""; }; - D594BE850FAE6219007A85F2 /* Joystick.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Joystick.m; sourceTree = ""; }; - D594BE880FAE64AD007A85F2 /* JSAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSAction.h; sourceTree = ""; }; - D594BE890FAE64AD007A85F2 /* JSAction.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JSAction.m; sourceTree = ""; }; - D594BEF70FAE6FF2007A85F2 /* JoystickController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JoystickController.h; sourceTree = ""; }; - D594BEF80FAE6FF2007A85F2 /* JoystickController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JoystickController.m; sourceTree = ""; }; + D594BE840FAE6219007A85F2 /* NJDevice.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NJDevice.h; sourceTree = ""; }; + D594BE850FAE6219007A85F2 /* NJDevice.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NJDevice.m; sourceTree = ""; }; + D594BE880FAE64AD007A85F2 /* NJInput.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NJInput.h; sourceTree = ""; }; + D594BE890FAE64AD007A85F2 /* NJInput.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NJInput.m; sourceTree = ""; }; + D594BEF70FAE6FF2007A85F2 /* NJInputController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NJInputController.h; sourceTree = ""; }; + D594BEF80FAE6FF2007A85F2 /* NJInputController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NJInputController.m; sourceTree = ""; }; D594BEFF0FAE7397007A85F2 /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = /System/Library/Frameworks/IOKit.framework; sourceTree = ""; }; D594BF810FAE9661007A85F2 /* ApplicationController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ApplicationController.h; sourceTree = ""; }; D594BF820FAE9661007A85F2 /* ApplicationController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ApplicationController.m; sourceTree = ""; }; @@ -89,7 +89,7 @@ EE1D7C9116E01E7000B000EB /* NSView+FirstResponder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSView+FirstResponder.m"; sourceTree = ""; }; EE1D7C9416E0ECCF00B000EB /* NSError+Description.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSError+Description.h"; sourceTree = ""; }; EE1D7C9516E0ECCF00B000EB /* NSError+Description.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSError+Description.m"; sourceTree = ""; }; - EEF86B7316E2241000674B87 /* NJActionPathElement.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NJActionPathElement.h; sourceTree = ""; }; + EEF86B7316E2241000674B87 /* NJInputPathElement.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NJInputPathElement.h; sourceTree = ""; }; EEF86B7416E298CD00674B87 /* NJEvents.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NJEvents.h; sourceTree = ""; }; /* End PBXFileReference section */ @@ -109,18 +109,18 @@ 080E96DDFE201D6D7F000001 /* Classes */ = { isa = PBXGroup; children = ( - D5617D290FAF579A00928B3A /* JSActionAnalog.h */, - D5617D2A0FAF579A00928B3A /* JSActionAnalog.m */, - D594BE840FAE6219007A85F2 /* Joystick.h */, - D594BE850FAE6219007A85F2 /* Joystick.m */, - D594BE880FAE64AD007A85F2 /* JSAction.h */, - D594BE890FAE64AD007A85F2 /* JSAction.m */, - D5617D240FAF579300928B3A /* JSActionHat.h */, - D5617D250FAF579300928B3A /* JSActionHat.m */, - D5617D180FAF568100928B3A /* JSActionButton.h */, - D5617D190FAF568100928B3A /* JSActionButton.m */, - D594BEF70FAE6FF2007A85F2 /* JoystickController.h */, - D594BEF80FAE6FF2007A85F2 /* JoystickController.m */, + D5617D290FAF579A00928B3A /* NJInputAnalog.h */, + D5617D2A0FAF579A00928B3A /* NJInputAnalog.m */, + D594BE840FAE6219007A85F2 /* NJDevice.h */, + D594BE850FAE6219007A85F2 /* NJDevice.m */, + D594BE880FAE64AD007A85F2 /* NJInput.h */, + D594BE890FAE64AD007A85F2 /* NJInput.m */, + D5617D240FAF579300928B3A /* NJInputHat.h */, + D5617D250FAF579300928B3A /* NJInputHat.m */, + D5617D180FAF568100928B3A /* NJInputButton.h */, + D5617D190FAF568100928B3A /* NJInputButton.m */, + D594BEF70FAE6FF2007A85F2 /* NJInputController.h */, + D594BEF80FAE6FF2007A85F2 /* NJInputController.m */, D594BF810FAE9661007A85F2 /* ApplicationController.h */, D594BF820FAE9661007A85F2 /* ApplicationController.m */, D5617A340FAEB74000928B3A /* ConfigsController.h */, @@ -145,7 +145,7 @@ 8BEFAD9B15C46BFF00823AEC /* TargetMouseScroll.m */, 8BEFAD9E15C476DC00823AEC /* TargetToggleMouseScope.h */, 8BEFAD9F15C476DC00823AEC /* TargetToggleMouseScope.m */, - EEF86B7316E2241000674B87 /* NJActionPathElement.h */, + EEF86B7316E2241000674B87 /* NJInputPathElement.h */, EEF86B7416E298CD00674B87 /* NJEvents.h */, ); name = Classes; @@ -291,15 +291,15 @@ buildActionMask = 2147483647; files = ( 8D11072D0486CEB800E47090 /* main.m in Sources */, - D594BE860FAE6219007A85F2 /* Joystick.m in Sources */, - D594BE8A0FAE64AD007A85F2 /* JSAction.m in Sources */, - D594BEF90FAE6FF2007A85F2 /* JoystickController.m in Sources */, + D594BE860FAE6219007A85F2 /* NJDevice.m in Sources */, + D594BE8A0FAE64AD007A85F2 /* NJInput.m in Sources */, + D594BEF90FAE6FF2007A85F2 /* NJInputController.m in Sources */, D594BF830FAE9661007A85F2 /* ApplicationController.m in Sources */, D5617A360FAEB74000928B3A /* ConfigsController.m in Sources */, D5617A390FAEBA1800928B3A /* Config.m in Sources */, - D5617D1A0FAF568100928B3A /* JSActionButton.m in Sources */, - D5617D260FAF579300928B3A /* JSActionHat.m in Sources */, - D5617D2B0FAF579A00928B3A /* JSActionAnalog.m in Sources */, + D5617D1A0FAF568100928B3A /* NJInputButton.m in Sources */, + D5617D260FAF579300928B3A /* NJInputHat.m in Sources */, + D5617D2B0FAF579A00928B3A /* NJInputAnalog.m in Sources */, D5617FD60FAFD06000928B3A /* Target.m in Sources */, D5617FD90FAFD1E600928B3A /* TargetKeyboard.m in Sources */, D5617FE40FAFD7B000928B3A /* TargetController.m in Sources */, diff --git a/JSAction.h b/JSAction.h deleted file mode 100644 index dc00a8d..0000000 --- a/JSAction.h +++ /dev/null @@ -1,26 +0,0 @@ -// -// JSAction.h -// Enjoy -// -// Created by Sam McCall on 4/05/09. -// Copyright 2009 University of Otago. All rights reserved. -// - -#import "NJActionPathElement.h" - -@interface JSAction : NSObject - -@property (nonatomic, assign) IOHIDElementCookie cookie; -@property (nonatomic, copy) NSArray *children; -@property (nonatomic, weak) id base; -@property (nonatomic, copy) NSString *name; -@property (nonatomic, assign) BOOL active; -@property (nonatomic, readonly) float magnitude; -@property (readonly) NSString *uid; - -- (id)initWithName:(NSString *)newName base:(id )newBase; - -- (void)notifyEvent:(IOHIDValueRef)value; -- (id)findSubActionForValue:(IOHIDValueRef)value; - -@end diff --git a/JSAction.m b/JSAction.m deleted file mode 100644 index 1cdbeb2..0000000 --- a/JSAction.m +++ /dev/null @@ -1,36 +0,0 @@ -// -// JSAction.m -// Enjoy -// -// Created by Sam McCall on 4/05/09. -// - -#import "JSAction.h" - -@implementation JSAction - -- (id)initWithName:(NSString *)newName base:(id )newBase { - if ((self = [super init])) { - self.name = newName; - self.base = newBase; - } - return self; -} - -- (id)findSubActionForValue:(IOHIDValueRef)value { - return NULL; -} - -- (NSString *)uid { - return [NSString stringWithFormat:@"%@~%@", [_base uid], _name]; -} - -- (void)notifyEvent:(IOHIDValueRef)value { - [self doesNotRecognizeSelector:_cmd]; -} - -- (float)magnitude { - return 0.f; -} - -@end diff --git a/JSActionAnalog.h b/JSActionAnalog.h deleted file mode 100644 index deaf3a5..0000000 --- a/JSActionAnalog.h +++ /dev/null @@ -1,17 +0,0 @@ -// -// JSActionAnalog.h -// Enjoy -// -// Created by Sam McCall on 5/05/09. -// Copyright 2009 University of Otago. All rights reserved. -// - -#import - -#import "JSAction.h" - -@interface JSActionAnalog : JSAction - -- (id)initWithIndex:(int)index rawMin:(long)rawMin rawMax:(long)rawMax; - -@end diff --git a/JSActionAnalog.m b/JSActionAnalog.m deleted file mode 100644 index 9c98f21..0000000 --- a/JSActionAnalog.m +++ /dev/null @@ -1,53 +0,0 @@ -// -// JSActionAnalog.m -// Enjoy -// -// Created by Sam McCall on 5/05/09. -// - -#define DEAD_ZONE 0.3 - -#import "JSActionAnalog.h" - -static float normalize(long p, long min, long max) { - return 2 * (p - min) / (float)(max - min) - 1; -} - -@implementation JSActionAnalog { - float magnitude; - long rawMin; - long rawMax; -} - -- (id)initWithIndex:(int)index rawMin:(long)rawMin_ rawMax:(long)rawMax_ { - if ((self = [super init])) { - self.name = [[NSString alloc] initWithFormat: @"Axis %d", index]; - self.children = @[[[JSAction alloc] initWithName:@"Low" base:self], - [[JSAction alloc] initWithName:@"High" base:self]]; - rawMax = rawMax_; - rawMin = rawMin_; - } - return self; -} - -- (id)findSubActionForValue:(IOHIDValueRef)value { - float mag = normalize(IOHIDValueGetIntegerValue(value), rawMin, rawMax); - if (mag < -DEAD_ZONE) - return self.children[0]; - else if (mag > DEAD_ZONE) - return self.children[1]; - else - return nil; -} - -- (void)notifyEvent:(IOHIDValueRef)value { - magnitude = normalize(IOHIDValueGetIntegerValue(value), rawMin, rawMax); - [self.children[0] setActive:magnitude < -DEAD_ZONE]; - [self.children[1] setActive:magnitude > DEAD_ZONE]; -} - -- (float)magnitude { - return magnitude; -} - -@end diff --git a/JSActionButton.h b/JSActionButton.h deleted file mode 100644 index 8a4bdc6..0000000 --- a/JSActionButton.h +++ /dev/null @@ -1,15 +0,0 @@ -// -// JSActionButton.h -// Enjoy -// -// Created by Sam McCall on 5/05/09. -// Copyright 2009 University of Otago. All rights reserved. -// - -#import "JSAction.h" - -@interface JSActionButton : JSAction - -- (id)initWithName:(NSString *)name idx:(int)idx max:(long)max; - -@end diff --git a/JSActionButton.m b/JSActionButton.m deleted file mode 100644 index 7d2572a..0000000 --- a/JSActionButton.m +++ /dev/null @@ -1,33 +0,0 @@ -// -// JSActionButton.m -// Enjoy -// -// Created by Sam McCall on 5/05/09. -// - -#import "JSActionButton.h" - -@implementation JSActionButton { - long _max; -} - -- (id)initWithName:(NSString *)name idx:(int)idx max:(long)max { - if ((self = [super init])) { - _max = max; - if (name.length) - self.name = [NSString stringWithFormat:@"Button %d - %@", idx, name]; - else - self.name = [NSString stringWithFormat:@"Button %d", idx]; - } - return self; -} - -- (id)findSubActionForValue:(IOHIDValueRef)val { - return (IOHIDValueGetIntegerValue(val) == _max) ? self : nil; -} - -- (void)notifyEvent:(IOHIDValueRef)value { - self.active = IOHIDValueGetIntegerValue(value) == _max; -} - -@end diff --git a/JSActionHat.h b/JSActionHat.h deleted file mode 100644 index 7c9ffce..0000000 --- a/JSActionHat.h +++ /dev/null @@ -1,15 +0,0 @@ -// -// JSActionHat.h -// Enjoy -// -// Created by Sam McCall on 5/05/09. -// Copyright 2009 University of Otago. All rights reserved. -// - -#import "JSAction.h" - -@interface JSActionHat : JSAction - -- (id)initWithIndex:(int)index; - -@end diff --git a/JSActionHat.m b/JSActionHat.m deleted file mode 100644 index 2cac39c..0000000 --- a/JSActionHat.m +++ /dev/null @@ -1,96 +0,0 @@ -// -// JSActionHat.m -// Enjoy -// -// Created by Sam McCall on 5/05/09. -// - -#import "JSActionHat.h" - -static BOOL active_eightway[36] = { - NO, NO, NO, NO , // center - YES, NO, NO, NO , // N - YES, NO, NO, YES, // NE - NO, NO, NO, YES, // E - NO, YES, NO, YES, // SE - NO, YES, NO, NO , // S - NO, YES, YES, NO , // SW - NO, NO, YES, NO , // W - YES, NO, YES, NO , // NW -}; - -static BOOL active_fourway[20] = { - NO, NO, NO, NO , // center - YES, NO, NO, NO , // N - NO, NO, NO, YES, // E - NO, YES, NO, NO , // S - NO, NO, YES, NO , // W -}; - -@implementation JSActionHat - -- (id)initWithIndex:(int)index { - if ((self = [super init])) { - self.children = @[[[JSAction alloc] initWithName:@"Up" base:self], - [[JSAction alloc] initWithName:@"Down" base:self], - [[JSAction alloc] initWithName:@"Left" base:self], - [[JSAction alloc] initWithName:@"Right" base:self]]; - self.name = [NSString stringWithFormat:@"Hat Switch %d", index]; - } - return self; -} - -- (id)findSubActionForValue:(IOHIDValueRef)value { - long parsed = IOHIDValueGetIntegerValue(value); - switch (IOHIDElementGetLogicalMax(IOHIDValueGetElement(value))) { - case 7: // 8-way switch, 0-7. - switch (parsed) { - case 0: return self.children[0]; - case 4: return self.children[1]; - case 6: return self.children[2]; - case 2: return self.children[3]; - default: return nil; - } - case 8: // 8-way switch, 1-8 (neutral 0). - switch (parsed) { - case 1: return self.children[0]; - case 5: return self.children[1]; - case 7: return self.children[2]; - case 3: return self.children[3]; - default: return nil; - } - case 3: // 4-way switch, 0-3. - switch (parsed) { - case 0: return self.children[0]; - case 2: return self.children[1]; - case 3: return self.children[2]; - case 1: return self.children[3]; - default: return nil; - } - case 4: // 4-way switch, 1-4 (neutral 0). - switch (parsed) { - case 1: return self.children[0]; - case 3: return self.children[1]; - case 4: return self.children[2]; - case 2: return self.children[3]; - default: return nil; - } - default: - return nil; - } -} - -- (void)notifyEvent:(IOHIDValueRef)value { - long parsed = IOHIDValueGetIntegerValue(value); - long size = IOHIDElementGetLogicalMax(IOHIDValueGetElement(value)); - // Skip first row in table if 0 is not neutral. - if (size & 1) { - parsed++; - size++; - } - BOOL *activechildren = (size == 8) ? active_eightway : active_fourway; - for (int i = 0; i < 4; i++) - [self.children[i] setActive:activechildren[parsed * 4 + i]]; -} - -@end diff --git a/Joystick.h b/Joystick.h deleted file mode 100644 index e5566f1..0000000 --- a/Joystick.h +++ /dev/null @@ -1,26 +0,0 @@ -// -// Joystick.h -// Enjoy -// -// Created by Sam McCall on 4/05/09. -// Copyright 2009 University of Otago. All rights reserved. -// - -#import "NJActionPathElement.h" - -@class JSAction; - -@interface Joystick : NSObject - -@property (nonatomic, assign) int index; -@property (nonatomic, copy) NSString *productName; -@property (nonatomic, assign) IOHIDDeviceRef device; -@property (nonatomic, copy) NSArray *children; -@property (nonatomic, readonly) NSString *name; -@property (readonly) NSString *uid; - -- (id)initWithDevice:(IOHIDDeviceRef)device; -- (JSAction *)handlerForEvent:(IOHIDValueRef)value; -- (JSAction *)actionForEvent:(IOHIDValueRef)value; - -@end diff --git a/Joystick.m b/Joystick.m deleted file mode 100644 index 4753caf..0000000 --- a/Joystick.m +++ /dev/null @@ -1,109 +0,0 @@ -// -// Joystick.m -// Enjoy -// -// Created by Sam McCall on 4/05/09. -// - -#import "Joystick.h" - -#import "JSAction.h" -#import "JSActionAnalog.h" -#import "JSActionButton.h" -#import "JSActionHat.h" - -static NSArray *ActionsForElement(IOHIDDeviceRef device, id base) { - CFArrayRef elements = IOHIDDeviceCopyMatchingElements(device, NULL, kIOHIDOptionsTypeNone); - NSMutableArray *children = [NSMutableArray arrayWithCapacity:CFArrayGetCount(elements)]; - - int buttons = 0; - int axes = 0; - int hats = 0; - - for (int i = 0; i < CFArrayGetCount(elements); i++) { - IOHIDElementRef element = (IOHIDElementRef)CFArrayGetValueAtIndex(elements, i); - int type = IOHIDElementGetType(element); - unsigned usage = IOHIDElementGetUsage(element); - unsigned usagePage = IOHIDElementGetUsagePage(element); - long max = IOHIDElementGetPhysicalMax(element); - long min = IOHIDElementGetPhysicalMin(element); - CFStringRef elName = IOHIDElementGetName(element); - - JSAction *action = nil; - - if (!(type == kIOHIDElementTypeInput_Misc - || type == kIOHIDElementTypeInput_Axis - || type == kIOHIDElementTypeInput_Button)) - continue; - - if (max - min == 1 || usagePage == kHIDPage_Button || type == kIOHIDElementTypeInput_Button) { - action = [[JSActionButton alloc] initWithName:(__bridge NSString *)elName - idx:++buttons - max:max]; - } else if (usage == kHIDUsage_GD_Hatswitch) { - action = [[JSActionHat alloc] initWithIndex:++hats]; - } else if (usage >= kHIDUsage_GD_X && usage <= kHIDUsage_GD_Rz) { - action = [[JSActionAnalog alloc] initWithIndex:++axes - rawMin:min - rawMax:max]; - } else { - continue; - } - - // TODO(jfw): Should be moved into better constructors. - action.base = base; - action.cookie = IOHIDElementGetCookie(element); - [children addObject:action]; - } - - CFRelease(elements); - return children; -} - -@implementation Joystick { - int vendorId; - int productId; -} - -- (id)initWithDevice:(IOHIDDeviceRef)dev { - if ((self = [super init])) { - self.device = dev; - self.productName = (__bridge NSString *)IOHIDDeviceGetProperty(dev, CFSTR(kIOHIDProductKey)); - vendorId = [(__bridge NSNumber *)IOHIDDeviceGetProperty(dev, CFSTR(kIOHIDVendorIDKey)) intValue]; - productId = [(__bridge NSNumber *)IOHIDDeviceGetProperty(dev, CFSTR(kIOHIDProductIDKey)) intValue]; - self.children = ActionsForElement(dev, self); - } - return self; -} - -- (NSString *)name { - return [NSString stringWithFormat:@"%@ #%d", _productName, _index]; -} - -- (id)base { - return nil; -} - -- (NSString *)uid { - return [NSString stringWithFormat: @"%d:%d:%d", vendorId, productId, _index]; -} - -- (JSAction *)findActionByCookie:(IOHIDElementCookie)cookie { - for (JSAction *child in _children) - if (child.cookie == cookie) - return child; - return nil; -} - -- (JSAction *)handlerForEvent:(IOHIDValueRef)value { - JSAction *mainAction = [self actionForEvent:value]; - return [mainAction findSubActionForValue:value]; -} - -- (JSAction *)actionForEvent:(IOHIDValueRef)value { - IOHIDElementRef elt = IOHIDValueGetElement(value); - IOHIDElementCookie cookie = IOHIDElementGetCookie(elt); - return [self findActionByCookie:cookie]; -} - -@end diff --git a/JoystickController.h b/JoystickController.h deleted file mode 100644 index d56f932..0000000 --- a/JoystickController.h +++ /dev/null @@ -1,28 +0,0 @@ -// -// JoystickController.h -// Enjoy -// -// Created by Sam McCall on 4/05/09. -// Copyright 2009 University of Otago. All rights reserved. -// - -@class Joystick; -@class JSAction; -@class ConfigsController; -@class TargetController; - -@interface JoystickController : NSObject { - IBOutlet NSOutlineView *outlineView; - IBOutlet TargetController *targetController; - IBOutlet ConfigsController *configsController; -} - -- (void)setup; -- (Joystick *)findJoystickByRef:(IOHIDDeviceRef)device; - -@property (nonatomic, readonly) JSAction *selectedAction; -@property (nonatomic, assign) NSPoint mouseLoc; -@property (nonatomic, assign) BOOL frontWindowOnly; -@property (nonatomic, assign) BOOL translatingEvents; - -@end diff --git a/JoystickController.m b/JoystickController.m deleted file mode 100644 index 2efd68f..0000000 --- a/JoystickController.m +++ /dev/null @@ -1,235 +0,0 @@ -// -// JoystickController.m -// Enjoy -// -// Created by Sam McCall on 4/05/09. -// - -#import "JoystickController.h" - -#import "Config.h" -#import "ConfigsController.h" -#import "Joystick.h" -#import "JSAction.h" -#import "Target.h" -#import "TargetController.h" -#import "NJEvents.h" - -@implementation JoystickController { - IOHIDManagerRef hidManager; - NSTimer *continuousTimer; - NSMutableArray *runningTargets; - NSMutableArray *_joysticks; -} - -- (id)init { - if ((self = [super init])) { - _joysticks = [[NSMutableArray alloc] initWithCapacity:16]; - runningTargets = [[NSMutableArray alloc] initWithCapacity:32]; - } - return self; -} - -- (void)dealloc { - [continuousTimer invalidate]; - IOHIDManagerClose(hidManager, kIOHIDOptionsTypeNone); - CFRelease(hidManager); -} - -- (void)expandRecursive:(id )pathElement { - if (pathElement) { - [self expandRecursive:pathElement.base]; - [outlineView expandItem:pathElement]; - } -} - -- (void)addRunningTarget:(Target *)target { - if (![runningTargets containsObject:target]) { - [runningTargets addObject:target]; - } - if (!continuousTimer) { - continuousTimer = [NSTimer scheduledTimerWithTimeInterval:1.f/60.f - target:self - selector:@selector(updateContinuousActions:) - userInfo:nil - repeats:YES]; - NSLog(@"Scheduled continuous target timer."); - } -} - -- (void)runTargetForDevice:(IOHIDDeviceRef)device value:(IOHIDValueRef)value { - Joystick *js = [self findJoystickByRef:device]; - JSAction *mainAction = [js actionForEvent:value]; - [mainAction notifyEvent:value]; - NSArray *children = mainAction.children ? mainAction.children : mainAction ? @[mainAction] : @[]; - for (JSAction *subaction in children) { - Target *target = configsController.currentConfig[subaction]; - target.magnitude = mainAction.magnitude; - target.running = subaction.active; - if (target.running && target.isContinuous) - [self addRunningTarget:target]; - } -} - -- (void)showTargetForDevice:(IOHIDDeviceRef)device value:(IOHIDValueRef)value { - Joystick *js = [self findJoystickByRef:device]; - JSAction *handler = [js handlerForEvent:value]; - if (!handler) - return; - - [self expandRecursive:handler]; - [outlineView selectRowIndexes:[NSIndexSet indexSetWithIndex:[outlineView rowForItem:handler]] byExtendingSelection: NO]; - [targetController focusKey]; -} - -static void input_callback(void *ctx, IOReturn inResult, void *inSender, IOHIDValueRef value) { - JoystickController *controller = (__bridge JoystickController *)ctx; - IOHIDDeviceRef device = IOHIDQueueGetDevice(inSender); - - if (controller.translatingEvents) { - [controller runTargetForDevice:device value:value]; - } else if ([NSApplication sharedApplication].mainWindow.isVisible) { - [controller showTargetForDevice:device value:value]; - } -} - -static int findAvailableIndex(NSArray *list, Joystick *js) { - for (int index = 1; ; index++) { - BOOL available = YES; - for (Joystick *used in list) { - if ([used.productName isEqualToString:js.productName] && used.index == index) { - available = NO; - break; - } - } - if (available) - return index; - } -} - -- (void)addJoystickForDevice:(IOHIDDeviceRef)device { - IOHIDDeviceRegisterInputValueCallback(device, input_callback, (__bridge void*)self); - Joystick *js = [[Joystick alloc] initWithDevice:device]; - js.index = findAvailableIndex(_joysticks, js); - [_joysticks addObject:js]; - [outlineView reloadData]; -} - -static void add_callback(void *ctx, IOReturn inResult, void *inSender, IOHIDDeviceRef device) { - JoystickController *controller = (__bridge JoystickController *)ctx; - [controller addJoystickForDevice:device]; -} - -- (Joystick *)findJoystickByRef:(IOHIDDeviceRef)device { - for (Joystick *js in _joysticks) - if (js.device == device) - return js; - return nil; -} - -static void remove_callback(void *ctx, IOReturn inResult, void *inSender, IOHIDDeviceRef device) { - JoystickController *controller = (__bridge JoystickController *)ctx; - [controller removeJoystickForDevice:device]; -} - -- (void)removeJoystickForDevice:(IOHIDDeviceRef)device { - Joystick *match = [self findJoystickByRef:device]; - IOHIDDeviceRegisterInputValueCallback(device, NULL, NULL); - if (match) { - [_joysticks removeObject:match]; - [outlineView reloadData]; - } - -} - -- (void)updateContinuousActions:(NSTimer *)timer { - self.mouseLoc = [NSEvent mouseLocation]; - for (Target *target in [runningTargets copy]) { - if (![target update:self]) { - [runningTargets removeObject:target]; - } - } - if (!runningTargets.count) { - [continuousTimer invalidate]; - continuousTimer = nil; - NSLog(@"Unscheduled continuous target timer."); - } -} - -#define NSSTR(e) ((NSString *)CFSTR(e)) - -- (void)setup { - hidManager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone); - NSArray *criteria = @[ @{ NSSTR(kIOHIDDeviceUsagePageKey) : @(kHIDPage_GenericDesktop), - NSSTR(kIOHIDDeviceUsageKey) : @(kHIDUsage_GD_Joystick) }, - @{ NSSTR(kIOHIDDeviceUsagePageKey) : @(kHIDPage_GenericDesktop), - NSSTR(kIOHIDDeviceUsageKey) : @(kHIDUsage_GD_GamePad) }, - @{ NSSTR(kIOHIDDeviceUsagePageKey) : @(kHIDPage_GenericDesktop), - NSSTR(kIOHIDDeviceUsageKey) : @(kHIDUsage_GD_MultiAxisController) } - ]; - IOHIDManagerSetDeviceMatchingMultiple(hidManager, (__bridge CFArrayRef)criteria); - - IOHIDManagerScheduleWithRunLoop(hidManager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); - IOReturn ret = IOHIDManagerOpen(hidManager, kIOHIDOptionsTypeNone); - if (ret != kIOReturnSuccess) { - [[NSAlert alertWithMessageText:@"Input devices are unavailable" - defaultButton:nil - alternateButton:nil - otherButton:nil - informativeTextWithFormat:@"Error 0x%08x occured trying to access your devices. " - @"Input may not be correctly detected or mapped.", - ret] - beginSheetModalForWindow:outlineView.window - modalDelegate:nil - didEndSelector:nil - contextInfo:nil]; - } - - IOHIDManagerRegisterDeviceMatchingCallback(hidManager, add_callback, (__bridge void *)self); - IOHIDManagerRegisterDeviceRemovalCallback(hidManager, remove_callback, (__bridge void *)self); -} - -- (JSAction *)selectedAction { - id item = [outlineView itemAtRow:outlineView.selectedRow]; - return (!item.children && item.base) ? item : nil; -} - -- (NSInteger)outlineView:(NSOutlineView *)outlineView - numberOfChildrenOfItem:(id )item { - return item ? item.children.count : _joysticks.count; -} - -- (BOOL)outlineView:(NSOutlineView *)outlineView - isItemExpandable:(id )item { - return item ? [[item children] count] > 0: YES; -} - -- (id)outlineView:(NSOutlineView *)outlineView - child:(NSInteger)index - ofItem:(id )item { - return item ? item.children[index] : _joysticks[index]; -} - -- (id)outlineView:(NSOutlineView *)outlineView -objectValueForTableColumn:(NSTableColumn *)tableColumn - byItem:(id )item { - return item ? item.name : @"root"; -} - -- (void)outlineViewSelectionDidChange:(NSNotification *)notification { - - [targetController loadCurrent]; -} - -- (void)setTranslatingEvents:(BOOL)translatingEvents { - if (translatingEvents != _translatingEvents) { - _translatingEvents = translatingEvents; - NSString *name = translatingEvents - ? NJEventTranslationActivated - : NJEventTranslationDeactivated; - [NSNotificationCenter.defaultCenter postNotificationName:name - object:self]; - } -} - -@end diff --git a/NJActionPathElement.h b/NJActionPathElement.h deleted file mode 100644 index f5eb0ca..0000000 --- a/NJActionPathElement.h +++ /dev/null @@ -1,9 +0,0 @@ -#import - -@protocol NJActionPathElement - -- (NSArray *)children; -- (id ) base; -- (NSString *)name; - -@end diff --git a/NJDevice.h b/NJDevice.h new file mode 100644 index 0000000..ec607ac --- /dev/null +++ b/NJDevice.h @@ -0,0 +1,26 @@ +// +// NJDevice.h +// Enjoy +// +// Created by Sam McCall on 4/05/09. +// Copyright 2009 University of Otago. All rights reserved. +// + +#import "NJInputPathElement.h" + +@class NJInput; + +@interface NJDevice : NSObject + +@property (nonatomic, assign) int index; +@property (nonatomic, copy) NSString *productName; +@property (nonatomic, assign) IOHIDDeviceRef device; +@property (nonatomic, copy) NSArray *children; +@property (nonatomic, readonly) NSString *name; +@property (readonly) NSString *uid; + +- (id)initWithDevice:(IOHIDDeviceRef)device; +- (NJInput *)handlerForEvent:(IOHIDValueRef)value; +- (NJInput *)inputForEvent:(IOHIDValueRef)value; + +@end diff --git a/NJDevice.m b/NJDevice.m new file mode 100644 index 0000000..69775d8 --- /dev/null +++ b/NJDevice.m @@ -0,0 +1,109 @@ +// +// NJDevice.m +// Enjoy +// +// Created by Sam McCall on 4/05/09. +// + +#import "NJDevice.h" + +#import "NJInput.h" +#import "NJInputAnalog.h" +#import "NJInputHat.h" +#import "NJInputButton.h" + +static NSArray *InputsForElement(IOHIDDeviceRef device, id base) { + CFArrayRef elements = IOHIDDeviceCopyMatchingElements(device, NULL, kIOHIDOptionsTypeNone); + NSMutableArray *children = [NSMutableArray arrayWithCapacity:CFArrayGetCount(elements)]; + + int buttons = 0; + int axes = 0; + int hats = 0; + + for (int i = 0; i < CFArrayGetCount(elements); i++) { + IOHIDElementRef element = (IOHIDElementRef)CFArrayGetValueAtIndex(elements, i); + int type = IOHIDElementGetType(element); + unsigned usage = IOHIDElementGetUsage(element); + unsigned usagePage = IOHIDElementGetUsagePage(element); + long max = IOHIDElementGetPhysicalMax(element); + long min = IOHIDElementGetPhysicalMin(element); + CFStringRef elName = IOHIDElementGetName(element); + + NJInput *input = nil; + + if (!(type == kIOHIDElementTypeInput_Misc + || type == kIOHIDElementTypeInput_Axis + || type == kIOHIDElementTypeInput_Button)) + continue; + + if (max - min == 1 || usagePage == kHIDPage_Button || type == kIOHIDElementTypeInput_Button) { + input = [[NJInputButton alloc] initWithName:(__bridge NSString *)elName + idx:++buttons + max:max]; + } else if (usage == kHIDUsage_GD_Hatswitch) { + input = [[NJInputHat alloc] initWithIndex:++hats]; + } else if (usage >= kHIDUsage_GD_X && usage <= kHIDUsage_GD_Rz) { + input = [[NJInputAnalog alloc] initWithIndex:++axes + rawMin:min + rawMax:max]; + } else { + continue; + } + + // TODO(jfw): Should be moved into better constructors. + input.base = base; + input.cookie = IOHIDElementGetCookie(element); + [children addObject:input]; + } + + CFRelease(elements); + return children; +} + +@implementation NJDevice { + int vendorId; + int productId; +} + +- (id)initWithDevice:(IOHIDDeviceRef)dev { + if ((self = [super init])) { + self.device = dev; + self.productName = (__bridge NSString *)IOHIDDeviceGetProperty(dev, CFSTR(kIOHIDProductKey)); + vendorId = [(__bridge NSNumber *)IOHIDDeviceGetProperty(dev, CFSTR(kIOHIDVendorIDKey)) intValue]; + productId = [(__bridge NSNumber *)IOHIDDeviceGetProperty(dev, CFSTR(kIOHIDProductIDKey)) intValue]; + self.children = InputsForElement(dev, self); + } + return self; +} + +- (NSString *)name { + return [NSString stringWithFormat:@"%@ #%d", _productName, _index]; +} + +- (id)base { + return nil; +} + +- (NSString *)uid { + return [NSString stringWithFormat: @"%d:%d:%d", vendorId, productId, _index]; +} + +- (NJInput *)findInputByCookie:(IOHIDElementCookie)cookie { + for (NJInput *child in _children) + if (child.cookie == cookie) + return child; + return nil; +} + +- (NJInput *)handlerForEvent:(IOHIDValueRef)value { + NJInput *mainInput = [self inputForEvent:value]; + return [mainInput findSubInputForValue:value]; +} + +- (NJInput *)inputForEvent:(IOHIDValueRef)value { + IOHIDElementRef elt = IOHIDValueGetElement(value); + IOHIDElementCookie cookie = IOHIDElementGetCookie(elt); + return [self findInputByCookie:cookie]; +} + +@end diff --git a/NJInput.h b/NJInput.h new file mode 100644 index 0000000..e2c8404 --- /dev/null +++ b/NJInput.h @@ -0,0 +1,26 @@ +// +// NJInput.h +// Enjoy +// +// Created by Sam McCall on 4/05/09. +// Copyright 2009 University of Otago. All rights reserved. +// + +#import "NJInputPathElement.h" + +@interface NJInput : NSObject + +@property (nonatomic, assign) IOHIDElementCookie cookie; +@property (nonatomic, copy) NSArray *children; +@property (nonatomic, weak) id base; +@property (nonatomic, copy) NSString *name; +@property (nonatomic, assign) BOOL active; +@property (nonatomic, readonly) float magnitude; +@property (readonly) NSString *uid; + +- (id)initWithName:(NSString *)newName base:(id )newBase; + +- (void)notifyEvent:(IOHIDValueRef)value; +- (id)findSubInputForValue:(IOHIDValueRef)value; + +@end diff --git a/NJInput.m b/NJInput.m new file mode 100644 index 0000000..cccda29 --- /dev/null +++ b/NJInput.m @@ -0,0 +1,36 @@ +// +// NJInput.m +// Enjoy +// +// Created by Sam McCall on 4/05/09. +// + +#import "NJInput.h" + +@implementation NJInput + +- (id)initWithName:(NSString *)newName base:(id )newBase { + if ((self = [super init])) { + self.name = newName; + self.base = newBase; + } + return self; +} + +- (id)findSubInputForValue:(IOHIDValueRef)value { + return NULL; +} + +- (NSString *)uid { + return [NSString stringWithFormat:@"%@~%@", [_base uid], _name]; +} + +- (void)notifyEvent:(IOHIDValueRef)value { + [self doesNotRecognizeSelector:_cmd]; +} + +- (float)magnitude { + return 0.f; +} + +@end diff --git a/NJInputAnalog.h b/NJInputAnalog.h new file mode 100644 index 0000000..e79ed89 --- /dev/null +++ b/NJInputAnalog.h @@ -0,0 +1,17 @@ +// +// NJInputAnalog.h +// Enjoy +// +// Created by Sam McCall on 5/05/09. +// Copyright 2009 University of Otago. All rights reserved. +// + +#import + +#import "NJInput.h" + +@interface NJInputAnalog : NJInput + +- (id)initWithIndex:(int)index rawMin:(long)rawMin rawMax:(long)rawMax; + +@end diff --git a/NJInputAnalog.m b/NJInputAnalog.m new file mode 100644 index 0000000..98ed018 --- /dev/null +++ b/NJInputAnalog.m @@ -0,0 +1,53 @@ +// +// NJInputAnalog.m +// Enjoy +// +// Created by Sam McCall on 5/05/09. +// + +#define DEAD_ZONE 0.3 + +#import "NJInputAnalog.h" + +static float normalize(long p, long min, long max) { + return 2 * (p - min) / (float)(max - min) - 1; +} + +@implementation NJInputAnalog { + float magnitude; + long rawMin; + long rawMax; +} + +- (id)initWithIndex:(int)index rawMin:(long)rawMin_ rawMax:(long)rawMax_ { + if ((self = [super init])) { + self.name = [[NSString alloc] initWithFormat: @"Axis %d", index]; + self.children = @[[[NJInput alloc] initWithName:@"Low" base:self], + [[NJInput alloc] initWithName:@"High" base:self]]; + rawMax = rawMax_; + rawMin = rawMin_; + } + return self; +} + +- (id)findSubInputForValue:(IOHIDValueRef)value { + float mag = normalize(IOHIDValueGetIntegerValue(value), rawMin, rawMax); + if (mag < -DEAD_ZONE) + return self.children[0]; + else if (mag > DEAD_ZONE) + return self.children[1]; + else + return nil; +} + +- (void)notifyEvent:(IOHIDValueRef)value { + magnitude = normalize(IOHIDValueGetIntegerValue(value), rawMin, rawMax); + [self.children[0] setActive:magnitude < -DEAD_ZONE]; + [self.children[1] setActive:magnitude > DEAD_ZONE]; +} + +- (float)magnitude { + return magnitude; +} + +@end diff --git a/NJInputButton.h b/NJInputButton.h new file mode 100644 index 0000000..31cba73 --- /dev/null +++ b/NJInputButton.h @@ -0,0 +1,15 @@ +// +// NJInputButton.h +// Enjoy +// +// Created by Sam McCall on 5/05/09. +// Copyright 2009 University of Otago. All rights reserved. +// + +#import "NJInput.h" + +@interface NJInputButton : NJInput + +- (id)initWithName:(NSString *)name idx:(int)idx max:(long)max; + +@end diff --git a/NJInputButton.m b/NJInputButton.m new file mode 100644 index 0000000..c500276 --- /dev/null +++ b/NJInputButton.m @@ -0,0 +1,33 @@ +// +// NJInputButton.m +// Enjoy +// +// Created by Sam McCall on 5/05/09. +// + +#import "NJInputButton.h" + +@implementation NJInputButton { + long _max; +} + +- (id)initWithName:(NSString *)name idx:(int)idx max:(long)max { + if ((self = [super init])) { + _max = max; + if (name.length) + self.name = [NSString stringWithFormat:@"Button %d - %@", idx, name]; + else + self.name = [NSString stringWithFormat:@"Button %d", idx]; + } + return self; +} + +- (id)findSubInputForValue:(IOHIDValueRef)val { + return (IOHIDValueGetIntegerValue(val) == _max) ? self : nil; +} + +- (void)notifyEvent:(IOHIDValueRef)value { + self.active = IOHIDValueGetIntegerValue(value) == _max; +} + +@end diff --git a/NJInputController.h b/NJInputController.h new file mode 100644 index 0000000..1c4853c --- /dev/null +++ b/NJInputController.h @@ -0,0 +1,28 @@ +// +// NJInputController.h +// Enjoy +// +// Created by Sam McCall on 4/05/09. +// Copyright 2009 University of Otago. All rights reserved. +// + +@class NJDevice; +@class NJInput; +@class ConfigsController; +@class TargetController; + +@interface NJInputController : NSObject { + IBOutlet NSOutlineView *outlineView; + IBOutlet TargetController *targetController; + IBOutlet ConfigsController *configsController; +} + +- (void)setup; +- (NJDevice *)findJoystickByRef:(IOHIDDeviceRef)device; + +@property (nonatomic, readonly) NJInput *selectedInput; +@property (nonatomic, assign) NSPoint mouseLoc; +@property (nonatomic, assign) BOOL frontWindowOnly; +@property (nonatomic, assign) BOOL translatingEvents; + +@end diff --git a/NJInputController.m b/NJInputController.m new file mode 100644 index 0000000..9ee6d04 --- /dev/null +++ b/NJInputController.m @@ -0,0 +1,235 @@ +// +// NJInputController.h +// Enjoy +// +// Created by Sam McCall on 4/05/09. +// + +#import "NJInputController.h" + +#import "Config.h" +#import "ConfigsController.h" +#import "NJDevice.h" +#import "NJInput.h" +#import "Target.h" +#import "TargetController.h" +#import "NJEvents.h" + +@implementation NJInputController { + IOHIDManagerRef hidManager; + NSTimer *continuousTimer; + NSMutableArray *runningTargets; + NSMutableArray *_joysticks; +} + +- (id)init { + if ((self = [super init])) { + _joysticks = [[NSMutableArray alloc] initWithCapacity:16]; + runningTargets = [[NSMutableArray alloc] initWithCapacity:32]; + } + return self; +} + +- (void)dealloc { + [continuousTimer invalidate]; + IOHIDManagerClose(hidManager, kIOHIDOptionsTypeNone); + CFRelease(hidManager); +} + +- (void)expandRecursive:(id )pathElement { + if (pathElement) { + [self expandRecursive:pathElement.base]; + [outlineView expandItem:pathElement]; + } +} + +- (void)addRunningTarget:(Target *)target { + if (![runningTargets containsObject:target]) { + [runningTargets addObject:target]; + } + if (!continuousTimer) { + continuousTimer = [NSTimer scheduledTimerWithTimeInterval:1.f/60.f + target:self + selector:@selector(updateContinuousInputs:) + userInfo:nil + repeats:YES]; + NSLog(@"Scheduled continuous target timer."); + } +} + +- (void)runTargetForDevice:(IOHIDDeviceRef)device value:(IOHIDValueRef)value { + NJDevice *js = [self findJoystickByRef:device]; + NJInput *mainInput = [js inputForEvent:value]; + [mainInput notifyEvent:value]; + NSArray *children = mainInput.children ? mainInput.children : mainInput ? @[mainInput] : @[]; + for (NJInput *subInput in children) { + Target *target = configsController.currentConfig[subInput]; + target.magnitude = mainInput.magnitude; + target.running = subInput.active; + if (target.running && target.isContinuous) + [self addRunningTarget:target]; + } +} + +- (void)showTargetForDevice:(IOHIDDeviceRef)device value:(IOHIDValueRef)value { + NJDevice *js = [self findJoystickByRef:device]; + NJInput *handler = [js handlerForEvent:value]; + if (!handler) + return; + + [self expandRecursive:handler]; + [outlineView selectRowIndexes:[NSIndexSet indexSetWithIndex:[outlineView rowForItem:handler]] byExtendingSelection: NO]; + [targetController focusKey]; +} + +static void input_callback(void *ctx, IOReturn inResult, void *inSender, IOHIDValueRef value) { + NJInputController *controller = (__bridge NJInputController *)ctx; + IOHIDDeviceRef device = IOHIDQueueGetDevice(inSender); + + if (controller.translatingEvents) { + [controller runTargetForDevice:device value:value]; + } else if ([NSApplication sharedApplication].mainWindow.isVisible) { + [controller showTargetForDevice:device value:value]; + } +} + +static int findAvailableIndex(NSArray *list, NJDevice *js) { + for (int index = 1; ; index++) { + BOOL available = YES; + for (NJDevice *used in list) { + if ([used.productName isEqualToString:js.productName] && used.index == index) { + available = NO; + break; + } + } + if (available) + return index; + } +} + +- (void)addJoystickForDevice:(IOHIDDeviceRef)device { + IOHIDDeviceRegisterInputValueCallback(device, input_callback, (__bridge void*)self); + NJDevice *js = [[NJDevice alloc] initWithDevice:device]; + js.index = findAvailableIndex(_joysticks, js); + [_joysticks addObject:js]; + [outlineView reloadData]; +} + +static void add_callback(void *ctx, IOReturn inResult, void *inSender, IOHIDDeviceRef device) { + NJInputController *controller = (__bridge NJInputController *)ctx; + [controller addJoystickForDevice:device]; +} + +- (NJDevice *)findJoystickByRef:(IOHIDDeviceRef)device { + for (NJDevice *js in _joysticks) + if (js.device == device) + return js; + return nil; +} + +static void remove_callback(void *ctx, IOReturn inResult, void *inSender, IOHIDDeviceRef device) { + NJInputController *controller = (__bridge NJInputController *)ctx; + [controller removeJoystickForDevice:device]; +} + +- (void)removeJoystickForDevice:(IOHIDDeviceRef)device { + NJDevice *match = [self findJoystickByRef:device]; + IOHIDDeviceRegisterInputValueCallback(device, NULL, NULL); + if (match) { + [_joysticks removeObject:match]; + [outlineView reloadData]; + } + +} + +- (void)updateContinuousInputs:(NSTimer *)timer { + self.mouseLoc = [NSEvent mouseLocation]; + for (Target *target in [runningTargets copy]) { + if (![target update:self]) { + [runningTargets removeObject:target]; + } + } + if (!runningTargets.count) { + [continuousTimer invalidate]; + continuousTimer = nil; + NSLog(@"Unscheduled continuous target timer."); + } +} + +#define NSSTR(e) ((NSString *)CFSTR(e)) + +- (void)setup { + hidManager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone); + NSArray *criteria = @[ @{ NSSTR(kIOHIDDeviceUsagePageKey) : @(kHIDPage_GenericDesktop), + NSSTR(kIOHIDDeviceUsageKey) : @(kHIDUsage_GD_Joystick) }, + @{ NSSTR(kIOHIDDeviceUsagePageKey) : @(kHIDPage_GenericDesktop), + NSSTR(kIOHIDDeviceUsageKey) : @(kHIDUsage_GD_GamePad) }, + @{ NSSTR(kIOHIDDeviceUsagePageKey) : @(kHIDPage_GenericDesktop), + NSSTR(kIOHIDDeviceUsageKey) : @(kHIDUsage_GD_MultiAxisController) } + ]; + IOHIDManagerSetDeviceMatchingMultiple(hidManager, (__bridge CFArrayRef)criteria); + + IOHIDManagerScheduleWithRunLoop(hidManager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); + IOReturn ret = IOHIDManagerOpen(hidManager, kIOHIDOptionsTypeNone); + if (ret != kIOReturnSuccess) { + [[NSAlert alertWithMessageText:@"Input devices are unavailable" + defaultButton:nil + alternateButton:nil + otherButton:nil + informativeTextWithFormat:@"Error 0x%08x occured trying to access your devices. " + @"Input may not be correctly detected or mapped.", + ret] + beginSheetModalForWindow:outlineView.window + modalDelegate:nil + didEndSelector:nil + contextInfo:nil]; + } + + IOHIDManagerRegisterDeviceMatchingCallback(hidManager, add_callback, (__bridge void *)self); + IOHIDManagerRegisterDeviceRemovalCallback(hidManager, remove_callback, (__bridge void *)self); +} + +- (NJInput *)selectedInput { + id item = [outlineView itemAtRow:outlineView.selectedRow]; + return (!item.children && item.base) ? item : nil; +} + +- (NSInteger)outlineView:(NSOutlineView *)outlineView + numberOfChildrenOfItem:(id )item { + return item ? item.children.count : _joysticks.count; +} + +- (BOOL)outlineView:(NSOutlineView *)outlineView + isItemExpandable:(id )item { + return item ? [[item children] count] > 0: YES; +} + +- (id)outlineView:(NSOutlineView *)outlineView + child:(NSInteger)index + ofItem:(id )item { + return item ? item.children[index] : _joysticks[index]; +} + +- (id)outlineView:(NSOutlineView *)outlineView +objectValueForTableColumn:(NSTableColumn *)tableColumn + byItem:(id )item { + return item ? item.name : @"root"; +} + +- (void)outlineViewSelectionDidChange:(NSNotification *)notification { + + [targetController loadCurrent]; +} + +- (void)setTranslatingEvents:(BOOL)translatingEvents { + if (translatingEvents != _translatingEvents) { + _translatingEvents = translatingEvents; + NSString *name = translatingEvents + ? NJEventTranslationActivated + : NJEventTranslationDeactivated; + [NSNotificationCenter.defaultCenter postNotificationName:name + object:self]; + } +} + +@end diff --git a/NJInputHat.h b/NJInputHat.h new file mode 100644 index 0000000..5290d71 --- /dev/null +++ b/NJInputHat.h @@ -0,0 +1,15 @@ +// +// NJInputHat.h +// Enjoy +// +// Created by Sam McCall on 5/05/09. +// Copyright 2009 University of Otago. All rights reserved. +// + +#import "NJInput.h" + +@interface NJInputHat : NJInput + +- (id)initWithIndex:(int)index; + +@end diff --git a/NJInputHat.m b/NJInputHat.m new file mode 100644 index 0000000..b7d0161 --- /dev/null +++ b/NJInputHat.m @@ -0,0 +1,96 @@ +// +// NJInputHat.m +// Enjoy +// +// Created by Sam McCall on 5/05/09. +// + +#import "NJInputHat.h" + +static BOOL active_eightway[36] = { + NO, NO, NO, NO , // center + YES, NO, NO, NO , // N + YES, NO, NO, YES, // NE + NO, NO, NO, YES, // E + NO, YES, NO, YES, // SE + NO, YES, NO, NO , // S + NO, YES, YES, NO , // SW + NO, NO, YES, NO , // W + YES, NO, YES, NO , // NW +}; + +static BOOL active_fourway[20] = { + NO, NO, NO, NO , // center + YES, NO, NO, NO , // N + NO, NO, NO, YES, // E + NO, YES, NO, NO , // S + NO, NO, YES, NO , // W +}; + +@implementation NJInputHat + +- (id)initWithIndex:(int)index { + if ((self = [super init])) { + self.children = @[[[NJInput alloc] initWithName:@"Up" base:self], + [[NJInput alloc] initWithName:@"Down" base:self], + [[NJInput alloc] initWithName:@"Left" base:self], + [[NJInput alloc] initWithName:@"Right" base:self]]; + self.name = [NSString stringWithFormat:@"Hat Switch %d", index]; + } + return self; +} + +- (id)findSubInputForValue:(IOHIDValueRef)value { + long parsed = IOHIDValueGetIntegerValue(value); + switch (IOHIDElementGetLogicalMax(IOHIDValueGetElement(value))) { + case 7: // 8-way switch, 0-7. + switch (parsed) { + case 0: return self.children[0]; + case 4: return self.children[1]; + case 6: return self.children[2]; + case 2: return self.children[3]; + default: return nil; + } + case 8: // 8-way switch, 1-8 (neutral 0). + switch (parsed) { + case 1: return self.children[0]; + case 5: return self.children[1]; + case 7: return self.children[2]; + case 3: return self.children[3]; + default: return nil; + } + case 3: // 4-way switch, 0-3. + switch (parsed) { + case 0: return self.children[0]; + case 2: return self.children[1]; + case 3: return self.children[2]; + case 1: return self.children[3]; + default: return nil; + } + case 4: // 4-way switch, 1-4 (neutral 0). + switch (parsed) { + case 1: return self.children[0]; + case 3: return self.children[1]; + case 4: return self.children[2]; + case 2: return self.children[3]; + default: return nil; + } + default: + return nil; + } +} + +- (void)notifyEvent:(IOHIDValueRef)value { + long parsed = IOHIDValueGetIntegerValue(value); + long size = IOHIDElementGetLogicalMax(IOHIDValueGetElement(value)); + // Skip first row in table if 0 is not neutral. + if (size & 1) { + parsed++; + size++; + } + BOOL *activechildren = (size == 8) ? active_eightway : active_fourway; + for (int i = 0; i < 4; i++) + [self.children[i] setActive:activechildren[parsed * 4 + i]]; +} + +@end diff --git a/NJInputPathElement.h b/NJInputPathElement.h new file mode 100644 index 0000000..8fe5c65 --- /dev/null +++ b/NJInputPathElement.h @@ -0,0 +1,9 @@ +#import + +@protocol NJInputPathElement + +- (NSArray *)children; +- (id ) base; +- (NSString *)name; + +@end diff --git a/Target.h b/Target.h index df3535b..d234162 100644 --- a/Target.h +++ b/Target.h @@ -6,7 +6,7 @@ // Copyright 2009 University of Otago. All rights reserved. // -@class JoystickController; +@class NJInputController; @interface Target : NSObject @@ -16,7 +16,7 @@ - (void)trigger; - (void)untrigger; -- (BOOL)update:(JoystickController *)jc; +- (BOOL)update:(NJInputController *)jc; - (NSDictionary *)serialize; + (Target *)targetDeserialize:(NSDictionary *)serialization diff --git a/Target.m b/Target.m index 493f94a..42d004c 100644 --- a/Target.m +++ b/Target.m @@ -63,7 +63,7 @@ - (void)untrigger { } -- (BOOL)update:(JoystickController *)jc { +- (BOOL)update:(NJInputController *)jc { return NO; } diff --git a/TargetController.h b/TargetController.h index 9c03c08..7f9e159 100644 --- a/TargetController.h +++ b/TargetController.h @@ -9,7 +9,7 @@ #import "NJKeyInputField.h" @class ConfigsController; -@class JoystickController; +@class NJInputController; @class Target; @class TargetMouseMove; @@ -22,7 +22,7 @@ IBOutlet NSTextField *title; IBOutlet NSPopUpButton *configPopup; IBOutlet ConfigsController *configsController; - IBOutlet JoystickController *joystickController; + IBOutlet NJInputController *joystickController; } @property (assign) BOOL enabled; diff --git a/TargetController.m b/TargetController.m index 48119c2..2e53917 100644 --- a/TargetController.m +++ b/TargetController.m @@ -9,8 +9,8 @@ #import "ConfigsController.h" #import "Config.h" -#import "JSAction.h" -#import "JoystickController.h" +#import "NJInput.h" +#import "NJInputController.h" #import "NJKeyInputField.h" #import "TargetConfig.h" #import "TargetController.h" @@ -98,7 +98,7 @@ } - (Target *)currentTarget { - return configsController.currentConfig[joystickController.selectedAction]; + return configsController.currentConfig[joystickController.selectedInput]; } - (Target *)makeTarget { @@ -145,7 +145,7 @@ - (void)commit { [self cleanUpInterface]; - configsController.currentConfig[joystickController.selectedAction] = [self makeTarget]; + configsController.currentConfig[joystickController.selectedInput] = [self makeTarget]; [configsController save]; } @@ -162,17 +162,17 @@ [scrollDirSelect setEnabled:enabled]; } -- (void)loadTarget:(Target *)target forAction:(JSAction *)action { - if (!action) { +- (void)loadTarget:(Target *)target forInput:(NJInput *)input { + if (!input) { self.enabled = NO; title.stringValue = @""; } else { self.enabled = YES; - NSString *actFullName = action.name; - for (id cur = action.base; cur; cur = cur.base) { - actFullName = [[NSString alloc] initWithFormat:@"%@ > %@", cur.name, actFullName]; + NSString *inpFullName = input.name; + for (id cur = input.base; cur; cur = cur.base) { + inpFullName = [[NSString alloc] initWithFormat:@"%@ > %@", cur.name, inpFullName]; } - title.stringValue = [[NSString alloc] initWithFormat:@"%@ > %@", configsController.currentConfig.name, actFullName]; + title.stringValue = [[NSString alloc] initWithFormat:@"%@ > %@", configsController.currentConfig.name, inpFullName]; } if ([target isKindOfClass:TargetKeyboard.class]) { @@ -209,7 +209,7 @@ } - (void)loadCurrent { - [self loadTarget:self.currentTarget forAction:joystickController.selectedAction]; + [self loadTarget:self.currentTarget forInput:joystickController.selectedInput]; } - (void)focusKey { diff --git a/TargetMouseMove.m b/TargetMouseMove.m index 3ec8f38..2806827 100644 --- a/TargetMouseMove.m +++ b/TargetMouseMove.m @@ -7,7 +7,7 @@ #import "TargetMouseMove.h" -#import "JoystickController.h" +#import "NJInputController.h" @implementation TargetMouseMove { int sign; @@ -32,13 +32,13 @@ return target; } -- (BOOL)update:(JoystickController *)jc { +- (BOOL)update:(NJInputController *)jc { if (fabsf(self.magnitude) < 0.01) { sign = 0; return NO; // dead zone } - // If the action crossed over High/Low, this target is done. + // If the input crossed over High/Low, this target is done. if (!sign) sign = self.magnitude < 0 ? -1 : 1; else if (sign / self.magnitude < 0) { diff --git a/TargetMouseScroll.m b/TargetMouseScroll.m index 6595628..ac3b852 100644 --- a/TargetMouseScroll.m +++ b/TargetMouseScroll.m @@ -37,13 +37,13 @@ } } -- (BOOL)update:(JoystickController *)jc { +- (BOOL)update:(NJInputController *)jc { if (fabsf(self.magnitude) < 0.01f) { sign = 0; return NO; // dead zone } - // If the action crossed over High/Low, this target is done. + // If the input crossed over High/Low, this target is done. if (!sign) sign = self.magnitude < 0 ? -1 : 1; else if (sign / self.magnitude < 0) { diff --git a/TargetToggleMouseScope.m b/TargetToggleMouseScope.m index 863a35f..499e9c9 100644 --- a/TargetToggleMouseScope.m +++ b/TargetToggleMouseScope.m @@ -8,7 +8,7 @@ #import "TargetToggleMouseScope.h" #import "ApplicationController.h" -#import "JoystickController.h" +#import "NJInputController.h" @implementation TargetToggleMouseScope @@ -29,7 +29,7 @@ // FIXME: It's hacky to get at the controller this way, but it's // also hacky to pass it. Shouldn't need to do either. ApplicationController *ac = NSApplication.sharedApplication.delegate; - JoystickController *jc = ac.jsController; + NJInputController *jc = ac.jsController; jc.frontWindowOnly = !jc.frontWindowOnly; }