Skip to content

Commit

Permalink
#62 0 arg constructors implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
David032 committed Jun 17, 2024
1 parent de6f78d commit 8400626
Show file tree
Hide file tree
Showing 9 changed files with 200 additions and 27 deletions.
15 changes: 12 additions & 3 deletions Source/skullOS.Modules/Adventure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ public class Adventure : Module, IAdventure

public Adventure(ICameraService camService = null)

Check warning on line 17 in Source/skullOS.Modules/Adventure.cs

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.
{
string now = DateTime.Now.ToString("M");
FileManager.CreateSubDirectory("Timelapse - " + now);
directory = FileManager.GetSkullDirectory() + @"/Timelapse - " + now + @"/";
if (camService == null)
{
cameraService = new CameraService();
Expand All @@ -27,8 +24,20 @@ public Adventure(ICameraService camService = null)
{
cameraService = camService;
}
Create();
}

public Adventure()
{
cameraService = new CameraService();
Create();
}

public override void Create()
{
string now = DateTime.Now.ToString("M");
FileManager.CreateSubDirectory("Timelapse - " + now);
directory = FileManager.GetSkullDirectory() + @"/Timelapse - " + now + @"/";
takePicture = new Timer(interval);
takePicture.AutoReset = true;
takePicture.Elapsed += TakePicture_Elapsed;
Expand Down
11 changes: 11 additions & 0 deletions Source/skullOS.Modules/Buzzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ public Buzzer(IBuzzerService buzzerService = null, int pwmPin = 13, IMelodyPlaye
}
}

public Buzzer()
{
PwmBuzzer = new BuzzerService(13); //This should really be read from a settings file
Player = new MelodyPlayer(PwmBuzzer.Buzzer);
}

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

public void PlayTune(Tunes tuneToPlay)
{
switch (tuneToPlay)
Expand Down
74 changes: 74 additions & 0 deletions Source/skullOS.Modules/Camera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,75 @@ public Camera(ICameraService camService = null, IMicrophoneService micService =
}
}

public Camera()
{
FileManager.CreateSubDirectory("Captures");
var cameraSettings = SettingsLoader.LoadConfig(@"Data/CameraSettings.txt");

CameraService = new CameraService();


if (cameraSettings.ContainsKey("UseMic"))
{
if (cameraSettings.TryGetValue("UseMic", out string shouldUseMic))
{
if (bool.Parse(shouldUseMic))
{
//Might this be null coalescable?
MicrophoneService = new MicrophoneService();
useMic = true;
}
else
{
//No Mic desired
}
}
}
if (cameraSettings.ContainsKey("CameraLight"))
{
if (cameraSettings.TryGetValue("CameraLight", out string lightPin))
{
Dictionary<string, int> pins = new Dictionary<string, int>
{
{ "CameraLight", int.Parse(lightPin) }
};

LedService = new LedService(pins);
}
}
if (cameraSettings.ContainsKey("UseBuzzer"))
{
if (cameraSettings.TryGetValue("UseBuzzer", out string shouldUseBuzzer))
{
if (bool.Parse(shouldUseBuzzer))
{
//This should be reading from the file!
BuzzerService = new BuzzerService(13);
useBuzzer = true;
}
else
{
//No buzzer desired
}
}
}
if (cameraSettings.ContainsKey("UseSpeaker"))
{
if (cameraSettings.TryGetValue("UseSpeaker", out string shouldUseSpeaker))
{
if (bool.Parse(shouldUseSpeaker))
{
SpeakerService = new SpeakerService();
useSpeaker = true;
}
else
{
//No Speaker desired
}
}
}
}

public async Task TakePicture()
{
if (!isActive)
Expand Down Expand Up @@ -222,5 +291,10 @@ public override async void OnAction(object? sender, EventArgs e)
break;
}
}

public override void Create()
{
throw new NotImplementedException();
}
}
}
5 changes: 5 additions & 0 deletions Source/skullOS.Modules/Downlink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
{
public class Downlink : Module, IDownlinkModule
{
public override void Create()
{
throw new NotImplementedException();
}

public override void OnAction(object? sender, EventArgs e)
{
throw new NotImplementedException();
Expand Down
1 change: 1 addition & 0 deletions Source/skullOS.Modules/Module.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public abstract class Module
protected SkullLogger? logger;
public abstract void OnEnable(string[] args);
public abstract void OnAction(object? sender, EventArgs e);
public abstract void Create();
public abstract override string ToString();
public void AttachLogger(SkullLogger logger)
{
Expand Down
63 changes: 62 additions & 1 deletion Source/skullOS.Modules/Prop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public class Prop : Module, IPropModule
ServoMotor rightFlap;

Dictionary<string, string> propSettings;
public Prop(ISpeakerService speaker = null, ILedService leds = null, string pathToSettings = @"Data/PropSettings.txt")
public Prop(ISpeakerService speaker = null, ILedService leds = null,
string pathToSettings = @"Data/PropSettings.txt")
{
propSettings = SettingsLoader.LoadConfig(pathToSettings);

Expand Down Expand Up @@ -92,6 +93,61 @@ public Prop(ISpeakerService speaker = null, ILedService leds = null, string path
}
}

public Prop()
{
propSettings = SettingsLoader.LoadConfig(@"Data/PropSettings.txt");

propSettings.TryGetValue("Sounds", out string soundsState);
bool useSounds = bool.Parse(soundsState);
if (propSettings.ContainsKey("Sounds") && useSounds)
{
SpeakerService = new SpeakerService();

SpeakerService.PlayAudio(@"Resources/computer-startup-music.mp3"); //This one won't await :(
sounds = Directory.GetFiles(@"Resources/Haro/Idles"); //This shouldn't be hardcoded like this at all >:(
numberOfIdles = sounds.Length;

PlayIdleSound = new Timer(interval)
{
AutoReset = true
};
PlayIdleSound.Elapsed += PlayIdleSound_Elapsed;
PlayIdleSound.Start();
}

propSettings.TryGetValue("Lights", out string lightsState);
bool useLights = bool.Parse(lightsState);
if (propSettings.ContainsKey("Lights") && useLights)
{
//LEDs should be read from the file as well
Dictionary<string, int> pins = new()
{
{ "LeftEye", 26 },
{"RightEye", 26 }
};

LedService = new LedService(pins);

foreach (var item in LedService.GetLeds())
{
string pin = item.Key;
LedService.TurnOn(pin);
}
}

propSettings.TryGetValue("Servos", out string servosState);
bool useServos = bool.Parse(servosState);
if (propSettings.ContainsKey("Servos") && useServos)
{
SoftwarePwmChannel leftPWM = new(5, 50);
leftFlap = new ServoMotor(leftPWM);
leftFlap.Start();
SoftwarePwmChannel rightPWM = new(6, 50);
rightFlap = new ServoMotor(rightPWM);
rightFlap.Start();
}
}

private void PlayIdleSound_Elapsed(object? sender, System.Timers.ElapsedEventArgs e)
{
Random random = new Random();
Expand Down Expand Up @@ -143,5 +199,10 @@ public override string ToString()
{
return "Prop";
}

public override void Create()
{
throw new NotImplementedException();
}
}
}
5 changes: 5 additions & 0 deletions Source/skullOS.Modules/QrCodeReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
{
public class QrCodeReader : Module, IQrCodeReaderModule
{
public override void Create()
{
throw new NotImplementedException();
}

public override void OnAction(object? sender, EventArgs e)
{
throw new NotImplementedException();
Expand Down
48 changes: 25 additions & 23 deletions Source/skullOS.Modules/Support.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,22 @@ public class Support : Module, ISupportModule
public Support(GpioController gpioController = null, ISpeakerService speaker = null, int signalPin = 4)
{
pin = signalPin;
LowBatteryAlert = new Timer(interval)
{
AutoReset = true,
};
LowBatteryAlert.Elapsed += LowBatteryAlert_Elapsed;

if (speaker == null)
{
speakerService = new SpeakerService();
}
else
{
speakerService = speaker;
}
speakerService = speaker ?? new SpeakerService();

if (gpioController == null)
{
controller = new GpioController();
}
else
{
controller = gpioController;
}
controller.OpenPin(pin);
controller.RegisterCallbackForPinValueChangedEvent(pin, PinEventTypes.Rising, OnLowBattery);
controller = gpioController ?? new GpioController();

Create();
}

public Support()
{
pin = 4; //This should really be read from a file

speakerService = new SpeakerService();

controller = new GpioController();
Create();
}

void OnLowBattery(object sender, PinValueChangedEventArgs args)
Expand Down Expand Up @@ -71,5 +62,16 @@ public override string ToString()
{
return "Support";
}

public override void Create()
{
LowBatteryAlert = new Timer(interval)
{
AutoReset = true,
};
LowBatteryAlert.Elapsed += LowBatteryAlert_Elapsed;
controller.OpenPin(pin);
controller.RegisterCallbackForPinValueChangedEvent(pin, PinEventTypes.Rising, OnLowBattery);
}
}
}
5 changes: 5 additions & 0 deletions Source/skullOS.Modules/Uplink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ namespace skullOS.Modules
{
public class Uplink : Module, IUplinkModule
{
public override void Create()
{
throw new NotImplementedException();
}

public override void OnAction(object? sender, EventArgs e)
{
throw new NotImplementedException();
Expand Down

0 comments on commit 8400626

Please sign in to comment.