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

@@ -0,0 +1,60 @@
//
// WTSonarPenDriver.h
//
// Created by Water Lou on 8/7/14.
// Copyright (c) 2014 First Water Tech Ltd. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
extern NSString *const _Nonnull WTSonarPenDriverStateChangedNotification;
typedef NS_ENUM(NSInteger, WTAudioPenDriverState) {
WTSonarPenDriverStateInit = 0, // wait for pen attach
WTSonarPenDriverStateCalibrating = 1, // calc min value (when audio source just switched
WTSonarPenDriverStateRunning = 2, // running
WTSonarPenDriverStateCalibratingMax = 3, // calibrating max value
WTSonarPenDriverStateNotSonarPen = 4, // headphone plugged but no a sonarpen, audio sound disabled
WTSonarPenDriverStateWaitingForPermission = 5, // starting, wait for user permission for microphone
WTSonarPenDriverStateNoMicrophonePermission = 6, // no started, no microphone permission
};
@class WTSonarPenDriver;
@protocol WTSonarPenDriverDelegate<NSObject>
@optional
- (void)sonarPenButtonPressed:(WTSonarPenDriver* _Nonnull)driver;
@end
@interface WTSonarPenDriver : NSObject
- (instancetype _Nonnull)init NS_UNAVAILABLE; // please call initWithApplication instead
- (instancetype _Nonnull) initWithApplication: (UIApplication * _Nullable)application NS_DESIGNATED_INITIALIZER;
- (void) start;
- (void) stop;
- (BOOL) isPenDown; // is pen touched
- (CGFloat) pressure; // current pressure
- (BOOL) isPenAttached;
- (WTAudioPenDriverState) state; // pen drive state
/// If button on the pen is pressed
- (BOOL) isButtonDown;
// set to YES, the driver will use current pressure as idle state value
// developer can set this to YES will no touch is detected, and NO with touch
@property (nonatomic) BOOL calibratingIdleValue;
@property (nonatomic) BOOL shouldCheckPenOnStart; // detect pen when plug
@property (nonatomic, weak, nullable) id <WTSonarPenDriverDelegate> delegate;
//- (void)startFullCalibration;
@end
BOOL isHeadphoneplugged(AVAudioSessionRouteDescription * _Nonnull route);

View File

@@ -0,0 +1,28 @@
//
// WTSonarPenTouchesHandler.h
//
// Created by Water Lou on 3/7/15.
// Copyright (c) 2015 First Water Tech Ltd. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface WTSonarPenTouchesHandler : NSObject
- (void)handleTouches:(UIEvent * _Nullable)event
view:(UIView * _Nonnull)view
penDown:(BOOL)penDownStatus;
// check if pen is down
- (BOOL)isPenDown;
// check if touch with large size touch
- (BOOL)isPalmTouchedBySize;
// get pen location if pen is down
- (CGPoint)penLocation;
// touch object that detect as pen
@property(readonly, nullable) UITouch *penTouch;
- (NSInteger)numberOfTouches;
@end

Binary file not shown.