public static void Main(string[] args) { ButtonEvents buts = new ButtonEvents(); var tokenSource = new CancellationTokenSource(); var token = tokenSource.Token; var dialog = new InfoDialog("Attach distance sensor", false); dialog.Show(); var sensor = SensorAttachment.Wait <MSAngleSensor>(token); //wait for sensor to attached on any port LcdConsole.WriteLine("Up reset angle"); LcdConsole.WriteLine("Down read RMP"); LcdConsole.WriteLine("Enter read angle"); LcdConsole.WriteLine("Left read raw"); LcdConsole.WriteLine("Esc. terminate"); buts.EscapePressed += () => { tokenSource.Cancel(); }; buts.EnterPressed += () => { LcdConsole.WriteLine("Angle: " + sensor.ReadAngle().ToString()); }; buts.UpPressed += () => { LcdConsole.WriteLine("Reset angle"); sensor.ResetAngle(); }; buts.DownPressed += () => { LcdConsole.WriteLine("Read RPM: " + sensor.ReadRPM().ToString()); }; buts.LeftPressed += () => { LcdConsole.WriteLine("Read raw: " + sensor.ReadRAW().ToString()); }; token.WaitHandle.WaitOne(); }
public static void Main(string[] args) { using (ButtonEvents buts = new ButtonEvents()) { var tokenSource = new CancellationTokenSource(); var token = tokenSource.Token; buts.EscapePressed += tokenSource.Cancel; var dialog = new InfoDialog("Attach distance sensor"); dialog.Show(); var sensor = SensorAttachment.Wait <MSDistanceSensor> (token); //wait for sensor to attached on any port if (!token.IsCancellationRequested) { LcdConsole.WriteLine("Up power on"); LcdConsole.WriteLine("Down power off"); LcdConsole.WriteLine("Enter read sensor"); LcdConsole.WriteLine("Left read voltage"); LcdConsole.WriteLine("Right read range type"); LcdConsole.WriteLine("Esc. terminate"); buts.EnterPressed += () => { LcdConsole.WriteLine("Sensor reading: " + sensor.ReadAsString()); }; buts.UpPressed += () => { LcdConsole.WriteLine("Power on"); sensor.PowerOn(); }; buts.DownPressed += () => { LcdConsole.WriteLine("Power off"); sensor.PowerOff(); }; buts.LeftPressed += () => { LcdConsole.WriteLine("Voltage: " + sensor.GetVolgage()); }; buts.RightPressed += () => { LcdConsole.WriteLine("Sensor range is : " + sensor.GetRange()); }; } token.WaitHandle.WaitOne(); } }