You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+36-10Lines changed: 36 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,19 +3,21 @@ nRF8001-Swift
3
3
4
4
**nRF8001-Swift** was written by **[Michael Teeuw](https://twitter.com/michmich)**
5
5
6
-
##What is it?
6
+
# What is it?
7
7
While working on one of my Arduino projects, I was in the need for a simple wrapper for communication with the [Adafruit Bluefruit LE nRF8001 Breakout](https://www.adafruit.com/products/1697).
8
8
9
9
Since I was unable to find one (especially one that was Swift-ready) I wrote a Swift-wrapper myself. It is based on a [Bluefruit LE Connect](https://github.com/adafruit/Bluefruit_LE_Connect).
10
10
11
11
It has all the basic needs for basic two way communication and is easy to implement.
12
12
13
13

14
-
*Image Courtesy of [Adafruit](https://www.adafruit.com/products/1697)*
14
+
*Image Courtesy of [Adafruit](https://www.adafruit.com/products/1697).*
15
15
16
-
##How to use
16
+
# How to use
17
17
Add the [NRFManager.swift](https://github.com/MichMich/nRF8001-Swift/blob/master/nRF8001-Swift/NRFManager.swift) file to your project and use the following implementation:
18
18
19
+
##Initialization
20
+
19
21
Use the shared instance:
20
22
21
23
```Swift
@@ -68,6 +70,7 @@ let nrfClosureExample = NRFManager(
68
70
)
69
71
```
70
72
73
+
###Properties
71
74
After initialization, it's possible to (re)set the following properties:
72
75
73
76
-`nrfManager.delegate` to set the delegate.
@@ -91,22 +94,43 @@ Additionally, the following properties are read-only:
91
94
## Instance methods
92
95
A NRFManager can receive the following method calls:
93
96
94
-
-`nrfManager.connect()` to start looking for a connection. Only necessary when `autoConnect` is set to `false`.
97
+
```Swift
98
+
nrfManager.connect()
99
+
```
100
+
Start looking for a connection. Only necessary when `autoConnect` is set to `false`.
95
101
96
-
-`nrfManager.disconnect()` to disconnect from the nRF8001 device. Note that when `autoConnect` is set to `true`, the NRFManager will be an annoying prick and start looking for an new connection instantly ...
102
+
```Swift
103
+
nrfManager.disconnect()
104
+
```
105
+
Disconnect from the nRF8001 device. Note that when `autoConnect` is set to `true`, the NRFManager will be an annoying prick and start looking for an new connection instantly ...
97
106
98
-
-`nrfManager.writeString(string:String) -> Bool` to send a String to the nRF8001 device. It will return a Bool to tell you if it was possible to send it. (If there is no current connection, this will return `false` in all other cases this will return `true`.)
107
+
```Swift
108
+
nrfManager.writeString(string:String) ->Bool
109
+
```
110
+
Send a String to the nRF8001 device. It will return a Bool to tell you if it was possible to send it. (If there is no current connection, this will return `false` in all other cases this will return `true`.)
99
111
100
-
-`nrfManager.writeData(data:NSData) -> Bool` to send raw data (NSData) to the nRF8001 device. It will return a Bool to tell you if it was possible to send it. (If there is no current connection, this will return `false` in all other cases this will return `true`.)
112
+
```Swift
113
+
nrfManager.writeData(data:NSData) ->Bool
114
+
```
115
+
Send raw data (NSData) to the nRF8001 device. It will return a Bool to tell you if it was possible to send it. (If there is no current connection, this will return `false` in all other cases this will return `true`.)
101
116
102
117
## Delegate methods
103
118
The following methods are part of the NRFManagerDelegate protocol:
104
119
105
-
-`nrfDidConnect(nrfManager:NRFManager)` is called when the NRFManager connects to the nRF8001 module. The `nrfManager` variable will contain a reference to the NRFManager instance which connected.
120
+
```Swift
121
+
nrfDidConnect(nrfManager:NRFManager)
122
+
```
123
+
Called when the NRFManager connects to the nRF8001 module. The `nrfManager` variable will contain a reference to the NRFManager instance which connected.
106
124
107
-
-`nrfDidDisconnect(nrfManager:NRFManager)` is called when the NRFManager disconnect from the nRF8001 module. The `nrfManager` variable will contain a reference to the NRFManager instance which disconnected.
125
+
```Swift
126
+
nrfDidDisconnect(nrfManager:NRFManager)
127
+
```
128
+
Called when the NRFManager disconnect from the nRF8001 module. The `nrfManager` variable will contain a reference to the NRFManager instance which disconnected.
108
129
109
-
-`nrfReceivedData(nrfManager:NRFManager, data:NSData, string:String)` is called when the NRFManager receives data from the nRF8001 module. The `nrfManager` variable will contain a reference to the NRFManager instance which received data. `data` will contain the raw data, `string` will contain the string representation of the received data.
Called when the NRFManager receives data from the nRF8001 module. The `nrfManager` variable will contain a reference to the NRFManager instance which received data. `data` will contain the raw data, `string` will contain the string representation of the received data.
110
134
111
135
## Delegates AND Closures?!
112
136
The reason I implemented both is because I was unable to decide what the best approach is. Personally I tend to prefer the delegate route.
@@ -187,6 +211,8 @@ class ViewController: UIViewController, NRFManagerDelegate {
187
211
}
188
212
```
189
213
214
+
You can check out the example project to see how it works. It includes both the delegate and closure usage.
215
+
190
216
## Yeah, cool! But how do I connect my Bluefruit Breakout Board?
191
217
192
218
Check Adafruit's [awesome tutorial](https://learn.adafruit.com/getting-started-with-the-nrf8001-bluefruit-le-breakout) on how to use the Bluefruit Breakout Board. You can use the echo example sketch to test out nRF8001-Swift.
0 commit comments