67 lines
2.2 KiB
C#
67 lines
2.2 KiB
C#
using Unosquare.Swan.Abstractions;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using System;
|
|
|
|
namespace Unosquare.RaspberryIO.Computer {
|
|
/// <summary>
|
|
/// The Official Raspberry Pi 7-inch touch display from the foundation
|
|
/// Some docs available here:
|
|
/// http://forums.pimoroni.com/t/official-7-raspberry-pi-touch-screen-faq/959
|
|
/// </summary>
|
|
public class DsiDisplay : SingletonBase<DsiDisplay> {
|
|
private const String BacklightFilename = "/sys/class/backlight/rpi_backlight/bl_power";
|
|
private const String BrightnessFilename = "/sys/class/backlight/rpi_backlight/brightness";
|
|
|
|
/// <summary>
|
|
/// Prevents a default instance of the <see cref="DsiDisplay"/> class from being created.
|
|
/// </summary>
|
|
private DsiDisplay() {
|
|
// placeholder
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets a value indicating whether the Pi Foundation Display files are present.
|
|
/// </summary>
|
|
/// <value>
|
|
/// <c>true</c> if this instance is present; otherwise, <c>false</c>.
|
|
/// </value>
|
|
public Boolean IsPresent => File.Exists(BrightnessFilename);
|
|
|
|
/// <summary>
|
|
/// Gets or sets the brightness of the DSI display via filesystem.
|
|
/// </summary>
|
|
/// <value>
|
|
/// The brightness.
|
|
/// </value>
|
|
public Byte Brightness {
|
|
get => this.IsPresent == false ? (Byte)0 : Byte.TryParse(File.ReadAllText(BrightnessFilename).Trim(), out Byte brightness) ? brightness : (Byte)0;
|
|
set {
|
|
if(this.IsPresent == false) {
|
|
return;
|
|
}
|
|
|
|
File.WriteAllText(BrightnessFilename, value.ToString(CultureInfo.InvariantCulture));
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets or sets a value indicating whether the backlight of the DSI display on.
|
|
/// This operation is performed via the file system
|
|
/// </summary>
|
|
/// <value>
|
|
/// <c>true</c> if this instance is backlight on; otherwise, <c>false</c>.
|
|
/// </value>
|
|
public Boolean IsBacklightOn {
|
|
get => this.IsPresent == false ? false : Int32.TryParse(File.ReadAllText(BacklightFilename).Trim(), out Int32 backlight) ? backlight == 0 : false;
|
|
set {
|
|
if(this.IsPresent == false) {
|
|
return;
|
|
}
|
|
|
|
File.WriteAllText(BacklightFilename, value ? "0" : "1");
|
|
}
|
|
}
|
|
}
|
|
}
|