-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: fuzzing function to see if we can shed some light on the keys o…
…n MK3
- Loading branch information
Showing
11 changed files
with
352 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// FuzzingWindowController.h | ||
// KompleteSynthesia | ||
// | ||
// Created by Till Toenshoff on 19.01.24. | ||
// | ||
|
||
#import <Cocoa/Cocoa.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@class HIDController; | ||
@protocol PreferencesDelegate; | ||
|
||
@interface FuzzingWindowController : NSWindowController | ||
|
||
@property (nonatomic, weak) IBOutlet NSTextField* initialCommand; | ||
@property (nonatomic, weak) IBOutlet NSTextField* currentControlCommand; | ||
@property (nonatomic, weak) IBOutlet NSSliderCell* delaySlider; | ||
|
||
@property (nonatomic, weak) HIDController* hidController; | ||
|
||
@property (nonatomic, weak) id<PreferencesDelegate> delegate; | ||
|
||
- (IBAction)start:(id)sender; | ||
- (IBAction)stop:(id)sender; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// | ||
// FuzzingWindowController.m | ||
// KompleteSynthesia | ||
// | ||
// Created by Till Toenshoff on 19.01.24. | ||
// | ||
|
||
#import "FuzzingWindowController.h" | ||
#import "HIDController.h" | ||
#import "PreferencesWindowController.h" | ||
|
||
/// Hacked together window for getting some ideas on how to control the lightguide on MK3 devices - totally ugly! | ||
|
||
static const NSTimeInterval kCommandUpdateTimerDelay = 0.01; | ||
static const NSTimeInterval kFuzzTimerDelay = 0.05; | ||
|
||
@interface FuzzingWindowController () | ||
@end | ||
|
||
@implementation FuzzingWindowController { | ||
NSTimer* commandUpdateTimer; | ||
NSTimer* fuzzTimer; | ||
} | ||
|
||
- (NSString*)hexStringFromBinaryData:(unsigned char*)data withLength:(size_t)length | ||
{ | ||
NSString* output = @""; | ||
for (int i = 0; i < length; i++) { | ||
if (i > 0) { | ||
output = [NSString stringWithFormat:@"%@ ", output]; | ||
} | ||
output = [NSString stringWithFormat:@"%@%02X", output, data[i]]; | ||
} | ||
return output; | ||
} | ||
|
||
- (void)windowDidLoad | ||
{ | ||
[super windowDidLoad]; | ||
|
||
[_delegate preferencesUpdatedKeyState:0x00 forKeyIndex:0]; | ||
|
||
_initialCommand.stringValue = [self hexStringFromBinaryData:_hidController.initialCommand | ||
withLength:_hidController.initialCommandLength]; | ||
|
||
commandUpdateTimer = [NSTimer | ||
scheduledTimerWithTimeInterval:kCommandUpdateTimerDelay | ||
repeats:YES | ||
block:^(NSTimer* timer) { | ||
self->_currentControlCommand.stringValue = | ||
[self hexStringFromBinaryData:self->_hidController.lightGuideUpdateMessage | ||
withLength:self->_hidController.lightGuideUpdateMessageSize]; | ||
}]; | ||
} | ||
|
||
- (IBAction)stop:(id)sender | ||
{ | ||
if (fuzzTimer != nil) { | ||
[fuzzTimer invalidate]; | ||
} | ||
} | ||
|
||
- (IBAction)start:(id)sender | ||
{ | ||
self->_hidController.lightGuideUpdateMessage[0] = 0x01; | ||
[_delegate preferencesUpdatedKeyState:0x06 forKeyIndex:0]; | ||
|
||
if (fuzzTimer != nil) { | ||
[fuzzTimer invalidate]; | ||
} | ||
|
||
fuzzTimer = [NSTimer | ||
scheduledTimerWithTimeInterval:kFuzzTimerDelay * _delaySlider.intValue | ||
repeats:YES | ||
block:^(NSTimer* timer) { | ||
[self->_hidController initKeyboardController:nil]; | ||
if (self->_hidController.lightGuideUpdateMessage[0] == 0xFF) { | ||
self->_hidController.lightGuideUpdateMessage[1] += 0x0C; | ||
} | ||
[_delegate preferencesUpdatedKeyState:self->_hidController.lightGuideUpdateMessage[1] | ||
forKeyIndex:0]; | ||
self->_hidController.lightGuideUpdateMessage[0]++; | ||
}]; | ||
} | ||
|
||
@end |
Oops, something went wrong.