Exemple #1
0
    protected override void OnStartExperiment()
    {
        var gpioname = (string)ex.GetParam("GPIO");
        var wavetype = ex.GetParam("WaveType").Convert <DigitalWaveType>();
        var freq     = ex.GetParam("Freq").Convert <float>();

        switch (gpioname)
        {
        case "ParallelPort":
            // On Average 5kHz
            gpio = new ParallelPort(Config.ParallelPort0);
            break;

        case "FTDI":
            // On Average 2kHz
            gpio = new FTDIGPIO();
            break;

        case "1208FS":
            // On Average 500Hz
            //gpio = new MCCDevice();
            break;
        }
        if (gpio != null)
        {
            gpiowave = new GPIOWave(gpio);
            switch (wavetype)
            {
            case DigitalWaveType.PWM:
                gpiowave.SetBitWave(0, freq);
                break;

            case DigitalWaveType.PoissonSpike:
                gpiowave.SetBitWave(0, 50, 2, 2, 0, 0);
                gpiowave.SetBitWave(1, 100, 2, 2, 0, 0);
                break;
            }
            gpiowave.StartAll();
        }
        else
        {
            Debug.LogWarning("No Valid GPIO.");
        }
    }
 protected override void OnStartExperiment()
 {
     if (ex.EventSyncProtocol.SyncMethods.Contains(SyncMethod.GPIO))
     {
         gpio = new ParallelPort(dataaddress: Config.ParallelPort0);
         if (!gpio.Found)
         {
             gpio = new FTDIGPIO();
         }
         if (!gpio.Found)
         {
             // gpio = new MCCDevice(config.MCCDevice, config.MCCDPort);
         }
         if (!gpio.Found)
         {
             Debug.LogWarning("No GPIO Sync Channel.");
         }
     }
     SetEnvActiveParam("Visible", false);
     SyncEvent();
 }
Exemple #3
0
 public BrewIO(IGPIO gpio)
 {
     _gpio            = gpio;
     SupportedOutputs = new []
     {
         new OutputDto
         {
             Output    = Outputs.Pid1Output,
             Pin       = _outputPinPid1,
             Name      = "Pid 1 Output",
             Value     = _gpio.Get(_outputPinPid1),
             Automatic = true
         },
         new OutputDto
         {
             Output    = Outputs.Pid2Output,
             Pin       = _outputPinPid2,
             Name      = "Pid 2 Output",
             Value     = _gpio.Get(_outputPinPid2),
             Automatic = true
         },
         new OutputDto
         {
             Output = Outputs.Output1,
             Pin    = _outputPinOutput1,
             Name   = "Mash pump",
             Value  = _gpio.Get(_outputPinOutput1)
         },
         new OutputDto
         {
             Output = Outputs.Output2,
             Pin    = _outputPinOutput2,
             Name   = "Sparge pump",
             Value  = _gpio.Get(_outputPinOutput2)
         }
     };
 }
        public InterruptManager(IPeripheral master, IGPIO irq = null, string gpioName = null, int subvector = -1)
        {
            if (!typeof(TInterrupt).IsEnum)
            {
                throw new ArgumentException("TInterrupt must be an enum");
            }

            this.master              = master;
            activeInterrupts         = new HashSet <TInterrupt>();
            enabledInterrupts        = new HashSet <TInterrupt>();
            subvectors               = new Dictionary <IGPIO, HashSet <TInterrupt> >();
            gpioNames                = new Dictionary <IGPIO, string>();
            nonsettableInterrupts    = new HashSet <TInterrupt>();
            enabledOnResetInterrupts = new HashSet <TInterrupt>();

            var subvectorIdToGpio = new Dictionary <int, IGPIO>();

            if (irq != null)
            {
                subvectorIdToGpio.Add(subvector, irq);
                gpioNames[irq] = gpioName ?? string.Empty;
            }
            else
            {
                // scan for irq providers
                foreach (var member in master.GetType().GetProperties())
                {
                    var irqProviderAttribute = (IrqProviderAttribute)member.GetCustomAttributes(typeof(IrqProviderAttribute), false).SingleOrDefault();
                    if (irqProviderAttribute == null)
                    {
                        continue;
                    }

                    var field = member.GetMethod.Invoke(master, new object[0]);
                    if (field == null)
                    {
                        throw new ArgumentException("Trying to create the InterruptManager instance, but the IrqProvider object is not initialized");
                    }
                    var gpioField = field as IGPIO;
                    if (gpioField == null)
                    {
                        throw new ArgumentException("IrqProviderAttribute can only be used on properties of type IGPIO.");
                    }

                    subvectorIdToGpio.Add(irqProviderAttribute.SubvectorId, gpioField);
                    gpioNames[gpioField] = irqProviderAttribute.Name ?? member.Name;
                }
            }

            // this iterates over all values of an enum (SpecialName here is to filter out non-value members of enum type)
            foreach (var member in typeof(TInterrupt).GetFields().Where(x => !x.Attributes.HasFlag(FieldAttributes.SpecialName)))
            {
                var subvectorId             = 0;
                var subvectorAttribute      = member.GetCustomAttributes(false).OfType <SubvectorAttribute>().SingleOrDefault();
                var nonsettableAttribute    = member.GetCustomAttributes(false).OfType <NotSettableAttribute>().SingleOrDefault();
                var enabledOnResetAttribute = member.GetCustomAttributes(false).OfType <EnabledOnResetAttribute>().SingleOrDefault();

                if (subvectorAttribute != null)
                {
                    if (!subvectorIdToGpio.ContainsKey(subvectorAttribute.SubvectorId))
                    {
                        throw new ArgumentException(string.Format("There is no gpio defined for subvector {0}", subvectorAttribute.SubvectorId));
                    }
                    subvectorId = subvectorAttribute.SubvectorId;
                }
                else
                {
                    if (!subvectorIdToGpio.ContainsKey(-1))
                    {
                        throw new ArgumentException("There is no default gpio defined");
                    }
                    subvectorId = -1;
                }

                var gpio = subvectorIdToGpio[subvectorId];
                if (!subvectors.TryGetValue(gpio, out HashSet <TInterrupt> interrupts))
                {
                    interrupts = new HashSet <TInterrupt>();
                    subvectors.Add(gpio, interrupts);
                }

                var interrupt = (TInterrupt)Enum.Parse(typeof(TInterrupt), member.Name);
                interrupts.Add(interrupt);
                if (nonsettableAttribute != null)
                {
                    nonsettableInterrupts.Add(interrupt);
                }

                if (enabledOnResetAttribute != null)
                {
                    enabledOnResetInterrupts.Add(interrupt);
                }
            }

            Reset();
        }
