예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }