Skip to content

Commit

Permalink
Lights still aren't quite there
Browse files Browse the repository at this point in the history
  • Loading branch information
David032 committed Oct 22, 2023
1 parent 2591163 commit 36f88e1
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 22 deletions.
2 changes: 2 additions & 0 deletions skullOS.Core/LED Elements/SkullLed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public SkullLed(string LedName, int ledPin, GpioController controller)
name = LedName;
pin = ledPin;
gpioController = controller;

gpioController.OpenPin(pin, PinMode.Output);
}

public void ToggleState()
Expand Down
8 changes: 4 additions & 4 deletions skullOS.Output/Data/Output.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
BuzzerPin = 17
NeoPixel = True
NeoPixelCount = 8
LedPin = 23
BuzzerPin=17
NeoPixel=True
NeoPixelCount=8
LedPin=23
56 changes: 42 additions & 14 deletions skullOS.Output/Output.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,63 @@ public class Output : Controller

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);
SkullNeoPixel? pixelDisplay = (SkullNeoPixel)outputDevices.Select(x => x).FirstOrDefault(x => x.Name == "NeoPixel");

Check warning on line 13 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.
pixelDisplay?.device.Image.SetPixel(0, 0, Color.AliceBlue);
var lifeLed = (SkullLed)outputDevices.Select(x => x).FirstOrDefault(x => x.Name == "Life Light");

Check warning on line 15 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.
lifeLed.ToggleState();

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

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Dereference of a possibly null reference.
}

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

if (settings.ContainsKey("Buzzer"))
#if DEBUG
Console.WriteLine("Output device settings contain:");
foreach (var item in settings)
{
Console.WriteLine(item.Key + " : " + item.Value);
}
#endif
if (settings.ContainsKey("BuzzerPin"))
{
settings.TryGetValue("Buzzer", out string BuzzerPin);
var deviceBuzzer = new SkullBuzzer("Buzzer", int.Parse(BuzzerPin));
outputDevices.Add(deviceBuzzer);
if (settings.TryGetValue("BuzzerPin", out string BuzzerPin))

Check warning on line 32 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);
}
}

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

Check warning on line 42 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);
}
}


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);
if (settings.TryGetValue("LedPin", out string pin))

Check warning on line 53 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 lifeLedPinNumber = Convert.ToInt32(pin);
SkullLed deviceLed = new("Life 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 Down
9 changes: 7 additions & 2 deletions skullOS.Output/SkullLed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ namespace skullOS.Output
{
public class SkullLed : SkullOutputDevice
{
public string name = "";
/// <summary>
/// SOMETHING IN HERE ISN'T WORKING!
/// </summary>
public int pin = 0;
public LedBehaviour state = LedBehaviour.Off;

Expand All @@ -14,14 +16,17 @@ public class SkullLed : SkullOutputDevice

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

gpioController.OpenPin(pin, PinMode.Output);
}

public void ToggleState()
{
gpioController.Write(pin, ((ledOn) ? PinValue.High : PinValue.Low));
ledOn = !ledOn;
}
}
}
3 changes: 1 addition & 2 deletions skullOS.Output/SkullNeoPixel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ public SkullNeoPixel(string name, int count)
};
using SpiDevice spi = SpiDevice.Create(spiSettings);

Ws2812b neopixel = new(spi, count);

neoPixel = new Ws2812b(spi, count);
}
}
}
8 changes: 8 additions & 0 deletions skullOS/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ public static async Task Main(string[] args)
break;
}

await Console.Out.WriteLineAsync("Testign output!");
int pin = 23;
GpioController controller = new();
if (!controller.IsPinOpen(23))
{
controller.OpenPin(23, PinMode.Output);
}
controller.Write(pin, PinValue.High);
await Task.Delay(Timeout.Infinite);
}

Expand Down

0 comments on commit 36f88e1

Please sign in to comment.