Skip to content

Commit 0c37a81

Browse files
committed
WIP
1 parent 57dcde4 commit 0c37a81

File tree

8 files changed

+42
-27
lines changed

8 files changed

+42
-27
lines changed

data/Living Room.scene

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"deviceId": "192.168.1.9",
2222
"deviceName": "Light Panels 50:72:54",
2323
"accessToken": "xI2UVHZzcbuWWMIbig1Zv9NhajekW0oC",
24-
"defaultFixtureConfig": {
24+
"defaultFixtureOptions": {
2525
"type": "PixelArray",
2626
"pixelFormat": "RGB8"
2727
}

data/config.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
{
2-
"runningShowPath": "Playa 2022.sparkle",
3-
"runningScenePath": "Living Room.scene"
4-
}
1+
{"runningShowPath":"Playa 2022.sparkle"}

src/commonMain/kotlin/baaahs/controller/NanoleafManager.kt

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ class NanoleafController(
108108
) : Controller {
109109
private val upSince = clock.now()
110110
private var accessToken: String? = config?.accessToken
111+
?: nanoleafAdapter.getAccessToken(deviceMetadata,)
111112
private var device = accessToken?.let {
112113
nanoleafAdapter.openDevice(deviceMetadata, it)
113114
}
@@ -126,7 +127,7 @@ class NanoleafController(
126127
deviceMetadata.deviceId,
127128
accessToken
128129
)
129-
override val defaultFixtureConfig: FixtureConfig?
130+
override val defaultFixtureOptions: FixtureOptions?
130131
get() = null
131132
override val defaultTransportConfig: TransportConfig?
132133
get() = null
@@ -136,9 +137,7 @@ class NanoleafController(
136137
override fun createTransport(
137138
entity: Model.Entity?,
138139
fixtureConfig: FixtureConfig,
139-
transportConfig: TransportConfig?,
140-
componentCount: Int,
141-
bytesPerComponent: Int
140+
transportConfig: TransportConfig?
142141
): Transport = object : Transport {
143142
override val name: String
144143
get() = deviceMetadata.deviceName
@@ -189,7 +188,7 @@ class NanoleafController(
189188

190189
return listOf(
191190
FixtureMapping(null,
192-
PixelArrayDevice.Config(
191+
PixelArrayDevice.Options(
193192
panels.size,
194193
PixelFormat.RGB8,
195194
pixelLocations = scaledPixelLocations
@@ -228,6 +227,7 @@ class NanoleafTransportConfig() : TransportConfig {
228227
expect class NanoleafAdapter(coroutineContext: CoroutineContext, clock: Clock) {
229228
fun start(callback: (NanoleafDeviceMetadata) -> Unit)
230229
fun stop()
230+
fun getAccessToken(deviceMetadata: NanoleafDeviceMetadata): String
231231
fun openDevice(deviceMetadata: NanoleafDeviceMetadata, accessToken: String): NanoleafDevice
232232
}
233233

@@ -274,7 +274,7 @@ data class NanoleafControllerConfig(
274274
override val deviceName: String,
275275
val accessToken: String? = null,
276276
override val fixtures: List<FixtureMappingData> = emptyList(),
277-
override val defaultFixtureConfig: FixtureConfig? = null,
277+
override val defaultFixtureOptions: FixtureOptions? = null,
278278
override val defaultTransportConfig: TransportConfig? = null
279279
) : ControllerConfig, NanoleafDeviceMetadata {
280280
override val title: String get() = deviceName
@@ -299,19 +299,22 @@ data class NanoleafControllerConfig(
299299
}
300300
}
301301

302-
override fun createFixturePreview(fixtureConfig: FixtureConfig, transportConfig: TransportConfig): FixturePreview {
302+
override fun createFixturePreview(
303+
fixtureOptions: FixtureOptions,
304+
transportConfig: TransportConfig
305+
): FixturePreview {
303306
val staticDmxMapping = dmxAllocator!!.allocate(
304-
fixtureConfig.componentCount!!,
305-
fixtureConfig.bytesPerComponent,
307+
fixtureOptions.componentCount!!,
308+
fixtureOptions.bytesPerComponent,
306309
transportConfig as DmxTransportConfig
307310
)
308-
val dmxPreview = error("foo")
311+
// val dmxPreview = error("foo")
309312

310313
return object : FixturePreview {
311-
override val fixtureConfig: ConfigPreview
312-
get() = fixtureConfig.preview()
314+
override val fixtureOptions: ConfigPreview
315+
get() = fixtureOptions.preview()
313316
override val transportConfig: ConfigPreview
314-
get() = dmxPreview
317+
get() = transportConfig.preview()
315318
}
316319
}
317320
}
@@ -329,8 +332,8 @@ class MutableNanoleafControllerConfig(config: NanoleafControllerConfig) : Mutabl
329332

330333
override val fixtures: MutableList<MutableFixtureMapping> =
331334
config.fixtures.map { it.edit() }.toMutableList()
332-
override var defaultFixtureConfig: MutableFixtureConfig? =
333-
config.defaultFixtureConfig?.edit()
335+
override var defaultFixtureOptions: MutableFixtureOptions? =
336+
config.defaultFixtureOptions?.edit()
334337
override var defaultTransportConfig: MutableTransportConfig? =
335338
config.defaultTransportConfig?.edit()
336339

@@ -339,7 +342,7 @@ class MutableNanoleafControllerConfig(config: NanoleafControllerConfig) : Mutabl
339342
hostName, port, deviceId, deviceName,
340343
accessToken,
341344
fixtures.map { it.build() },
342-
defaultFixtureConfig?.build(),
345+
defaultFixtureOptions?.build(),
343346
defaultTransportConfig?.build()
344347
)
345348

src/commonMain/kotlin/baaahs/device/PixelFormat.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,13 @@ enum class PixelFormat {
116116
setter(redF, greenF, blueF)
117117
}
118118

119+
override fun readColorInts(reader: ByteArrayReader, setter: (Int, Int, Int) -> Unit) {
120+
val greenI = reader.readByte().asUnsignedToInt()
121+
val redI = reader.readByte().asUnsignedToInt()
122+
val blueI = reader.readByte().asUnsignedToInt()
123+
setter(redI, greenI, blueI)
124+
}
125+
119126
override fun writeColor(color: Color, buf: ByteArrayWriter) {
120127
buf.writeByte(1) // Mode: manual dimming
121128
buf.writeByte(0) // Palette (garbage!)

src/commonMain/kotlin/baaahs/plugin/sound_analysis/SoundAnalysisPlugin.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ class SoundAnalysisFeedContext(
382382
textureBuffer.position = 0
383383
textureBuffer = FloatBuffer(sampleBuffer)
384384
} catch (e: Exception) {
385-
println("texture buffer size == ${textureBuffer.size}")
385+
// println("texture buffer size == ${textureBuffer.size}")
386386
println("sample buffer size == ${sampleBuffer.size}")
387387
e.printStackTrace()
388388
}

src/jsMain/kotlin/baaahs/app/ui/controllers/NanoleafControllerEditorView.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ import baaahs.scene.EditingController
66
import baaahs.ui.unaryMinus
77
import baaahs.ui.value
88
import baaahs.ui.xComponent
9-
import kotlinx.js.jso
9+
import js.core.jso
1010
import mui.material.Container
1111
import mui.material.TextField
1212
import mui.system.sx
1313
import react.*
1414
import react.dom.onChange
15+
import web.cssom.Display
16+
import web.cssom.FlexDirection
1517

1618
private val NanoleafControllerEditorView = xComponent<NanoleafControllerEditorProps>("NanoleafControllerEditor") { props ->
1719
val appContext = useContext(appContext)
@@ -42,8 +44,8 @@ private val NanoleafControllerEditorView = xComponent<NanoleafControllerEditorPr
4244
Container {
4345
attrs.classes = jso { root = -styles.propertiesEditSection }
4446
attrs.sx {
45-
display = csstype.Display.flex
46-
flexDirection = csstype.FlexDirection.column
47+
display = Display.flex
48+
flexDirection = FlexDirection.column
4749
}
4850

4951
TextField {

src/jsMain/kotlin/baaahs/controller/NanoleafAdapter.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ actual class NanoleafAdapter actual constructor(coroutineContext: CoroutineConte
1010
actual fun stop() {
1111
}
1212

13+
actual fun getAccessToken(deviceMetadata: NanoleafDeviceMetadata): String {
14+
TODO("not implemented")
15+
}
16+
1317
actual fun openDevice(
1418
deviceMetadata: NanoleafDeviceMetadata,
1519
accessToken: String

src/jvmMain/kotlin/baaahs/controller/NanoleafAdapter.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ actual class NanoleafAdapter actual constructor(
3737
actual fun stop() {
3838
}
3939

40+
actual fun getAccessToken(deviceMetadata: NanoleafDeviceMetadata): String {
41+
return NanoleafSetup.createAccessToken(deviceMetadata.hostName, deviceMetadata.port)
42+
}
43+
4044
actual fun openDevice(
4145
deviceMetadata: NanoleafDeviceMetadata,
4246
accessToken: String
@@ -54,8 +58,6 @@ actual class NanoleafAdapter actual constructor(
5458
override val deviceName: String,
5559
val accessToken: String
5660
) : baaahs.controller.NanoleafDevice {
57-
58-
// val accessToken = NanoleafSetup.createAccessToken(meta.hostName, meta.port)
5961
// val accessToken = "xI2UVHZzcbuWWMIbig1Zv9NhajekW0oC"
6062
val device: NanoleafDevice = NanoleafDevice.createDevice(hostName, port, accessToken)
6163
.also { it.enableExternalStreaming() }

0 commit comments

Comments
 (0)