Commit f48e1e16 authored by David's avatar David

Adding gizmos and designing camera flow

parent ce721e07
Pipeline #4 failed with stages
in 32 seconds
package `is`.kow.deskscreen.camera
import `is`.kow.deskscreen.MainController
import com.github.thomasnield.rxkotlinfx.doOnNextFx
import com.github.thomasnield.rxkotlinfx.observeOnFx
import com.hopding.jrpicam.RPiCamera
import io.reactivex.Observable
import io.reactivex.schedulers.Schedulers
import javafx.event.ActionEvent
import mu.KotlinLogging
import tornadofx.*
import java.awt.image.BufferedImage
import java.nio.file.Paths
......@@ -14,6 +18,8 @@ class CameraController : Controller() {
private val camera: RPiCamera?
private val mainController: MainController by inject()
private val cameraStateModel: CameraStateModel by inject()
init {
//Only care that the folders exist
//TODO: add a cleanup mechanism that only keeps some number of pictures, or some amount of space or something
......@@ -33,11 +39,46 @@ class CameraController : Controller() {
}
}
fun takePicture(): BufferedImage? {
return camera
?.setRotation(270)
?.setDateTimeOn()
?.setFullPreviewOn()
?.takeBufferedStill()
fun takePicture(actionEvents: Observable<ActionEvent>) {
actionEvents
.observeOn(Schedulers.io())
.doOnNextFx {
//UPdate state
cameraStateModel.state.set(PictureTakingState.TAKING)
}
.map {
val timeout = 5
//Handles the timer countdown
Observable.range(timeout, 0)
.observeOnFx()
.map {
cameraStateModel.countdownPercentage.value = it / timeout.toDouble()
}
.subscribe()
//The camera blocks things. need to also start the countdown observable for the thing.
//TODO: when it's not the pi, just use some image with the same dimensions!
camera
?.setRotation(270)
?.setDateTimeOn()
?.setTimeout(timeout)
?.setFullPreviewOn()
?.takeBufferedStill()
}
.doOnNextFx {
cameraStateModel.image.value = it
cameraStateModel.state.set(PictureTakingState.PREVIEWING)
}
.subscribe()
}
fun keepPicture() {
}
fun rejectPicture() {
}
}
\ No newline at end of file
package `is`.kow.deskscreen.camera
import com.github.thomasnield.rxkotlinfx.actionEvents
import javafx.beans.binding.Bindings
import javafx.beans.binding.BooleanBinding
import javafx.beans.property.SimpleDoubleProperty
import javafx.beans.property.SimpleObjectProperty
import javafx.geometry.Pos
import javafx.scene.control.ProgressBar
......@@ -22,6 +24,9 @@ class CameraState {
val stateProperty = SimpleObjectProperty<PictureTakingState>(this, "state", PictureTakingState.READY)
var state by stateProperty
val countdownPercentageProperty = SimpleDoubleProperty(this, "countdown", 5.0)
var countdownPercentage by countdownPercentageProperty
}
class CameraStateModel : ItemViewModel<CameraState>() {
......@@ -29,21 +34,28 @@ class CameraStateModel : ItemViewModel<CameraState>() {
val image: SimpleObjectProperty<BufferedImage> = bind(CameraState::imageProperty)
val state: SimpleObjectProperty<PictureTakingState> = bind(CameraState::stateProperty)
val countdownPercentage = bind(CameraState::countdownPercentageProperty)
val previewing: BooleanBinding = Bindings.equal(PictureTakingState.PREVIEWING, state)
val readyToTake: BooleanBinding = Bindings.equal(PictureTakingState.READY, state) //Huh, why isn't that true to start with....
val readyToTake: BooleanBinding = Bindings.equal(PictureTakingState.READY, state)
}
class CameraView : View() {
private val logger = KotlinLogging.logger {}
private val cameraLoadingView: CameraLoadingView by inject()
private val cameraStateModel: CameraStateModel by inject()
private val cameraController: CameraController by inject()
init {
//set up the state, it's weird that I even have to do this, the initial value doesn't work
cameraStateModel.state.set(PictureTakingState.READY)
}
override fun onDock() {
//Hook up an observable to the state to have it swap views when ready
}
override val root = borderpane {
//Left and right can be 160px max
......@@ -59,6 +71,8 @@ class CameraView : View() {
enableWhen {
cameraStateModel.previewing
}
cameraController.takePicture(actionEvents())
//Picture is good, enabled only after a capture
//Make it green
}
......@@ -73,7 +87,7 @@ class CameraView : View() {
label("Delay to take picture")
hbox {
progressbar {
//countdown timer for photo taking
bind(cameraStateModel.countdownPercentage)
//Set max width to the same as something?
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment