diff --git a/app/src/androidTest/java/pl/rmakowiecki/smartalarmcore/ExampleInstrumentedTest.java b/app/src/androidTest/java/pl/rmakowiecki/smartalarmcore/ExampleInstrumentedTest.java
deleted file mode 100644
index 8d5763c..0000000
--- a/app/src/androidTest/java/pl/rmakowiecki/smartalarmcore/ExampleInstrumentedTest.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package pl.rmakowiecki.smartalarmcore;
-
-import android.content.Context;
-import android.support.test.InstrumentationRegistry;
-import android.support.test.runner.AndroidJUnit4;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import static org.junit.Assert.*;
-
-/**
- * Instrumentation test, which will execute on an Android device.
- *
- * @see Testing documentation
- */
-@RunWith(AndroidJUnit4.class)
-public class ExampleInstrumentedTest {
- @Test
- public void useAppContext() throws Exception {
- // Context of the app under test.
- Context appContext = InstrumentationRegistry.getTargetContext();
-
- assertEquals("pl.rmakowiecki.smartalarmcore", appContext.getPackageName());
- }
-}
diff --git a/app/src/main/java/pl/rmakowiecki/smartalarmcore/AlarmActivity.kt b/app/src/main/java/pl/rmakowiecki/smartalarmcore/AlarmActivity.kt
index eb1ca6a..0347806 100644
--- a/app/src/main/java/pl/rmakowiecki/smartalarmcore/AlarmActivity.kt
+++ b/app/src/main/java/pl/rmakowiecki/smartalarmcore/AlarmActivity.kt
@@ -8,6 +8,7 @@ import android.util.Log
import pl.rmakowiecki.smartalarmcore.peripheral.beam.BeamBreakDetectorPeriphery
import pl.rmakowiecki.smartalarmcore.peripheral.camera.CameraPeripheryContract
import pl.rmakowiecki.smartalarmcore.peripheral.motion.MotionSensorPeriphery
+import pl.rmakowiecki.smartalarmcore.peripheral.soundalarm.SoundAlarmPeriphery
import pl.rmakowiecki.smartalarmcore.remote.AlarmBackendContract
import pl.rmakowiecki.smartalarmcore.setup.UsbSetupProviderContract
@@ -17,7 +18,6 @@ class AlarmActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
-// printWifiNetworkStatus() test
alarmController = initSystemController()
}
@@ -25,6 +25,7 @@ class AlarmActivity : AppCompatActivity() {
BeamBreakDetectorPeriphery(),
MotionSensorPeriphery(),
CameraPeripheryContract.create(this),
+ SoundAlarmPeriphery(),
AlarmBackendContract.create(this),
UsbSetupProviderContract.create(this)
)
diff --git a/app/src/main/java/pl/rmakowiecki/smartalarmcore/AlarmController.kt b/app/src/main/java/pl/rmakowiecki/smartalarmcore/AlarmController.kt
index 32c8d8e..3829244 100644
--- a/app/src/main/java/pl/rmakowiecki/smartalarmcore/AlarmController.kt
+++ b/app/src/main/java/pl/rmakowiecki/smartalarmcore/AlarmController.kt
@@ -7,6 +7,7 @@ import pl.rmakowiecki.smartalarmcore.extensions.applyIoSchedulers
import pl.rmakowiecki.smartalarmcore.extensions.logD
import pl.rmakowiecki.smartalarmcore.peripheral.AlarmTriggerPeripheralDevice
import pl.rmakowiecki.smartalarmcore.peripheral.camera.CameraPeripheryContract
+import pl.rmakowiecki.smartalarmcore.peripheral.soundalarm.SoundAlarmPeriphery
import pl.rmakowiecki.smartalarmcore.remote.AlarmBackendContract
import pl.rmakowiecki.smartalarmcore.remote.models.AlarmTriggerReason
import pl.rmakowiecki.smartalarmcore.remote.models.SecurityIncident
@@ -16,6 +17,7 @@ class AlarmController(
private val beamBreakDetector: AlarmTriggerPeripheralDevice,
private val motionSensor: AlarmTriggerPeripheralDevice,
private val camera: CameraPeripheryContract,
+ private val soundAlarmPeriphery: SoundAlarmPeriphery,
private val backendInteractor: AlarmBackendContract,
private val usbSetupProvider: UsbSetupProviderContract
) {
@@ -71,7 +73,8 @@ class AlarmController(
updateAlarmTriggerState(it)
if (it == TRIGGERED) {
reportAlarmIncident(AlarmTriggerReason.BEAM_BREAK_DETECTOR)
- }
+ soundAlarmPeriphery.startSiren()
+ } else soundAlarmPeriphery.stopSiren()
}
)
}
@@ -84,10 +87,12 @@ class AlarmController(
.applyIoSchedulers()
.subscribeBy(
onNext = {
- updateAlarmTriggerState(it)
+ // updateAlarmTriggerState(it)
if (it == TRIGGERED) {
- reportAlarmIncident(AlarmTriggerReason.MOTION_SENSOR)
- }
+// reportAlarmIncident(AlarmTriggerReason.MOTION_SENSOR)
+ logD("motion sensor triggered")
+ soundAlarmPeriphery.startSiren()
+ } else soundAlarmPeriphery.stopSiren()
}
)
}
diff --git a/app/src/main/java/pl/rmakowiecki/smartalarmcore/peripheral/soundalarm/SoundAlarmPeriphery.kt b/app/src/main/java/pl/rmakowiecki/smartalarmcore/peripheral/soundalarm/SoundAlarmPeriphery.kt
new file mode 100644
index 0000000..f6e276e
--- /dev/null
+++ b/app/src/main/java/pl/rmakowiecki/smartalarmcore/peripheral/soundalarm/SoundAlarmPeriphery.kt
@@ -0,0 +1,38 @@
+package pl.rmakowiecki.smartalarmcore.peripheral.soundalarm
+
+import com.google.android.things.pio.Gpio
+import com.google.android.things.pio.PeripheralManagerService
+import pl.rmakowiecki.smartalarmcore.extensions.logE
+
+private const val PIN_NAME = "BCM21"
+
+class SoundAlarmPeriphery {
+
+ private lateinit var alarmSirenGpio: Gpio
+
+ init {
+ initAndRegisterGpioCallback()
+ }
+
+ private fun initAndRegisterGpioCallback() {
+ val service = PeripheralManagerService()
+ try {
+ alarmSirenGpio = service.openGpio(PIN_NAME)
+ alarmSirenGpio.apply {
+ setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW)
+ }
+
+ } catch (ex: Exception) {
+ ex.printStackTrace()
+ logE("GPIO exception")
+ }
+ }
+
+ fun startSiren() {
+ alarmSirenGpio.value = true
+ }
+
+ fun stopSiren() {
+ alarmSirenGpio.value = false
+ }
+}
diff --git a/app/src/main/java/pl/rmakowiecki/smartalarmcore/remote/AlarmBackendInteractor.kt b/app/src/main/java/pl/rmakowiecki/smartalarmcore/remote/AlarmBackendInteractor.kt
index 68650cb..6ec5e4e 100644
--- a/app/src/main/java/pl/rmakowiecki/smartalarmcore/remote/AlarmBackendInteractor.kt
+++ b/app/src/main/java/pl/rmakowiecki/smartalarmcore/remote/AlarmBackendInteractor.kt
@@ -133,12 +133,22 @@ class AlarmBackendInteractor(private val activity: AlarmActivity) : AlarmBackend
}
override fun uploadIncidentPhoto(photoBytes: ByteArray, uniqueIncidentId: String, photoNumber: Int): Single = Single.create { emitter ->
+ val photoFileName = "$uniqueIncidentId#$photoNumber.jpg"
+
storageNode.child(CORE_DEVICE_DIRECTORY)
.child(IMAGES_DIRECTORY)
.child(getCurrentBackendUser()?.uid ?: "non_assignable_incidents")
- .child("$uniqueIncidentId#$photoNumber.jpg")
+ .child(photoFileName)
.putBytes(photoBytes)
- .addOnCompleteListener { emitter.onSuccess(it.isSuccessful) }
+ .addOnCompleteListener {
+ databaseNode
+ .child(getCurrentBackendUser()?.uid)
+ .child("incidents")
+ .child(uniqueIncidentId)
+ .child("photos")
+ .child("$photoNumber")
+ .setValue(it.isSuccessful)
+ }
}
}