Refactor code structure for improved readability and maintainability
This commit is contained in:
54
DaireApplication/Loops/TouchLoop.cs
Normal file
54
DaireApplication/Loops/TouchLoop.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using DaireApplication.Views;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DaireApplication.Loops
|
||||
{
|
||||
public class TouchLoop
|
||||
{
|
||||
static void SetBrightness(int value)
|
||||
{
|
||||
//File.WriteAllText("/sys/class/backlight/backlight/brightness", value.ToString());
|
||||
}
|
||||
public static async void Touch(MainWindow _mainWindow)
|
||||
{
|
||||
static void WatchInput(int bright, MainWindow _mainWindow)
|
||||
{
|
||||
|
||||
string inputDevice = "/dev/input/event1"; // adjust based on your touch device
|
||||
using (FileStream fs = new FileStream(inputDevice, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
byte[] buffer = new byte[24];
|
||||
|
||||
fs.Read(buffer, 0, buffer.Length);
|
||||
_mainWindow.lastActivity = DateTime.Now;
|
||||
SetBrightness(bright); // Restore brightness if touch
|
||||
}
|
||||
}
|
||||
|
||||
var screenData = _mainWindow._screeen.ReadScreens()?[0];
|
||||
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
screenData = _mainWindow._screeen.ReadScreens()?[0];
|
||||
int brightnessValue = (int)((screenData.brightness) / 100.0 * 255);
|
||||
MainWindow.isOff = false;
|
||||
//WatchInput(brightnessValue, _mainWindow);
|
||||
Thread.Sleep(200);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user