implement SonarPen

This commit is contained in:
2018-08-15 02:20:23 +02:00
parent e4e7719f83
commit a37ea5309b
9 changed files with 151 additions and 2 deletions

View File

@@ -9,6 +9,7 @@
#import "AppDelegate.h"
#import "GameViewController.h"
#include "app.h"
#include <WTSonarPenDriver.h>
void global_exception_handler(NSException* e)
{
@@ -28,6 +29,7 @@ void global_signal_handler(int e)
@interface AppDelegate () {
GameViewController* view;
WTSonarPenDriver* sonarpen_driver;
}
@end
@@ -40,9 +42,38 @@ void global_signal_handler(int e)
return true;
}
- (float)sonarpen_pressure
{
return [sonarpen_driver isPenAttached] ? [sonarpen_driver pressure] : 1.f;
}
- (void)penStatusChanged
{
switch (sonarpen_driver.state) {
case WTSonarPenDriverStateInit:
NSLog(@"Status: Initializing"); break;
case WTSonarPenDriverStateRunning:
NSLog(@"Status: Running"); break;
case WTSonarPenDriverStateCalibrating:
NSLog(@"Status: Calibrating"); break;
case WTSonarPenDriverStateNotSonarPen:
NSLog(@"Status: Not a Sonar Pen"); break;
case WTSonarPenDriverStateCalibratingMax:
NSLog(@"Status: Calibrating Max Value"); break;
case WTSonarPenDriverStateWaitingForPermission:
NSLog(@"Status: Wait for Permission"); break;
case WTSonarPenDriverStateNoMicrophonePermission:
NSLog(@"Status: No Microphone Permission"); break;
}
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
NSSetUncaughtExceptionHandler(&global_exception_handler);
sonarpen_driver = [[WTSonarPenDriver alloc] initWithApplication:application];
[sonarpen_driver start];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(penStatusChanged) name:WTSonarPenDriverStateChangedNotification object:nil];
view = (GameViewController*)self.window.rootViewController;
return YES;
}