public Form1(Hardware hw) { _up = hw.GPIO_PIN_DIGITAL[0]; _down = hw.GPIO_PIN_DIGITAL[1]; InitializeComponent(); }
/// <summary>Registers a GPIO pin in the system</summary> /// <param name="Pin">Pin number</param> /// <param name="Name">Name for the pin</param> /// <param name="Key">Virtual Key to attach to the pin</param> /// <remarks> /// <para>Useful method for registering a pin that acts as a button</para> /// </para>NOTE: This should only be called from an overload of the /// <see cref="LoadDefaultComponents()"/> Method</para> /// </remarks> protected GpioPort RegisterPin(string Name, Cpu.Pin Pin, VirtualKey Key) { GpioPort retVal = RegisterPin(Name, Pin); retVal.VirtualKey = Key; return(retVal); }
public void Write(GpioPort port, GpioPin pin, GpioPinValue value) { byte olatRegister; byte olatRegisterValues; if (port == GpioPort.A) { olatRegister = OLATA; } else { olatRegister = OLATB; } olatRegisterValues = _readRegister(olatRegister); var pinAddress = _pins[pin.ToString()]; if (value == GpioPinValue.Low) { var pinMask = (byte)(0xFF ^ pinAddress); olatRegisterValues &= pinMask; } else { //high olatRegisterValues |= pinAddress; } _writeRegister(olatRegister, olatRegisterValues); }
public GpioPinValue Read(GpioPort port, GpioPin pin) { byte gpioRegister; byte gpioRegisterValues; if (port == GpioPort.A) { gpioRegister = GPIOA; } else { gpioRegister = GPIOB; } gpioRegisterValues = _readRegister(gpioRegister); var pinAddress = _pins[pin.ToString()]; if ((byte)(gpioRegisterValues & pinAddress) == 0x00) { return(GpioPinValue.Low); } else { return(GpioPinValue.High); } }
public RelayAdaptor(GpioPort port, Models.IoTKiTHardwareStatus hw, Dispatcher dispatcher) { relayPort = port; hwStatus = hw; uiDispatcher = dispatcher; relayPort.OnGpioActivity += relayPort_OnGpioActivity; }
void relayPort_OnGpioActivity(GpioPort sender, bool edge) { Debug.WriteLine("OnGpioActivity"); uiDispatcher.Invoke(() => { hwStatus.RelayStatus = edge; }); }
public Hardware(Emulator emulator) { Emulator = emulator; ONBOARD_LED = InstallGpioComponent("ONBOARD_LED"); ONBOARD_SW1 = InstallGpioComponent("ONBOARD_SW1"); GPIO_PIN_ANALOG = new GpioPort[PortCountAnalog]; for (int i = 0; i < GPIO_PIN_ANALOG.Length; i++) GPIO_PIN_ANALOG[i] = InstallGpioComponent("GPIO_PIN_A" + i); GPIO_PIN_DIGITAL = new GpioPort[PortCountDigital]; for (int i = 0; i < GPIO_PIN_DIGITAL.Length; i++) GPIO_PIN_DIGITAL[i] = InstallGpioComponent("GPIO_PIN_D" + i); }
public override void SetupComponent() { this.GpioPorts.MaxPorts = 128; GpioPort motorUp = new GpioPort(); motorUp.ComponentId = "MotorUpButton"; motorUp.Pin = (Microsoft.SPOT.Hardware.Cpu.Pin)20; motorUp.ModesAllowed = GpioPortMode.InputPort; motorUp.ModesExpected = GpioPortMode.InputPort; GpioPort motorDown = new GpioPort(); motorDown.ComponentId = "MotorDownButton"; motorDown.Pin = (Microsoft.SPOT.Hardware.Cpu.Pin)21; motorDown.ModesAllowed = GpioPortMode.InputPort; motorDown.ModesExpected = GpioPortMode.InputPort; GpioPort dataPortBankZero = new GpioPort(); dataPortBankZero.ComponentId = "DataPortBankZero"; dataPortBankZero.Pin = (Microsoft.SPOT.Hardware.Cpu.Pin)0; dataPortBankZero.ModesAllowed = GpioPortMode.OutputPort; dataPortBankZero.ModesExpected = GpioPortMode.OutputPort; GpioPort dataPortBankOne = new GpioPort(); dataPortBankOne.ComponentId = "DataPortBankOne"; dataPortBankOne.Pin = (Microsoft.SPOT.Hardware.Cpu.Pin)0; dataPortBankOne.ModesAllowed = GpioPortMode.OutputPort; dataPortBankOne.ModesExpected = GpioPortMode.OutputPort; GpioPort dataPortClock = new GpioPort(); dataPortClock.ComponentId = "DataPortClock"; dataPortClock.Pin = (Microsoft.SPOT.Hardware.Cpu.Pin)0; dataPortClock.ModesAllowed = GpioPortMode.OutputPort; dataPortClock.ModesExpected = GpioPortMode.OutputPort; GpioPort dataPortLatch = new GpioPort(); dataPortLatch.ComponentId = "DataPortLatch"; dataPortLatch.Pin = (Microsoft.SPOT.Hardware.Cpu.Pin)0; dataPortLatch.ModesAllowed = GpioPortMode.OutputPort; dataPortLatch.ModesExpected = GpioPortMode.OutputPort; this.RegisterComponent(motorUp); this.RegisterComponent(motorDown); this.RegisterComponent(dataPortBankZero); this.RegisterComponent(dataPortBankOne); this.RegisterComponent(dataPortClock); this.RegisterComponent(dataPortLatch); base.SetupComponent(); }
/// <summary>Registers a GPIO pin in the system</summary> /// <param name="Name">Name for the pin</param> /// <param name="Pin">Pin number</param> /// <param name="ExpectedMode">Expected mode for the pin</param> /// <param name="AllowedMode">Allowed modes for the pin</param> /// <remarks> /// <para>Useful method for registering a pin</para> /// </para>NOTE: This should only be called from an overload of the /// <see cref="LoadDefaultComponents()"/> Method</para> /// </remarks> protected GpioPort RegisterPin(string Name, Cpu.Pin Pin, GpioPortMode ExpectedMode, GpioPortMode AllowedMode) { if (this.State != EmulatorState.Configuration) { throw new InvalidOperationException( "Cannot register GPIO Pins unless emulator is in the Configuration state"); } GpioPort port = new GpioPort(); port.Pin = Pin; port.ModesAllowed = AllowedMode; port.ModesExpected = ExpectedMode; port.ComponentId = Name; RegisterComponent(port); return(port); }
/// <summary> /// This method preserves the OLAT / GPIO settings of all pins and /// will only modify the pin requested and set it to the directionality specified /// </summary> /// <param name="port">Port A or Port B</param> /// <param name="pin">GPIO 0-7</param> /// <param name="mode">Input or Output</param> public void SetGpioPinDriveMode(GpioPort port, GpioPin pin, GpioPinDriveMode mode) { byte olatRegister; byte iodirRegister; byte olatRegisterValues; byte iodirRegisterValues; if (port == GpioPort.A) { olatRegister = OLATA; iodirRegister = IODIRA; } else { olatRegister = OLATB; iodirRegister = IODIRB; } //get read values to preserve olatRegisterValues = _readRegister(olatRegister); iodirRegisterValues = _readRegister(iodirRegister); var pinAddress = _pins[pin.ToString()]; switch (mode) { case GpioPinDriveMode.Input: var inputPinMask = (byte)(0x00 ^ pinAddress); //exclusive OR so that we only change the one pin - others remain unchanged iodirRegisterValues |= inputPinMask; break; case GpioPinDriveMode.Output: //output logic needs to be low prior to switching to output var outputPinMask = (byte)(0xFF ^ pinAddress); olatRegisterValues &= outputPinMask; _writeRegister(olatRegister, olatRegisterValues); iodirRegisterValues &= outputPinMask; break; default: Debug.WriteLine("Pin mode not current supported"); throw new Exception("Pin mode not currently supported"); break; } _writeRegister(iodirRegister, iodirRegisterValues); }
public Form1(Emulator emulator) { _emulator = emulator; _motorUpButtonPort = _emulator.FindComponentById("MotorUpButton") as GpioPort; _motorDownButtonPort = _emulator.FindComponentById("MotorDownButton") as GpioPort; _dataPortClock = _emulator.FindComponentById("DataPortClock") as GpioPort; _dataPortLatch = _emulator.FindComponentById("DataPortLatch") as GpioPort; _dataPortBankZero = _emulator.FindComponentById("DataPortBankZero") as GpioPort; _dataPortBankOne = _emulator.FindComponentById("DataPortBankOne") as GpioPort; InitializeComponent(); _dataPortClock.OnGpioActivity +=new GpioActivity(_dataPortClock_OnGpioActivity); _dataPortLatch.OnGpioActivity +=new GpioActivity(_dataPortLatch_OnGpioActivity); _dataPortBankZero.OnGpioActivity += new GpioActivity(_dataPortBankZero_OnGpioActivity); _dataPortBankOne.OnGpioActivity += new GpioActivity(_dataPortBankOne_OnGpioActivity); }
public Form1(Emulator emulator) { if (emulator == null) throw new ArgumentNullException("emulator"); InitializeComponent(); GpioPort gpioOut0 = (GpioPort)emulator.FindComponentById("GPIOOut0"); this.gpioOut0CheckBox.Text = "GPIO Output Port at Pin " + (int)gpioOut0.Pin; gpioOut0.OnGpioActivity += new GpioActivity(gpioOut0_OnGpioActivity); GpioPort gpioOut1 = (GpioPort)emulator.FindComponentById("GPIOOut1"); this.gpioOut1CheckBox.Text = "GPIO Output Port at Pin " + (int)gpioOut1.Pin; gpioOut1.OnGpioActivity += new GpioActivity(gpioOut1_OnGpioActivity); this.gpioIn0 = (GpioPort)emulator.FindComponentById("GPIOIn0"); this.gpioIn0CheckBox.Text = "GPIO Input Port at Pin " + (int)this.gpioIn0.Pin; this.gpioIn1 = (GpioPort)emulator.FindComponentById("GPIOIn1"); this.gpioIn1Button.Text = "GPIO Input Port at Pin " + (int)this.gpioIn1.Pin; }
public override void SetupComponent() { this.GpioPorts.MaxPorts = 128; GpioPort motorUp = new GpioPort(); motorUp.ComponentId = "MotorUpButton"; motorUp.Pin = (Microsoft.SPOT.Hardware.Cpu.Pin)20; motorUp.ModesAllowed = GpioPortMode.InputPort; motorUp.ModesExpected = GpioPortMode.InputPort; GpioPort motorDown = new GpioPort(); motorDown.ComponentId = "MotorDownButton"; motorDown.Pin = (Microsoft.SPOT.Hardware.Cpu.Pin)21; motorDown.ModesAllowed = GpioPortMode.InputPort; motorDown.ModesExpected = GpioPortMode.InputPort; this.RegisterComponent(motorUp); this.RegisterComponent(motorDown); base.SetupComponent(); }
private GpioPort RegisterOutput(string id) { GpioPort port = this.FindComponentById(id) as GpioPort; if (port != null) { if (port.ModesAllowed == GpioPortMode.InputOutputPort || port.ModesAllowed == GpioPortMode.OutputPort) { _log.Info("Id={0} is an output pin so register it for events", id); port.OnGpioActivity += new GpioActivity(Port_OnGpioActivity); } else { _log.Warn("Id={0} must not be an output pin", id); } } else { _log.Warn("Output was not registered Id={0}", id); } return(port); }
public override void InitializeComponent() { base.InitializeComponent(); _gpio_d0Port = RegisterOutput("GPIO_PIN_D0"); _gpio_d1Port = RegisterOutput("GPIO_PIN_D1"); _gpio_d2Port = RegisterOutput("GPIO_PIN_D2"); _gpio_d3Port = RegisterOutput("GPIO_PIN_D3"); _gpio_d4Port = RegisterOutput("GPIO_PIN_D4"); _gpio_d5Port = RegisterOutput("GPIO_PIN_D5"); _gpio_d6Port = RegisterOutput("GPIO_PIN_D6"); _gpio_d7Port = RegisterOutput("GPIO_PIN_D7"); _gpio_d8Port = RegisterOutput("GPIO_PIN_D8"); _gpio_d9Port = RegisterOutput("GPIO_PIN_D9"); _gpio_d10Port = RegisterOutput("GPIO_PIN_D10"); _gpio_d11Port = RegisterOutput("GPIO_PIN_D11"); _gpio_d12Port = RegisterOutput("GPIO_PIN_D12"); _gpio_d13Port = RegisterOutput("GPIO_PIN_D13"); _onBoardLedPort = RegisterOutput("ONBOARD_LED"); _onBoardSwitch1 = this.FindComponentById("ONBOARD_SW1") as GpioPort; _eventAggregator.Subscribe(this); }
public void Setup() { if (setup) { return; } GpioPort.Setup(); allPeripherals = new object[] { MotorLeft, MotorRight, LedFront, LedRear, Sonar, IrLeft, IrRight, IrLeftLine, IrRightLine, Switch, ServoPan, ServoTilt//, VideoStreaming }; // setup all peripherals foreach (var periph in GetAllPeripherals <ISetupable>()) { periph.Setup(); } setup = true; }
public Form1(Emulator emulator) { if (emulator == null) { throw new ArgumentNullException("emulator"); } InitializeComponent(); GpioPort gpioOut0 = (GpioPort)emulator.FindComponentById("GPIOOut0"); this.gpioOut0CheckBox.Text = "GPIO Output Port at Pin " + (int)gpioOut0.Pin; gpioOut0.OnGpioActivity += new GpioActivity(gpioOut0_OnGpioActivity); GpioPort gpioOut1 = (GpioPort)emulator.FindComponentById("GPIOOut1"); this.gpioOut1CheckBox.Text = "GPIO Output Port at Pin " + (int)gpioOut1.Pin; gpioOut1.OnGpioActivity += new GpioActivity(gpioOut1_OnGpioActivity); this.gpioIn0 = (GpioPort)emulator.FindComponentById("GPIOIn0"); this.gpioIn0CheckBox.Text = "GPIO Input Port at Pin " + (int)this.gpioIn0.Pin; this.gpioIn1 = (GpioPort)emulator.FindComponentById("GPIOIn1"); this.gpioIn1Button.Text = "GPIO Input Port at Pin " + (int)this.gpioIn1.Pin; }
/// <summary>Registers a GPIO pin in the system</summary> /// <param name="name">Name for the pin</param> /// <param name="pin">Pin number</param> /// <param name="expectedMode">Expected mode for the pin</param> /// <param name="allowedMode">Allowed modes for the pin</param> /// <remarks> /// <para>Useful method for registering a pin</para> /// <para>NOTE: This should only be called from an overload of the /// <see cref="EmulatorService.LoadDefaultComponents()"/> Method</para> /// </remarks> protected GpioPort RegisterPin(string name, Cpu.Pin pin, GpioPortMode expectedMode, GpioPortMode allowedMode) { if (State != EmulatorState.Configuration) throw new InvalidOperationException( "Cannot register GPIO Pins unless emulator is in the Configuration state"); var port = new GpioPort {Pin = pin, ModesAllowed = allowedMode, ModesExpected = expectedMode, ComponentId = name}; RegisterComponent(port); return port; }
void Port_OnGpioActivity(GpioPort sender, bool edge) { _log.Info("Emulator Service GpioPort Fired {0} {1}", sender.Pin, edge); _eventAggregator.Publish <OutputGpioEventArgs>(new OutputGpioEventArgs((int)sender.Pin, edge)); }
/// <summary>Registers a GPIO pin in the system</summary> /// <param name="Name">Name for the pin</param> /// <param name="Pin">Pin number</param> /// <param name="ExpectedMode">Expected mode for the pin</param> /// <param name="AllowedMode">Allowed modes for the pin</param> /// <remarks> /// <para>Useful method for registering a pin</para> /// </para>NOTE: This should only be called from an overload of the /// <see cref="LoadDefaultComponents()"/> Method</para> /// </remarks> protected GpioPort RegisterPin(string Name, Cpu.Pin Pin, GpioPortMode ExpectedMode, GpioPortMode AllowedMode) { if (this.State != EmulatorState.Configuration) throw new InvalidOperationException( "Cannot register GPIO Pins unless emulator is in the Configuration state"); GpioPort port = new GpioPort(); port.Pin = Pin; port.ModesAllowed = AllowedMode; port.ModesExpected = ExpectedMode; port.ComponentId = Name; RegisterComponent(port); return port; }
private void gpioOut1_OnGpioActivity(GpioPort sender, bool edge) { BeginInvoke(new MethodInvoker(delegate { this.gpioOut0CheckBox.Checked = edge; })); }
private void GpioPortSafeWrite(GpioPort port, bool value) { port.Invoke(new GpioPortWriteDelegate(port.Write), value); }
void _dataPortLatch_OnGpioActivity(GpioPort sender, bool edge) { throw new NotImplementedException(); }
void Port_OnGpioActivity(GpioPort sender, bool edge) { Action action = () => BackColor = edge ? Color.Red : Color.White; UpdateUI(action); }