Esempio n. 1
0
        //no need to setup pin this is done for you
        public bool InputPin(PinEnum pin)
        {
            bool returnValue = false;

            //if we havent used the pin before, or if we used it as an output before, set it up
            if (!_inExported.Contains(pin) || _outExported.Contains(pin))
            {
                SetupPin(pin, DirectionEnum.IN);
            }

            string filename = GetFilenameValue(pin);

            if (File.Exists(filename))
            {
                string readValue = File.ReadAllText(filename);
                if (readValue.Length > 0 && readValue[0] == '1')
                {
                    returnValue = true;
                }
            }
            else
            {
                throw new Exception(string.Format("Cannot read from {0}. File does not exist", pin));
            }

            Debug.WriteLine("input from pin " + pin + ", value was " + returnValue);

            return(returnValue);
        }
Esempio n. 2
0
        /// <summary>
        /// this gets called automatically when we try and output to, or input from, a pin
        /// </summary>
        /// <param name="pin"></param>
        /// <param name="direction"></param>
        private void SetupPin(PinEnum pin, DirectionEnum direction)
        {
            //unexport if it we're using it already
            if (_outExported.Contains(pin) || _inExported.Contains(pin))
            {
                UnexportPin(pin);
            }

            //export
            File.WriteAllText(GPIO_PATH + "export", GetPinNumber(pin));

            Debug.WriteLine("exporting pin " + pin + " as " + direction);

            // set i/o direction
            File.WriteAllText(GPIO_PATH + pin + "/direction", direction.ToString().ToLower());

            //record the fact that we've setup that pin
            if (direction == DirectionEnum.OUT)
            {
                _outExported.Add(pin);
            }
            else
            {
                _inExported.Add(pin);
            }
        }
Esempio n. 3
0
        //no need to setup pin this is done for you
        public void OutputPin(PinEnum pin, bool value)
        {
            //if we havent used the pin before,  or if we used it as an input before, set it up
            if (!_outExported.Contains(pin) || _inExported.Contains(pin)) SetupPin(pin, DirectionEnum.OUT);

            string writeValue = "0";
            if (value) writeValue = "1";
            File.WriteAllText(GetFilenameValue(pin), writeValue);

            Debug.WriteLine("output to pin " + pin + ", value was " + value);
        }
Esempio n. 4
0
        private string GetFilenameValue(PinEnum pin)
        {
            string result;

            if (_filenames4Values.TryGetValue((int)pin, out result))
            {
                return(result);
            }
            result = GPIO_PATH + pin + "/value";
            _filenames4Values.Add((int)pin, result);
            return(result);
        }
Esempio n. 5
0
        /// <summary>
        /// Meldet alle <i>Direct Show</i> Ein- und Ausgänge dieses Filters. Diese
        /// sind abhängig vom aktuellen Betriebsmodus als Demultiplexer oder
        /// Datenquelle.
        /// </summary>
        /// <returns>Eine Auflistung über die Ein- und Ausgänge.</returns>
        public IEnumPins EnumPins()
        {
            // Create
            var pinEnum = new PinEnum();

            // Fill pins
            if (DataManager != null)
            {
                // Report all
                pinEnum.Add(DataManager);
                pinEnum.Add(DataManager.TIFConnector);
            }

            // Report
            return(pinEnum);
        }
Esempio n. 6
0
        //no need to setup pin this is done for you
        public void OutputPin(PinEnum pin, bool value)
        {
            //if we havent used the pin before,  or if we used it as an input before, set it up
            if (!_outExported.Contains(pin) || _inExported.Contains(pin))
            {
                SetupPin(pin, DirectionEnum.OUT);
            }

            string writeValue = "0";

            if (value)
            {
                writeValue = "1";
            }
            File.WriteAllText(GetFilenameValue(pin), writeValue);

            Debug.WriteLine("output to pin " + pin + ", value was " + value);
        }
