Esempio n. 1
0
        public IMotor PwmMotor(int pin, float tweenFactor, float speedMultiplier, bool flipped)
        {
            string pinName = kPwmPinNameByExportNumber[pin];

            beagleBoneGpioConfigurationManager.SetPinMode(pinName, PinMode.Pwm);

            if (!Directory.Exists(BuildPinPath(pin)))
            {
                internalFileSystemProxy.WriteText(kPwmExportPath, pin.ToString());
            }

            internalFileSystemProxy.WriteText(
                BuildPinPath(pin, kRunKey),
                "0");

            internalFileSystemProxy.WriteText(
                BuildPinPath(pin, kPeriodNanosecondsKey),
                kPwmCyclePeriod.ToString());

            internalFileSystemProxy.WriteText(
                BuildPinPath(pin, kRunKey),
                "1");

            var dutyValue = deviceValueFactory.FromFile <int>(
                BuildPinPath(pin, kDutyNanosecondsKey),
                DeviceValueAccess.ReadWrite);

            dutyValue.Set(1500000);
            Thread.Sleep(1000);
            dutyValue.Set(0);
            Thread.Sleep(1000);
            dutyValue.Set(1500000);

            return(new GpioMotorImpl(
                       $"PWM_Pin{pin}_{pinName}",
                       deviceValueFactory.TweeningAdapter(
                           deviceValueFactory.IntToFloatAdapter(
                               dutyValue,
                               -1500000,
                               (int)(399000 * (flipped ? -1 : 1) * speedMultiplier) // accounts for rounding error
                               ), tweenFactor)));
        }