PcycleSDK API - Pcycle/PcycleSDK-iOS GitHub Wiki

1.初始化
-(instancetype) initWithDelegate:(id<PcycleSDKDelegate>) delegate;

**委托:**委托方法中会返回调用初始化后蓝牙接口状态

-(void) pcycleSDK:(PcycleSDK *) pcycleSDK didInit:(CBCentralManagerState) state;

枚举类型 PcycleRollStickAction

typedef NS_ENUM(NSInteger, CBCentralManagerState) {
	CBCentralManagerStateUnknown = 0,
	CBCentralManagerStateResetting,
	CBCentralManagerStateUnsupported,
	CBCentralManagerStateUnauthorized,
	CBCentralManagerStatePoweredOff,
	CBCentralManagerStatePoweredOn,
};

2.扫描

开始扫描Pcycle设备,开启后在后台不停扫描

-(void) scanForPcycleDevices;

**委托:**委托方法中会返回扫描结果,开启扫描后,每扫描到一个新的设备,就返回一个结果(名称,UUID,RSSI)

-(void) pcycleSDK:(PcycleSDK *) pcycleSDK discoverPcycleDevice:(NSString *)name UUID:(NSString *)uuid RSSI:(NSNumber *)RSSI;

3.停止扫描
-(void) stopScan;

4.连接

连接指定UUID设备

-(void) connectToPcycleDevice:(NSString*) UUID;

**委托:**连接成功返回名称和UUID,否则返回错误信息(error)

-(void) pcycleSDK:(PcycleSDK *) pcycleSDK didConnectToPcycleDevice:(NSString *)name UUID:(NSString *)uuid error:(NSError *) error;

5.断开连接
-(void) disconnectPcycleDevice:(NSString*) UUID;

6.发送获取速度请求
-(void) requestCurrentVelocity;

**委托:**请求成功返回速度值(单位 m/s,精确到小数点后1位),否则返回错误信息(error)

-(void) pcycleSDK:(PcycleSDK *) pcycleSDK didRequestCurrentVelocity:(float) metersPerSecond error:(NSError *) error;

7.设置阻力

允许的取值范围为[0,100],单位牛顿 (精确到小数点后1位)

-(void) setResistance:(float) newton;

**委托:**成功返回设置的阻力值,失败返回错误信息(error)

-(void) pcycleSDK:(PcycleSDK *) pcycleSDK didSetResistance:(float) newton error:(NSError *) error;

8.摇杆信息委托

定义该方法后,当摇杆状态发生变化时,会触发此方法,返回当前的摇杆动作

-(void) pcycleSDK:(PcycleSDK *) pcycleSDK rollStickRolled:(PcycleRollStickAction) action error:(NSError *) error;

枚举类型 PcycleRollStickAction

typedef NS_ENUM(NSInteger, PcycleRollStickAction) {
    PcycleRollStickActionOrign = 0,
    PcycleRollStickActionUp,
    PcycleRollStickActionDown,
    PcycleRollStickActionLeft,
    PcycleRollStickActionRight,
    PcycleRollStickActionLeftUp,
    PcycleRollStickActionRightUp,
    PcycleRollStickActionLeftDown,
    PcycleRollStickActionRightDown
};

9.按钮信息委托

定义该方法后,当摇杆状态发生变化时,会触发此方法,返回点击的按钮序号

-(void) pcycleSDK:(PcycleSDK *) pcycleSDK buttonPressed:(NSNumber *) buttonIndex error:(NSError *) error;

10.发送获取踏频请求
- (void)requestStepFreq;

**委托:**请求成功返回踏频值(单位 c/m,精确到小数点后1位),否则返回错误信息(error)

-(void) pcycleSDK:(PcycleSDK *) pcycleSDK didRequestStepFreq:(float) cirlesPerMinute error:(NSError *) error;

11.请求固件版本
-(void) requestFirmwareVer;

**委托:**请求成功返回固件版本值,否则返回错误信息(error)

-(void) pcycleSDK:(PcycleSDK *) pcycleSDK didRequestFirmwareVer:(int) version error:(NSError *) error;