Skip to content

Commit 803e407

Browse files
committed
Fix loading animations from file with wrong ID
Fix connection trying to send running animations to local connection
1 parent 58db48e commit 803e407

3 files changed

Lines changed: 13 additions & 12 deletions

File tree

src/main/java/animatedledstrip/cmdline/CommandLine.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package animatedledstrip.cmdline
22

33
import kotlinx.coroutines.*
4+
import org.pmw.tinylog.Configurator
5+
import org.pmw.tinylog.Level
46
import java.io.EOFException
57
import java.io.ObjectInputStream
68
import java.io.ObjectOutputStream
@@ -17,6 +19,10 @@ class CommandLine {
1719

1820
private var readerJob: Job? = null
1921

22+
init {
23+
Configurator.defaultConfig().level(Level.OFF).activate()
24+
}
25+
2026
fun loop() {
2127
println("Welcome to the AnimatedLEDStrip Server console")
2228
while (!endCmdLine) {

src/main/java/animatedledstrip/server/AnimationHandler.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ internal class AnimationHandler(
6666
if (!it.isDirectory && it.name.endsWith(".anim")) try {
6767
ObjectInputStream(FileInputStream(it)).apply {
6868
val obj = readObject() as AnimationData
69-
addAnimation(obj)
69+
addAnimation(obj, obj.id)
7070
close()
7171
}
7272
} catch (e: ClassCastException) {
@@ -91,7 +91,7 @@ internal class AnimationHandler(
9191
*
9292
* @param params An AnimationData instance containing data about the animation to be run
9393
*/
94-
fun addAnimation(params: AnimationData) {
94+
fun addAnimation(params: AnimationData, animId: String? = null) {
9595

9696
/* Special "Animation" type that the client sends to end an animation */
9797
if (params.animation == Animation.ENDANIMATION)
@@ -105,7 +105,7 @@ internal class AnimationHandler(
105105
/* Animations that can be run repeatedly */
106106
false -> {
107107
if (params.continuous) {
108-
val id = (random() * 100000000).toInt().toString()
108+
val id = animId ?: (random() * 100000000).toInt().toString()
109109
continuousAnimations[id] =
110110
ContinuousRunAnimation(id, params, leds, this)
111111
Logger.trace(continuousAnimations)

src/main/java/animatedledstrip/server/SocketConnections.kt

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,19 +102,15 @@ object SocketConnections {
102102
while (server.running) {
103103
try {
104104
clientSocket = serverSocket.accept()
105-
Logger.trace { "Accepted new connection on port $port" }
106-
Logger.trace { "Initializing input stream" }
107105
val socIn = ObjectInputStream(clientSocket!!.getInputStream())
108-
Logger.trace { "Initializing output stream" }
109106
socOut = ObjectOutputStream(clientSocket!!.getOutputStream())
110107
Logger.info { "Connection on port $port Established" }
111108
connected = true
112-
Logger.debug { "Sending currently running animations to GUI" }
113109
// Send all current running continuous animations to newly connected client
114-
server.animationHandler.continuousAnimations.forEach {
115-
Logger.info { "Sending ${it.value}"}
116-
it.value.sendStartAnimation(this@Connection)
117-
}
110+
if (port != 1118)
111+
server.animationHandler.continuousAnimations.forEach {
112+
it.value.sendStartAnimation(this@Connection)
113+
}
118114
var input: Any?
119115
while (connected) {
120116
Logger.trace { "Waiting for input" }
@@ -190,7 +186,6 @@ object SocketConnections {
190186
withTimeout(5000) {
191187
withContext(Dispatchers.IO) {
192188
socOut?.writeObject(str)
193-
// ?: Logger.debug { "Could not send string $str: Connection socket null" }
194189
}
195190
}
196191
}

0 commit comments

Comments
 (0)