Example #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)));
        }
        public void Initialize()
        {
            if (initialized)
            {
                return;
            }
            initialized = true;

            // ReSharper disable once StringLiteralTypo
            const string kCapeManagerSlotsPath = "/sys/devices/bone_capemgr.*/slots";
            var          capeManagerPath       = internalFileSystemProxy.ResolveAbsolutePath(kCapeManagerSlotsPath);

            const string kExportAllPins = "cape-universaln";

            try {
                internalFileSystemProxy.WriteText(capeManagerPath, kExportAllPins);
            } catch (IOException e) when(e.Message.Contains("File already exists") && Environment.OSVersion.Platform == PlatformID.Unix)
            {
                // Pins already exported.
            }
        }
Example #3
0
 public void Set(T value) => internalFileSystemProxy.WriteText(path, ValueSerializer <T> .Serialize(value, access));