Skip to content

Commit

Permalink
More hardcoded bits
Browse files Browse the repository at this point in the history
But the buzzer is now working! Needed to be a passive one rather than an active one
  • Loading branch information
David032 committed Oct 23, 2023
1 parent 503f743 commit 8efbf8f
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 56 deletions.
8 changes: 0 additions & 8 deletions skullOS.Camera/Camera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ 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;
GpioButton actionButton;

public Camera()

Check warning on line 16 in skullOS.Camera/Camera.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Non-nullable field 'device' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 16 in skullOS.Camera/Camera.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Non-nullable field 'actionButton' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.
Expand Down Expand Up @@ -42,12 +40,6 @@ public override bool Setup(GpioController controller)
.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)
{
case "Image":
Expand Down
7 changes: 7 additions & 0 deletions skullOS.Core/Constants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace skullOS
{
public static class Constants
{
public const string prefix = "skullOS.";
}
}
39 changes: 29 additions & 10 deletions skullOS.Interlink/Interlink.cs
Original file line number Diff line number Diff line change
@@ -1,47 +1,66 @@
using skullOS.Core;
using Iot.Device.Buzzer;
using skullOS.Core;
using skullOS.Core.Interfaces;
using System.Device.Gpio;

namespace skullOS.Interlink
{
public class Interlink : Controller
{
public List<ISubSystem> subSystems = new();
Camera.Camera cameraModule;
Output.Output outputModule;


public override void Run(GpioController controller)
{
throw new NotImplementedException();
Console.WriteLine("Interlink ran successfully!");
}

public override bool Setup(GpioController controller)
{
throw new NotImplementedException();
Link();
return true;
}

public override void Stop()
{
throw new NotImplementedException();
}

public void Link(List<ISubSystem> activeModules)
public void Link()
{
cameraModule = (Camera.Camera)activeModules.Select(x => x).Where(x => x.ToString() == "Camera").FirstOrDefault();
outputModule = (Output.Output)activeModules.Select(x => x).Where(x => x.ToString() == "Output").FirstOrDefault();
Console.WriteLine("Linkable modules!");
foreach (var item in subSystems)
{
Console.WriteLine(item.ToString());
}

cameraModule = (Camera.Camera)subSystems.Select(x => x).Where(x => x.ToString() == "skullOS.Camera.Camera").FirstOrDefault();

Check warning on line 39 in skullOS.Interlink/Interlink.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Converting null literal or possible null value to non-nullable type.

Check warning on line 39 in skullOS.Interlink/Interlink.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Possible null reference assignment.
outputModule = (Output.Output)subSystems.Select(x => x).Where(x => x.ToString() == "skullOS.Output.Output").FirstOrDefault();

cameraModule.GetButton().Press += PlayBuzzerWhenActivated;
//Need to do picture led
cameraModule.GetButton().Press += FlashLightWhenActivatedAsync;

Console.WriteLine(cameraModule.GetCamera().Settings);
}



#region Cross Module functions

private void PlayBuzzerWhenActivated(object? sender, EventArgs e)
public void PlayBuzzerWhenActivated(object? sender, EventArgs e)
{
var buzzer = (Buzzer)outputModule.outputDevices.Select(x => x).FirstOrDefault(x => x.Name == "Buzzer").Device;
buzzer.PlayTone(1000, 3000);
}

private async void FlashLightWhenActivatedAsync(object? sender, EventArgs e)
{
Output.SkullBuzzer? buzzer = (Output.SkullBuzzer)outputModule.outputDevices.Select(x => x).FirstOrDefault(x => x.Name == "Buzzer");
buzzer?.device.PlayTone(300, 1);
//Output.SkullLed? led = (Output.SkullLed)outputModule.outputDevices.Select(x => x).FirstOrDefault(x => x.Name == "Camera Light");
//led.TurnOn();
//await Task.Delay(15000);
//led.TurnOff();
}

#endregion
Expand Down
5 changes: 3 additions & 2 deletions skullOS.Output/Data/Output.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
BuzzerPin=17
BuzzerPin=13
NeoPixel=True
NeoPixelCount=8
LedPin=23
LedPin=23
CameraLed=26
97 changes: 62 additions & 35 deletions skullOS.Output/Output.cs
Original file line number Diff line number Diff line change
@@ -1,73 +1,88 @@
using skullOS.Core;
using Iot.Device.Buzzer;
using Iot.Device.Ws28xx;
using skullOS.Core;
using System.Device.Gpio;
using System.Device.Spi;
using System.Drawing;

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

public override void Run(GpioController controller)
{
SkullNeoPixel? pixelDisplay = (SkullNeoPixel)outputDevices.Select(x => x).FirstOrDefault(x => x.Name == "NeoPixel");
pixelDisplay?.device.Image.SetPixel(0, 0, Color.AliceBlue);
pixelDisplay.device.Update();
SkullLed? lifeLed = (SkullLed)outputDevices.Select(x => x).FirstOrDefault(x => x.Name == "Life Light");
lifeLed.TurnOn();
Console.WriteLine("### OUTPUT DEVICE WARMUP CHECKS ###");

Ws2812b? pixelDisplay = (Ws2812b)outputDevices.Select(x => x).FirstOrDefault(x => x.Name == "NeoPixel").Device;

Check warning on line 18 in skullOS.Output/Output.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Dereference of a possibly null reference.
pixelDisplay?.Image.SetPixel(0, 0, Color.AliceBlue);
pixelDisplay.Update();

Check warning on line 20 in skullOS.Output/Output.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Dereference of a possibly null reference.

//SkullLed? lifeLed = (SkullLed)outputDevices.Select(x => x).FirstOrDefault(x => x.Name == "Life Light");
//lifeLed.TurnOn();

var buzzer = (Buzzer)outputDevices.Select(x => x).FirstOrDefault(x => x.Name == "Buzzer").Device;

Check warning on line 25 in skullOS.Output/Output.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Dereference of a possibly null reference.
buzzer.PlayTone(1000, 3000);
}

public override bool Setup(GpioController controller)
{
var settings = SettingsLoader.LoadConfig(@"Data/Output.txt");
var defaultValue = new KeyValuePair<string, string>("", "");
#if DEBUG
Console.WriteLine("Output device settings contain:");
foreach (var item in settings)
{
Console.WriteLine(item.Key + " : " + item.Value);
}
#endif

if (settings.ContainsKey("BuzzerPin"))
{
if (settings.TryGetValue("BuzzerPin", out string BuzzerPin))

Check warning on line 36 in skullOS.Output/Output.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Converting null literal or possible null value to non-nullable type.
{
int buzzerPinNumber = Convert.ToInt32(BuzzerPin);
SkullBuzzer deviceBuzzer = new("Buzzer", buzzerPinNumber);
outputDevices.Add(deviceBuzzer);
Buzzer buzzer = new(buzzerPinNumber);
outputDevices.Add(new OutputDevice("Buzzer", buzzer));

}
}

if (settings.ContainsKey("NeoPixel"))
{
if (settings.TryGetValue("NeoPixelCount", out string count))

Check warning on line 47 in skullOS.Output/Output.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Converting null literal or possible null value to non-nullable type.
{
int neoPixelPinNumber = Convert.ToInt32(count);
SkullNeoPixel deviceNeoPixel = new("NeoPixel", neoPixelPinNumber);
outputDevices.Add(deviceNeoPixel);
int neoPixelLedCount = Convert.ToInt32(count);
SpiConnectionSettings spiSettings = new(0, 0)
{
ClockFrequency = 2_400_000,
Mode = SpiMode.Mode0,
DataBitLength = 8
};
using SpiDevice spi = SpiDevice.Create(spiSettings);

Ws2812b neoPixel = new Ws2812b(spi, neoPixelLedCount);
outputDevices.Add(new OutputDevice("NeoPixel", neoPixel));
}
}


if (settings.ContainsKey("LedPin"))
{
if (settings.TryGetValue("LedPin", out string pin))
{
int lifeLedPinNumber = Convert.ToInt32(pin);
SkullLed deviceLed = new("Life Light", lifeLedPinNumber, controller);
//if (settings.ContainsKey("LedPin"))
//{
// if (settings.TryGetValue("LedPin", out string pin))
// {
// int lifeLedPinNumber = Convert.ToInt32(pin);
// SkullLed deviceLed = new("Life Light", lifeLedPinNumber, controller);

outputDevices.Add(deviceLed);
}
}
// outputDevices.Add(deviceLed);
// }
//}

//if (settings.ContainsKey("CameraLed"))
//{
// if (settings.TryGetValue("CameraLed", out string pin))
// {
// int lifeLedPinNumber = Convert.ToInt32(pin);
// SkullLed deviceLed = new("Camera Light", lifeLedPinNumber, controller);

// outputDevices.Add(deviceLed);
// }
//}

#if DEBUG
Console.WriteLine("The following output devices have been registered:");
foreach (var item in outputDevices)
{
Console.WriteLine(item.Name);
}
#endif
return true;
}

Expand All @@ -76,4 +91,16 @@ public override void Stop()
throw new NotImplementedException();
}
}

public class OutputDevice
{
public string Name = "";
public Object Device;

public OutputDevice(string name, Object device)
{
Name = name;
Device = device;
}
}
}
3 changes: 2 additions & 1 deletion skullOS/Data/Modules.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Camera = True
Output = True
Output = True
Interlink = True
12 changes: 12 additions & 0 deletions skullOS/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ public static bool SetupModules(List<ISubSystem> systemsLoaded, GpioController c
{
foreach (var system in systemsLoaded)
{


Console.WriteLine("Setting up " + system.ToString());
if (system.ToString().Equals("skullOS.Interlink.Interlink"))
{
Console.WriteLine("Giving linker data!");
Interlink.Interlink linker = (Interlink.Interlink)systemsLoaded.Select(x => x).FirstOrDefault(x => x.ToString() == "skullOS.Interlink.Interlink");
linker.subSystems = systemsLoaded;
}



if (!system.Setup(controller))
{
throw new Exception($"{system} failed to load");
Expand Down

0 comments on commit 8efbf8f

Please sign in to comment.