Exemple #5
0
 public static void SetGPIO(IGPIO gpio)
 {
     GPIOevents = gpio;
 }
Exemple #6
0
 public static void Blink(this IGPIO gpio)
 {
     gpio.Set();
     gpio.Unset();
 }
Exemple #7
0
 public static void Unset(this IGPIO gpio)
 {
     gpio.Set(false);
 }
Exemple #8
0
 public static void Set(this IGPIO gpio)
 {
     gpio.Set(true);
 }
Exemple #9
0
 public GPIOWave(IGPIO gpio, float lowcutofffreq = 0.00001f, float highcutofffreq = 10000f)
 {
     this.gpio           = gpio;
     this.lowcutofffreq  = lowcutofffreq;
     this.highcutofffreq = highcutofffreq;
 }
Exemple #10
0
        public GPIO()
        {
            if (GPIOevents == null)
            {
                GPIOevents = this;
            }
            else
            {
                throw new Exception("Can't create more GPIO Controler");
            }

            Pi.Init <BootstrapWiringPi>();

            //Buzzer
            buzzer         = Pi.Gpio[25];
            buzzer.PinMode = GpioPinDriveMode.Output;

            //buttons
            IGpioPin[] buttons = { Pi.Gpio[17], Pi.Gpio[27], Pi.Gpio[22], Pi.Gpio[23], Pi.Gpio[24] };

            for (int i = 0; i < buttonsStatus.Length; i++)
            {
                buttonsStatus[i] = false;
            }
            var nextLongPressTimer = new Stopwatch();

            foreach (var button in buttons)
            {
                button.PinMode = GpioPinDriveMode.Input;

                var ButtonTask = new Task(async() =>
                {
                    while (true)
                    {
                        if (button.Value)
                        {
                            switch (button.BcmPinNumber)
                            {
                            case 17:
                                if (!buttonsStatus[0])
                                {
                                    OnButtonClick?.Invoke(ButtonId.Pause);
                                }
                                buttonsStatus[0] = true;
                                break;

                            case 27:
                                nextLongPressTimer.Start();
                                if (!buttonsStatus[1])
                                {
                                    OnButtonClick?.Invoke(ButtonId.Next);
                                }
                                if (!longButtonStatus && nextLongPressTimer.ElapsedMilliseconds >= 3000)
                                {
                                    OnButtonClick?.Invoke(ButtonId.LongNext);
                                    longButtonStatus = true;
                                }
                                buttonsStatus[1] = true;
                                break;

                            case 22:
                                if (!buttonsStatus[2])
                                {
                                    OnButtonClick?.Invoke(ButtonId.User1);
                                }
                                buttonsStatus[2] = true;
                                break;

                            case 23:
                                if (!buttonsStatus[3])
                                {
                                    OnButtonClick?.Invoke(ButtonId.User2);
                                }
                                buttonsStatus[3] = true;
                                break;

                            case 24:
                                if (!buttonsStatus[4])
                                {
                                    OnButtonClick?.Invoke(ButtonId.User3);
                                }
                                buttonsStatus[4] = true;
                                break;
                            }
                        }
                        else
                        {
                            switch (button.BcmPinNumber)
                            {
                            case 17:
                                buttonsStatus[0] = false;
                                break;

                            case 27:
                                nextLongPressTimer.Reset();
                                buttonsStatus[1] = false;
                                longButtonStatus = false;
                                break;

                            case 22:
                                buttonsStatus[2] = false;
                                break;

                            case 23:
                                buttonsStatus[3] = false;
                                break;

                            case 24:
                                buttonsStatus[4] = false;
                                break;
                            }
                        }
                        await Task.Delay(100);
                    }
                });
                ButtonTask.Start();
            }
            //Bluetooth
            //var bt = new Bluetooth();
        }
 public InterruptHandler(IGPIO gpio)
 {
     irqs           = new Dictionary <TRegister, IrqState>();
     flagToRegister = new Dictionary <TFlag, FlagState>();
     this.gpio      = gpio;
 }
Exemple #12
0
 public IrqNode(IGPIO destination, Action changeCallback)
 {
     this.destination    = destination;
     this.changeCallback = changeCallback;
 }