mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
Updated send waypoint intent
This commit is contained in:
parent
c09291e1b2
commit
8d65985521
2 changed files with 51 additions and 13 deletions
|
|
@ -11388,6 +11388,9 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"Expiration" : {
|
||||
|
||||
},
|
||||
"Expire" : {
|
||||
"localizations" : {
|
||||
|
|
@ -15747,6 +15750,12 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"Latitude in degrees (e.g., 37.7749)" : {
|
||||
|
||||
},
|
||||
"Latitude must be between -90 and 90 degrees" : {
|
||||
|
||||
},
|
||||
"LED Heartbeat" : {
|
||||
"localizations" : {
|
||||
|
|
@ -16055,6 +16064,7 @@
|
|||
}
|
||||
},
|
||||
"Location" : {
|
||||
"extractionState" : "stale",
|
||||
"localizations" : {
|
||||
"de" : {
|
||||
"stringUnit" : {
|
||||
|
|
@ -16493,6 +16503,12 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"Longitude in degrees (e.g., -122.4194)" : {
|
||||
|
||||
},
|
||||
"Longitude must be between -180 and 180 degrees" : {
|
||||
|
||||
},
|
||||
"LoRa" : {
|
||||
"localizations" : {
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@ import AppIntents
|
|||
import MeshtasticProtobufs
|
||||
|
||||
struct SendWaypointIntent: AppIntent {
|
||||
|
||||
var defaultDate = Date.now.addingTimeInterval(60 * 480)
|
||||
|
||||
static var title = LocalizedStringResource("Send a Waypoint")
|
||||
|
||||
|
|
@ -23,13 +25,24 @@ struct SendWaypointIntent: AppIntent {
|
|||
@Parameter(title: "Emoji", default: "📍")
|
||||
var emojiParameter: String?
|
||||
|
||||
@Parameter(title: "Location")
|
||||
var locationParameter: CLPlacemark
|
||||
// Replace CLPlacemark with latitude and longitude parameters
|
||||
@Parameter(title: "Latitude", description: "Latitude in degrees (e.g., 37.7749)")
|
||||
var latitudeParameter: Double
|
||||
|
||||
@Parameter(title: "Longitude", description: "Longitude in degrees (e.g., -122.4194)")
|
||||
var longitudeParameter: Double
|
||||
|
||||
@Parameter(title: "Locked", default: false)
|
||||
var isLocked: Bool
|
||||
|
||||
@Parameter(title: "Expiration")
|
||||
var expiration: Date?
|
||||
|
||||
func perform() async throws -> some IntentResult {
|
||||
if !BLEManager.shared.isConnected {
|
||||
throw AppIntentErrors.AppIntentError.notConnected
|
||||
}
|
||||
|
||||
// Provide default values if parameters are nil
|
||||
let name = nameParameter ?? "Dropped Pin"
|
||||
let description = descriptionParameter ?? ""
|
||||
|
|
@ -50,24 +63,35 @@ struct SendWaypointIntent: AppIntent {
|
|||
throw $emojiParameter.needsValueError("Must be a single emoji")
|
||||
}
|
||||
|
||||
// Validate latitude and longitude
|
||||
guard abs(latitudeParameter) <= 90 else {
|
||||
throw $latitudeParameter.needsValueError("Latitude must be between -90 and 90 degrees")
|
||||
}
|
||||
guard abs(longitudeParameter) <= 180 else {
|
||||
throw $longitudeParameter.needsValueError("Longitude must be between -180 and 180 degrees")
|
||||
}
|
||||
|
||||
var newWaypoint = Waypoint()
|
||||
|
||||
if let latitude = locationParameter.location?.coordinate.latitude {
|
||||
newWaypoint.latitudeI = Int32(latitude * 10_000_000)
|
||||
}
|
||||
|
||||
if let longitude = locationParameter.location?.coordinate.longitude {
|
||||
newWaypoint.longitudeI = Int32(longitude * 10_000_000)
|
||||
}
|
||||
// Set latitude and longitude directly
|
||||
newWaypoint.latitudeI = Int32(latitudeParameter * 10_000_000)
|
||||
newWaypoint.longitudeI = Int32(longitudeParameter * 10_000_000)
|
||||
|
||||
newWaypoint.id = UInt32.random(in: UInt32(UInt8.max)..<UInt32.max)
|
||||
// Unicode scalar value for the icon emoji string
|
||||
let unicodeScalers = emoji.unicodeScalars
|
||||
// First element as an UInt32
|
||||
let unicode = unicodeScalers[unicodeScalers.startIndex].value
|
||||
newWaypoint.icon = unicode
|
||||
newWaypoint.name = name
|
||||
newWaypoint.description_p = description
|
||||
|
||||
if let expirationDate = expiration {
|
||||
newWaypoint.expire = UInt32(expirationDate.timeIntervalSince1970)
|
||||
}
|
||||
|
||||
if isLocked {
|
||||
newWaypoint.lockedTo = UInt32(BLEManager.shared.connectedPeripheral!.num)
|
||||
}
|
||||
|
||||
if !BLEManager.shared.sendWaypoint(waypoint: newWaypoint) {
|
||||
throw AppIntentErrors.AppIntentError.message("Failed to Send Waypoint")
|
||||
}
|
||||
|
|
@ -75,11 +99,9 @@ struct SendWaypointIntent: AppIntent {
|
|||
}
|
||||
|
||||
private func isValidSingleEmoji(_ emoji: String) -> Bool {
|
||||
// This regex pattern is for matching a single emoji
|
||||
let emojiPattern = "^([\\p{So}\\p{Cn}])$"
|
||||
let regex = try? NSRegularExpression(pattern: emojiPattern, options: [])
|
||||
let matches = regex?.matches(in: emoji, options: [], range: NSRange(location: 0, length: emoji.utf16.count))
|
||||
|
||||
return matches?.count == 1
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue