Skip to content

Commit

Permalink
Some more bits
Browse files Browse the repository at this point in the history
  • Loading branch information
David032 committed Oct 22, 2023
1 parent 15f4dac commit 2591163
Show file tree
Hide file tree
Showing 22 changed files with 282 additions and 24 deletions.
20 changes: 20 additions & 0 deletions ServoSkull.sln
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "skullOS.Core", "skullOS.Core\skullOS.Core.csproj", "{464B162B-62FC-49CC-A6AB-72DBE959DD8C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "skullOS", "skullOS\skullOS.csproj", "{6D3C5D36-0002-4EFD-A3B9-0924D6D3CCD8}"
ProjectSection(ProjectDependencies) = postProject
{9AC8960C-539A-4B2C-9D24-5169AF4337FA} = {9AC8960C-539A-4B2C-9D24-5169AF4337FA}
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "skullOS.Camera", "skullOS.Camera\skullOS.Camera.csproj", "{D4E9CB35-2264-4717-BDB6-7797E84B5DFE}"
EndProject
Expand All @@ -24,6 +27,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "skullOS.Input.Tests", "skul
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "skullOS.Core.Tests", "skullOS.Core.Tests\skullOS.Core.Tests.csproj", "{BA89208E-E059-45A3-8A0D-4052063C79D4}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{B50B951E-DF9B-49DD-9CAC-ED8B01C6B1E7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "skullOS.Output", "skullOS.Output\skullOS.Output.csproj", "{9AC8960C-539A-4B2C-9D24-5169AF4337FA}"
ProjectSection(ProjectDependencies) = postProject
{464B162B-62FC-49CC-A6AB-72DBE959DD8C} = {464B162B-62FC-49CC-A6AB-72DBE959DD8C}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -66,10 +76,20 @@ Global
{BA89208E-E059-45A3-8A0D-4052063C79D4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BA89208E-E059-45A3-8A0D-4052063C79D4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BA89208E-E059-45A3-8A0D-4052063C79D4}.Release|Any CPU.Build.0 = Release|Any CPU
{9AC8960C-539A-4B2C-9D24-5169AF4337FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9AC8960C-539A-4B2C-9D24-5169AF4337FA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9AC8960C-539A-4B2C-9D24-5169AF4337FA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9AC8960C-539A-4B2C-9D24-5169AF4337FA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{9B4C6E1D-BE16-40F3-AFB7-369ACA5BFDBC} = {B50B951E-DF9B-49DD-9CAC-ED8B01C6B1E7}
{45513FCC-E0E9-4C2A-A48F-239A380347BC} = {B50B951E-DF9B-49DD-9CAC-ED8B01C6B1E7}
{237A08B2-E8F4-4384-A894-4C356CE45E92} = {B50B951E-DF9B-49DD-9CAC-ED8B01C6B1E7}
{BA89208E-E059-45A3-8A0D-4052063C79D4} = {B50B951E-DF9B-49DD-9CAC-ED8B01C6B1E7}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {FA7BE016-5699-47F3-A654-08A907CE1F11}
EndGlobalSection
Expand Down
30 changes: 26 additions & 4 deletions skullOS.Camera/Camera.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Iot.Device.Button;
using Iot.Device.Media;
using skullOS.Core;
using System.Device.Gpio;

namespace skullOS.Camera
{
Expand All @@ -10,27 +11,40 @@ public class Camera : Controller
VideoDevice device;
VideoConnectionSettings deviceSettings = new(busId: 0, captureSize: (2560, 1440), pixelFormat: VideoPixelFormat.JPEG);

skullOS.Core.LED_Elements.SkullLed cameraLight;
bool hasCameraLed = false;
public Camera()
{

}

public override void Run()
public override void Run(GpioController controller)
{
}

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

var cameraMode = settings
.Select(x => x)
.Where(x => x.Key == "Mode")
.FirstOrDefault();
.FirstOrDefault(defaultValue);
var pinToActOn = settings
.Select(x => x)
.Where(x => x.Key == "Pin")
.FirstOrDefault();
.FirstOrDefault(defaultValue);
var ledPin = settings
.Select(x => x)
.Where(x => x.Key == "LedPin")
.FirstOrDefault(defaultValue);

if (!ledPin.Equals(defaultValue))
{
cameraLight = new Core.LED_Elements.SkullLed("Camera Light", int.Parse(ledPin.Value), controller);
hasCameraLed = true;
}

switch (cameraMode.Value)
{
Expand All @@ -39,8 +53,16 @@ public override bool Setup()
GpioButton button = new(int.Parse(pinToActOn.Value));
button.Press += (sender, e) =>
{
if (hasCameraLed)
{
cameraLight.ToggleState();
}
Console.WriteLine($"({DateTime.Now}) Picture taken!");
device.Capture($"{DateTime.Now:yyyyMMddHHmmss}.jpg");
if (hasCameraLed)
{
cameraLight.ToggleState();
}
};

break;
Expand Down
3 changes: 2 additions & 1 deletion skullOS.Camera/Data/Settings.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Pin=25
Mode=Image
Mode=Image
LedPin=26
5 changes: 3 additions & 2 deletions skullOS.Core/Controller.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using skullOS.Core.Interfaces;
using System.Device.Gpio;

namespace skullOS.Core
{
public abstract class Controller : ISubSystem
{
public abstract void Run();
public abstract void Run(GpioController controller);

public abstract bool Setup();
public abstract bool Setup(GpioController controller);

public abstract void Stop();
}
Expand Down
8 changes: 5 additions & 3 deletions skullOS.Core/Interfaces/ISubSystem.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
namespace skullOS.Core.Interfaces
using System.Device.Gpio;

namespace skullOS.Core.Interfaces
{
public interface ISubSystem
{
bool Setup();
bool Setup(GpioController controller);

void Run();
void Run(GpioController controller);

void Stop();
}
Expand Down
33 changes: 33 additions & 0 deletions skullOS.Core/LED Elements/SkullLed.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Device.Gpio;

namespace skullOS.Core.LED_Elements
{
public enum LedBehaviour
{
On,
Off,
OnEvent
}

public class SkullLed
{
public string name = "";
public int pin = 0;
public LedBehaviour state = LedBehaviour.Off;

private GpioController gpioController;
bool ledOn = false;

public SkullLed(string LedName, int ledPin, GpioController controller)
{
name = LedName;
pin = ledPin;
gpioController = controller;
}

public void ToggleState()
{
gpioController.Write(pin, ((ledOn) ? PinValue.High : PinValue.Low));
}
}
}
2 changes: 1 addition & 1 deletion skullOS.Core/skullOS.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
Expand Down
5 changes: 3 additions & 2 deletions skullOS.Input/Input.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using skullOS.Core;
using System.Device.Gpio;

namespace skullOS.Input
{
Expand All @@ -15,12 +16,12 @@ public List<InputDevice> InputDevices
get { return inputDevices; }
}

public override void Run()
public override void Run(GpioController controller)
{
throw new NotImplementedException();
}

public override bool Setup()
public override bool Setup(GpioController controller)
{
throw new NotImplementedException();
}
Expand Down
4 changes: 4 additions & 0 deletions skullOS.Output/Data/Output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
BuzzerPin = 17
NeoPixel = True
NeoPixelCount = 8
LedPin = 23
50 changes: 50 additions & 0 deletions skullOS.Output/Output.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using skullOS.Core;
using System.Device.Gpio;
using System.Drawing;

namespace skullOS.Output
{
public class Output : Controller
{
public List<SkullOutputDevice> outputDevices = new();

public override void Run(GpioController controller)
{
var pixelDisplay = (SkullNeoPixel)outputDevices.Select(x => x).Where(x => x.Name == "NeoPixel").FirstOrDefault();
pixelDisplay.device.Image.SetPixel(0, 0, Color.AliceBlue);
}

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

if (settings.ContainsKey("Buzzer"))
{
settings.TryGetValue("Buzzer", out string BuzzerPin);
var deviceBuzzer = new SkullBuzzer("Buzzer", int.Parse(BuzzerPin));
outputDevices.Add(deviceBuzzer);
}
if (settings.ContainsKey("NeoPixel"))
{
settings.TryGetValue("NeoPixelCount", out string count);
var deviceNeoPixel = new SkullNeoPixel("NeoPixel", int.Parse(count));
outputDevices.Add(deviceNeoPixel);
}

if (settings.ContainsKey("LedPin"))
{
settings.TryGetValue("LedPin", out string pin);
var deviceLed = new skullOS.Output.SkullLed("Life Light", int.Parse(pin), controller);
outputDevices.Add(deviceLed);
}

return true;
}

public override void Stop()
{
throw new NotImplementedException();
}
}
}
22 changes: 22 additions & 0 deletions skullOS.Output/SkullBuzzer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Iot.Device.Buzzer;

namespace skullOS.Output
{
internal class SkullBuzzer : SkullOutputDevice
{
int Pin = 0;
public Buzzer device
{
get { return buzzer; }
}
Buzzer buzzer;


public SkullBuzzer(string name, int pin)
{
this.Name = name;
this.Pin = pin;
buzzer = new Buzzer(pin);
}
}
}
27 changes: 27 additions & 0 deletions skullOS.Output/SkullLed.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using skullOS.Core.LED_Elements;
using System.Device.Gpio;

namespace skullOS.Output
{
public class SkullLed : SkullOutputDevice
{
public string name = "";
public int pin = 0;
public LedBehaviour state = LedBehaviour.Off;

private GpioController gpioController;
bool ledOn = false;

public SkullLed(string LedName, int ledPin, GpioController controller)
{
name = LedName;
pin = ledPin;
gpioController = controller;
}

public void ToggleState()
{
gpioController.Write(pin, ((ledOn) ? PinValue.High : PinValue.Low));
}
}
}
30 changes: 30 additions & 0 deletions skullOS.Output/SkullNeoPixel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Iot.Device.Ws28xx;
using System.Device.Spi;

namespace skullOS.Output
{
internal class SkullNeoPixel : SkullOutputDevice
{
public Ws2812b device
{
get { return neoPixel; }
}
Ws2812b neoPixel;

public SkullNeoPixel(string name, int count)
{
this.Name = name;

SpiConnectionSettings spiSettings = new(0, 0)
{
ClockFrequency = 2_400_000,
Mode = SpiMode.Mode0,
DataBitLength = 8
};
using SpiDevice spi = SpiDevice.Create(spiSettings);

Ws2812b neopixel = new(spi, count);

}
}
}
7 changes: 7 additions & 0 deletions skullOS.Output/SkullOutputDevice.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace skullOS.Output
{
public abstract class SkullOutputDevice
{
public string Name = "";
}
}
19 changes: 19 additions & 0 deletions skullOS.Output/skullOS.Output.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\skullOS.Core\skullOS.Core.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="Data\Output.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
12 changes: 12 additions & 0 deletions skullOS.Tests/MockGpioController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Device.Gpio;

namespace skullOS.Tests
{
internal class MockGpioController : GpioController
{
public MockGpioController()
{

}
}
}
Loading

0 comments on commit 2591163

Please sign in to comment.