/// <summary> /// Initializes a new <see cref="SoftPwm"/> instance. /// </summary> public SoftPwm() { // Get GPIO gpioController = GpioController.GetDefault(); // Make sure we have it if (gpioController == null) { throw new DeviceNotFoundException("GPIO"); } // How many pins pinCount = gpioController.PinCount; // Create pin lookup pins = new Dictionary<int, SoftPwmPin>(pinCount); // Create stopwatch = new Stopwatch(); // Defaults actualFrequency = MIN_FREQUENCY; ticksPerSecond = Stopwatch.Frequency; // Create the updater. Default to 0 seconds between updates, meaning run as fast as possible. // IMPORTANT: Do not use Scheduler.Default, create a new Scheduler. // This puts us in parallel priority with other sensors and allows // us to run on a separate core if available. updater = new ScheduledUpdater(scheduleOptions: new ScheduleOptions(0), scheduler: new Scheduler()); updater.SetUpdateAction(Update); }
/// <summary> /// Initializes a new <see cref="AnalogSensor"/> instance. /// </summary> public AnalogSensor() { // Create updater updater = new ScheduledUpdater(new ScheduleOptions(reportInterval: 100)); updater.SetUpdateAction(Update); updater.Starting += (s, e) => EnsureInitialized(); // Create events readingChangedEvent = new ObservableEvent<IAnalogSensor, AnalogSensorReadingChangedEventArgs>(updater); }
/// <summary> /// Initializes a new <see cref="SS944"/> instance. /// </summary> public SS944() { // Create updater updater = new ScheduledUpdater(new ScheduleOptions(reportInterval: 100)); updater.SetUpdateAction(Update); updater.Starting += (s, e) => EnsureInitialized(); // Create events readingChangedEvent = new ObservableEvent<IThumbstick, ThumbstickReadingChangedEventArgs>(updater); }
/// <summary> /// Initializes a new <see cref="GraphicsDisplayPanel"/> instance. /// </summary> public GraphicsDisplayPanel() { // Theme this.DefaultStyleKey = typeof(GraphicsDisplayPanel); // Create the updater. Default to 1 second between updates. // IMPORTANT: Do not use Scheduler.Default, create a new Scheduler. // This puts us in parallel priority with other sensors and allows // us to run on a separate core if available. updater = new ScheduledUpdater(scheduleOptions: new ScheduleOptions(1000), scheduler: new Scheduler()); updater.SetAsyncUpdateAction(RenderAsyncAction); }
public void Dispose() { if (updater != null) { updater.Dispose(); updater = null; } // Dispose each pin lock(pins) { for (int i = pinCount - 1; i >= 0; i--) { if (pins.ContainsKey(i)) { pins[i].Pin.Dispose(); pins.Remove(i); } } } pins = null; }
public void Dispose() { if (updater != null) { updater.Dispose(); updater = null; } if (adcChannel != null) { adcChannel.Dispose(); adcChannel = null; } isInitialized = false; }
public void Dispose() { if (updater != null) { updater.Dispose(); updater = null; } if (buttonPin != null) { buttonPin.Dispose(); buttonPin = null; } if (xChannel != null) { xChannel.Dispose(); xChannel = null; } if (yChannel != null) { yChannel.Dispose(); yChannel = null; } isInitialized = false; }