Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the XL Tank Sensor parsing #458

Merged
merged 3 commits into from
Nov 10, 2022
Merged
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Meadow.Hardware;
using System;
using Meadow.Hardware;
using Meadow.Units;

namespace Meadow.Foundation.Sensors.Distance
Expand Down Expand Up @@ -42,7 +43,7 @@ Length ReadSensorSerial()
}

private void SerialMessagePort_MessageReceived(object sender, SerialMessageData e)
{
{
//R###\n //cm
//R####\n //mm
//R####\n //cm
Expand All @@ -53,7 +54,16 @@ private void SerialMessagePort_MessageReceived(object sender, SerialMessageData
{ return; }

//strip the leading R
var value = double.Parse(message.Substring(1));
string cleaned = message.Substring(1);

// get index of space
var spaceIndex = message.FirstIndexOf(new char[] { ' ' });
if (spaceIndex > 0)
{
cleaned = cleaned.Substring(0, spaceIndex);
}

var value = double.Parse(cleaned);

Length.UnitType units = GetUnitsForSensor(sensorType);

Expand Down