Repository navigation
Conversation
…he inquiry BattVoltageSensor read bytes 3-4 whatever its place in the packet. VBATT (0x03) follows the low-noise accel on a Shimmer3 when that is on, and is the last channel on a Shimmer3R, so the raw value came from another sensor's bytes. It was not reached anyway. interpretDataPacketFormat starts with disableSensors(), and its VBatt case only counted the two bytes, so every inquiry left the battery off. connect(), writeInfoMem and setSensors all end with one, which undid the Shimmer3's InfoMem enable. On a Shimmer3R the sensor was not created, configured or disabled at all. - BattVoltageSensor gets a packetIndex and reads there. With no index yet, or one past the end of the packet, it adds nothing. - The VBatt case sets the index and enables the sensor. - The Shimmer3R branches of createSensors, initializeSensors and disableSensors handle it as the Shimmer3 ones do. - The calibration moves into BattVoltageSensor.calibrate(raw:), unchanged: U12 at 3 V times 2, as the Java driver and the C# API use on both generations. SensorTest decodes four Shimmer3R packets with the battery as the last channel. The Shimmer3Protocol wiring is not reachable from a unit test. Co-Authored-By: Claude Opus 5.5 <[email protected]>
marknolan
marked this pull request as ready for review
November 11, 2026 16:42
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
DEV-1449. The battery (VBATT, channel 0x03) is now read where it actually sits in the packet, and the inquiry response turns it on. That works on both a Shimmer3 and a Shimmer3R. This is older than the sound level work in #29, and was noted there under "Seen in passing".
What was wrong
Fixed offset.
BattVoltageSensor.processDataalways readsensorPacket[3..<5], the first channel after the 3-byte timestamp. VBATT is only there when nothing comes before it:In the packets used by the new tests, bytes 3-4 are the magnetometer's, raw 46 or 43. That would have been reported as 63-67 mV.
Never on after connect.
interpretDataPacketFormatstarts withdisableSensors(), and itsVBattcase only added 2 to the packet size. So every inquiry turned the battery off and nothing turned it back on.connect(),writeInfoMemandsetSensorsall end with an inquiry, which undid the Shimmer3's InfoMem enable. The battery signal never reached the ObjectCluster on either generation.Not set up on a Shimmer3R. The Shimmer3R branches of
createSensors,initializeSensorsanddisableSensorsskippedbattVoltageSensor.Changes
BattVoltageSensorhas apacketIndexand reads the battery there. With no index yet, or one past the end of the packet, it adds nothing, rather than reading the wrong bytes or out of range.VBattcase ofinterpretDataPacketFormatsets the index and enables the sensor, as the other sensors' cases do.BattVoltageSensor.calibrate(raw:), unchanged.Calibration: checked, no change
Swift's
raw * 3000/4095 * 2is what the other APIs use, on both generations:SensorADC.calibrateU12AdcValueToMillivolts(raw, 0, 3, 1) * 2, with no Shimmer3R branch.CalibrateU12AdcValue(raw, 0, 3, 1) * 2.0as the Shimmer3 one.Tests
Four cases are added to
SensorTest:testBatteryCalibrationtestBatteryDecodesAtItsIndextestBatteryWithoutAUsableIndexAddsNothingtestBatteryFromShimmer3RPacketsThe last one uses four packets a Shimmer3R streamed, the same packets as the sound level test on #29:
These cases need
packetIndex, so they don't compile onmain.No Swift toolchain was available, so CI on this PR is the first time the code is compiled and run. The
Shimmer3Protocolwiring (theVBattcase and the three Shimmer3R branches) isn't reachable from a unit test, because the protocol class needs a liveCBPeripheral. It has not been run against a device.Sibling APIs
None needs this fix. Each one finds the battery by its position in the inquiry's channel list, not at a fixed byte:
getSignalIndex(BATTERY).getSignalIndex(V_SENSE_BATT), and the same in its Xamarin copy.With #29
Both PRs change
Shimmer3Protocol.swiftandSensorTest.swift, at different places.git merge-treemerges this branch withDEV-1413_sound_levelcleanly.🤖 Generated with Claude Code