Esempio n. 7
0
        /// <summary>
        /// this gets called automatically when we try and output to, or input from, a pin
        /// </summary>
        /// <param name="pin"></param>
        /// <param name="direction"></param>
        private void SetupPin(PinEnum pin, DirectionEnum direction)
        {
            //unexport if it we're using it already
            if (_outExported.Contains(pin) || _inExported.Contains(pin)) UnexportPin(pin);

            //export
            File.WriteAllText(GPIO_PATH + "export", GetPinNumber(pin));

            Debug.WriteLine("exporting pin " + pin + " as " + direction);

            // set i/o direction
            File.WriteAllText(GPIO_PATH + pin + "/direction", direction.ToString().ToLower());

            //record the fact that we've setup that pin
            if (direction == DirectionEnum.OUT)
                _outExported.Add(pin);
            else
                _inExported.Add(pin);
        }
Esempio n. 8
0
        /// <summary>
        /// if for any reason you want to unexport a particular pin use this, otherwise just call CleanUpAllPins when you're done
        /// </summary>
        /// <param name="pin"></param>
        public void UnexportPin(PinEnum pin)
        {
            bool found = false;

            if (_outExported.Contains(pin))
            {
                found = true;
                _outExported.Remove(pin);
            }
            if (_inExported.Contains(pin))
            {
                found = true;
                _inExported.Remove(pin);
            }

            if (found)
            {
                File.WriteAllText(GPIO_PATH + "unexport", GetPinNumber(pin));
                Debug.WriteLine("unexporting  pin " + pin);
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Meldet alle <i>Direct Show</i> Ein- und Ausgänge dieses Filters. Diese
        /// sind abhängig vom aktuellen Betriebsmodus als Demultiplexer oder
        /// Datenquelle.
        /// </summary>
        /// <returns>Eine Auflistung über die Ein- und Ausgänge.</returns>
        public IEnumPins EnumPins()
        {
            // Create
            PinEnum pinEnum = new PinEnum();

            // Audio
            if (m_Audio != null)
            {
                if (m_Audio.Pin != null)
                {
                    pinEnum.Add(m_Audio.Pin);
                }
            }
            if (m_Video != null)
            {
                if (m_Video.Pin != null)
                {
                    pinEnum.Add(m_Video.Pin);
                }
            }

            // Report
            return(pinEnum);
        }
Esempio n. 10
0
 public SetPinCommand(PinEnum pin, sbyte number, ushort value)
 {
     Pin    = pin;
     Number = number;
     Value  = value;
 }
Esempio n. 11
0
 private static string GetPinNumber(PinEnum pin)
 {
     return(((int)pin).ToString()); //e.g. returns 17 for enum value of gpio17
 }
Esempio n. 12
0
        //no need to setup pin this is done for you
        public bool InputPin(PinEnum pin)
        {
            bool returnValue = false;

            //if we havent used the pin before, or if we used it as an output before, set it up
            if (!_inExported.Contains(pin) || _outExported.Contains(pin)) SetupPin(pin, DirectionEnum.IN);

            string filename = GetFilenameValue(pin);
            if (File.Exists(filename))
            {
                string readValue = File.ReadAllText(filename);
                if (readValue.Length > 0 && readValue[0] == '1') returnValue = true;
            }
            else
                throw new Exception(string.Format("Cannot read from {0}. File does not exist", pin));

            Debug.WriteLine("input from pin " + pin + ", value was " + returnValue);

            return returnValue;
        }
Esempio n. 13
0
 private static string GetPinNumber(PinEnum pin)
 {
     return ((int)pin).ToString(); //e.g. returns 17 for enum value of gpio17
 }
Esempio n. 14
0
        /// <summary>
        /// if for any reason you want to unexport a particular pin use this, otherwise just call CleanUpAllPins when you're done
        /// </summary>
        /// <param name="pin"></param>
        public void UnexportPin(PinEnum pin)
        {
            bool found = false;
            if (_outExported.Contains(pin))
            {
                found = true;
                _outExported.Remove(pin);
            }
            if (_inExported.Contains(pin))
            {
                found = true;
                _inExported.Remove(pin);
            }

            if (found)
            {
                File.WriteAllText(GPIO_PATH + "unexport", GetPinNumber(pin));
                Debug.WriteLine("unexporting  pin " + pin);
            }
        }
Esempio n. 15
0
 private string GetFilenameValue(PinEnum pin)
 {
     string result;
     if (_filenames4Values.TryGetValue((int)pin, out result))
         return result;
     result = GPIO_PATH + pin + "/value";
     _filenames4Values.Add((int)pin,result);
     return result;
 }