Skip to content

Commit

Permalink
add irdb parser, fix keys
Browse files Browse the repository at this point in the history
  • Loading branch information
makeevrserg committed Aug 12, 2024
1 parent a442ced commit 1d37941
Show file tree
Hide file tree
Showing 12 changed files with 244 additions and 55 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/call-validate-gradle-wrapper.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: "Validate gradle wrapper"
on:
workflow_call:

jobs:
validation:
name: "Validate gradle wrapper"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
- uses: gradle/wrapper-validation-action@f9c9c575b8b21b6485636a91ffecd10e558c62f6 # v3
69 changes: 69 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Pull Request CI

on:
pull_request:
branches:
- 'dev'

# Concurrency strategy:
# github.workflow: distinguish this workflow from others
# github.event_name: distinguish `push` event from `pull_request` and 'merge_group' event
# github.ref_name: distinguish branch
# github.repository: distinguish owner+repository
#
# Reference:
# https://docs.github.com/en/actions/using-jobs/using-concurrency
# https://docs.github.com/en/actions/learn-github-actions/contexts#github-context
concurrency:
group: ${{ github.workflow }}-${{ github.event_name }}-${{github.ref_name}}-${{github.repository}}
cancel-in-progress: true


jobs:
validate_gradle_wrapper:
name: "Validate gradle wrapper"
uses: ./.github/workflows/call-validate-gradle-wrapper.yml
info:
name: "Display concurrency info"
runs-on: ubuntu-latest
needs: [ validate_gradle_wrapper ]
steps:
- run: |
echo "github.workflow=${{ github.workflow }}"
echo "github.event_name=${{ github.event_name }}"
echo "github.ref_name=${{ github.ref_name }}"
echo "github.repository=${{ github.repository }}"
check_kenerator_configuration:
name: "Check config generation is fine"
runs-on: ubuntu-latest
needs: [ validate_gradle_wrapper ]
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
with:
submodules: 'recursive'
- name: Set up JDK 1.17
uses: actions/setup-java@6a0805fcefea3d4657a47ac4c165951e33482018 # v4
with:
distribution: 'temurin'
java-version: '17'
- name: Run configuration kenerator
uses: gradle/gradle-build-action@ac2d340dc04d9e1113182899e983b5400c17cda1 # v3
with:
arguments: :modules:kenerator:configuration:run
check_db_configuration:
name: "Check config generation is fine"
runs-on: ubuntu-latest
needs: [ validate_gradle_wrapper ]
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
with:
submodules: 'recursive'
- name: Set up JDK 1.17
uses: actions/setup-java@6a0805fcefea3d4657a47ac4c165951e33482018 # v4
with:
distribution: 'temurin'
java-version: '17'
- name: Run SQL kenerator
uses: gradle/gradle-build-action@ac2d340dc04d9e1113182899e983b5400c17cda1 # v3
with:
arguments: :modules:kenerator:sql:run
2 changes: 1 addition & 1 deletion IRDB
Submodule IRDB updated 5863 files
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ object InfraredRemoteEncoder {
val raw = this as? InfraredRemote.Raw
val parsed = this as? InfraredRemote.Parsed
return SignalModel.FlipperRemote(
name = this.name,
name = null.orEmpty(), // the name should not affect hash
type = this.type,
protocol = parsed?.protocol,
address = parsed?.address,
Expand All @@ -30,31 +30,8 @@ object InfraredRemoteEncoder {
)
}

private fun SignalModel.FlipperRemote.toInfraredRemote(): InfraredRemote {
return runCatching {
InfraredRemote.Parsed(
nameInternal = name,
typeInternal = type,
protocol = protocol ?: error("Not parsed remote"),
address = address ?: error("Not parsed remote"),
command = command ?: error("Not parsed remote")
)
}.getOrNull() ?: InfraredRemote.Raw(
nameInternal = name,
typeInternal = type,
frequency = frequency ?: error("Not raw remote"),
dutyCycle = dutyCycle ?: error("Not raw remote"),
data = data ?: error("Not raw remote")
)
}

fun encode(remote: InfraredRemote): ByteArray {
val fRemote = remote.toFlipperRemote()
return json.encodeToString(fRemote).encodeToByteArray()
}

fun decode(byteArray: ByteArray): InfraredRemote {
val fRemote: SignalModel.FlipperRemote = json.decodeFromString(byteArray.decodeToString())
return fRemote.toInfraredRemote()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ private fun generateDevicesConfigFiles() {
).onEach { irFile ->
val config = DefaultDeviceConfigGenerator(AnyDeviceKeyNamesProvider)
.generate(irFile)
if (config.keyMap.isEmpty()) error("Config file for ${irFile} is empty")
val configFile = irFile.parentFile.resolve("config.json")
val string = json.encodeToString(config)
configFile.writeText(string)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ object DeviceKeyExt {
DeviceKey.ENERGY_SAVE -> listOf(
CategoryType.FAN
)

DeviceKey.SHUTTER -> listOf(
CategoryType.CAMERA
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,12 @@ import java.io.File
class DefaultDeviceConfigGenerator(private val keyNamesProvider: DeviceKeyNamesProvider) : DeviceConfigGenerator {
override fun generate(irFile: File): DeviceConfiguration {
val remotes = DeviceConfigGenerator.parseRemotes(irFile)
val remoteNameToCount = remotes.groupBy { it.name }
val deviceKeyToInstance = remotes.mapNotNull {
val name = it.name
val deviceKey = keyNamesProvider.getKey(name) ?: return@mapNotNull null
val byteArray = InfraredRemoteEncoder.encode(it)
val hash = JvmEncoder(ByteArrayEncoder.Algorithm.SHA_256).encode(byteArray)
val identifier = when {
(remoteNameToCount[name]?.size ?: 0) > 1 -> IfrKeyIdentifier.Sha256(name = name, hash = hash)
else -> IfrKeyIdentifier.Name(name = name)
}
val identifier = IfrKeyIdentifier.Sha256(name = name, hash = hash)
deviceKey to identifier
}.associate { pair -> pair }
return DeviceConfiguration(deviceKeyToInstance)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ interface DeviceKeyNamesProvider {
companion object {
fun DeviceKeyNamesProvider.getKey(keyName: String): DeviceKey? {
return DeviceKey.entries
.firstOrNull { deviceKey -> getKeyNames(deviceKey).contains(keyName) }
.firstOrNull { deviceKey ->
getKeyNames(deviceKey).any { it.equals(keyName, true) }
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,40 @@ import com.flipperdevices.ifrmvp.generator.config.device.api.DeviceKeyNamesProvi
object AnyDeviceKeyNamesProvider : DeviceKeyNamesProvider {
@Suppress("LongMethod", "CyclomaticComplexMethod")
override fun getKeyNames(key: DeviceKey): List<String> {
// NOT CASE-SENSITIVE!!!
return when (key) {
DeviceKey.PWR -> listOf(
"power",
"pwr",
"power",
"power_r",
"on",
"on_off",
"on/off",
)

DeviceKey.VOL_DOWN -> listOf(
"vol-",
"vol-_r"
"vol-_r",
"voldown"
)

DeviceKey.VOL_UP -> listOf(
"vol+",
"vol+_r"
"vol+_r",
"volup"
)

DeviceKey.CH_UP -> listOf(
"ch+",
"ch+_r"
"ch+_r",
"ch_next"
)

DeviceKey.CH_DOWN -> listOf(
"ch-",
"ch-_r"
"ch-_r",
"ch_prev"
)

DeviceKey.FOCUS_MORE -> listOf(
Expand Down Expand Up @@ -133,7 +141,8 @@ object AnyDeviceKeyNamesProvider : DeviceKeyNamesProvider {

DeviceKey.FAN_SPEED -> listOf(
"fanspeed",
"fan_speed"
"fan_speed",
"speed"
)

DeviceKey.NEAR -> listOf(
Expand All @@ -150,7 +159,8 @@ object AnyDeviceKeyNamesProvider : DeviceKeyNamesProvider {
)

DeviceKey.WIND_SPEED -> listOf(
"wind_speed"
"wind_speed",
"strength"
)

DeviceKey.MODE -> listOf(
Expand All @@ -159,11 +169,17 @@ object AnyDeviceKeyNamesProvider : DeviceKeyNamesProvider {
)

DeviceKey.FAN_SPEED_UP -> listOf(
"fanspeed+"
"fanspeed+",
"fan+",
"fan_up",
"speed_up"
)

DeviceKey.FAN_SPEED_DOWN -> listOf(
"fanspeed-"
"fanspeed-",
"fan-",
"fan_dn",
"speed_down"
)

DeviceKey.SHAKE_WIND -> listOf(
Expand All @@ -175,17 +191,30 @@ object AnyDeviceKeyNamesProvider : DeviceKeyNamesProvider {
)

DeviceKey.TEMPERATURE_UP -> listOf(
"temperature_up"
"temperature_up",
"heat+",
"heat_hi",
"temp+",
"heat_up"
)

DeviceKey.TEMPERATURE_DOWN -> listOf(
"temperature_down"
"temperature_down",
"heat-",
"heat_lo",
"temp-",
"heat_down"
)

DeviceKey.ENERGY_SAVE -> listOf(
"energy save",
"energy save_r"
)

DeviceKey.SHUTTER -> listOf(
"shutter",
"trigger"
)
}
}
}
Loading

0 comments on commit 1d37941

Please sign in to comment.