Skip to content

Commit

Permalink
refactor: remove protobuf dependency from HardwareModel
Browse files Browse the repository at this point in the history
  • Loading branch information
andrekir committed Dec 13, 2024
1 parent 6506de9 commit 22fafe8
Showing 1 changed file with 37 additions and 35 deletions.
72 changes: 37 additions & 35 deletions app/src/main/java/com/geeksville/mesh/model/DeviceHardware.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package com.geeksville.mesh.model

import androidx.annotation.DrawableRes
import com.geeksville.mesh.MeshProtos.HardwareModel
import com.geeksville.mesh.R
import kotlinx.serialization.Serializable
Expand All @@ -29,7 +30,7 @@ data class DeviceHardware(
val supportLevel: Int? = null,
val displayName: String,
val tags: List<String>? = listOf(),
val image: Int,
@DrawableRes val image: Int,
val requiresDfu: Boolean? = null,
)

Expand All @@ -54,44 +55,45 @@ data class DeviceHardwareDto(
supportLevel = supportLevel,
displayName = displayName,
tags = tags,
image = HardwareModel.forNumber(hwModel).getDeviceVectorImage(),
image = getDrawableFrom(hwModel),
requiresDfu = requiresDfu
)
}

@Suppress("CyclomaticComplexMethod")
private fun HardwareModel.getDeviceVectorImage(): Int = when (this) {
HardwareModel.DIY_V1 -> R.drawable.hw_diy
HardwareModel.HELTEC_HT62 -> R.drawable.hw_heltec_ht62_esp32c3_sx1262
HardwareModel.HELTEC_MESH_NODE_T114 -> R.drawable.hw_heltec_mesh_node_t114
HardwareModel.HELTEC_V3 -> R.drawable.hw_heltec_v3
HardwareModel.HELTEC_VISION_MASTER_E213 -> R.drawable.hw_heltec_vision_master_e213
HardwareModel.HELTEC_VISION_MASTER_E290 -> R.drawable.hw_heltec_vision_master_e290
HardwareModel.HELTEC_VISION_MASTER_T190 -> R.drawable.hw_heltec_vision_master_t190
HardwareModel.HELTEC_WIRELESS_PAPER -> R.drawable.hw_heltec_wireless_paper
HardwareModel.HELTEC_WIRELESS_TRACKER -> R.drawable.hw_heltec_wireless_tracker
HardwareModel.HELTEC_WIRELESS_TRACKER_V1_0 -> R.drawable.hw_heltec_wireless_tracker_v1_0
HardwareModel.HELTEC_WSL_V3 -> R.drawable.hw_heltec_wsl_v3
HardwareModel.NANO_G2_ULTRA -> R.drawable.hw_nano_g2_ultra
HardwareModel.RPI_PICO -> R.drawable.hw_pico
HardwareModel.NRF52_PROMICRO_DIY -> R.drawable.hw_promicro
HardwareModel.RAK11310 -> R.drawable.hw_rak11310
HardwareModel.RAK4631 -> R.drawable.hw_rak4631
HardwareModel.RPI_PICO2 -> R.drawable.hw_rpipicow
HardwareModel.SENSECAP_INDICATOR -> R.drawable.hw_seeed_sensecap_indicator
HardwareModel.SEEED_XIAO_S3 -> R.drawable.hw_seeed_xiao_s3
HardwareModel.STATION_G2 -> R.drawable.hw_station_g2
HardwareModel.T_DECK -> R.drawable.hw_t_deck
HardwareModel.T_ECHO -> R.drawable.hw_t_echo
HardwareModel.T_WATCH_S3 -> R.drawable.hw_t_watch_s3
HardwareModel.TBEAM -> R.drawable.hw_tbeam
HardwareModel.LILYGO_TBEAM_S3_CORE -> R.drawable.hw_tbeam_s3_core
HardwareModel.TLORA_C6 -> R.drawable.hw_tlora_c6
HardwareModel.TLORA_T3_S3 -> R.drawable.hw_tlora_t3s3_v1
HardwareModel.TLORA_V2_1_1P6 -> R.drawable.hw_tlora_v2_1_1_6
HardwareModel.TLORA_V2_1_1P8 -> R.drawable.hw_tlora_v2_1_1_8
HardwareModel.TRACKER_T1000_E -> R.drawable.hw_tracker_t1000_e
HardwareModel.WIO_WM1110 -> R.drawable.hw_wio_tracker_wm1110
HardwareModel.WISMESH_TAP -> R.drawable.hw_rak_wismeshtap
@DrawableRes
private fun getDrawableFrom(hwModel: Int): Int = when (hwModel) {
HardwareModel.DIY_V1_VALUE -> R.drawable.hw_diy
HardwareModel.HELTEC_HT62_VALUE -> R.drawable.hw_heltec_ht62_esp32c3_sx1262
HardwareModel.HELTEC_MESH_NODE_T114_VALUE -> R.drawable.hw_heltec_mesh_node_t114
HardwareModel.HELTEC_V3_VALUE -> R.drawable.hw_heltec_v3
HardwareModel.HELTEC_VISION_MASTER_E213_VALUE -> R.drawable.hw_heltec_vision_master_e213
HardwareModel.HELTEC_VISION_MASTER_E290_VALUE -> R.drawable.hw_heltec_vision_master_e290
HardwareModel.HELTEC_VISION_MASTER_T190_VALUE -> R.drawable.hw_heltec_vision_master_t190
HardwareModel.HELTEC_WIRELESS_PAPER_VALUE -> R.drawable.hw_heltec_wireless_paper
HardwareModel.HELTEC_WIRELESS_TRACKER_VALUE -> R.drawable.hw_heltec_wireless_tracker
HardwareModel.HELTEC_WIRELESS_TRACKER_V1_0_VALUE -> R.drawable.hw_heltec_wireless_tracker_v1_0
HardwareModel.HELTEC_WSL_V3_VALUE -> R.drawable.hw_heltec_wsl_v3
HardwareModel.NANO_G2_ULTRA_VALUE -> R.drawable.hw_nano_g2_ultra
HardwareModel.RPI_PICO_VALUE -> R.drawable.hw_pico
HardwareModel.NRF52_PROMICRO_DIY_VALUE -> R.drawable.hw_promicro
HardwareModel.RAK11310_VALUE -> R.drawable.hw_rak11310
HardwareModel.RAK4631_VALUE -> R.drawable.hw_rak4631
HardwareModel.RPI_PICO2_VALUE -> R.drawable.hw_rpipicow
HardwareModel.SENSECAP_INDICATOR_VALUE -> R.drawable.hw_seeed_sensecap_indicator
HardwareModel.SEEED_XIAO_S3_VALUE -> R.drawable.hw_seeed_xiao_s3
HardwareModel.STATION_G2_VALUE -> R.drawable.hw_station_g2
HardwareModel.T_DECK_VALUE -> R.drawable.hw_t_deck
HardwareModel.T_ECHO_VALUE -> R.drawable.hw_t_echo
HardwareModel.T_WATCH_S3_VALUE -> R.drawable.hw_t_watch_s3
HardwareModel.TBEAM_VALUE -> R.drawable.hw_tbeam
HardwareModel.LILYGO_TBEAM_S3_CORE_VALUE -> R.drawable.hw_tbeam_s3_core
HardwareModel.TLORA_C6_VALUE -> R.drawable.hw_tlora_c6
HardwareModel.TLORA_T3_S3_VALUE -> R.drawable.hw_tlora_t3s3_v1
HardwareModel.TLORA_V2_1_1P6_VALUE -> R.drawable.hw_tlora_v2_1_1_6
HardwareModel.TLORA_V2_1_1P8_VALUE -> R.drawable.hw_tlora_v2_1_1_8
HardwareModel.TRACKER_T1000_E_VALUE -> R.drawable.hw_tracker_t1000_e
HardwareModel.WIO_WM1110_VALUE -> R.drawable.hw_wio_tracker_wm1110
HardwareModel.WISMESH_TAP_VALUE -> R.drawable.hw_rak_wismeshtap
else -> R.drawable.hw_unknown
}

0 comments on commit 22fafe8

Please sign in to comment.