/// <summary> /// Handle motor update message from Scribbler /// </summary> public void MotorNotificationHandler(brick.Replace notify) { if (notify == null) throw new ArgumentNullException("notify"); if (beeping) return; if (notify.Body.MotorLeft < 100 && notify.Body.MotorRight < 100) { SpawnIterator(ToneHandler); } }
/// <summary> /// Handle sensor update message from Scribbler /// </summary> public void SensorNotificationHandler(brick.Replace notify) { _state.LeftSensor.RawMeasurement = notify.Body.LightLeft; _state.CenterSensor.RawMeasurement = notify.Body.LightCenter; _state.RightSensor.RawMeasurement = notify.Body.LightRight; _state.LeftSensor.TimeStamp = DateTime.Now; _state.CenterSensor.TimeStamp = DateTime.Now; _state.RightSensor.TimeStamp = DateTime.Now; _state.LeftSensor.NormalizedMeasurement = (double)_state.LeftSensor.RawMeasurement / (double)_state.LeftSensor.RawMeasurementRange; _state.CenterSensor.NormalizedMeasurement = (double)_state.CenterSensor.RawMeasurement / (double)_state.CenterSensor.RawMeasurementRange; _state.RightSensor.NormalizedMeasurement = (double)_state.RightSensor.RawMeasurement / (double)_state.RightSensor.RawMeasurementRange; bool changed = true; if (changed) { //notify subscribers on any bumper pressed or unpressed _subMgrPort.Post(new submgr.Submit(_state, DsspActions.UpdateRequest)); } }
/// <summary> /// Handle sensor update message from Scribbler /// </summary> public void SensorNotificationHandler(brick.Replace notify) { //update state foreach (bumper.ContactSensor sensor in _state.Sensors) { bool newval = true; if (sensor.Name.ToUpper().Contains("LEFT")) { newval = !notify.Body.IRLeft; //NOTE: inverting logic here } else if (sensor.Name.ToUpper().Contains("RIGHT")) { newval = !notify.Body.IRRight; } else LogError("Bumper name missmatch"); bool changed = (sensor.Pressed != newval); sensor.TimeStamp = DateTime.Now; sensor.Pressed = newval; if (changed) { //notify subscribers on any bumper pressed or unpressed _subMgrPort.Post(new submgr.Submit(sensor, DsspActions.UpdateRequest)); } } }