Example #1
0
        public SoftwarePwmController(IGpioController controller)
        {
            // Get GPIO
            m_GpioController = controller;

            // How many pins
            m_PinCount = m_GpioController.PinCount;

            // Create pin lookup
            m_Pins = new Dictionary <GpioEnum, SoftPwmPin>(m_PinCount);

            // Create
            m_Stopwatch = new Stopwatch();

            // Defaults
            m_ActualFrequency = MIN_FREQUENCY;
            m_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.
            m_Updater = new ScheduledUpdater(new ScheduleOptions(0), new Scheduler());
            m_Updater.SetUpdateAction(Update);
        }
Example #2
0
        /// <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);
        }
Example #3
0
        /// <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);
        }
Example #4
0
        /// <summary>
        /// Initializes a new <see cref="AnalogSensor"/> instance.
        /// </summary>
        public AnalogSensor()
        {
            // Create updater
            updater = new ScheduledUpdater(new ScheduleOptions(reportInterval: 100));
            updater.SetUpdateAction(() => Update(true));
            updater.Starting += (s, e) => EnsureInitialized();

            // Create events
            readingChangedEvent = new ObservableEvent <IAnalogSensor, AnalogSensorReadingChangedEventArgs>(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);
        }
Example #6
0
        /// <inheritdoc/>
        public void Dispose()
        {
            if (updater != null)
            {
                updater.Dispose();
                updater = null;
            }

            if (adcChannel != null)
            {
                adcChannel.Dispose();
                adcChannel = null;
            }

            isInitialized = false;
        }
Example #7
0
        public void Dispose()
        {
            if (m_Updater != null)
            {
                m_Updater.Dispose();
                m_Updater = null;
            }

            // Dispose each pin
            lock (m_Pins)
            {
                foreach (var pinKey in m_Pins.Keys.ToArray())
                {
                    m_Pins[pinKey].Pin.Dispose();
                    m_Pins.Remove(pinKey);
                }
            }

            m_Pins = null;
        }
Example #8
0
 /// <inheritdoc/>
 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;
 }
Example #9
0
 /// <inheritdoc/>
 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;
 }