Exemplo n.º 1
0
        //this gets called automatically when we try and output to, or input from, a pin
        private void SetupPin(RaspiGpio pin, enumDirection 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));

            if (DEBUG)
            {
                Console.WriteLine("exporting pin " + pin + " as " + direction);
            }

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

            //record the fact that we've setup that pin
            if (direction == enumDirection.OUT)
            {
                outExported.Add(pin);
            }
            else
            {
                inExported.Add(pin);
            }
        }
Exemplo n.º 2
0
        //no need to setup pin this is done for you
        public void OutputPin(RaspiGpio 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, enumDirection.OUT);
            }

            string writeValue = "0";

            if (value)
            {
                writeValue = "1";
            }
            File.WriteAllText(GPIO_PATH + pin.ToString() + "/value", writeValue);

            if (DEBUG)
            {
                Console.WriteLine("output to pin " + pin + ", value was " + value);
            }
        }
Exemplo n.º 3
0
        //this gets called automatically when we try and output to, or input from, a pin
        private void SetupPin(RaspiGpio pin, enumDirection 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));

            if (DEBUG) Console.WriteLine("exporting pin " + pin + " as " + direction);

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

            //record the fact that we've setup that pin
            if (direction == enumDirection.OUT)
                outExported.Add(pin);
            else
                inExported.Add(pin);
        }
Exemplo n.º 4
0
        //no need to setup pin this is done for you
        public void OutputPin(RaspiGpio 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, enumDirection.OUT);

            string writeValue = "0";
            if (value) writeValue = "1";
            File.WriteAllText(GPIO_PATH + pin.ToString() + "/value", writeValue);

            if (DEBUG) Console.WriteLine("output to pin " + pin + ", value was " + value);
        }
Exemplo n.º 5
0
        //no need to setup pin this is done for you
        public bool InputPin(RaspiGpio 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, enumDirection.IN);

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

            if (DEBUG) Console.WriteLine("input from pin " + pin + ", value was " + returnValue);

            return returnValue;
        }