Esempio n. 1
0
        //no need to setup pin this is done for you
        public bool InputPin(enumPIN 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;
        }
Esempio n. 2
0
    //no need to setup pin this is done for you
    public void OutputPin(enumPIN 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);
        }
    }
Esempio n. 3
0
        //no need to setup pin this is done for you
        public void OutputPin(enumPIN 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);
        }
Esempio n. 4
0
        //this gets called automatically when we try and output to, or input from, a pin
        private void SetupPin(enumPIN 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);
        }