Skip to content

Commit

Permalink
Fix same remotes (#6)
Browse files Browse the repository at this point in the history
- add ability to filter same remotes
- fix next channel button
  • Loading branch information
makeevrserg authored Sep 3, 2024
1 parent 1358f05 commit a27081e
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 16 deletions.
2 changes: 1 addition & 1 deletion IRDB
Submodule IRDB updated 4077 files
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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|[email protected]
# Java
Expand Down
Original file line number Diff line number Diff line change
@@ -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<InfraredRemote> {
return raw
.let(FlipperFileFormat.Companion::fromFileContent)
.let(InfraredKeyParser::mapParsedKeyToInfraredRemotes)

}

fun parseRemotes(file: File): List<InfraredRemote> {
return file
.readText()
.let(::parseRemotes)
}

fun toInfraredFormat(remotes: List<InfraredRemote>): 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")
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ object AnyDeviceKeyNamesProvider : DeviceKeyNamesProvider {
"chann_up",
"chan up",
"up",
"next",
"up/ch+",
"tv_ch+",
)
Expand All @@ -76,7 +75,6 @@ object AnyDeviceKeyNamesProvider : DeviceKeyNamesProvider {
"chann_down",
"chan down",
"down",
"prev",
"tv_ch-",
)

Expand Down

0 comments on commit a27081e

Please sign in to comment.