Skip to content
This repository has been archived by the owner on Aug 10, 2022. It is now read-only.

Commit

Permalink
Update SWAN
Browse files Browse the repository at this point in the history
  • Loading branch information
geoperez committed Aug 15, 2019
1 parent 9a95746 commit fff5efc
Show file tree
Hide file tree
Showing 28 changed files with 137 additions and 129 deletions.
2 changes: 2 additions & 0 deletions StyleCop.Analyzers.ruleset
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
<Rule Id="CA1063" Action="Warning" />
<Rule Id="CA1065" Action="Warning" />
<Rule Id="CA1301" Action="Warning" />
<Rule Id="CA1302" Action="Hidden" />
<Rule Id="CA1303" Action="Hidden" />
<Rule Id="CA1400" Action="Warning" />
<Rule Id="CA1401" Action="Warning" />
<Rule Id="CA1403" Action="Warning" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace Unosquare.RaspberryIO.Peripherals
{
using Abstractions;
using Swan.Logging;
using System;
using System.Collections.Generic;
using Abstractions;
using Swan;

/// <summary>
/// Read and write different types of Radio-Frequency IDentification (RFID) cards on your
Expand Down
9 changes: 5 additions & 4 deletions src/Unosquare.RaspberryIO.Playground/Extra/Extra.Button.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
namespace Unosquare.RaspberryIO.Playground
namespace Unosquare.RaspberryIO.Playground.Extra
{
using Abstractions;
using System;
using Swan;
using Swan.Logging;
using Abstractions;
using Unosquare.RaspberryIO.Peripherals;

public static partial class Extra
Expand All @@ -16,7 +17,7 @@ public static void TestButton()
var button = new Button(inputPin, GpioPinResistorPullMode.PullUp);

button.Pressed += (s, e) => LogMessageOnEvent("Pressed");
button.Released += (s, e) => LogMessageOnEvent("Realeased");
button.Released += (s, e) => LogMessageOnEvent("Released");

while (true)
{
Expand All @@ -32,7 +33,7 @@ private static void LogMessageOnEvent(string message)
{
Console.Clear();
message.Info();
ExitMessage.WriteLine();
Terminal.WriteLine(ExitMessage);
}
}
}
15 changes: 9 additions & 6 deletions src/Unosquare.RaspberryIO.Playground/Extra/Extra.Led.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
namespace Unosquare.RaspberryIO.Playground
namespace Unosquare.RaspberryIO.Playground.Extra
{
using Abstractions;
using Swan;
using Swan.Logging;
using System;
using System.Threading;
using System.Threading.Tasks;
using Abstractions;
using Swan;
using WiringPi;

public static partial class Extra
Expand Down Expand Up @@ -61,7 +62,7 @@ private static void Blink(CancellationToken cancellationToken) =>
var ledState = isOn ? "on" : "off";
Console.Clear();
$"Blinking {ledState}".Info();
ExitMessage.WriteLine();
Terminal.WriteLine(ExitMessage);
Thread.Sleep(500);
}

Expand All @@ -73,11 +74,13 @@ private static void Dim(CancellationToken cancellationToken) =>
{
Console.Clear();
"Dimming".Info();
ExitMessage.WriteLine();
Terminal.WriteLine(ExitMessage);

var pin = (GpioPin)Pi.Gpio[BcmPin.Gpio13];
pin.PinMode = GpioPinDriveMode.PwmOutput;
pin.PwmMode = PwmMode.Balanced;
pin.PwmClockDivisor = 2;

while (!cancellationToken.IsCancellationRequested)
{
for (var x = 0; x <= 100; x++)
Expand All @@ -97,4 +100,4 @@ private static void Dim(CancellationToken cancellationToken) =>
pin.Write(0);
});
}
}
}
4 changes: 2 additions & 2 deletions src/Unosquare.RaspberryIO.Playground/Extra/Extra.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Unosquare.RaspberryIO.Playground
namespace Unosquare.RaspberryIO.Playground.Extra
{
using System;
using System.Collections.Generic;
Expand All @@ -22,7 +22,7 @@ public static void ShowMenu()
do
{
Console.Clear();
var mainOption = "Extra Examples".ReadPrompt(MainOptions, "Esc to exit this menu");
var mainOption = Terminal.ReadPrompt("Extra Examples", MainOptions, "Esc to exit this menu");

switch (mainOption.Key)
{
Expand Down
15 changes: 6 additions & 9 deletions src/Unosquare.RaspberryIO.Playground/Extra/PiOled.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
namespace Unosquare.RaspberryIO.Playground
namespace Unosquare.RaspberryIO.Playground.Extra
{
using System;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Threading;
using Swan;
using Swan.Abstractions;
using Swan.Logging;
using Swan.Threading;
using Unosquare.RaspberryIO.Peripherals;

internal class PiOled : RunnerBase
{
private OledDisplaySsd1306 _display;
Expand All @@ -20,7 +20,7 @@ internal PiOled(bool isEnabled)
// placeholder
}

protected override void Setup()
protected override void OnSetup()
{
_display = new OledDisplaySsd1306(OledDisplaySsd1306.DisplayModel.Display128X32);
}
Expand Down Expand Up @@ -104,9 +104,6 @@ protected override void DoBackgroundWork(CancellationToken ct)
bitmap.Dispose();
}

protected override void Cleanup()
{
_display.Dispose();
}
protected override void Cleanup() => _display.Dispose();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
namespace Unosquare.RaspberryIO.Playground
namespace Unosquare.RaspberryIO.Playground.Peripherals
{
using System;
using Swan;
using Swan.Logging;
using Unosquare.RaspberryIO.Peripherals;

public static partial class Peripherals
Expand All @@ -26,7 +27,7 @@ public static void TestAccelerometer()
Console.Clear();
$"\nAccelerometer:\n{e.Accel}\n\nGyroscope:\n{e.Gyro}\n\nTemperature: {Math.Round(e.Temperature, 2)}°C\n"
.Info("GY-521");
ExitMessage.WriteLine();
Terminal.WriteLine(ExitMessage);
};

// Run accelerometer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
namespace Unosquare.RaspberryIO.Playground
namespace Unosquare.RaspberryIO.Playground.Peripherals
{
using Abstractions;
using System;
using Swan;
using Swan.Logging;
using Unosquare.RaspberryIO.Abstractions;
using Unosquare.RaspberryIO.Peripherals;

public static partial class Peripherals
Expand Down Expand Up @@ -42,7 +43,7 @@ public static void TestInfraredSensor()
}
}

ExitMessage.WriteLine();
Terminal.WriteLine(ExitMessage);
};

while (true)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
namespace Unosquare.RaspberryIO.Playground
namespace Unosquare.RaspberryIO.Playground.Peripherals
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Swan;
using Swan.Logging;
using Unosquare.RaspberryIO.Peripherals;

public static partial class Peripherals
Expand All @@ -24,7 +25,7 @@ public static void ShowRfidMenu()
do
{
Console.Clear();
var mainOption = "Rfid".ReadPrompt(RfidOptions, "Esc to exit this menu");
var mainOption = Terminal.ReadPrompt("Rfid", RfidOptions, "Esc to exit this menu");

switch (mainOption.Key)
{
Expand Down Expand Up @@ -146,7 +147,7 @@ private static void CardDetected()
// Print UID
$"Card UID: {cardUid[0]},{cardUid[1]},{cardUid[2]},{cardUid[3]}".Info();

ExitMessage.WriteLine();
Terminal.WriteLine(ExitMessage);

while (true)
{
Expand All @@ -166,7 +167,7 @@ private static void WriteCard()
"Testing RFID".Info();

var device = new RFIDControllerMfrc522(Pi.Spi.Channel0, 500000, Pi.Gpio[18]);
var userInput = "Insert a message to be written in the card (16 characters only)".ReadLine().Truncate(16);
var userInput = Terminal.ReadLine("Insert a message to be written in the card (16 characters only)").Truncate(16);
"Place the card on the sensor".Info();

while (true)
Expand Down Expand Up @@ -196,7 +197,8 @@ private static void WriteCard()
device.ClearCardSelection();
"Data has been written".Info();

ExitMessage.WriteLine();
Terminal.WriteLine(ExitMessage);

while (true)
{
var input = Console.ReadKey(true).Key;
Expand Down Expand Up @@ -248,7 +250,8 @@ private static void ReadCard()
}

device.ClearCardSelection();
ExitMessage.WriteLine();
Terminal.WriteLine(ExitMessage);

while (true)
{
var input = Console.ReadKey(true).Key;
Expand Down Expand Up @@ -315,7 +318,8 @@ private static void ReadAllCardSectors()

device.ClearCardSelection();

ExitMessage.WriteLine();
Terminal.WriteLine(ExitMessage);

while (true)
{
var input = Console.ReadKey(true).Key;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
namespace Unosquare.RaspberryIO.Playground
namespace Unosquare.RaspberryIO.Playground.Peripherals
{
using Abstractions;
using System;
using Swan;
using Swan.Logging;
using Unosquare.RaspberryIO.Abstractions;
using Unosquare.RaspberryIO.Peripherals;

public static partial class Peripherals
Expand All @@ -13,6 +14,7 @@ public static partial class Peripherals
public static void TestTempSensor()
{
Console.Clear();

using (var sensor = DhtSensor.Create(DhtType.Dht11, Pi.Gpio[BcmPin.Gpio04]))
{
var totalReadings = 0.0;
Expand All @@ -26,7 +28,7 @@ public static void TestTempSensor()
Console.Clear();
validReadings++;
$"Temperature: \n {e.Temperature:0.00}°C \n {e.TemperatureFahrenheit:0.00}°F \n Humidity: {e.HumidityPercentage:P0}\n\n".Info("DHT11");
ExitMessage.WriteLine();
Terminal.WriteLine(ExitMessage);
};

sensor.Start();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
namespace Unosquare.RaspberryIO.Playground
namespace Unosquare.RaspberryIO.Playground.Peripherals
{
using Abstractions;
using System;
using Abstractions;
using Swan;
using Swan.Logging;
using Unosquare.RaspberryIO.Peripherals;

public static partial class Peripherals
Expand Down Expand Up @@ -35,17 +36,18 @@ public static void TestUltrasonicSensor()
color = ConsoleColor.White;

var distance = e.Distance < 57 ? e.Distance : 58;
$"{new string('█', (int)distance)}".WriteLine(color);
"--------------------------------------------------------->".WriteLine();
" 10 20 30 40 50 cm".WriteLine();
$"Obstacle detected at {e.Distance:N2}cm / {e.DistanceInch:N2}in\n".WriteLine();

Terminal.WriteLine($"{new string('█', (int)distance)}", color);
Terminal.WriteLine("--------------------------------------------------------->");
Terminal.WriteLine(" 10 20 30 40 50 cm");
Terminal.WriteLine($"Obstacle detected at {e.Distance:N2}cm / {e.DistanceInch:N2}in\n");
}
else
{
"No obstacles detected.\n".Info("HC - SR04");
}

ExitMessage.WriteLine();
Terminal.WriteLine(ExitMessage);
};

sensor.Start();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Unosquare.RaspberryIO.Playground
namespace Unosquare.RaspberryIO.Playground.Peripherals
{
using System;
using System.Collections.Generic;
Expand All @@ -24,7 +24,7 @@ public static void ShowMenu()
do
{
Console.Clear();
var mainOption = "Peripherals".ReadPrompt(MainOptions, "Esc to exit this menu");
var mainOption = Terminal.ReadPrompt("Peripherals", MainOptions, "Esc to exit this menu");

switch (mainOption.Key)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#if NET461
namespace Unosquare.RaspberryIO.Playground
namespace Unosquare.RaspberryIO.Playground.Peripherals
{
using Swan;
using Swan.Formatters;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using Swan;
using Swan.Formatters;
using Swan.Logging;
using Unosquare.RaspberryIO.Peripherals;

public static partial class Peripherals
Expand All @@ -22,7 +23,7 @@ public static void TestLedStripGraphics()
try
{
using (var bitmap =
new System.Drawing.Bitmap(Path.Combine(Runtime.EntryAssemblyDirectory, "fractal.jpg")))
new System.Drawing.Bitmap(Path.Combine(SwanRuntime.EntryAssemblyDirectory, "fractal.jpg")))
{
$"Loaded bitmap with format {bitmap.PixelFormat}".Info();
pixels = new BitmapBuffer(bitmap);
Expand All @@ -42,7 +43,7 @@ public static void TestLedStripGraphics()
var thread = new Thread(() =>
{
var strip = new LedStripAPA102C(60 * 4, 1, 1000000); // 1 Mhz is sufficient for such a short strip (only 240 LEDs)
var millisecondsPerFrame = 1000 / 25;
const int millisecondsPerFrame = 1000 / 25;
var lastRenderTime = DateTime.UtcNow;
var currentFrameNumber = 0;

Expand Down Expand Up @@ -79,7 +80,7 @@ public static void TestLedStripGraphics()
if (delayMilliseconds > 0 && exitAnimation == false)
Thread.Sleep(delayMilliseconds);
else
$"Lagging framerate: {delayMilliseconds} milliseconds".Info();
$"Lagging frame rate: {delayMilliseconds} milliseconds".Info();

frameTimes.Enqueue((int)DateTime.UtcNow.Subtract(lastRenderTime).TotalMilliseconds);
lastRenderTime = DateTime.UtcNow;
Expand Down Expand Up @@ -121,7 +122,7 @@ public static void TestLedStrip()
var thread = new Thread(() =>
{
var strip = new LedStripAPA102C(60 * 4);
var millisecondsPerFrame = 1000 / 25;
const int millisecondsPerFrame = 1000 / 25;
var lastRenderTime = DateTime.UtcNow;

var tailSize = strip.LedCount;
Expand Down
Loading

0 comments on commit fff5efc

Please sign in to comment.