All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.silverspoon.bulldog.linux.gpio.LinuxDigitalOutput Maven / Gradle / Ivy

There is a newer version: 0.3.0
Show newest version
package io.silverspoon.bulldog.linux.gpio;

import io.silverspoon.bulldog.core.Signal;
import io.silverspoon.bulldog.core.gpio.Pin;
import io.silverspoon.bulldog.core.gpio.base.AbstractDigitalOutput;
import io.silverspoon.bulldog.linux.sysfs.SysFsPin;

public class LinuxDigitalOutput extends AbstractDigitalOutput {

   private SysFsPin sysFsPin;

   public LinuxDigitalOutput(Pin pin) {
      super(pin);
      sysFsPin = createSysFsPin(pin);
   }

   protected SysFsPin createSysFsPin(Pin pin) {
      return new SysFsPin(pin.getAddress());
   }

   @Override
   protected void setupImpl() {
      exportPinIfNecessary();
   }

   @Override
   protected void teardownImpl() {
      unexportPin();
   }

   protected void exportPinIfNecessary() {
      sysFsPin.exportIfNecessary();
      sysFsPin.setDirection("out");
   }

   protected void unexportPin() {
      sysFsPin.unexport();
   }

   @Override
   protected void applySignalImpl(Signal signal) {
      sysFsPin.setValue(signal);
   }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy