Skip to content

Commit

Permalink
Add configuration in JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
TekuSP committed Dec 24, 2023
1 parent 00032d8 commit afede4c
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 9 deletions.
25 changes: 25 additions & 0 deletions OpenHalo.nfproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@
<Private>True</Private>
<SpecificVersion>True</SpecificVersion>
</Reference>
<Reference Include="nanoFramework.Json, Version=2.2.103.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
<HintPath>packages\nanoFramework.Json.2.2.103\lib\nanoFramework.Json.dll</HintPath>
<Private>True</Private>
<SpecificVersion>True</SpecificVersion>
</Reference>
<Reference Include="nanoFramework.Networking.Sntp, Version=1.6.25.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
<HintPath>packages\nanoFramework.Networking.Sntp.1.6.25\lib\nanoFramework.Networking.Sntp.dll</HintPath>
<Private>True</Private>
Expand All @@ -88,6 +93,11 @@
<Private>True</Private>
<SpecificVersion>True</SpecificVersion>
</Reference>
<Reference Include="nanoFramework.System.Runtime, Version=1.0.6.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
<HintPath>packages\nanoFramework.System.Runtime.1.0.6\lib\nanoFramework.System.Runtime.dll</HintPath>
<Private>True</Private>
<SpecificVersion>True</SpecificVersion>
</Reference>
<Reference Include="nanoFramework.System.Text, Version=1.2.54.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
<HintPath>packages\nanoFramework.System.Text.1.2.54\lib\nanoFramework.System.Text.dll</HintPath>
<Private>True</Private>
Expand All @@ -98,6 +108,11 @@
<Private>True</Private>
<SpecificVersion>True</SpecificVersion>
</Reference>
<Reference Include="System.IO.FileSystem, Version=1.1.32.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
<HintPath>packages\nanoFramework.System.IO.FileSystem.1.1.32\lib\System.IO.FileSystem.dll</HintPath>
<Private>True</Private>
<SpecificVersion>True</SpecificVersion>
</Reference>
<Reference Include="System.IO.Streams, Version=1.1.52.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
<HintPath>packages\nanoFramework.System.IO.Streams.1.1.52\lib\System.IO.Streams.dll</HintPath>
<Private>True</Private>
Expand All @@ -118,6 +133,16 @@
<Private>True</Private>
<SpecificVersion>True</SpecificVersion>
</Reference>
<Reference Include="Windows.Storage, Version=1.5.45.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
<HintPath>packages\nanoFramework.Windows.Storage.1.5.45\lib\Windows.Storage.dll</HintPath>
<Private>True</Private>
<SpecificVersion>True</SpecificVersion>
</Reference>
<Reference Include="Windows.Storage.Streams, Version=1.14.32.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
<HintPath>packages\nanoFramework.Windows.Storage.Streams.1.14.32\lib\Windows.Storage.Streams.dll</HintPath>
<Private>True</Private>
<SpecificVersion>True</SpecificVersion>
</Reference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand Down
41 changes: 32 additions & 9 deletions OpenHaloApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@
using System.Device.Gpio;
using System.Diagnostics;
using nanoFramework.Hardware.Esp32;
using System.IO;
using Windows.Storage;
using nanoFramework.Json;
using OpenHalo.Configs;

namespace OpenHalo
{
public class OpenHaloApplication : Application
{
static Window mainWindow;

Check warning on line 18 in OpenHaloApplication.cs

View workflow job for this annotation

GitHub Actions / Build NanoFramework SLN (Release)

Field 'OpenHaloApplication.mainWindow' is never assigned to, and will always have its default value null

static MainConfig config;
public static void Main()
{
int backLightPin = 8;
Expand Down Expand Up @@ -43,14 +47,33 @@ public static void Main()
OpenHaloApplication myApplication = new OpenHaloApplication();
Console.WriteLine("Framework initialized!");
Console.WriteLine("Loading config...");


Console.WriteLine("Loading first time setup window...");


Console.WriteLine("Loading connecting window...");


Console.WriteLine("Searching for configuration file...");
if (File.Exists("I:\\configuration.json"))
{
Console.WriteLine("Found configuration file, reading...");
var file = StorageFile.GetFileFromPath("I:\\configuration.json");
var configString = FileIO.ReadText(file);
try
{
config = (MainConfig)JsonConvert.DeserializeObject(configString, typeof(MainConfig));
Console.WriteLine("Configuration file read succesfully.");
}
catch
{
Console.WriteLine("Configuration file damaged. Recreating file.");
file.Delete();
}
}
if (!File.Exists("I:\\configuration.json"))
{
Console.WriteLine("No configuration loaded.");
Console.WriteLine("Loading first time setup window...");
}
else
{
Console.WriteLine("Configuration loaded.");
Console.WriteLine("Loading connecting window...");
}
Console.WriteLine("Rendering and launching app!");
myApplication.Run(mainWindow);
}
Expand Down
5 changes: 5 additions & 0 deletions packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,20 @@
<package id="nanoFramework.Graphics" version="1.2.4" targetFramework="netnanoframework10" />
<package id="nanoFramework.Graphics.Core" version="1.2.4" targetFramework="netnanoframework10" />
<package id="nanoFramework.Hardware.Esp32" version="1.6.12" targetFramework="netnanoframework10" />
<package id="nanoFramework.Json" version="2.2.103" targetFramework="netnanoframework10" />
<package id="nanoFramework.Networking.Sntp" version="1.6.25" targetFramework="netnanoframework10" />
<package id="nanoFramework.ResourceManager" version="1.2.19" targetFramework="netnanoframework10" />
<package id="nanoFramework.Runtime.Events" version="1.11.15" targetFramework="netnanoframework10" />
<package id="nanoFramework.Runtime.Native" version="1.6.12" targetFramework="netnanoframework10" />
<package id="nanoFramework.System.Collections" version="1.5.31" targetFramework="netnanoframework10" />
<package id="nanoFramework.System.Device.Gpio" version="1.1.38" targetFramework="netnanoframework10" />
<package id="nanoFramework.System.IO.FileSystem" version="1.1.32" targetFramework="netnanoframework10" />
<package id="nanoFramework.System.IO.Streams" version="1.1.52" targetFramework="netnanoframework10" />
<package id="nanoFramework.System.Net" version="1.10.64" targetFramework="netnanoframework10" />
<package id="nanoFramework.System.Net.Http" version="1.5.113" targetFramework="netnanoframework10" />
<package id="nanoFramework.System.Runtime" version="1.0.6" targetFramework="netnanoframework10" />
<package id="nanoFramework.System.Text" version="1.2.54" targetFramework="netnanoframework10" />
<package id="nanoFramework.System.Threading" version="1.1.32" targetFramework="netnanoframework10" />
<package id="nanoFramework.Windows.Storage" version="1.5.45" targetFramework="netnanoframework10" />
<package id="nanoFramework.Windows.Storage.Streams" version="1.14.32" targetFramework="netnanoframework10" />
</packages>

0 comments on commit afede4c

Please sign in to comment.