diff --git a/IRDB b/IRDB index f3ebbeb..4af2edc 160000 --- a/IRDB +++ b/IRDB @@ -1 +1 @@ -Subproject commit f3ebbebed2309526538ef7f81ef0dc2ca6064a35 +Subproject commit 4af2edcce8b5757f7b41d6ee727a68ecdc6aa4f7 diff --git a/gradle.properties b/gradle.properties index 89b3488..40718d3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,10 +5,10 @@ org.gradle.configureondemand=true org.gradle.caching=true org.gradle.parallel=true # Gradle project core -makeevrserg.project.name=IfrBackend -makeevrserg.project.url=https://github.com/makeevrserg/IfrSample +makeevrserg.project.name=IRDBBackend +makeevrserg.project.url=https://github.com/flipperdevices/IRDB-Backend makeevrserg.project.group=com.flipperdevices.ifrmvp.backend -makeevrserg.project.version.string=0.3.0 +makeevrserg.project.version.string=0.4.0 makeevrserg.project.description=Api for IfrSample makeevrserg.project.developers=makeevrserg|Makeev Roman|makeevrserg@gmail.com # Java diff --git a/modules/infrared/src/main/kotlin/com/flipperdevices/infrared/editor/util/InfraredMapper.kt b/modules/infrared/src/main/kotlin/com/flipperdevices/infrared/editor/util/InfraredMapper.kt new file mode 100644 index 0000000..c48d53d --- /dev/null +++ b/modules/infrared/src/main/kotlin/com/flipperdevices/infrared/editor/util/InfraredMapper.kt @@ -0,0 +1,68 @@ +package com.flipperdevices.infrared.editor.util + +import com.flipperdevices.bridge.dao.api.model.FlipperFileFormat +import com.flipperdevices.infrared.editor.model.InfraredRemote +import com.flipperdevices.infrared.editor.viewmodel.FULL_IR_FILETYPE +import com.flipperdevices.infrared.editor.viewmodel.FULL_VERSION_1 +import com.flipperdevices.infrared.editor.viewmodel.InfraredKeyParser +import com.flipperdevices.infrared.editor.viewmodel.KEY_ADDRESS +import com.flipperdevices.infrared.editor.viewmodel.KEY_COMMAND +import com.flipperdevices.infrared.editor.viewmodel.KEY_DATA +import com.flipperdevices.infrared.editor.viewmodel.KEY_DUTY_CYCLE +import com.flipperdevices.infrared.editor.viewmodel.KEY_FREQUENCY +import com.flipperdevices.infrared.editor.viewmodel.KEY_NAME +import com.flipperdevices.infrared.editor.viewmodel.KEY_PROTOCOL +import com.flipperdevices.infrared.editor.viewmodel.KEY_TYPE +import java.io.File + +object InfraredMapper { + fun parseRemotes(raw: String): List { + return raw + .let(FlipperFileFormat.Companion::fromFileContent) + .let(InfraredKeyParser::mapParsedKeyToInfraredRemotes) + + } + + fun parseRemotes(file: File): List { + return file + .readText() + .let(::parseRemotes) + } + + fun toInfraredFormat(remotes: List): String { + return buildString { + append(FULL_IR_FILETYPE) + append("\n") + append(FULL_VERSION_1) + + remotes.forEachIndexed { index, remote -> + append("\n") + append("# ") + append("\n") + append("$KEY_NAME: ${remote.name}") + append("\n") + append("$KEY_TYPE: ${remote.type}") + append("\n") + when (remote) { + is InfraredRemote.Parsed -> { + append("${KEY_PROTOCOL}: ${remote.protocol}") + append("\n") + append("${KEY_ADDRESS}: ${remote.address}") + append("\n") + append("${KEY_COMMAND}: ${remote.command}") + } + + is InfraredRemote.Raw -> { + append("${KEY_FREQUENCY}: ${remote.frequency}") + append("\n") + append("${KEY_DUTY_CYCLE}: ${remote.dutyCycle}") + append("\n") + append("${KEY_DATA}: ${remote.data}") + } + } + } + append("\n") + } + } + +} \ No newline at end of file diff --git a/modules/infrared/src/main/kotlin/com/flipperdevices/infrared/editor/viewmodel/InfraredKeyParser.kt b/modules/infrared/src/main/kotlin/com/flipperdevices/infrared/editor/viewmodel/InfraredKeyParser.kt index 947f769..023314e 100644 --- a/modules/infrared/src/main/kotlin/com/flipperdevices/infrared/editor/viewmodel/InfraredKeyParser.kt +++ b/modules/infrared/src/main/kotlin/com/flipperdevices/infrared/editor/viewmodel/InfraredKeyParser.kt @@ -3,18 +3,20 @@ package com.flipperdevices.infrared.editor.viewmodel import com.flipperdevices.bridge.dao.api.model.FlipperFileFormat import com.flipperdevices.infrared.editor.model.InfraredRemote -private const val KEY_NAME = "name" -private const val KEY_TYPE = "type" -private const val KEY_TYPE_RAW = "raw" -private const val KEY_TYPE_PARSED = "parsed" +internal const val FULL_IR_FILETYPE = "Filetype: IR signals file" +internal const val FULL_VERSION_1 = "Version: 1" +internal const val KEY_NAME = "name" +internal const val KEY_TYPE = "type" +internal const val KEY_TYPE_RAW = "raw" +internal const val KEY_TYPE_PARSED = "parsed" -private const val KEY_PROTOCOL = "protocol" -private const val KEY_ADDRESS = "address" -private const val KEY_COMMAND = "command" +internal const val KEY_PROTOCOL = "protocol" +internal const val KEY_ADDRESS = "address" +internal const val KEY_COMMAND = "command" -private const val KEY_FREQUENCY = "frequency" -private const val KEY_DUTY_CYCLE = "duty_cycle" -private const val KEY_DATA = "data" +internal const val KEY_FREQUENCY = "frequency" +internal const val KEY_DUTY_CYCLE = "duty_cycle" +internal const val KEY_DATA = "data" private val allFields = listOf( KEY_NAME, diff --git a/modules/kenerator/configuration/src/main/kotlin/com/flipperdevices/ifrmvp/generator/config/Main.kt b/modules/kenerator/configuration/src/main/kotlin/com/flipperdevices/ifrmvp/generator/config/Main.kt index 9b25a48..d4093ba 100644 --- a/modules/kenerator/configuration/src/main/kotlin/com/flipperdevices/ifrmvp/generator/config/Main.kt +++ b/modules/kenerator/configuration/src/main/kotlin/com/flipperdevices/ifrmvp/generator/config/Main.kt @@ -16,6 +16,7 @@ import com.flipperdevices.ifrmvp.generator.config.category.api.TvsCategoryConfig import com.flipperdevices.ifrmvp.generator.config.device.api.DefaultDeviceConfigGenerator import com.flipperdevices.ifrmvp.generator.config.device.api.any.AnyDeviceKeyNamesProvider import com.flipperdevices.ifrmvp.parser.util.ParserPathResolver +import com.flipperdevices.infrared.editor.util.InfraredMapper import com.flipperdevices.infrared.editor.viewmodel.InfraredKeyParser import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json @@ -108,8 +109,29 @@ fun printAllKeys() { } +private fun filterSameInfraredFiles() { + ParserPathResolver.categories + .forEach { category -> + ParserPathResolver.brands(category.name) + .forEach { brand -> + ParserPathResolver.brandIfrFiles( + category = category.name, + brand = brand.name + ).forEach { irFile -> + val remotes = InfraredMapper.parseRemotes(irFile) + val distinctRemotes = remotes.distinctBy { it } + val sameRemotesCount = remotes.size - distinctRemotes.size + if (sameRemotesCount < 0) error("wtf") + if (sameRemotesCount == 0) return@forEach + irFile.writeText(InfraredMapper.toInfraredFormat(distinctRemotes)) + } + } + } +} + fun main() { generateCategoriesConfigFiles() generateDevicesConfigFiles() // printAllKeys() +// filterSameInfraredFiles() } diff --git a/modules/kenerator/configuration/src/main/kotlin/com/flipperdevices/ifrmvp/generator/config/device/api/any/AnyDeviceKeyNamesProvider.kt b/modules/kenerator/configuration/src/main/kotlin/com/flipperdevices/ifrmvp/generator/config/device/api/any/AnyDeviceKeyNamesProvider.kt index ec9e0ed..2bb2b0f 100644 --- a/modules/kenerator/configuration/src/main/kotlin/com/flipperdevices/ifrmvp/generator/config/device/api/any/AnyDeviceKeyNamesProvider.kt +++ b/modules/kenerator/configuration/src/main/kotlin/com/flipperdevices/ifrmvp/generator/config/device/api/any/AnyDeviceKeyNamesProvider.kt @@ -63,7 +63,6 @@ object AnyDeviceKeyNamesProvider : DeviceKeyNamesProvider { "chann_up", "chan up", "up", - "next", "up/ch+", "tv_ch+", ) @@ -76,7 +75,6 @@ object AnyDeviceKeyNamesProvider : DeviceKeyNamesProvider { "chann_down", "chan down", "down", - "prev", "tv_ch-", )