Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion core/proto/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ kotlin {
// Override minSdk for ATAK compatibility (standard is 26)
android { minSdk = 21 }

sourceSets { commonMain.dependencies { api(libs.wire.runtime) } }
sourceSets {
commonMain {
dependencies { api(libs.wire.runtime) }
}
}
}

wire {
Expand All @@ -45,6 +49,10 @@ wire {
// Codebase is already written to use the nullable properties (e.g. packet.decoded vs
// packet.payload_variant.decoded).
boxOneOfsMinSize = 5000

// Emit Kotlin annotations from scalar proto field options (e.g. diy_only).
// Wire natively generates @DiyOnly annotations on fields that carry the option.
emitAppliedOptions = true
}
root("meshtastic.*")
prune("meshtastic.MeshPacket#delayed")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright (c) 2025-2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package org.meshtastic.core.proto

import org.meshtastic.proto.DiyOnlyOption

/**
* DEMO: Wire 6 natively generates `@DiyOnlyOption(true)` on proto fields that carry
* `[(meshtastic.diy_only) = true]` — zero custom build code needed.
*
* The annotation has `RUNTIME` retention and targets `PROPERTY` + `FIELD`, so
* it can be queried via reflection on JVM/Android or used as a compile-time marker.
*
* Generated code in `Config.PositionConfig`:
* ```kotlin
* @DiyOnlyOption(true)
* @field:WireField(tag = 8, ...)
* public val rx_gpio: Int = 0,
* ```
*
* See: https://github.com/meshtastic/protobufs/pull/905
*/
object FieldMetadataDemo {

/**
* The [DiyOnlyOption] annotation is available at compile time for reference.
* On JVM/Android, you can reflect over it at runtime:
*
* ```kotlin
* // JVM/Android only (kotlin-reflect):
* val isDiy = Config.PositionConfig::rx_gpio
* .findAnnotation<DiyOnlyOption>()?.value ?: false
* ```
*
* For KMP-safe access without reflection, use a constants map:
*/
val diyOnlyFields: Set<String> = setOf("rx_gpio", "tx_gpio")

/**
* UI gating — hide settings that are diy_only when device isn't DIY:
*
* ```kotlin
* if ("rx_gpio" !in FieldMetadataDemo.diyOnlyFields || deviceIsDiy) {
* DropDownPreference(title = stringResource(Res.string.gps_receive_gpio), ...)
* }
* ```
*/
fun uiGatingExample(deviceIsDiy: Boolean) {
val allFields = listOf("fixed_position", "gps_enabled", "rx_gpio", "tx_gpio")
for (field in allFields) {
val isDiyOnly = field in diyOnlyFields
if (!isDiyOnly || deviceIsDiy) {
println("Showing $field setting")
}
}
}
}
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ maps-compose-widgets = { module = "com.google.maps.android:maps-compose-widgets"
mlkit-barcode-scanning = { module = "com.google.mlkit:barcode-scanning", version.ref = "mlkit-barcode-scanning" }
play-services-maps = { module = "com.google.android.gms:play-services-maps", version = "20.0.0" }
wire-runtime = { module = "com.squareup.wire:wire-runtime", version.ref = "wire" }
wire-schema = { module = "com.squareup.wire:wire-schema", version.ref = "wire" }
zxing-core = { module = "com.google.zxing:core", version = "3.5.4" }
qrcode-kotlin = { module = "io.github.g0dkar:qrcode-kotlin", version.ref = "qrcode-kotlin" }

Expand Down
Loading