/// <summary> /// Constructor for a single 7seg click. /// </summary> /// <param name="socket">mikroBUS socket number.</param> /// <param name="radix">Numerical base or radix. Allowed values are /// <c>Decimal</c> and <c>Hexadecimal</c>.</param> /// <param name="blanking">Zero blanking. Allowed values are /// <c>None</c>, <c>Leading</c>, and <c>Full</c>.</param> /// <param name="pwmfreq">PWM frequency. Set to zero to use GPIO /// instead of PWM.</param> /// <param name="remdev">Remote I/O server device object.</param> public Board(int socket, Base radix = Base.Decimal, ZeroBlanking blanking = ZeroBlanking.None, int pwmfreq = 100, IO.Remote.Device remdev = null) { // Create Remote I/O server device object, if one wasn't supplied if (remdev == null) { remdev = new IO.Remote.Device(); } // Create a mikroBUS socket object IO.Remote.mikroBUS.Socket S = new IO.Remote.mikroBUS.Socket(socket); // Configure hardware reset GPIO pin myRSTgpio = remdev.GPIO_Create(S.RST, IO.Interfaces.GPIO.Direction.Output, true); // Issue hardware reset Reset(); // Configure PWM pin -- Prefer PWM over GPIO, if possible, and // assume full brightness until otherwise changed. myPWMgpio = null; myPWMout = null; if ((pwmfreq > 0) && (S.PWMOut != IO.Remote.Device.Unavailable)) { myPWMout = remdev.PWM_Create(S.PWMOut, pwmfreq, 100.0); } else if (S.PWM != IO.Remote.Device.Unavailable) { myPWMgpio = remdev.GPIO_Create(S.PWM, IO.Interfaces.GPIO.Direction.Output, true); } // Configure 74HC595 shift register chain mychain = new SN74HC595.Device(remdev.SPI_Create(S.SPIDev, IO.Devices.SN74HC595.Device.SPI_Mode, 8, IO.Devices.SN74HC595.Device.SPI_MaxFreq), 2); myradix = radix; myblanking = blanking; Clear(); }
/// <summary> /// Constructor for a single 7seg click. /// </summary> /// <param name="socket">mikroBUS socket number.</param> /// <param name="radix">Numerical base or radix. Allowed values are /// <c>Decimal</c> and <c>Hexadecimal</c>.</param> /// <param name="blanking">Zero blanking. Allowed values are /// <c>None</c>, <c>Leading</c>, and <c>Full</c>.</param> /// <param name="pwmfreq">PWM frequency. Set to zero to use GPIO /// instead of PWM.</param> public Board(int socket, Base radix = Base.Decimal, ZeroBlanking blanking = ZeroBlanking.None, int pwmfreq = 100) { IO.Objects.libsimpleio.mikroBUS.Socket S = new IO.Objects.libsimpleio.mikroBUS.Socket(socket); // Configure RST pin myRSTgpio = new IO.Objects.libsimpleio.GPIO.Pin(S.RST, IO.Interfaces.GPIO.Direction.Output, true); // Configure PWM pin -- Prefer PWM over GPIO, if possible, and // assume full brightness until otherwise changed. myPWMgpio = null; myPWMout = null; if ((pwmfreq > 0) && (S.PWMOut.available)) { myPWMout = new IO.Objects.libsimpleio.PWM.Output(S.PWMOut, pwmfreq, 100.0); } else if (S.PWM.available) { myPWMgpio = new IO.Objects.libsimpleio.GPIO.Pin(S.PWM, IO.Interfaces.GPIO.Direction.Output, true); } // Configure 74HC595 shift register chain mychain = new SN74HC595.Device(new IO.Objects.libsimpleio.SPI.Device(S.SPIDev, IO.Devices.SN74HC595.Device.SPI_Mode, 8, IO.Devices.SN74HC595.Device.SPI_MaxFreq, S.CS.available ? new IO.Objects.libsimpleio.GPIO.Pin(S.CS, IO.Interfaces.GPIO.Direction.Output, true) : null), 2); mybase = radix; myblanking = blanking; Clear(); }
/// <summary> /// Constructor for a single GPIO output pin. /// </summary> /// <param name="dev">SN74HC595 device object.</param> /// <param name="pos">Bit position, numbered left to right. /// Zero indicates the most significant bit of the first shift /// register stage.</param> /// <param name="state">Initial GPIO output state.</param> public Pin(IO.Devices.SN74HC595.Device dev, int pos, bool state = false) { // Validate parameters if (pos < 0) { throw new System.Exception("Invalid bit index"); } if (pos / 8 + 1 > dev.Length) { throw new System.Exception("Invalid bit index"); } // Calculate byte index and bit mask mydev = dev; myindex = pos / 8; mymask = (byte)(1 << (7 - pos % 8)); // Write initial state this.state = state; }