Skip to content

Commit

Permalink
Merge pull request #13 from David032/12-refactor-file-structure---gen…
Browse files Browse the repository at this point in the history
…erated-f

12 Refactor file structure - Generated files
  • Loading branch information
David032 authored Nov 14, 2023
2 parents 6d9818d + 1dc8604 commit e2d3b69
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -366,3 +366,5 @@ ServoSkullDemo/Builds
skullOS/skullOs/

skullOS/skullOSselfContained/

skullOS/builds/
13 changes: 7 additions & 6 deletions skullOS.Camera/Camera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,19 @@ public override void Run(GpioController controller)

public override bool Setup(GpioController controller, I2cDevice i2CDevice)
{
var settings = SettingsLoader.LoadConfig(@"Data/Settings.txt");
var defaultValue = new KeyValuePair<string, string>("", "");
FileManager.CreateSubDirectory("Captures");
Dictionary<string, string> settings = SettingsLoader.LoadConfig(@"Data/Settings.txt");
KeyValuePair<string, string> defaultValue = new("", "");

var cameraMode = settings
KeyValuePair<string, string> cameraMode = settings
.Select(x => x)
.Where(x => x.Key == "Mode")
.FirstOrDefault(defaultValue);
var pinToActOn = settings
KeyValuePair<string, string> pinToActOn = settings
.Select(x => x)
.Where(x => x.Key == "Pin")
.FirstOrDefault(defaultValue);
var ledPin = settings
KeyValuePair<string, string> ledPin = settings
.Select(x => x)
.Where(x => x.Key == "LedPin")
.FirstOrDefault(defaultValue);
Expand Down Expand Up @@ -66,7 +67,7 @@ public override bool Setup(GpioController controller, I2cDevice i2CDevice)
private void TakePicture(object? sender, EventArgs e)
{
Console.WriteLine($"({DateTime.Now}) Picture taken!");
device.Capture($"{DateTime.Now:yyyyMMddHHmmss}.jpg");
device.Capture($"{FileManager.GetSkullDirectory()}/Captures/{DateTime.Now:yyyyMMddHHmmss}.jpg");
}

public override void Stop()
Expand Down
35 changes: 35 additions & 0 deletions skullOS.Core/FileManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
namespace skullOS.Core
{
public static class FileManager
{
private static string rootDirectoryPath = string.Empty;

public static void CreateSkullDirectory()
{
DirectoryInfo rootDirectory = null;

Check warning on line 9 in skullOS.Core/FileManager.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Converting null literal or possible null value to non-nullable type.
string pathToPersonalDir = @Environment.GetFolderPath(Environment.SpecialFolder.Personal);
try
{
rootDirectory = Directory.CreateDirectory(@pathToPersonalDir + @"/skullOS", unixCreateMode: UnixFileMode.UserRead | UnixFileMode.UserWrite | UnixFileMode.UserExecute);

Check warning on line 13 in skullOS.Core/FileManager.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

This call site is reachable on all platforms. 'Directory.CreateDirectory(string, UnixFileMode)' is unsupported on: 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
rootDirectoryPath = rootDirectory.FullName;

Check warning on line 19 in skullOS.Core/FileManager.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Dereference of a possibly null reference.
}

public static string GetSkullDirectory()
{
return rootDirectoryPath;
}

public static void CreateSubDirectory(string directoryName)
{
if (rootDirectoryPath != string.Empty)
{
Directory.CreateDirectory(@rootDirectoryPath + "/" + directoryName);
}
}
}
}
7 changes: 6 additions & 1 deletion skullOS/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Iot.Device.Bmxx80;
using skullOS.Core;
using skullOS.Core.Interfaces;
using System.Device.Gpio;
using System.Device.I2c;
Expand Down Expand Up @@ -34,8 +35,12 @@ public static async Task Main(string[] args)
await Task.Delay(Timeout.Infinite);
}

static void Run(Modules modulesToLoad = null)
static void Run(Modules modulesToLoad = null, bool shouldCreateDirectory = true)
{
if (shouldCreateDirectory)
{
FileManager.CreateSkullDirectory();
}
GpioController controller = new();

const int busId = 1;
Expand Down

0 comments on commit e2d3b69

Please sign in to comment.