Commit 58d1b85e authored by Akinwale Ariwodola's avatar Akinwale Ariwodola
Browse files

Updated GPIO class to return Value? for the Read method.

parent b3489c96
......@@ -122,9 +122,9 @@ namespace Nanite.IO
}
}
public static int Read(int pin)
public static Value? Read(int pin)
{
int value = -1;
int pinValue = -1;
try
{
......@@ -132,7 +132,7 @@ namespace Nanite.IO
using (StreamReader reader = new StreamReader(new FileStream(
Path.Combine(pinPath, GPIOValue), FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))
{
int.TryParse(reader.ReadToEnd(), out value);
int.TryParse(reader.ReadToEnd(), out pinValue);
}
}
catch (IOException ex)
......@@ -140,7 +140,12 @@ namespace Nanite.IO
throw new GPIOException("Unable to read the pin value.", ex);
}
return value;
if (pinValue != 0 && pinValue != 1)
{
return null;
}
return (Value) pinValue;
}
}
}
......@@ -21,13 +21,15 @@ using Nanite.Exceptions;
namespace NaniteIoSample
{
class MainClass
class Program
{
public static void Main (string[] args)
{
/*// Simple GPIO
// Simple GPIO
GPIO.PinMode(18, GPIO.Direction.Output);
for (int i = 0; i < 10; i++)
// This will blink a LED connected to pin 18 50 times
for (int i = 0; i < 50; i++)
{
GPIO.Write(18, GPIO.Value.High);
Thread.Sleep(200);
......@@ -36,7 +38,10 @@ namespace NaniteIoSample
Thread.Sleep(200);
}
// Extended IO via I2C
// Close the pin after we're done
GPIO.ClosePin(18);
/*// Extended IO via I2C
using (I2CExtendedIO eio = new I2CExtendedIO())
{
try
......@@ -59,20 +64,6 @@ namespace NaniteIoSample
}
}*/
using (I2CExtendedIO eio = new I2CExtendedIO())
{
try
{
eio.Open(0x08);
int pinValue = eio.DigitalRead(12);
//eio.DigitalWrite(12, GPIO.Value.High);
//eio.DigitalWrite(13, GPIO.Value.High);
}
catch (ExtendedIOException ex)
{
Console.WriteLine(ex.ToString());
}
}
Console.ReadLine();
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment