using Unosquare.RaspberryIO.Camera; using Unosquare.RaspberryIO.Computer; using Unosquare.RaspberryIO.Gpio; using Unosquare.RaspberryIO.Native; using System.Threading.Tasks; using Unosquare.Swan.Components; using System; namespace Unosquare.RaspberryIO { /// /// Our main character. Provides access to the Raspberry Pi's GPIO, system and board information and Camera /// public static class Pi { private static readonly Object SyncLock = new Object(); /// /// Initializes static members of the class. /// static Pi() { lock(SyncLock) { // Extraction of embedded resources Resources.EmbeddedResources.ExtractAll(); // Instance assignments Gpio = GpioController.Instance; Info = SystemInfo.Instance; Timing = Timing.Instance; Spi = SpiBus.Instance; I2C = I2CBus.Instance; Camera = CameraController.Instance; PiDisplay = DsiDisplay.Instance; } } #region Components /// /// Provides access to the Raspberry Pi's GPIO as a collection of GPIO Pins. /// public static GpioController Gpio { get; } /// /// Provides information on this Raspberry Pi's CPU and form factor. /// public static SystemInfo Info { get; } /// /// Provides access to The PI's Timing and threading API /// public static Timing Timing { get; } /// /// Provides access to the 2-channel SPI bus /// public static SpiBus Spi { get; } /// /// Provides access to the functionality of the i2c bus. /// public static I2CBus I2C { get; } /// /// Provides access to the official Raspberry Pi Camera /// public static CameraController Camera { get; } /// /// Provides access to the official Raspberry Pi 7-inch DSI Display /// public static DsiDisplay PiDisplay { get; } /// /// Gets the logger source name. /// internal static String LoggerSource => typeof(Pi).Namespace; #endregion #region Methods /// /// Restarts the Pi. Must be running as SU /// /// The process result public static async Task RestartAsync() => await ProcessRunner.GetProcessResultAsync("reboot", null, null); /// /// Restarts the Pi. Must be running as SU /// /// The process result public static ProcessResult Restart() => RestartAsync().GetAwaiter().GetResult(); /// /// Halts the Pi. Must be running as SU /// /// The process result public static async Task ShutdownAsync() => await ProcessRunner.GetProcessResultAsync("halt", null, null); /// /// Halts the Pi. Must be running as SU /// /// The process result public static ProcessResult Shutdown() => ShutdownAsync().GetAwaiter().GetResult(); #endregion } }