Skip to content

Commit

Permalink
Convert code from java version to kotlin (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
sknull committed Dec 27, 2023
1 parent a51d29e commit 2ca7a62
Show file tree
Hide file tree
Showing 116 changed files with 4,662 additions and 71 deletions.
52 changes: 40 additions & 12 deletions docs/colors-lmair.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,48 @@ dark yellow 404000
dark magenta 400040
dark cyan 004040

Background purple-green {group:background;color:#8000ff,#004000,#8000ff,#004000} bicolor purple-green 192.168.178.30:8888/v1/hybrid/json/hexColor?hexColors=8000ff,004000,8000ff,004000,8000ff,004000,8000ff&turnOn=true&
Background green-purple {group:background;color:#004000,#8000ff,#004000,#8000ff} bicolor green-purple 192.168.178.30:8888/v1/hybrid/json/hexColor?hexColors=004000,8000ff,004000,8000ff,004000,8000ff,004000&turnOn=true&

Background blue-green {group:background;color:#0000ff,#004000,#0000ff,#004000} bicolor blue-green 192.168.178.30:8888/v1/hybrid/json/hexColor?hexColors=0000ff,00ff00,0000ff,00ff00,0000ff,00ff00,0000ff&turnOn=true&
Background green-blue {group:background;color:#004000,#0000ff,#004000,#0000ff} bicolor green-blue 192.168.178.30:8888/v1/hybrid/json/hexColor?hexColors=00ff00,0000ff,00ff00,0000ff,00ff00,0000ff,00ff00&turnOn=true&
Background Rainbow Blue-Red {group:background;color:#0000ff,#00ffff,#00ff00,#ffff00,#ff8000,#ff0000} 192.168.178.30:8888/v1/hybrid/json/hexColor?hexColors=0000ff,00ffff,00ff00,80ff00,ffff00,ff3000,ff0000&turnOn=true&
Background Rainbow Red-Blue {group:background;color:#ff0000,#ff8000,#ffff00,#00ff00,#00ffff,#0000ff} 192.168.178.30:8888/v1/hybrid/json/hexColor?hexColors=ff0000,ff3000,ffff00,80ff00,00ff00,00ffff,0000ff&turnOn=true&

Background blue-cyan {group:background;color:#0000ff,#00ffff,#0000ff,#00ffff} bicolor blue-cyan 192.168.178.30:8888/v1/hybrid/json/hexColor?hexColors=0000ff,00ffff,0000ff,00ffff,0000ff,00ffff,0000ff&turnOn=true&
Background cyan-blue {group:background;color:#00ffff,#0000ff,#00ffff,#0000ff} bicolor cyan-blue 192.168.178.30:8888/v1/hybrid/json/hexColor?hexColors=00ffff,0000ff,00ffff,0000ff,00ffff,0000ff,00ffff&turnOn=true&
Background Rainbow Dark Blue-Red {group:background;color:#000080,#008080,#008000,#808000,#808000,#800000} Hybrid Rainbow Dark Blue-Red 192.168.178.30:8888/v1/hybrid/json/hexColor?hexColors=000080,008080,008000,808000,808000,803000,800000&turnOn=true&
Background Rainbow Dark Red-Blue {group:background;color:#800000,#808000,#808000,#008000,#008080,#000080} Hybrid Rainbow Dark Red-Blue 192.168.178.30:8888/v1/hybrid/json/hexColor?hexColors=800000,803000,808000,808000,008000,008080,000080&turnOn=true&

Background blue-yellow {group:background;color:#0000ff,#ffff00,#0000ff,#ffff00} bicolor blue-yellow 192.168.178.30:8888/v1/hybrid/json/hexColor?hexColors=0000ff,ffff00,0000ff,ffff00,0000ff,ffff00,0000ff&turnOn=true&
Background yellow-blue {group:background;color:#ffff00,#0000ff,#ffff00,#0000ff} bicolor yellow-blue 192.168.178.30:8888/v1/hybrid/json/hexColor?hexColors=ffff00,0000ff,ffff00,0000ff,ffff00,0000ff,ffff00&turnOn=true&
Background purple-green {group:background;color:#8000ff,#004000,#8000ff,#004000,#8000ff} bicolor purple-green 192.168.178.30:8888/v1/hybrid/json/hexColor?hexColors=8000ff,004000,8000ff,004000,8000ff,004000,8000ff&turnOn=true&
Background green-purple {group:background;color:#004000,#8000ff,#004000,#8000ff,#004000} bicolor green-purple 192.168.178.30:8888/v1/hybrid/json/hexColor?hexColors=004000,8000ff,004000,8000ff,004000,8000ff,004000&turnOn=true&

Background green-yellow {group:background;color:#00ff00,#ffff00,#00ff00,#ffff00} bicolor green-yellow 192.168.178.30:8888/v1/hybrid/json/hexColor?hexColors=00ff00,ffff00,00ff00,ffff00,00ff00,ffff00,00ff00&turnOn=true&
Background yellow-green {group:background;color:#ffff00,#00ff00,#ffff00,#00ff00} bicolor yellow-green 192.168.178.30:8888/v1/hybrid/json/hexColor?hexColors=ffff00,00ff00,ffff00,00ff00,ffff00,00ff00,ffff00&turnOn=true&
Background blue-green {group:background;color:#0000ff,#004000,#0000ff,#004000,#0000ff} bicolor blue-green 192.168.178.30:8888/v1/hybrid/json/hexColor?hexColors=0000ff,00ff00,0000ff,00ff00,0000ff,00ff00,0000ff&turnOn=true&
Background green-blue {group:background;color:#004000,#0000ff,#004000,#0000ff,#004000} bicolor green-blue 192.168.178.30:8888/v1/hybrid/json/hexColor?hexColors=00ff00,0000ff,00ff00,0000ff,00ff00,0000ff,00ff00&turnOn=true&

Background purple-yellow {group:background;color:#8000ff,#ffff00,#8000ff,#ffff00} bicolor purple-yellow 192.168.178.30:8888/v1/hybrid/json/hexColor?hexColors=8000ff,ffff00,8000ff,ffff00,8000ff,ffff00,8000ff&turnOn=true&
Background yellow-purple {group:background;color:#ffff00,#8000ff,#ffff00,#8000ff} bicolor yellow-purple 192.168.178.30:8888/v1/hybrid/json/hexColor?hexColors=ffff00,8000ff,ffff00,8000ff,ffff00,8000ff,ffff00&turnOn=true&
Background blue-cyan {group:background;color:#0000ff,#00ffff,#0000ff,#00ffff,#0000ff} bicolor blue-cyan 192.168.178.30:8888/v1/hybrid/json/hexColor?hexColors=0000ff,00ffff,0000ff,00ffff,0000ff,00ffff,0000ff&turnOn=true&
Background cyan-blue {group:background;color:#00ffff,#0000ff,#00ffff,#0000ff,#00ffff} bicolor cyan-blue 192.168.178.30:8888/v1/hybrid/json/hexColor?hexColors=00ffff,0000ff,00ffff,0000ff,00ffff,0000ff,00ffff&turnOn=true&

Background blue-yellow {group:background;color:#0000ff,#ffff00,#0000ff,#ffff00,#0000ff} bicolor blue-yellow 192.168.178.30:8888/v1/hybrid/json/hexColor?hexColors=0000ff,ffff00,0000ff,ffff00,0000ff,ffff00,0000ff&turnOn=true&
Background yellow-blue {group:background;color:#ffff00,#0000ff,#ffff00,#0000ff,#ffff00} bicolor yellow-blue 192.168.178.30:8888/v1/hybrid/json/hexColor?hexColors=ffff00,0000ff,ffff00,0000ff,ffff00,0000ff,ffff00&turnOn=true&

Background blue-white {group:background;color:#0000ff,#ffffff,#0000ff,#ffffff,#0000ff} bicolor blue-white 192.168.178.30:8888/v1/hybrid/json/hexColor?hexColors=0000ff,ffffff,0000ff,ffffff,0000ff,ffffff,0000ff&turnOn=true&
Background white-blue {group:background;color:#ffffff,#0000ff,#ffffff,#0000ff,#ffffff} bicolor white-blue 192.168.178.30:8888/v1/hybrid/json/hexColor?hexColors=ffffff,0000ff,ffffff,0000ff,ffffff,0000ff,ffffff&turnOn=true&

Background green-yellow {group:background;color:#00ff00,#ffff00,#00ff00,#ffff00,#00ff00} bicolor green-yellow 192.168.178.30:8888/v1/hybrid/json/hexColor?hexColors=00ff00,ffff00,00ff00,ffff00,00ff00,ffff00,00ff00&turnOn=true&
Background yellow-green {group:background;color:#ffff00,#00ff00,#ffff00,#00ff00,#ffff00} bicolor yellow-green 192.168.178.30:8888/v1/hybrid/json/hexColor?hexColors=ffff00,00ff00,ffff00,00ff00,ffff00,00ff00,ffff00&turnOn=true&

Background purple-yellow {group:background;color:#8000ff,#ffff00,#8000ff,#ffff00,#8000ff} bicolor purple-yellow 192.168.178.30:8888/v1/hybrid/json/hexColor?hexColors=8000ff,ffff00,8000ff,ffff00,8000ff,ffff00,8000ff&turnOn=true&
Background yellow-purple {group:background;color:#ffff00,#8000ff,#ffff00,#8000ff,#ffff00} bicolor yellow-purple 192.168.178.30:8888/v1/hybrid/json/hexColor?hexColors=ffff00,8000ff,ffff00,8000ff,ffff00,8000ff,ffff00&turnOn=true&

Background purple-orange {group:background;color:#8000ff,#ff8000,#8000ff,#ff8000,#8000ff} bicolor purple-yellow 192.168.178.30:8888/v1/hybrid/json/hexColor?hexColors=8000ff,ff8000,8000ff,ff8000,8000ff,ff8000,8000ff&turnOn=true&
Background orange-purple {group:background;color:#ff8000,#8000ff,#ff8000,#8000ff,#ff8000} bicolor yellow-purple 192.168.178.30:8888/v1/hybrid/json/hexColor?hexColors=ff8000,8000ff,ff8000,8000ff,ff8000,8000ff,ff8000&turnOn=true&

Background red-orange {group:background;color:#ff0000,#ff8000,#ff0000,#ff8000,#ff0000} bicolor purple-yellow 192.168.178.30:8888/v1/hybrid/json/hexColor?hexColors=ff0000,ff8000,ff0000,ff8000,ff0000,ff8000,ff0000&turnOn=true&
Background orange-red {group:background;color:#ff8000,#ff0000,#ff8000,#ff0000,#ff8000} bicolor yellow-purple 192.168.178.30:8888/v1/hybrid/json/hexColor?hexColors=ff8000,ff0000,ff8000,ff0000,ff8000,ff0000,ff8000&turnOn=true&

Background yellow-orange {group:background;color:#ffff00,#ff8000,#ffff00,#ff8000,#ffff00} bicolor purple-yellow 192.168.178.30:8888/v1/hybrid/json/hexColor?hexColors=ffff00,ff8000,ffff00,ff8000,ffff00,ff8000,ffff00&turnOn=true&
Background orange-yellow {group:background;color:#ff8000,#ffff00,#ff8000,#ffff00,#ff8000} bicolor yellow-purple 192.168.178.30:8888/v1/hybrid/json/hexColor?hexColors=ff8000,ffff00,ff8000,ffff00,ff8000,ffff00,ff8000&turnOn=true&

Background red-green {group:background;color:#ff0000,#00ff00,#ff0000,#00ff00,#ff0000} bicolor red-green 192.168.178.30:8888/v1/hybrid/json/hexColor?hexColors=ff0000,00ff00,ff0000,00ff00,ff0000,00ff00,ff0000&turnOn=true&
Background green-red {group:background;color:#00ff00,#ff0000,#00ff00,#ff0000,#00ff00} bicolor green-red 192.168.178.30:8888/v1/hybrid/json/hexColor?hexColors=00ff00,ff0000,00ff00,ff0000,00ff00,ff0000,00ff00&turnOn=true&

Background red-blue {group:background;color:#ff0000,#0000ff,#ff0000,#0000ff,#ff0000} bicolor red-blue 192.168.178.30:8888/v1/hybrid/json/hexColor?hexColors=ff0000,0000ff,ff0000,0000ff,ff0000,0000ff,ff0000&turnOn=true&
Background blue-red {group:background;color:#0000ff,#ff0000,#0000ff,#ff0000,#0000ff} bicolor blue-red 192.168.178.30:8888/v1/hybrid/json/hexColor?hexColors=0000ff,ff0000,0000ff,ff0000,0000ff,ff0000,0000ff&turnOn=true&

Background green-orange {group:background;color:#00ff00,#ff8000,#00ff00,#ff8000,#00ff00} bicolor green-orange 192.168.178.30:8888/v1/hybrid/json/hexColor?hexColors=00ff00,ff8000,00ff00,ff8000,00ff00,ff8000,00ff00&turnOn=true&
Background orange-green {group:background;color:#ff8000,#00ff00,#ff8000,#00ff00,#ff8000} bicolor orange-green 192.168.178.30:8888/v1/hybrid/json/hexColor?hexColors=ff8000,00ff00,ff8000,00ff00,ff8000,00ff00,ff8000&turnOn=true&
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ class RGBColor(
blue: Int = 0
) : RGBBaseColor<RGBColor>(red, green, blue) {

constructor(value: Long) : this(
red = min(a = 255, b = (value and 0x00ff0000L shr 16).toInt()),
green = min(a = 255, b = (value and 0x0000ff00L shr 8).toInt()),
blue = min(a = 255, b = (value and 0x000000ffL).toInt())
)

constructor(hex: String) : this(java.lang.Long.decode(if (hex.startsWith("#") || hex.startsWith("0x")) hex else "#$hex"))

override fun parameterMap(): Map<String, Int> = mapOf(
"Red" to red,
"Green" to green,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ import jssc.SerialPortException
import org.apache.commons.lang3.StringUtils


open class DMXInterface {
open class DmxInterface {

val dmxFrame = DmxFrame()

private var serialPort: SerialPort? = null

companion object {
fun load(type: DMXInterfaceType): DMXInterface {
fun load(type: DmxInterfaceType): DmxInterface {
return when (type) {
DMXInterfaceType.Serial -> DMXInterface()
DMXInterfaceType.Dummy -> DMXInterfaceDummy()
DMXInterfaceType.Rest -> DMXInterfaceRest()
DmxInterfaceType.Serial -> DmxInterface()
DmxInterfaceType.Dummy -> DmxInterfaceDummy()
DmxInterfaceType.Rest -> DmxInterfaceRest()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.visualdigits.kotlin.klanglicht.model.dmx


class DMXInterfaceDummy : DMXInterface() {
class DmxInterfaceDummy : DmxInterface() {

override fun toString(): String {
return repr()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package de.visualdigits.kotlin.klanglicht.model.dmx

class DMXInterfaceRest : DMXInterface() {
class DmxInterfaceRest : DmxInterface() {

override fun toString(): String {
return repr()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package de.visualdigits.kotlin.klanglicht.model.dmx

enum class DMXInterfaceType {
enum class DmxInterfaceType {

Serial,
Dummy,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package de.visualdigits.kotlin.klanglicht.model.dmx
import org.slf4j.LoggerFactory

class DmxRepeater(
val dmxInterface: DMXInterface,
val dmxInterface: DmxInterface,
val dmxFrameTime: Long
) : Thread("DMX Repeater") {

Expand All @@ -18,8 +18,8 @@ class DmxRepeater(
var dmxRepeater: DmxRepeater? = null

fun instance(
dmxInterface: DMXInterface,
dmxFrameTime: Long
dmxInterface: DmxInterface,
dmxFrameTime: Long = 200
): DmxRepeater {
if (dmxRepeater == null) {
dmxRepeater = DmxRepeater(dmxInterface, dmxFrameTime / 2)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package de.visualdigits.kotlin.klanglicht.model.parameter

interface Fadeable<T : Fadeable<T>> {

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package de.visualdigits.kotlin.klanglicht.model.preferences


class ColorState(
var hexColor: String? = null,
var gain: Float? = null,
var on: Boolean = false
)

Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package de.visualdigits.kotlin.klanglicht.model.preferences

import de.visualdigits.kotlin.klanglicht.model.dmx.DMXInterfaceType
import de.visualdigits.kotlin.klanglicht.model.dmx.DmxInterfaceType


data class Dmx(
val port: String = "",
val interfaceType: DMXInterfaceType = DMXInterfaceType.Dummy,
val interfaceType: DmxInterfaceType = DmxInterfaceType.Dummy,
val frameTime: Long = 40L,
val devices: List<DmxDevice> = listOf()
)
) {

val dmxDevices: Map<String, DmxDevice> = devices.associateBy { it.baseChannel.toString() }
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ data class DmxDevice(
val model: String = "",
val mode: String = "",
val baseChannel: Int = 0,
val gain: Double = 0.0
val gain: Float = 0.0f
) {
var fixture: Fixture? = null
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package de.visualdigits.kotlin.klanglicht.model.preferences

import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.module.kotlin.jacksonMapperBuilder
import de.visualdigits.kotlin.klanglicht.model.dmx.DMXInterface
import de.visualdigits.kotlin.klanglicht.model.dmx.DMXInterfaceDummy
import de.visualdigits.kotlin.klanglicht.model.dmx.DmxInterface
import de.visualdigits.kotlin.klanglicht.model.dmx.DmxInterfaceDummy
import de.visualdigits.kotlin.klanglicht.model.fixture.Channel
import de.visualdigits.kotlin.klanglicht.model.fixture.Fixtures
import de.visualdigits.kotlin.klanglicht.model.parameter.Scene
Expand All @@ -21,7 +21,7 @@ data class Preferences(

var klanglichtDir: File = File(".")

var dmxInterface: DMXInterface = DMXInterfaceDummy()
var dmxInterface: DmxInterface = DmxInterfaceDummy()

/** contains the list of channels for a given base dmx channel. */
var fixtures: Map<Int, List<Channel>> = mapOf()
Expand All @@ -44,7 +44,7 @@ data class Preferences(
Pair(service.name, service)
}.toMap()

val dmxInterface = DMXInterface.load(dmx.interfaceType)
val dmxInterface = DmxInterface.load(dmx.interfaceType)
dmxInterface.open(dmx.port)
this.dmxInterface = dmxInterface
}
Expand All @@ -55,7 +55,10 @@ data class Preferences(

var preferences: Preferences? = null

fun load(klanglichtDir: File, preferencesFileName: String = "preferences.json"): Preferences {
fun load(
klanglichtDir: File,
preferencesFileName: String = "preferences.json"
): Preferences {
if (preferences == null) {
val prefs = mapper.readValue(
Paths.get(klanglichtDir.canonicalPath, "preferences", preferencesFileName).toFile(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package de.visualdigits.kotlin.klanglicht.model.preferences
data class ShellyDevice(
val name: String = "",
val model: String = "",
val command: String = "",
val ipAddress: String = "",
val gain: Int = 0
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import java.io.File
import kotlin.math.ceil

@Disabled("for local testing only")
class DMXInterfaceTest {
class DmxInterfaceTest {

private val prefs = Preferences.load(
klanglichtDir = File(ClassLoader.getSystemResource(".klanglicht").toURI()),
preferencesFileName = System.getenv("preferencesFileName")?:"preferences_livingroom.json"
preferencesFileName = System.getenv("preferencesFileName")?:"preferences_livingroom_dummy.json"
)

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
{
"name" : "wohnzimmer",

"services": [
{
"name": "lmair",
"manufacturer" : "JB-Media",
"model" : "Light-Manager Air",
"url": "http://192.168.178.28"
},
{
"name": "receiver",
"manufacturer" : "Yamaha",
"model" : "RX-V6A",
"url": "http://192.168.178.46"
}
],

"shelly": {
"devices": [
{
"name": "Starwars",
"model": "shelly-rgbw",
"ipAddress": "192.168.178.54",
"gain": 30
},
{
"name": "Rgbw",
"model": "shelly-rgbw",
"ipAddress": "192.168.178.48",
"gain": 1
},
{
"name": "Bar",
"model": "shelly-rgbw",
"ipAddress": "192.168.178.55",
"gain": 20
},
{
"name": "Flur",
"model": "shelly-1",
"ipAddress": "192.168.178.38",
"gain": 0
},
{
"name": "Schlafzimmer",
"model": "shelly-1",
"ipAddress": "192.168.178.40",
"gain": 0
},
{
"name": "Wohnzimmer",
"model": "shelly-2.5",
"ipAddress": "192.168.178.37",
"gain": 0
},
{
"name": "Kristall",
"model": "plug-s",
"ipAddress": "192.168.178.51",
"gain": 0
},
{
"name": "Regal",
"model": "shelly-plug-s",
"ipAddress": "192.168.178.39",
"gain": 0
}
]
},

"dmx": {
"port": "COM8",
"interfaceType": "Dummy",
"frameTime": 40,
"devices" : [ {
"manufacturer" : "Cameo",
"model" : "Flat PAR Can RGB 10 IR",
"mode" : "6-Channel Mode",
"baseChannel" : 1,
"gain": 0.5
}, {
"manufacturer" : "Cameo",
"model" : "Flat PAR Can RGBW",
"mode" : "8-Channel Mode",
"baseChannel" : 7,
"gain": 1.0
}, {
"manufacturer" : "Cameo",
"model" : "Flat PAR Can RGB 10 IR",
"mode" : "6-Channel Mode",
"baseChannel" : 15,
"gain": 0.5
}, {
"manufacturer" : "Cameo",
"model" : "Flat PAR Can RGBW",
"mode" : "8-Channel Mode",
"baseChannel" : 21,
"gain": 1.0
}, {
"manufacturer" : "Cameo",
"model" : "Flat PAR Can RGB 10 IR",
"mode" : "6-Channel Mode",
"baseChannel" : 29,
"gain": 0.5
} ]
}
}
Loading

0 comments on commit 2ca7a62

Please sign in to comment.