protected override async Task roundtrip() { string cmd = "psonar"; string resp = await commTask.SendAndReceive(cmd); if (!string.IsNullOrWhiteSpace(resp)) { if (resp.Trim().IndexOf(" ") > 0) { string[] splitResp = resp.Trim().Split(new char[] { ' ' }); if (splitResp.Length == 4) { int rangeFRcm; int rangeFLcm; int rangeBRcm; int rangeBLcm; if (int.TryParse(splitResp[0].Trim(), out rangeFRcm) && int.TryParse(splitResp[1].Trim(), out rangeFLcm) && int.TryParse(splitResp[2].Trim(), out rangeBRcm) && int.TryParse(splitResp[3].Trim(), out rangeBLcm)) { if (lastRangeFRcm != rangeFRcm || lastRangeFLcm != rangeFLcm || lastRangeBRcm != rangeBRcm || lastRangeBLcm != rangeBLcm) { this.RangeFRcm = rangeFRcm; this.RangeFLcm = rangeFLcm; this.RangeBRcm = rangeBRcm; this.RangeBLcm = rangeBLcm; lastRangeFRcm = rangeFRcm; lastRangeFLcm = rangeFLcm; lastRangeBRcm = rangeBRcm; lastRangeBLcm = rangeBLcm; DistanceChanged?.Invoke(this); } return; } } } } Debug.WriteLineIf(!cancellationToken.IsCancellationRequested, "ParkingSonar: roundtrip() : could not parse response: '" + resp + "'"); }
private void OnDistanceChanged() { var e = new StepperDistanceChangedEventHandlerArgs(); DistanceChanged?.Invoke(this, e); }
private void FixedUpdate() { _distance++; DistanceChanged?.Invoke(_distance); }