Browse Source

Nivåer og programmer

main
Stian Fredrik Aune 1 year ago
parent
commit
f3ff66b8fd
  1. 11
      webui-react/src/pages/runtime/ControlsBoi.tsx
  2. 2
      ykonsole-core/src/main/kotlin/net/aiterp/git/ykonsole2/domain/runtime/Event.kt
  3. 2
      ykonsole-core/src/main/kotlin/net/aiterp/git/ykonsole2/infrastructure/drivers/ProgramEnforcer.kt
  4. 2
      ykonsole-core/src/main/kotlin/net/aiterp/git/ykonsole2/infrastructure/drivers/WorkoutWriter.kt
  5. 2
      ykonsole-core/src/main/kotlin/net/aiterp/git/ykonsole2/infrastructure/testing/TestDriver.kt
  6. 2
      ykonsole-core/src/test/kotlin/net/aiterp/git/ykonsole2/infrastructure/drivers/ProgramEnforcerTest.kt
  7. 2
      ykonsole-exporter/src/main/kotlin/net/aiterp/git/ykonsole2/infrastructure/WorkoutExporter.kt
  8. 2
      ykonsole-iconsole/src/main/kotlin/net/aiterp/git/ykonsole2/infrastructure/IConsole.kt
  9. 55
      ykonsole-iconsole/src/main/kotlin/net/aiterp/git/ykonsole2/infrastructure/iconsole/Client.kt
  10. 2
      ykonsole-ktor/src/main/kotlin/net/aiterp/git/ykonsole2/application/routes/ws/Connection.kt

11
webui-react/src/pages/runtime/ControlsBoi.tsx

