-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from XYOracleNetwork/develop
include swift package support with minor doc update
- Loading branch information
Showing
65 changed files
with
5,985 additions
and
18 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: Swift Build | ||
|
||
on: | ||
push: | ||
branches-ignore: | ||
- "master" | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: macOS-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Build | ||
run: | | ||
swift build -Xswiftc "-sdk" -Xswiftc "`xcrun --sdk iphonesimulator --show-sdk-path`" -Xswiftc "-target" -Xswiftc "x86_64-apple-ios13.0-simulator" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
{ | ||
"object": { | ||
"pins": [ | ||
{ | ||
"package": "Apollo", | ||
"repositoryURL": "https://github.com/apollographql/apollo-ios.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "6b1b04334f73879232a4ab5320c5431ad295020a", | ||
"version": "0.23.0" | ||
} | ||
}, | ||
{ | ||
"package": "Promises", | ||
"repositoryURL": "https://github.com/google/promises", | ||
"state": { | ||
"branch": null, | ||
"revision": "6b6f4fe3385ed37389fb231bc40be81de2f1230f", | ||
"version": "1.2.8" | ||
} | ||
}, | ||
{ | ||
"package": "XyBaseSdk", | ||
"repositoryURL": "https://github.com/XYOracleNetwork/sdk-base-swift.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "837e268d9b167d02fa8a047b15b0f7cca6eff75b", | ||
"version": "1.0.4" | ||
} | ||
}, | ||
{ | ||
"package": "SQLite.swift", | ||
"repositoryURL": "https://github.com/stephencelis/SQLite.swift.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "0a9893ec030501a3956bee572d6b4fdd3ae158a1", | ||
"version": "0.12.2" | ||
} | ||
}, | ||
{ | ||
"package": "Starscream", | ||
"repositoryURL": "https://github.com/daltoniam/Starscream", | ||
"state": { | ||
"branch": null, | ||
"revision": "e6b65c6d9077ea48b4a7bdda8994a1d3c6969c8d", | ||
"version": "3.1.1" | ||
} | ||
}, | ||
{ | ||
"package": "swift-nio-zlib-support", | ||
"repositoryURL": "https://github.com/apple/swift-nio-zlib-support.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "37760e9a52030bb9011972c5213c3350fa9d41fd", | ||
"version": "1.0.0" | ||
} | ||
} | ||
] | ||
}, | ||
"version": 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
// | ||
// XYConstants.swift | ||
// XYBleSdk | ||
// | ||
// Created by Darren Sutherland on 9/7/18. | ||
// Copyright © 2018 XY - The Findables Company. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
internal struct XYConstants { | ||
static let DEVICE_TUNING_SECONDS_INTERVAL_CONNECTED_RSSI_READ = 3 | ||
static let DEVICE_TUNING_LOCATION_CHANGE_THRESHOLD = 10.0 | ||
static let DEVICE_TUNING_SECONDS_EXIT_CHECK_INTERVAL = 1.0 | ||
static let DEVICE_TUNING_SECONDS_WITHOUT_SIGNAL_FOR_EXITING = 12.0 | ||
|
||
static let DEVICE_TUNING_SECONDS_WITHOUT_SIGNAL_FOR_EXIT_GAP_SIZE = 2.0 | ||
static let DEVICE_TUNING_SECONDS_WITHOUT_SIGNAL_FOR_EXIT_WINDOW_COUNT = 3 | ||
static let DEVICE_TUNING_SECONDS_WITHOUT_SIGNAL_FOR_EXIT_WINDOW_SIZE = 2.5 | ||
|
||
static let DEVICE_POWER_LOW: UInt8 = 0x04 | ||
static let DEVICE_POWER_HIGH: UInt8 = 0x08 | ||
static let DEVICE_LOCK_DEFAULT = Data([0x2f, 0xbe, 0xa2, 0x07, 0x52, 0xfe, 0xbf, 0x31, 0x1d, 0xac, 0x5d, 0xfa, 0x7d, 0x77, 0x76, 0x80]) | ||
static let DEVICE_LOCK_XY4 = Data([0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f]) | ||
|
||
static let DEVICE_CONNECTABLE_SOURCE_UUID_XY4 = NSUUID(uuidString: "00000000-785F-0000-0000-0401F4AC4EA4") | ||
static let DEVICE_CONNECTABLE_SOURCE_UUID_DEFAULT = NSUUID(uuidString: "a500248c-abc2-4206-9bd7-034f4fc9ed10") | ||
} | ||
|
||
public enum XYDeviceProximity: Int { | ||
case none | ||
case outOfRange | ||
case veryFar | ||
case far | ||
case medium | ||
case near | ||
case veryNear | ||
case touching | ||
|
||
public static func fromSignalStrength(_ strength: Int) -> XYDeviceProximity { | ||
if strength == -999 { return XYDeviceProximity.none } | ||
if strength >= -40 { return XYDeviceProximity.touching } | ||
if strength >= -60 { return XYDeviceProximity.veryNear } | ||
if strength >= -70 { return XYDeviceProximity.near } | ||
if strength >= -80 { return XYDeviceProximity.medium } | ||
if strength >= -90 { return XYDeviceProximity.far } | ||
if strength >= -200 { return XYDeviceProximity.veryFar } | ||
return XYDeviceProximity.outOfRange | ||
} | ||
|
||
public static let defaultProximity: Int = -999 | ||
} | ||
|
||
public enum XYButtonType2 : Int { | ||
case none | ||
case single | ||
case double | ||
case long | ||
} | ||
|
||
|
||
|
||
public enum XYFinderSong { | ||
case off | ||
case findIt | ||
|
||
public func values(for device: XYDeviceFamily) -> [UInt8] { | ||
switch self { | ||
case .off: | ||
switch device.id { | ||
case XY4BluetoothDevice.id: | ||
return [0xff, 0x03] | ||
default: | ||
return [0xff] | ||
} | ||
case .findIt: | ||
switch device.id { | ||
case XY4BluetoothDevice.id: | ||
return [0x0b, 0x03] | ||
case XY2BluetoothDevice.id: | ||
return [0x01] | ||
default: | ||
return [0x02] | ||
} | ||
} | ||
|
||
} | ||
} | ||
|
||
// A generic semaphore lock with configurable lock amounts and timeout | ||
internal class GenericLock { | ||
|
||
// Default 5 minute wait time | ||
private static let genericLockTimeout: TimeInterval = 300 | ||
|
||
private let | ||
semaphore: DispatchSemaphore, | ||
waitTimeout: TimeInterval | ||
|
||
init(_ value: Int = 1, timeout: TimeInterval = GenericLock.genericLockTimeout) { | ||
self.semaphore = DispatchSemaphore(value: value) | ||
self.waitTimeout = timeout | ||
} | ||
|
||
public func lock() { | ||
if self.semaphore.wait(timeout: .now() + self.waitTimeout) == .timedOut { | ||
self.unlock() | ||
} | ||
} | ||
|
||
public func unlock() { | ||
self.semaphore.signal() | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// | ||
// XYCentralAgent.swift | ||
// XYBleSdk | ||
// | ||
// Created by Darren Sutherland on 11/1/18. | ||
// Copyright © 2018 XY - The Findables Company. All rights reserved. | ||
// | ||
|
||
import CoreBluetooth | ||
import Promises | ||
|
||
// An agent that allows for adding connecting to the Central in an XYBluetoothDevice connection block | ||
// or any other Promises chain | ||
public final class XYCentralAgent: XYCentralDelegate { | ||
private let | ||
central = XYCentral.instance, | ||
delegateKey: String | ||
|
||
private lazy var promise = Promise<Void>.pending() | ||
|
||
public init() { | ||
self.delegateKey = "XYCentralAgent:\(UUID.init().uuidString)" | ||
} | ||
|
||
@discardableResult public func powerOn() -> Promise<Void> { | ||
guard self.central.state != .poweredOn else { return Promise(()) } | ||
|
||
self.central.setDelegate(self, key: self.delegateKey) | ||
self.central.enable() | ||
|
||
return promise.always(on: XYCentral.centralQueue) { | ||
self.central.removeDelegate(for: self.delegateKey) | ||
} | ||
} | ||
|
||
public func stateChanged(newState: CBManagerState) { | ||
newState == .poweredOn ? | ||
promise.fulfill(()) : | ||
promise.reject(XYBluetoothError.couldNotPowerOnCentral) | ||
} | ||
|
||
// Unused | ||
public func located(peripheral: XYPeripheral) {} | ||
public func discovered(beacon: XYIBeaconDefinition) {} | ||
public func connected(peripheral: XYPeripheral) {} | ||
public func timeout() {} | ||
public func couldNotConnect(peripheral: XYPeripheral) {} | ||
public func disconnected(periperhal: XYPeripheral) {} | ||
} |
Oops, something went wrong.