Skip to content

Commit

Permalink
Merge pull request #22 from XYOracleNetwork/develop
Browse files Browse the repository at this point in the history
Base Changes
  • Loading branch information
Arie Trouw authored Dec 29, 2018
2 parents 82f96c2 + a33586f commit bd1cae0
Show file tree
Hide file tree
Showing 28 changed files with 265 additions and 255 deletions.
2 changes: 1 addition & 1 deletion sdk-android-library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ dependencies {
api "androidx.annotation:annotation:1.0.1"

localImplementation project(':xycore')
jitpackApi 'com.github.XYOracleNetwork:sdk-core-android:1.0.3'
jitpackApi 'com.github.XYOracleNetwork:sdk-core-android:1.1.0'

implementation 'com.github.kotlin-graphics:kotlin-unsigned:v2.1'
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ class CallByVersion : XYBase() {
return
}
}
logError("No Call for OS Version Found", true)
log.error("No Call for OS Version Found", true)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ open class XY2BluetoothDevice(context: Context, scanResult: XYScanResult, hash:
val sensorService = SensorService(this)

override fun find(): Deferred<XYBluetoothResult<Int>> {
logInfo("find")
log.info("find")
return controlService.buzzerSelect.set(2)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ open class XY3BluetoothDevice(context: Context, scanResult: XYScanResult, hash:

private val buttonListener = object : XYBluetoothGattCallback() {
override fun onCharacteristicChanged(gatt: BluetoothGatt?, characteristic: BluetoothGattCharacteristic?) {
logInfo("onCharacteristicChanged")
log.info("onCharacteristicChanged")
super.onCharacteristicChanged(gatt, characteristic)
if (characteristic?.uuid == controlService.button.uuid) {
reportButtonPressed(buttonPressFromInt(characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 0)))
Expand All @@ -64,27 +64,27 @@ open class XY3BluetoothDevice(context: Context, scanResult: XYScanResult, hash:
override val prefix = "xy:ibeacon"

override fun find(): Deferred<XYBluetoothResult<Int>> {
logInfo("find")
log.info("find")
return controlService.buzzerSelect.set(2)
}

override fun lock(): Deferred<XYBluetoothResult<ByteArray>> {
logInfo("lock")
log.info("lock")
return basicConfigService.lock.set(DEFAULT_LOCK_CODE)
}

override fun unlock(): Deferred<XYBluetoothResult<ByteArray>> {
logInfo("unlock")
log.info("unlock")
return basicConfigService.unlock.set(DEFAULT_LOCK_CODE)
}

override fun stayAwake(): Deferred<XYBluetoothResult<Int>> {
logInfo("stayAwake")
log.info("stayAwake")
return extendedConfigService.registration.set(1)
}

override fun fallAsleep(): Deferred<XYBluetoothResult<Int>> {
logInfo("fallAsleep")
log.info("fallAsleep")
return extendedConfigService.registration.set(0)
}

Expand All @@ -93,7 +93,7 @@ open class XY3BluetoothDevice(context: Context, scanResult: XYScanResult, hash:
if (scanResult != null) {
if (pressFromScanResult(scanResult)) {
if (now - lastButtonPressTime > BUTTON_ADVERTISEMENT_LENGTH) {
logInfo("onDetect: pressFromScanResult: first")
log.info("onDetect: pressFromScanResult: first")
reportButtonPressed(ButtonPress.Single)
lastButtonPressTime = now
}
Expand All @@ -102,9 +102,9 @@ open class XY3BluetoothDevice(context: Context, scanResult: XYScanResult, hash:
}

private fun enableButtonNotifyIfConnected() {
logInfo("enableButtonNotifyIfConnected")
log.info("enableButtonNotifyIfConnected")
if (connectionState == ConnectionState.Connected) {
logInfo("enableButtonNotifyIfConnected: Connected")
log.info("enableButtonNotifyIfConnected: Connected")
controlService.button.enableNotify(true)
}
}
Expand Down Expand Up @@ -187,13 +187,13 @@ open class XY3BluetoothDevice(context: Context, scanResult: XYScanResult, hash:
}

fun reportGlobalButtonPressed(device: XY3BluetoothDevice, state: ButtonPress) {
logInfo("reportButtonPressed (Global)")
log.info("reportButtonPressed (Global)")
GlobalScope.launch {
synchronized(globalListeners) {
for (listener in globalListeners) {
val xyFinderListener = listener.value as? XYFinderBluetoothDevice.Listener
if (xyFinderListener != null) {
logInfo("reportButtonPressed: $xyFinderListener")
log.info("reportButtonPressed: $xyFinderListener")
GlobalScope.launch {
when (state) {
ButtonPress.Single -> xyFinderListener.buttonSinglePressed(device)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ open class XY4BluetoothDevice(context: Context, scanResult: XYScanResult, hash:

private val buttonListener = object : XYBluetoothGattCallback() {
override fun onCharacteristicChanged(gatt: BluetoothGatt?, characteristic: BluetoothGattCharacteristic?) {
logInfo("onCharacteristicChanged")
log.info("onCharacteristicChanged")
super.onCharacteristicChanged(gatt, characteristic)
if (characteristic?.uuid == primary.buttonState.uuid) {
reportButtonPressed(buttonPressFromInt(characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 0)))
Expand All @@ -62,42 +62,42 @@ open class XY4BluetoothDevice(context: Context, scanResult: XYScanResult, hash:
override val prefix = "xy:ibeacon"

override fun find(): Deferred<XYBluetoothResult<Int>> {
logInfo("find")
log.info("find")
return primary.buzzer.set(11)
}

override fun lock(): Deferred<XYBluetoothResult<ByteArray>> {
logInfo("lock")
log.info("lock")
return primary.lock.set(DefaultLockCode)
}

override fun unlock(): Deferred<XYBluetoothResult<ByteArray>> {
logInfo("unlock")
log.info("unlock")
return primary.unlock.set(DefaultLockCode)
}

override fun stayAwake(): Deferred<XYBluetoothResult<Int>> {
logInfo("stayAwake")
log.info("stayAwake")
return primary.stayAwake.set(1)
}

override fun fallAsleep(): Deferred<XYBluetoothResult<Int>> {
logInfo("fallAsleep")
log.info("fallAsleep")
return primary.stayAwake.set(0)
}

override fun batteryLevel(): Deferred<XYBluetoothResult<Int>> {
logInfo("batteryLevel")
log.info("batteryLevel")
return batteryService.level.get()
}

override fun onDetect(scanResult: XYScanResult?) {
super.onDetect(scanResult)
if (scanResult != null) {
if (pressFromScanResult(scanResult)) {
logInfo("onDetect: pressFromScanResult: true")
log.info("onDetect: pressFromScanResult: true")
if (now - lastButtonPressTime > BUTTON_ADVERTISEMENT_LENGTH) {
logInfo("onDetect: pressFromScanResult: first")
log.info("onDetect: pressFromScanResult: first")
reportButtonPressed(ButtonPress.Single)
lastButtonPressTime = now
}
Expand Down Expand Up @@ -128,15 +128,15 @@ open class XY4BluetoothDevice(context: Context, scanResult: XYScanResult, hash:

private fun enableButtonNotifyIfConnected() {

logInfo("enableButtonNotifyIfConnected")
log.info("enableButtonNotifyIfConnected")
if (connectionState == ConnectionState.Connected) {
logInfo("enableButtonNotifyIfConnected: Connected")
log.info("enableButtonNotifyIfConnected: Connected")
primary.buttonState.enableNotify(true)
}
}

override fun onConnectionStateChange(newState: Int) {
logInfo("onConnectionStateChange")
log.info("onConnectionStateChange")
super.onConnectionStateChange(newState)
enableButtonNotifyIfConnected()
}
Expand Down Expand Up @@ -198,13 +198,13 @@ open class XY4BluetoothDevice(context: Context, scanResult: XYScanResult, hash:
}

fun reportGlobalButtonPressed(device: XY4BluetoothDevice, state: ButtonPress) {
logInfo("reportButtonPressed (Global)")
log.info("reportButtonPressed (Global)")
GlobalScope.launch {
synchronized(globalListeners) {
for (listener in globalListeners) {
val xyFinderListener = listener.value as? XYFinderBluetoothDevice.Listener
if (xyFinderListener != null) {
logInfo("reportButtonPressed: $xyFinderListener")
log.info("reportButtonPressed: $xyFinderListener")
GlobalScope.launch {
when (state) {
ButtonPress.Single -> xyFinderListener.buttonSinglePressed(device)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ open class XYBluetoothDevice(context: Context, device: BluetoothDevice?, private
checkingForExit = true
GlobalScope.launch {
while (checkingForExit) {
//logInfo("checkForExit: $id : $rssi : $now : $outOfRangeDelay : $lastAdTime : $lastAccessTime")
//log.info("checkForExit: $id : $rssi : $now : $outOfRangeDelay : $lastAdTime : $lastAccessTime")
delay(outOfRangeDelay)

//check if something else has already marked it as exited
Expand All @@ -108,7 +108,7 @@ open class XYBluetoothDevice(context: Context, device: BluetoothDevice?, private
}

internal open fun onEnter() {
logInfo("onEnter: $address")
log.info("onEnter: $address")
enterCount++
lastAdTime = now
synchronized(listeners) {
Expand All @@ -122,7 +122,7 @@ open class XYBluetoothDevice(context: Context, device: BluetoothDevice?, private
}

internal open fun onExit() {
logInfo("onExit: $address")
log.info("onExit: $address")
exitCount++
synchronized(listeners) {
for ((_, listener) in listeners) {
Expand Down Expand Up @@ -161,11 +161,11 @@ open class XYBluetoothDevice(context: Context, device: BluetoothDevice?, private
}

override fun onConnectionStateChange(newState: Int) {
logInfo("onConnectionStateChange: $id : $newState: $listeners.size")
log.info("onConnectionStateChange: $id : $newState: $listeners.size")
synchronized(listeners) {
for ((tag, listener) in listeners) {
GlobalScope.launch {
logInfo("connectionStateChanged: $tag : $newState")
log.info("connectionStateChanged: $tag : $newState")
listener.connectionStateChanged(this@XYBluetoothDevice, newState)
if (newState == BluetoothGatt.STATE_CONNECTED) {
lastAccessTime = now
Expand All @@ -191,7 +191,7 @@ open class XYBluetoothDevice(context: Context, device: BluetoothDevice?, private
}

fun addListener(key: String, listener: Listener) {
logInfo("addListener:$key:$listener")
log.info("addListener:$key:$listener")
GlobalScope.launch {
synchronized(listeners) {
listeners.put(key, listener)
Expand All @@ -200,7 +200,7 @@ open class XYBluetoothDevice(context: Context, device: BluetoothDevice?, private
}

fun removeListener(key: String) {
logInfo("removeListener:$key")
log.info("removeListener:$key")
GlobalScope.launch {
synchronized(listeners) {
listeners.remove(key)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,57 +127,57 @@ open class XYFinderBluetoothDevice(context: Context, scanResult: XYScanResult, h

//signal the user to where it is, usually make it beep
open fun find(): Deferred<XYBluetoothResult<Int>> {
logError(UnsupportedOperationException().toString(), true)
log.error(UnsupportedOperationException().toString(), true)
return asyncBle {
return@asyncBle XYBluetoothResult<Int>(XYBluetoothError("Not Implemented"))
}
}

//turn off finding, if supported
open fun stopFind(): Deferred<XYBluetoothResult<Int>> {
logError(UnsupportedOperationException(), true)
log.error(UnsupportedOperationException(), true)
return asyncBle {
return@asyncBle XYBluetoothResult<Int>(XYBluetoothError("Not Implemented"))
}
}

open fun lock(): Deferred<XYBluetoothResult<ByteArray>> {
logError(UnsupportedOperationException(), true)
log.error(UnsupportedOperationException(), true)
return asyncBle {
return@asyncBle XYBluetoothResult<ByteArray>(XYBluetoothError("Not Implemented"))
}
}

open fun unlock(): Deferred<XYBluetoothResult<ByteArray>> {
logError(UnsupportedOperationException(), true)
log.error(UnsupportedOperationException(), true)
return asyncBle {
return@asyncBle XYBluetoothResult<ByteArray>(XYBluetoothError("Not Implemented"))
}
}

open fun stayAwake(): Deferred<XYBluetoothResult<Int>> {
logError(UnsupportedOperationException(), true)
log.error(UnsupportedOperationException(), true)
return asyncBle {
return@asyncBle XYBluetoothResult<Int>(XYBluetoothError("Not Implemented"))
}
}

open fun fallAsleep(): Deferred<XYBluetoothResult<Int>> {
logError(UnsupportedOperationException(), true)
log.error(UnsupportedOperationException(), true)
return asyncBle {
return@asyncBle XYBluetoothResult<Int>(XYBluetoothError("Not Implemented"))
}
}

open fun restart(): Deferred<XYBluetoothResult<Int>> {
logError(UnsupportedOperationException(), true)
log.error(UnsupportedOperationException(), true)
return asyncBle {
return@asyncBle XYBluetoothResult<Int>(XYBluetoothError("Not Implemented"))
}
}

open fun batteryLevel(): Deferred<XYBluetoothResult<Int>> {
logError(UnsupportedOperationException(), true)
log.error(UnsupportedOperationException(), true)
return asyncBle {
return@asyncBle XYBluetoothResult<Int>(XYBluetoothError("Not Implemented"))
}
Expand Down Expand Up @@ -210,13 +210,13 @@ open class XYFinderBluetoothDevice(context: Context, scanResult: XYScanResult, h
}

internal open fun reportButtonPressed(state: ButtonPress) {
logInfo("reportButtonPressed")
log.info("reportButtonPressed")
GlobalScope.launch {
synchronized(listeners) {
for (listener in listeners) {
val xyFinderListener = listener.value as? Listener
if (xyFinderListener != null) {
logInfo("reportButtonPressed: $xyFinderListener")
log.info("reportButtonPressed: $xyFinderListener")
GlobalScope.launch {
when (state) {
ButtonPress.Single -> xyFinderListener.buttonSinglePressed(this@XYFinderBluetoothDevice)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ open class XYGpsBluetoothDevice(context: Context, scanResult: XYScanResult, hash
override val prefix = "xy:gps"

override fun find(): Deferred<XYBluetoothResult<Int>> {
logInfo("find")
log.info("find")
return controlService.buzzerSelect.set(1)
}

Expand All @@ -62,7 +62,7 @@ open class XYGpsBluetoothDevice(context: Context, scanResult: XYScanResult, hash
}

// fun reportButtonPressed(state: Int) {
// logInfo("reportButtonPressed")
// log.info("reportButtonPressed")
// synchronized(listeners) {
// for (listener in listeners) {
// val xy3Listener = listener as? Listener
Expand Down Expand Up @@ -115,13 +115,13 @@ open class XYGpsBluetoothDevice(context: Context, scanResult: XYScanResult, hash
}

fun reportGlobalButtonPressed(device: XYGpsBluetoothDevice, state: ButtonPress) {
logInfo("reportButtonPressed (Global)")
log.info("reportButtonPressed (Global)")
GlobalScope.launch {
synchronized(globalListeners) {
for (listener in globalListeners) {
val xyFinderListener = listener.value as? XYFinderBluetoothDevice.Listener
if (xyFinderListener != null) {
logInfo("reportButtonPressed: $xyFinderListener")
log.info("reportButtonPressed: $xyFinderListener")
GlobalScope.launch {
when (state) {
ButtonPress.Single -> xyFinderListener.buttonSinglePressed(device)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ open class XYIBeaconBluetoothDevice(context: Context, scanResult: XYScanResult?,
UUID(high, low)
} catch (ex: BufferUnderflowException) {
// can throw a BufferUnderflowException if the beacon sends an invalid value for UUID.
logError("refreshGatt catch $ex", true)
log.error("refreshGatt catch $ex", true)
return null
}
} else {
Expand Down
Loading

0 comments on commit bd1cae0

Please sign in to comment.