@ -18,6 +18,7 @@ interface Option {
}
const skipMessages = ["Ikke hopp over", "Hopp over straks", "Hopp over nå"];
const ENABLE_SKIP = false;
export function ControlsBoi() {
const {workout, disconnect, start, stop, setLevel, skip} = useContext(RuntimeContext);
@ -40,13 +41,13 @@ export function ControlsBoi() {
if (workout.status === WorkoutStatus.Started) {
btnList.push({icon: faPause, onClick: stop});
if (workout.program) {
if (workout.program && ENABLE_SKIP) {
const text = nextSkip > 0 ? `${nextSkip - lastTime} sek.` : "";
btnList.push({icon: faFastForward, text, warning: nextSkip >= 0, onClick: () => setMode("skip")});
} else {
btnList.push({icon: faArrowUpRightDots, onClick: () => setMode("level")});
}
btnList.push({icon: faArrowUpRightDots, onClick: () => setMode("level")});
}
if (isStopped) {
@ -104,10 +105,10 @@ export function ControlsBoi() {
}, [workout, disconnect]);
useEffect(() => {
if (lastState?.level && mode === "level") {
if (lastState?.level && mode === "level" && sel === 0) {
setSel(lastState.level - 1);
}
}, [lastState, mode]);
}, [lastState, mode, sel]);
useEffect(() => {
if (lastState?.time) {

2
ykonsole-core/src/main/kotlin/net/aiterp/git/ykonsole2/domain/runtime/Event.kt

@ -12,7 +12,7 @@ object Started : Event()
object Stopped : Event()
data class MilestoneReached(val keyValue: Value, val current: List<Value>, val diff: List<Value>) : Event()
object Connected : Event()
data class Connected(val initial: Boolean) : Event()
object Disconnected : Event()
object Skipped : Event()

2
ykonsole-core/src/main/kotlin/net/aiterp/git/ykonsole2/infrastructure/drivers/ProgramEnforcer.kt

@ -42,7 +42,7 @@ class ProgramEnforcer(
}
override suspend fun onEvent(event: Event, input: FlowBus<Command>) {
if (event is Connected) {
if (event is Connected && event.initial) {
// Start program on connecting
val programId = workoutRepo.findActive()?.apply {
lastTransition = WorkoutState(workoutId = id)

2
ykonsole-core/src/main/kotlin/net/aiterp/git/ykonsole2/infrastructure/drivers/WorkoutWriter.kt

@ -23,7 +23,7 @@ class WorkoutWriter(
stateRepo.save(newState)
}
Connected -> {
is Connected -> {
foundWorkout.status = WorkoutStatus.Connected
workoutRepo.save(foundWorkout)
}

2
ykonsole-core/src/main/kotlin/net/aiterp/git/ykonsole2/infrastructure/testing/TestDriver.kt

@ -43,7 +43,7 @@ class TestDriver(private val secondLength: Duration) : ActiveDriver() {
if (command.device.connectionString.startsWith("test:")) {
delay(Random.nextInt(100..300).milliseconds)
connected = true
Connected
Connected(initial = true)
} else {
log.info("Ignoring device: ${command.device.name}")
null

2
ykonsole-core/src/test/kotlin/net/aiterp/git/ykonsole2/infrastructure/drivers/ProgramEnforcerTest.kt

@ -73,7 +73,7 @@ internal class ProgramEnforcerTest {
coEvery { output.collect(any(), any()) } coAnswers {
val func = arg<suspend (value: Event) -> Unit>(1)
func.invoke(Connected)
func.invoke(Connected(initial = true))
func.invoke(Started)
events.forEach { func.invoke(it) }
}

2
ykonsole-exporter/src/main/kotlin/net/aiterp/git/ykonsole2/infrastructure/WorkoutExporter.kt

@ -17,7 +17,7 @@ class WorkoutExporter(
private var workoutId: String = ""
override suspend fun onEvent(event: Event, input: FlowBus<Command>) {
if (event is Connected) {
if (event is Connected && event.initial) {
workoutId = workoutRepo.findActive()?.id ?: ""
}

2
ykonsole-iconsole/src/main/kotlin/net/aiterp/git/ykonsole2/infrastructure/IConsole.kt

@ -150,7 +150,7 @@ class IConsole : ActiveDriver() {
logger.info("Device is now ready")
connected = true
output.emitBlocking(Connected)
output.emitBlocking(Connected(initial = bonusTime == 0))
}
if (res is MaxLevelResponse) {

55
ykonsole-iconsole/src/main/kotlin/net/aiterp/git/ykonsole2/infrastructure/iconsole/Client.kt

@ -1,55 +0,0 @@
package net.aiterp.git.ykonsole2.infrastructure.iconsole
import com.welie.blessed.*
import net.aiterp.git.ykonsole2.domain.runtime.Connected
import net.aiterp.git.ykonsole2.domain.runtime.Disconnected
import net.aiterp.git.ykonsole2.domain.runtime.ErrorOccurred
import net.aiterp.git.ykonsole2.domain.runtime.Event
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.channels.trySendBlocking
import kotlinx.coroutines.runBlocking
internal class Client(
private val connectionString: String,
private val eventCh: Channel<Event>,
) {
private lateinit var central: BluetoothCentralManager
private var current: BluetoothPeripheral? = null
init {
val cbPeripheral = object : BluetoothPeripheralCallback() {
override fun onCharacteristicUpdate(
peripheral: BluetoothPeripheral,
value: ByteArray,
characteristic: BluetoothGattCharacteristic,
status: BluetoothCommandStatus,
) {
val response = Response.fromBytes(value)
}
}
val cbScan = object : BluetoothCentralManagerCallback() {
override fun onConnectedPeripheral(peripheral: BluetoothPeripheral) {
current = peripheral
runBlocking { eventCh.send(Connected) }
}
override fun onConnectionFailed(peripheral: BluetoothPeripheral, status: BluetoothCommandStatus) {
runBlocking {
eventCh.send(ErrorOccurred("$connectionString: $status"))
}
}
override fun onDiscoveredPeripheral(peripheral: BluetoothPeripheral, scanResult: ScanResult) {
if (peripheral.address != connectionString) return
central.stopScan()
central.connectPeripheral(peripheral, cbPeripheral)
}
}
central = BluetoothCentralManager(cbScan)
central.scanForPeripheralsWithNames(arrayOf())
central.getPeripheral("")
}
}

2
ykonsole-ktor/src/main/kotlin/net/aiterp/git/ykonsole2/application/routes/ws/Connection.kt

@ -53,7 +53,7 @@ fun Route.sockets(
eventBus.collect(forceAll = true) { event ->
when (event) {
Connected, Started, Stopped, Disconnected, Skipped -> {
is Connected, Started, Stopped, Disconnected, Skipped -> {
sendSerialized(SocketOutput(event = SocketOutput.EventDTO(name = event.name)))
if (event is Disconnected) close()

Loading…
Cancel
Save