summaryrefslogtreecommitdiff
path: root/Waydio.h
blob: 346d687d498f7bc3490d5512804982b6cc8c1891 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
//
//  Waydio.h
//  waydio_comms_demo
//
//  Created by Tim Redfern on 01/09/2013.
//
//

//
//  ios_brsp_lib
//  Created by Michael Testa on 11/1/12.
//  Copyright (c) 2012 BlueRadios, Inc. All rights reserved.
//

//The BRSP service UUID.  Use this in a CBCentralManager scan to filter
#define BRSP_SERVICE_UUID @"DA2B84F1-6279-48DE-BDC0-AFBEA0226079"

#import <Foundation/Foundation.h>
#import <CoreBluetooth/CoreBluetooth.h>
#import "AppDelegate.h"
#import "Brsp.h"

@class Waydio;

@protocol WaydioDelegate <NSObject>

@required
/**
 Called when the open status has changed after a call to either open or close.
 @param waydio    The Waydio object generating this event
 @param isOpen  YES == Open
 */
- (void)waydio:(Waydio*)waydio OpenStatusChanged:(BOOL)isOpen;
/**
 Called when the measured weight changes
 @param waydio    The Waydio object generating this event
 @param weight
 */
- (void)waydio:(Waydio*)waydio WeightChanged:(Float32)weight;
/**
 Called when the battery level changes
 @param waydio    The Waydio object generating this event
 @param batteryPercent
 */
- (void)waydio:(Waydio*)waydio BatteryChanged:(Float32)batteryPercent;
/**
 Called when the isSending changes
 @param waydio    The Waydio object generating this event
 @param isOpen  YES == Pressed
 */
- (void)waydio:(Waydio*)waydio ButtonChanged:(BOOL)isPressed;

@optional

/**
 Used to pass on CBPeripheral errors that may occur
 @param brsp    The Brsp object generating this event
 @param error   NSError object containing the error
 */
- (void)waydio:(Waydio*)waydio ErrorReceived:(NSError*)error;

@end

/**
 Class used to interact with the Waydio peripheral
 */
@interface Waydio : NSObject <CBPeripheralDelegate, BrspDelegate, CBCentralManagerDelegate> {
    
    id <WaydioDelegate> delegate;
    BrspMode _lastMode;
    NSTimer * weighTimer;
    NSTimer * batteryTimer;
    NSTimer * buttonTimer;
    int command;
    bool button;
    int battery;
}

/**
 The delegate used for WaydioDelegate events.
 */
@property (retain) id <WaydioDelegate> delegate;
/**
 A pointer to the CBPeripheral object that is associated with this device.
 */
@property (nonatomic, readonly) CBPeripheral *peripheral;
/**
 An integer indicating the level of security enforced by the Waydio service on the opened port
 0 == None, 1 == Unauthenticated Pairing With Encryption, 2 == Authenticated Pairing With Encryption, 99 = Unknown
 */
@property (nonatomic, readonly) NSUInteger securityLevel;
/**
 Waydio open/closed status
 YES = Open
 */
@property (nonatomic, readonly) BOOL isOpen;

/**
 The BRSP object used to communicate with waydio
 */
@property (strong, nonatomic) Brsp *brspObject;

/**
 A Convenience function that returns a CBUUID for the brsp Service
 @return CBUUID object for service "DA2B84F1-6279-48DE-BDC0-AFBEA0226079"
 */
+ (CBUUID *) brspServiceUUID;

/**
 Initializer for this class
 @param peripheral The CBPeripheral object to be used
 @return self
 @note  Changes peripheral.delegate to self.  If peripheral.delegate is set another object, initWithPeripheral and open will have to be called again
 to reinitialize.
 @note  The default input and output buffer sizes are 1024 bytes
 */
- (id)initWithPeripheral:(CBPeripheral*)peripheral;

/**
 An alternate initializer for this class which sets the input and output buffer sizes.
 Use this if the default buffer sizes are not adequate
 @param peripheral  The CBPeripheral object to be used
 @param in_size     The fixed input buffer size to use
 @param out_size    The fixed output buffer size to use
 @return self
 @note  Changes peripheral.delegate to self.  If peripheral.delegate is set another object, initWithPeripheral and open will have to be called again
 to reinitialize.
 @note  The default input and output buffer sizes are 1024 bytes
 */
- (id)initWithPeripheral:(CBPeripheral*)peripheral InputBufferSize:(NSUInteger)in_size OutputBufferSize:(NSUInteger)out_size;

/**
 Opens a Waydio connection. (Prepares peipheral for using the Waydio service, characteristics, and notifications)
 */
//- (void)open;

- (void)sendCommand:(NSString *)str;


/**
 Closes a Waydio connection. (Turns off notifications, etc)
 */
- (void)close;


@end