From fff5efc0bcb9592adeba5f3e4a522f743df4b7dc Mon Sep 17 00:00:00 2001
From: Geo Perez <1775792+geoperez@users.noreply.github.com>
Date: Wed, 14 Aug 2019 21:49:27 -0500
Subject: [PATCH] Update SWAN
---
StyleCop.Analyzers.ruleset | 2 ++
.../Rfid/RFIDControllerMfrc522.cs | 4 +--
.../Extra/Extra.Button.cs | 9 +++---
.../Extra/Extra.Led.cs | 15 ++++++----
.../Extra/Extra.cs | 4 +--
.../Extra/PiOled.cs | 15 ++++------
.../Peripherals/Peripherals.Accelerometer.cs | 5 ++--
.../Peripherals/Peripherals.IR.cs | 7 +++--
.../Peripherals/Peripherals.Rfid.cs | 18 ++++++-----
.../Peripherals/Peripherals.TempHum.cs | 8 +++--
.../Peripherals/Peripherals.Ultrasonic.cs | 16 +++++-----
.../Peripherals/Peripherals.cs | 4 +--
.../Peripherals/Program.LedStrip.cs | 15 +++++-----
.../Program.cs | 10 +++----
.../System/System.Info.cs | 6 ++--
.../System/SystemCamera.cs | 18 +++++------
.../System/SystemDisplay.cs | 5 ++--
.../System/SystemTests.cs | 2 +-
.../System/SystemVolume.cs | 19 ++++++------
.../Unosquare.RaspberryIO.Playground.csproj | 2 +-
.../Camera/CameraController.cs | 9 +++---
.../Computer/AudioSettings.cs | 3 +-
.../Computer/Bluetooth.cs | 3 +-
.../Computer/DsiDisplay.cs | 30 ++++++++-----------
.../Computer/NetworkSettings.cs | 4 +--
.../Computer/SystemInfo.cs | 24 +++++++--------
src/Unosquare.RaspberryIO/Pi.cs | 7 +++--
.../Unosquare.RaspberryIO.csproj | 2 +-
28 files changed, 137 insertions(+), 129 deletions(-)
diff --git a/StyleCop.Analyzers.ruleset b/StyleCop.Analyzers.ruleset
index d35b16a..593cbf0 100644
--- a/StyleCop.Analyzers.ruleset
+++ b/StyleCop.Analyzers.ruleset
@@ -14,6 +14,8 @@
+
+
diff --git a/src/Unosquare.RaspberryIO.Peripherals/Rfid/RFIDControllerMfrc522.cs b/src/Unosquare.RaspberryIO.Peripherals/Rfid/RFIDControllerMfrc522.cs
index a5cef58..a3a219e 100644
--- a/src/Unosquare.RaspberryIO.Peripherals/Rfid/RFIDControllerMfrc522.cs
+++ b/src/Unosquare.RaspberryIO.Peripherals/Rfid/RFIDControllerMfrc522.cs
@@ -1,9 +1,9 @@
namespace Unosquare.RaspberryIO.Peripherals
{
+ using Abstractions;
+ using Swan.Logging;
using System;
using System.Collections.Generic;
- using Abstractions;
- using Swan;
///
/// Read and write different types of Radio-Frequency IDentification (RFID) cards on your
diff --git a/src/Unosquare.RaspberryIO.Playground/Extra/Extra.Button.cs b/src/Unosquare.RaspberryIO.Playground/Extra/Extra.Button.cs
index a8270c9..b2a7679 100644
--- a/src/Unosquare.RaspberryIO.Playground/Extra/Extra.Button.cs
+++ b/src/Unosquare.RaspberryIO.Playground/Extra/Extra.Button.cs
@@ -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
@@ -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)
{
@@ -32,7 +33,7 @@ private static void LogMessageOnEvent(string message)
{
Console.Clear();
message.Info();
- ExitMessage.WriteLine();
+ Terminal.WriteLine(ExitMessage);
}
}
}
diff --git a/src/Unosquare.RaspberryIO.Playground/Extra/Extra.Led.cs b/src/Unosquare.RaspberryIO.Playground/Extra/Extra.Led.cs
index 31ef0d8..c0e0824 100644
--- a/src/Unosquare.RaspberryIO.Playground/Extra/Extra.Led.cs
+++ b/src/Unosquare.RaspberryIO.Playground/Extra/Extra.Led.cs
@@ -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
@@ -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);
}
@@ -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++)
@@ -97,4 +100,4 @@ private static void Dim(CancellationToken cancellationToken) =>
pin.Write(0);
});
}
-}
+}
\ No newline at end of file
diff --git a/src/Unosquare.RaspberryIO.Playground/Extra/Extra.cs b/src/Unosquare.RaspberryIO.Playground/Extra/Extra.cs
index 5e56372..61172ff 100644
--- a/src/Unosquare.RaspberryIO.Playground/Extra/Extra.cs
+++ b/src/Unosquare.RaspberryIO.Playground/Extra/Extra.cs
@@ -1,4 +1,4 @@
-namespace Unosquare.RaspberryIO.Playground
+namespace Unosquare.RaspberryIO.Playground.Extra
{
using System;
using System.Collections.Generic;
@@ -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)
{
diff --git a/src/Unosquare.RaspberryIO.Playground/Extra/PiOled.cs b/src/Unosquare.RaspberryIO.Playground/Extra/PiOled.cs
index c1f8a2d..9051825 100644
--- a/src/Unosquare.RaspberryIO.Playground/Extra/PiOled.cs
+++ b/src/Unosquare.RaspberryIO.Playground/Extra/PiOled.cs
@@ -1,4 +1,4 @@
-namespace Unosquare.RaspberryIO.Playground
+namespace Unosquare.RaspberryIO.Playground.Extra
{
using System;
using System.Diagnostics;
@@ -6,10 +6,10 @@
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;
@@ -20,7 +20,7 @@ internal PiOled(bool isEnabled)
// placeholder
}
- protected override void Setup()
+ protected override void OnSetup()
{
_display = new OledDisplaySsd1306(OledDisplaySsd1306.DisplayModel.Display128X32);
}
@@ -104,9 +104,6 @@ protected override void DoBackgroundWork(CancellationToken ct)
bitmap.Dispose();
}
- protected override void Cleanup()
- {
- _display.Dispose();
- }
+ protected override void Cleanup() => _display.Dispose();
}
}
diff --git a/src/Unosquare.RaspberryIO.Playground/Peripherals/Peripherals.Accelerometer.cs b/src/Unosquare.RaspberryIO.Playground/Peripherals/Peripherals.Accelerometer.cs
index a8038e9..f23f5c5 100644
--- a/src/Unosquare.RaspberryIO.Playground/Peripherals/Peripherals.Accelerometer.cs
+++ b/src/Unosquare.RaspberryIO.Playground/Peripherals/Peripherals.Accelerometer.cs
@@ -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
@@ -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
diff --git a/src/Unosquare.RaspberryIO.Playground/Peripherals/Peripherals.IR.cs b/src/Unosquare.RaspberryIO.Playground/Peripherals/Peripherals.IR.cs
index d491e8b..17a1bcd 100644
--- a/src/Unosquare.RaspberryIO.Playground/Peripherals/Peripherals.IR.cs
+++ b/src/Unosquare.RaspberryIO.Playground/Peripherals/Peripherals.IR.cs
@@ -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
@@ -42,7 +43,7 @@ public static void TestInfraredSensor()
}
}
- ExitMessage.WriteLine();
+ Terminal.WriteLine(ExitMessage);
};
while (true)
diff --git a/src/Unosquare.RaspberryIO.Playground/Peripherals/Peripherals.Rfid.cs b/src/Unosquare.RaspberryIO.Playground/Peripherals/Peripherals.Rfid.cs
index 00bab17..ba91514 100644
--- a/src/Unosquare.RaspberryIO.Playground/Peripherals/Peripherals.Rfid.cs
+++ b/src/Unosquare.RaspberryIO.Playground/Peripherals/Peripherals.Rfid.cs
@@ -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
@@ -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)
{
@@ -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)
{
@@ -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)
@@ -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;
@@ -248,7 +250,8 @@ private static void ReadCard()
}
device.ClearCardSelection();
- ExitMessage.WriteLine();
+ Terminal.WriteLine(ExitMessage);
+
while (true)
{
var input = Console.ReadKey(true).Key;
@@ -315,7 +318,8 @@ private static void ReadAllCardSectors()
device.ClearCardSelection();
- ExitMessage.WriteLine();
+ Terminal.WriteLine(ExitMessage);
+
while (true)
{
var input = Console.ReadKey(true).Key;
diff --git a/src/Unosquare.RaspberryIO.Playground/Peripherals/Peripherals.TempHum.cs b/src/Unosquare.RaspberryIO.Playground/Peripherals/Peripherals.TempHum.cs
index e536433..d626e31 100644
--- a/src/Unosquare.RaspberryIO.Playground/Peripherals/Peripherals.TempHum.cs
+++ b/src/Unosquare.RaspberryIO.Playground/Peripherals/Peripherals.TempHum.cs
@@ -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
@@ -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;
@@ -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();
diff --git a/src/Unosquare.RaspberryIO.Playground/Peripherals/Peripherals.Ultrasonic.cs b/src/Unosquare.RaspberryIO.Playground/Peripherals/Peripherals.Ultrasonic.cs
index 0aa4a18..5f327fa 100644
--- a/src/Unosquare.RaspberryIO.Playground/Peripherals/Peripherals.Ultrasonic.cs
+++ b/src/Unosquare.RaspberryIO.Playground/Peripherals/Peripherals.Ultrasonic.cs
@@ -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
@@ -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();
diff --git a/src/Unosquare.RaspberryIO.Playground/Peripherals/Peripherals.cs b/src/Unosquare.RaspberryIO.Playground/Peripherals/Peripherals.cs
index 0dc1114..14f7b83 100644
--- a/src/Unosquare.RaspberryIO.Playground/Peripherals/Peripherals.cs
+++ b/src/Unosquare.RaspberryIO.Playground/Peripherals/Peripherals.cs
@@ -1,4 +1,4 @@
-namespace Unosquare.RaspberryIO.Playground
+namespace Unosquare.RaspberryIO.Playground.Peripherals
{
using System;
using System.Collections.Generic;
@@ -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)
{
diff --git a/src/Unosquare.RaspberryIO.Playground/Peripherals/Program.LedStrip.cs b/src/Unosquare.RaspberryIO.Playground/Peripherals/Program.LedStrip.cs
index 8bd97d5..d4b0193 100644
--- a/src/Unosquare.RaspberryIO.Playground/Peripherals/Program.LedStrip.cs
+++ b/src/Unosquare.RaspberryIO.Playground/Peripherals/Program.LedStrip.cs
@@ -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
@@ -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);
@@ -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;
@@ -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;
@@ -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;
diff --git a/src/Unosquare.RaspberryIO.Playground/Program.cs b/src/Unosquare.RaspberryIO.Playground/Program.cs
index cd30c67..9fcd510 100644
--- a/src/Unosquare.RaspberryIO.Playground/Program.cs
+++ b/src/Unosquare.RaspberryIO.Playground/Program.cs
@@ -1,9 +1,10 @@
namespace Unosquare.RaspberryIO.Playground
{
- using Swan;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
+ using Swan;
+ using Swan.Logging;
using WiringPi;
///
@@ -27,14 +28,13 @@ public static async Task Main()
{
$"Starting program at {DateTime.Now}".Info();
- Terminal.Settings.DisplayLoggingMessageType = LogMessageType.Info | LogMessageType.Warning | LogMessageType.Error;
Pi.Init();
var exit = false;
do
{
Console.Clear();
- var mainOption = "Main options".ReadPrompt(MainOptions, "Esc to exit this program");
+ var mainOption = Terminal.ReadPrompt("Main options", MainOptions, "Esc to exit this program");
switch (mainOption.Key)
{
@@ -42,10 +42,10 @@ public static async Task Main()
await SystemTests.ShowMenu().ConfigureAwait(false);
break;
case ConsoleKey.P:
- Peripherals.ShowMenu();
+ Peripherals.Peripherals.ShowMenu();
break;
case ConsoleKey.X:
- Extra.ShowMenu();
+ Extra.Extra.ShowMenu();
break;
case ConsoleKey.Escape:
exit = true;
diff --git a/src/Unosquare.RaspberryIO.Playground/System/System.Info.cs b/src/Unosquare.RaspberryIO.Playground/System/System.Info.cs
index 1834a46..eb8fbf7 100644
--- a/src/Unosquare.RaspberryIO.Playground/System/System.Info.cs
+++ b/src/Unosquare.RaspberryIO.Playground/System/System.Info.cs
@@ -1,10 +1,11 @@
namespace Unosquare.RaspberryIO.Playground
{
using Computer;
+ using Swan;
+ using Swan.Logging;
using System;
using System.Linq;
using System.Threading.Tasks;
- using Swan;
public static partial class SystemTests
{
@@ -14,6 +15,7 @@ private static async Task TestSystemInfo()
$"GPIO Controller initialized successfully with {Pi.Gpio.Count} pins".Info();
$"{Pi.Info}".Info();
+
try
{
$"BoardModel {Pi.Info.BoardModel}".Info();
@@ -38,7 +40,7 @@ private static async Task TestSystemInfo()
.ToList()
.ForEach(x => x.Info());
- ExitMessage.WriteLine();
+ Terminal.WriteLine(ExitMessage);
while (true)
{
diff --git a/src/Unosquare.RaspberryIO.Playground/System/SystemCamera.cs b/src/Unosquare.RaspberryIO.Playground/System/SystemCamera.cs
index beac734..1a99b53 100644
--- a/src/Unosquare.RaspberryIO.Playground/System/SystemCamera.cs
+++ b/src/Unosquare.RaspberryIO.Playground/System/SystemCamera.cs
@@ -1,11 +1,12 @@
namespace Unosquare.RaspberryIO.Playground
{
using Camera;
+ using Swan;
+ using Swan.Logging;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
- using Swan;
public static class SystemCamera
{
@@ -23,7 +24,7 @@ public static void ShowMenu()
do
{
Console.Clear();
- var mainOption = "System".ReadPrompt(MainOptions, "Esc to exit this menu");
+ var mainOption = Terminal.ReadPrompt("System", MainOptions, "Esc to exit this menu");
switch (mainOption.Key)
{
@@ -42,9 +43,9 @@ private static void CaptureImage()
{
Console.Clear();
- var imageWidth = "Set the image width:".ReadNumber(640);
- var imageHeight = "Set the image height:".ReadNumber(480);
- var fileName = "Set the file name:".ReadLine();
+ var imageWidth = Terminal.ReadNumber("Set the image width:", 640);
+ var imageHeight = Terminal.ReadNumber("Set the image height:", 480);
+ var fileName = Terminal.ReadLine("Set the file name:");
Console.Clear();
@@ -58,7 +59,7 @@ private static void CaptureImage()
$"Date Created: {DateTime.Now:MM/dd/yyyy}".Info();
$"At {DefaultPicturePath}\n".Info();
- "Press Esc key to continue . . .".WriteLine();
+ Terminal.WriteLine("Press Esc key to continue . . .");
while (true)
{
@@ -101,12 +102,11 @@ private static void CaptureVideo()
Pi.Camera.OpenVideoStream(
videoSettings,
- onDataCallback: data =>
+ data =>
{
videoByteCount += data.Length;
videoEventCount++;
- },
- onExitCallback: null);
+ });
Console.ForegroundColor = ConsoleColor.Red;
Console.Write($" {(char)0x25CF} ");
diff --git a/src/Unosquare.RaspberryIO.Playground/System/SystemDisplay.cs b/src/Unosquare.RaspberryIO.Playground/System/SystemDisplay.cs
index de43dee..d4a1e29 100644
--- a/src/Unosquare.RaspberryIO.Playground/System/SystemDisplay.cs
+++ b/src/Unosquare.RaspberryIO.Playground/System/SystemDisplay.cs
@@ -1,6 +1,6 @@
namespace Unosquare.RaspberryIO.Playground
{
- using Swan;
+ using Swan.Logging;
using System;
using System.Threading.Tasks;
@@ -9,7 +9,6 @@ public static class SystemDisplay
public static async Task ShowMenu()
{
var exit = false;
- ConsoleKey key;
while (!exit)
{
@@ -18,7 +17,7 @@ public static async Task ShowMenu()
$"Brightness: {Pi.PiDisplay.Brightness}".Info();
$"Blacklight: [{(Pi.PiDisplay.IsBacklightOn ? (char)0x2714 : (char)0x2718)}]\n".Info();
- key = Console.ReadKey(true).Key;
+ var key = Console.ReadKey(true).Key;
switch (key)
{
diff --git a/src/Unosquare.RaspberryIO.Playground/System/SystemTests.cs b/src/Unosquare.RaspberryIO.Playground/System/SystemTests.cs
index 8901376..0ddd7b9 100644
--- a/src/Unosquare.RaspberryIO.Playground/System/SystemTests.cs
+++ b/src/Unosquare.RaspberryIO.Playground/System/SystemTests.cs
@@ -23,7 +23,7 @@ public static async Task ShowMenu()
do
{
Console.Clear();
- var mainOption = "System".ReadPrompt(MainOptions, "Esc to exit this menu");
+ var mainOption = Terminal.ReadPrompt("System", MainOptions, "Esc to exit this menu");
switch (mainOption.Key)
{
diff --git a/src/Unosquare.RaspberryIO.Playground/System/SystemVolume.cs b/src/Unosquare.RaspberryIO.Playground/System/SystemVolume.cs
index 9580a10..7a6eb28 100644
--- a/src/Unosquare.RaspberryIO.Playground/System/SystemVolume.cs
+++ b/src/Unosquare.RaspberryIO.Playground/System/SystemVolume.cs
@@ -1,8 +1,9 @@
namespace Unosquare.RaspberryIO.Playground
{
- using Swan;
using System;
using System.Threading.Tasks;
+ using Swan;
+ using Swan.Logging;
public static class SystemVolume
{
@@ -26,10 +27,10 @@ public static async Task ShowMenu()
UpdateProgress(CurrentLevel);
- "Press UpArrow key to increment volume".WriteLine();
- "Press DownArrow key to decrement volume".WriteLine();
- "Press M key to Mute on/off\n".WriteLine();
- var key = "Press Esc key to continue . . .".ReadKey(true).Key;
+ Terminal.WriteLine("Press UpArrow key to increment volume");
+ Terminal.WriteLine("Press DownArrow key to decrement volume");
+ Terminal.WriteLine("Press M key to Mute on/off\n");
+ var key = Terminal.ReadKey("Press Esc key to continue . . .").Key;
var validOption = false;
while (!validOption)
@@ -64,11 +65,11 @@ public static async Task ShowMenu()
private static void UpdateProgress(int level)
{
var filler = level / 10;
- ConsoleColor color;
- "\r[".Write();
+ Terminal.Write("\r[");
for (var i = 1; i <= 10; ++i)
{
+ ConsoleColor color;
if (i <= filler)
{
if (i < 6)
@@ -83,10 +84,10 @@ private static void UpdateProgress(int level)
color = ConsoleColor.Black;
}
- $"{(char)0x275A}".Write(color);
+ Terminal.Write($"{(char)0x275A}", color);
}
- $"] {level}%\n\n".Write();
+ Terminal.Write($"] {level}%\n\n");
}
}
}
diff --git a/src/Unosquare.RaspberryIO.Playground/Unosquare.RaspberryIO.Playground.csproj b/src/Unosquare.RaspberryIO.Playground/Unosquare.RaspberryIO.Playground.csproj
index 75694d4..219722d 100644
--- a/src/Unosquare.RaspberryIO.Playground/Unosquare.RaspberryIO.Playground.csproj
+++ b/src/Unosquare.RaspberryIO.Playground/Unosquare.RaspberryIO.Playground.csproj
@@ -26,7 +26,7 @@
all
runtime; build; native; contentfiles; analyzers
-
+
diff --git a/src/Unosquare.RaspberryIO/Camera/CameraController.cs b/src/Unosquare.RaspberryIO/Camera/CameraController.cs
index cba238a..2f72903 100644
--- a/src/Unosquare.RaspberryIO/Camera/CameraController.cs
+++ b/src/Unosquare.RaspberryIO/Camera/CameraController.cs
@@ -1,11 +1,10 @@
namespace Unosquare.RaspberryIO.Camera
{
+ using Swan;
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
- using Unosquare.Swan.Abstractions;
- using Swan.Components;
///
/// The Raspberry Pi's camera controller wrapping raspistill and raspivid programs.
@@ -99,7 +98,7 @@ public Task CaptureImageJpegAsync(int width, int height, CancellationTok
CaptureWidth = width,
CaptureHeight = height,
CaptureJpegQuality = 90,
- CaptureTimeoutMilliseconds = 300
+ CaptureTimeoutMilliseconds = 300,
};
return CaptureImageAsync(settings, ct);
@@ -130,7 +129,7 @@ public void OpenVideoStream(Action onDataCallback, Action onExitCallback
CaptureTimeoutMilliseconds = 0,
CaptureDisplayPreview = false,
CaptureWidth = 1920,
- CaptureHeight = 1080
+ CaptureHeight = 1080,
};
OpenVideoStream(settings, onDataCallback, onExitCallback);
@@ -144,7 +143,7 @@ public void OpenVideoStream(Action onDataCallback, Action onExitCallback
/// The on exit callback.
/// Cannot use camera module because it is currently busy.
/// CaptureTimeoutMilliseconds.
- public void OpenVideoStream(CameraVideoSettings settings, Action onDataCallback, Action onExitCallback)
+ public void OpenVideoStream(CameraVideoSettings settings, Action onDataCallback, Action onExitCallback = null)
{
if (Instance.IsBusy)
throw new InvalidOperationException("Cannot use camera module because it is currently busy.");
diff --git a/src/Unosquare.RaspberryIO/Computer/AudioSettings.cs b/src/Unosquare.RaspberryIO/Computer/AudioSettings.cs
index 9607d30..206cd88 100644
--- a/src/Unosquare.RaspberryIO/Computer/AudioSettings.cs
+++ b/src/Unosquare.RaspberryIO/Computer/AudioSettings.cs
@@ -1,10 +1,9 @@
namespace Unosquare.RaspberryIO.Computer
{
+ using Swan;
using System;
using System.Linq;
using System.Threading.Tasks;
- using Swan.Abstractions;
- using Swan.Components;
///
/// Settings for audio device.
diff --git a/src/Unosquare.RaspberryIO/Computer/Bluetooth.cs b/src/Unosquare.RaspberryIO/Computer/Bluetooth.cs
index b51ad69..154f237 100644
--- a/src/Unosquare.RaspberryIO/Computer/Bluetooth.cs
+++ b/src/Unosquare.RaspberryIO/Computer/Bluetooth.cs
@@ -1,12 +1,11 @@
namespace Unosquare.RaspberryIO.Computer
{
- using Swan.Abstractions;
- using Swan.Components;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
+ using Swan;
///
/// Represents the Bluetooth information.
diff --git a/src/Unosquare.RaspberryIO/Computer/DsiDisplay.cs b/src/Unosquare.RaspberryIO/Computer/DsiDisplay.cs
index cda8210..cd49aaf 100644
--- a/src/Unosquare.RaspberryIO/Computer/DsiDisplay.cs
+++ b/src/Unosquare.RaspberryIO/Computer/DsiDisplay.cs
@@ -2,7 +2,7 @@
{
using System.Globalization;
using System.IO;
- using Unosquare.Swan.Abstractions;
+ using Swan;
///
/// The Official Raspberry Pi 7-inch touch display from the foundation
@@ -38,16 +38,14 @@ private DsiDisplay()
///
public byte Brightness
{
- get
- {
- if (IsPresent == false) return 0;
-
- return byte.TryParse(File.ReadAllText(BrightnessFilename).Trim(), out var brightness) ? brightness : (byte)0;
- }
+ get =>
+ IsPresent
+ ? byte.TryParse(File.ReadAllText(BrightnessFilename).Trim(), out var brightness) ? brightness : (byte)0 :
+ (byte)0;
set
{
- if (IsPresent == false) return;
- File.WriteAllText(BrightnessFilename, value.ToString(CultureInfo.InvariantCulture));
+ if (IsPresent)
+ File.WriteAllText(BrightnessFilename, value.ToString(CultureInfo.InvariantCulture));
}
}
@@ -60,17 +58,13 @@ public byte Brightness
///
public bool IsBacklightOn
{
- get
- {
- if (IsPresent == false) return false;
-
- return int.TryParse(File.ReadAllText(BacklightFilename).Trim(), out var value) && value == 0;
- }
+ get =>
+ IsPresent && (int.TryParse(File.ReadAllText(BacklightFilename).Trim(), out var value) &&
+ value == 0);
set
{
- if (IsPresent == false) return;
-
- File.WriteAllText(BacklightFilename, value ? "0" : "1");
+ if (IsPresent)
+ File.WriteAllText(BacklightFilename, value ? "0" : "1");
}
}
}
diff --git a/src/Unosquare.RaspberryIO/Computer/NetworkSettings.cs b/src/Unosquare.RaspberryIO/Computer/NetworkSettings.cs
index 627b525..9d88ff7 100644
--- a/src/Unosquare.RaspberryIO/Computer/NetworkSettings.cs
+++ b/src/Unosquare.RaspberryIO/Computer/NetworkSettings.cs
@@ -1,8 +1,8 @@
namespace Unosquare.RaspberryIO.Computer
{
using Swan;
- using Swan.Abstractions;
- using Swan.Components;
+ using Swan.Logging;
+ using Swan.Net;
using System;
using System.Collections.Generic;
using System.IO;
diff --git a/src/Unosquare.RaspberryIO/Computer/SystemInfo.cs b/src/Unosquare.RaspberryIO/Computer/SystemInfo.cs
index 576c423..8fda3a8 100644
--- a/src/Unosquare.RaspberryIO/Computer/SystemInfo.cs
+++ b/src/Unosquare.RaspberryIO/Computer/SystemInfo.cs
@@ -1,19 +1,19 @@
namespace Unosquare.RaspberryIO.Computer
{
- using Abstractions;
- using Native;
- using Swan.Components;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
- using Unosquare.Swan.Abstractions;
+ using Abstractions;
+ using Native;
+ using Swan;
+ using Swan.DependencyInjection;
///
/// Retrieves the RaspberryPI System Information.
- ///
+ ///
/// http://raspberry-pi-guide.readthedocs.io/en/latest/system.html.
///
public sealed class SystemInfo : SingletonBase
@@ -301,7 +301,7 @@ public override string ToString()
return string.Join(Environment.NewLine, propertyValues2.ToArray());
}
-
+
private void ExtractOS()
{
try
@@ -339,21 +339,21 @@ private void ExtractBoardVersion()
{
RaspberryPiVersion = PiVersion.Unknown;
if (Enum.IsDefined(typeof(PiVersion), boardVersion))
- RaspberryPiVersion = (PiVersion) boardVersion;
+ RaspberryPiVersion = (PiVersion)boardVersion;
if ((boardVersion & NewStyleCodesMask) == NewStyleCodesMask)
{
NewStyleRevisionCodes = true;
RevisionNumber = boardVersion & 0xF;
- _boardModel = (BoardModel) ((boardVersion >> 4) & 0xFF);
- _processorModel = (ProcessorModel) ((boardVersion >> 12) & 0xF);
- _manufacturer = (Manufacturer) ((boardVersion >> 16) & 0xF);
- _memorySize = (MemorySize) ((boardVersion >> 20) & 0x7);
+ _boardModel = (BoardModel)((boardVersion >> 4) & 0xFF);
+ _processorModel = (ProcessorModel)((boardVersion >> 12) & 0xF);
+ _manufacturer = (Manufacturer)((boardVersion >> 16) & 0xF);
+ _memorySize = (MemorySize)((boardVersion >> 20) & 0x7);
}
}
if (hasSysInfo)
- BoardRevision = (int) DependencyContainer.Current.Resolve().BoardRevision;
+ BoardRevision = (int)DependencyContainer.Current.Resolve().BoardRevision;
}
catch
{
diff --git a/src/Unosquare.RaspberryIO/Pi.cs b/src/Unosquare.RaspberryIO/Pi.cs
index 160da3d..da26d36 100644
--- a/src/Unosquare.RaspberryIO/Pi.cs
+++ b/src/Unosquare.RaspberryIO/Pi.cs
@@ -1,11 +1,12 @@
namespace Unosquare.RaspberryIO
{
- using System;
- using System.Threading.Tasks;
using Abstractions;
using Camera;
using Computer;
- using Swan.Components;
+ using Swan;
+ using Swan.DependencyInjection;
+ using System;
+ using System.Threading.Tasks;
///
/// Our main character. Provides access to the Raspberry Pi's GPIO, system and board information and Camera.
diff --git a/src/Unosquare.RaspberryIO/Unosquare.RaspberryIO.csproj b/src/Unosquare.RaspberryIO/Unosquare.RaspberryIO.csproj
index 60321df..a41a373 100644
--- a/src/Unosquare.RaspberryIO/Unosquare.RaspberryIO.csproj
+++ b/src/Unosquare.RaspberryIO/Unosquare.RaspberryIO.csproj
@@ -29,7 +29,7 @@ This library enables developers to use the various Raspberry Pi's hardware modul
all
runtime; build; native; contentfiles; analyzers
-
+