Skip to content

Commit

Permalink
Added support for the weight telemetry field
Browse files Browse the repository at this point in the history
  • Loading branch information
jake-b committed Jan 1, 2025
1 parent 3cdd095 commit 1049409
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -31070,6 +31070,9 @@
}
}
}
},
"WEIGHT" : {

},
"What does the lock mean?" : {
"localizations" : {
Expand Down
28 changes: 27 additions & 1 deletion Meshtastic/Views/Helpers/Weather/LocalWeatherConditions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,33 @@ struct DistanceCompactWidget: View {
}
HStack {
Text("\(distance)")
.font(distance.length < 4 ? .system(size: 62) : .system(size: 46) )
.font(distance.length < 4 ? .system(size: 50) : .system(size: 40) )
Text(unit)
.font(.system(size: 14))
}
}
.frame(minWidth: 100, idealWidth: 125, maxWidth: 150, minHeight: 120, idealHeight: 130, maxHeight: 140)
.padding()
.background(.tertiary, in: RoundedRectangle(cornerRadius: 20, style: .continuous))
}
}

struct WeightCompactWidget: View {
let weight: String
let unit: String

var body: some View {
VStack(alignment: .leading) {
HStack(alignment: .firstTextBaseline) {
Image(systemName: "scalemass")
.imageScale(.small)
.foregroundColor(.accentColor)
Text("WEIGHT")
.font(.callout)
}
HStack {
Text("\(weight)")
.font(weight.length < 4 ? .system(size: 50) : .system(size: 40) )
Text(unit)
.font(.system(size: 14))
}
Expand Down
19 changes: 19 additions & 0 deletions Meshtastic/Views/Nodes/EnvironmentMetricsLog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,25 @@ struct EnvironmentMetricsLog: View {
}
}
}
Button {
node.objectWillChange.send()
for element in node.telemetries ?? [] {
if let element = element as? TelemetryEntity {
element.weight = Float.random(in: 0...100)
element.distance = Float.random(in: 0...1000)
}
}
node.latestEnvironmentMetrics?.weight = Float.random(in: 0...100)
node.latestEnvironmentMetrics?.distance = Float.random(in: 0...1000)
do {
try context.save()
} catch {
context.rollback()
Logger.data.info("📖 debug \(error) ")
}
} label: {
Text("Debug")
}
Button {
exportString = telemetryToCsvFile(telemetry: environmentMetrics, metricsType: 1)
isExporting = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,29 @@ extension MetricsColumnList {
)
} ?? Text("--")
}),


//Weight
MetricsTableColumn(
id: "weight",
keyPath: \.weight,
name: "Weight",
abbreviatedName: "kg",
minWidth: 30, maxWidth: 60,
visible: false,
tableBody: { _, weight in
weight.map {
let weight = Measurement(
value: Double($0), unit: UnitMass.kilograms)
return Text(
weight.formatted(
.measurement(
width: .abbreviated,
numberFormatStyle: .number.precision(
.fractionLength(0))))
)
} ?? Text("--")
}),

// Timestamp Series Configuration -- for use in table only
MetricsTableColumn(
id: "time",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,32 @@ extension MetricsSeriesList {
.alignsMarkStylesWithPlotArea()
}
}),

// Radiation
MetricsChartSeries(
id: "weight",
keyPath: \.weight,
name: "Weight",
abbreviatedName: "kg",
visible: false,
foregroundStyle: { _ in
.linearGradient(
colors: [Color(UIColor.brown.darker(componentDelta: 0.5)), .brown],
startPoint: .bottom, endPoint: .top
)
},
chartBody: { series, _, time, radiation in
if let radiation {
LineMark(
x: .value("Time", time),
y: .value(series.abbreviatedName, radiation)
)
.interpolationMethod(.catmullRom)
.foregroundStyle(by: .value("Series", series.abbreviatedName))
.lineStyle(StrokeStyle(lineWidth: 4))
.alignsMarkStylesWithPlotArea()
}
})
])
}
}
Expand Down
3 changes: 3 additions & 0 deletions Meshtastic/Views/Nodes/Helpers/NodeDetail.swift
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@ struct NodeDetail: View {
if let radiation = node.latestEnvironmentMetrics?.radiation {
RadiationCompactWidget(radiation: String(format: "%.1f", radiation), unit: "µR/h")
}
if let weight = node.latestEnvironmentMetrics?.weight {
WeightCompactWidget(weight: String(format: "%.1f", weight), unit: "kg")
}
}
.padding(node.latestEnvironmentMetrics?.iaq ?? -1 > 0 ? .bottom : .vertical)
}
Expand Down

0 comments on commit 1049409

Please sign in to comment.