-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hardware Services implemented, modules laid out, camera implemented but not tested Still need to work out what I'm doing about the api
- Loading branch information
Showing
23 changed files
with
340 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using Iot.Device.Buzzer; | ||
using skullOS.HardwareServices.Interfaces; | ||
|
||
namespace skullOS.HardwareServices | ||
{ | ||
public class BuzzerService : IBuzzerService | ||
{ | ||
public Buzzer Buzzer { get; private set; } | ||
public BuzzerService(int pinNumber) | ||
{ | ||
Buzzer = new Buzzer(pinNumber); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using Iot.Device.Media; | ||
using skullOS.HardwareServices.Interfaces; | ||
using System.Diagnostics; | ||
|
||
namespace skullOS.HardwareServices | ||
{ | ||
public class CameraService : ICameraService | ||
{ | ||
public VideoDevice Camera { get; private set; } | ||
private Process? cameraCommand; | ||
private TaskCompletionSource<bool> eventHandled; | ||
|
||
public CameraService(VideoConnectionSettings cameraSettings = null) | ||
{ | ||
cameraSettings ??= new(busId: 0, captureSize: (2592, 1944), pixelFormat: VideoPixelFormat.JPEG); | ||
Camera = VideoDevice.Create(cameraSettings); | ||
Camera.Settings.HorizontalFlip = true; | ||
Camera.Settings.VerticalFlip = true; | ||
} | ||
|
||
#region SharpCamera code(https://github.com/David032/sharpCamera) for recording video | ||
public void RecordVideo(string outputDirectory, int duration) | ||
{ | ||
try | ||
{ | ||
using (cameraCommand = new Process()) | ||
{ | ||
string args = "-o " + outputDirectory + "/" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".h264 -t " + (duration * 1000); | ||
cameraCommand.StartInfo.UseShellExecute = false; | ||
cameraCommand.StartInfo.FileName = "raspivid"; | ||
cameraCommand.StartInfo.Arguments = args; | ||
|
||
#if DEBUG | ||
Console.Out.WriteLine(cameraCommand.StartInfo.Arguments); | ||
#endif | ||
|
||
cameraCommand.Start(); | ||
} | ||
} | ||
catch (Exception e) | ||
{ | ||
Console.WriteLine(e.Message); | ||
} | ||
} | ||
|
||
public async Task RecordVideoAsync(string outputDirectory, int duration) | ||
{ | ||
eventHandled = new TaskCompletionSource<bool>(); | ||
using (cameraCommand = new Process()) | ||
{ | ||
try | ||
{ | ||
string args = "-o " + outputDirectory + "/" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".h264 -t " + (duration * 1000); | ||
cameraCommand.StartInfo.UseShellExecute = false; | ||
cameraCommand.StartInfo.FileName = "raspivid"; | ||
cameraCommand.StartInfo.Arguments = args; | ||
cameraCommand.EnableRaisingEvents = true; | ||
cameraCommand.Exited += new EventHandler(VideoRecorded); | ||
#if DEBUG | ||
Console.Out.WriteLine(cameraCommand.StartInfo.Arguments); | ||
#endif | ||
cameraCommand.Start(); | ||
} | ||
catch (Exception e) | ||
{ | ||
Console.WriteLine(e.Message); | ||
return; | ||
} | ||
|
||
await Task.WhenAny(eventHandled.Task, Task.Delay(duration * 1000)); | ||
} | ||
} | ||
|
||
private void VideoRecorded(object sender, EventArgs e) | ||
{ | ||
eventHandled.TrySetResult(true); | ||
} | ||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace skullOS.HardwareServices.Interfaces | ||
{ | ||
public interface IBuzzerService | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace skullOS.HardwareServices.Interfaces | ||
{ | ||
public interface ICameraService | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace skullOS.HardwareServices.Interfaces | ||
{ | ||
public interface ILedService | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace skullOS.HardwareServices.Interfaces | ||
{ | ||
public interface IMicrophoneService | ||
{ | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
skullOS.HardwareServices/Interfaces/IProgrammableLedService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace skullOS.HardwareServices.Interfaces | ||
{ | ||
public interface IProgrammableLedService | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace skullOS.HardwareServices.Interfaces | ||
{ | ||
public interface ISpeakerService | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using skullOS.HardwareServices.Interfaces; | ||
|
||
namespace skullOS.HardwareServices | ||
{ | ||
public class LedService : ILedService | ||
{ | ||
public Dictionary<string, int> LEDs { get; private set; } | ||
|
||
public LedService(Dictionary<string, int> leds) | ||
{ | ||
LEDs = leds; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Iot.Device.Media; | ||
using skullOS.HardwareServices.Interfaces; | ||
|
||
namespace skullOS.HardwareServices | ||
{ | ||
public class MicrophoneService : IMicrophoneService | ||
{ | ||
public SoundDevice Microphone { get; private set; } | ||
|
||
public MicrophoneService(SoundConnectionSettings micSettings = null) | ||
{ | ||
micSettings ??= new SoundConnectionSettings(); | ||
Microphone = SoundDevice.Create(micSettings); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Iot.Device.Ws28xx; | ||
using skullOS.HardwareServices.Interfaces; | ||
using System.Device.Spi; | ||
|
||
namespace skullOS.HardwareServices | ||
{ | ||
public class ProgrammableLedService : IProgrammableLedService | ||
{ | ||
public Ws2812b LedArray { get; private set; } | ||
|
||
public ProgrammableLedService(SpiDevice spi, int width = 9) | ||
{ | ||
LedArray = new Ws2812b(spi, width); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Iot.Device.Media; | ||
using skullOS.HardwareServices.Interfaces; | ||
|
||
namespace skullOS.HardwareServices | ||
{ | ||
public class SpeakerService : ISpeakerService | ||
{ | ||
public SoundDevice Speaker { get; private set; } | ||
|
||
public SpeakerService(SoundConnectionSettings micSettings) | ||
{ | ||
micSettings ??= new SoundConnectionSettings(); | ||
Speaker = SoundDevice.Create(micSettings); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Iot.Device.Bindings" Version="3.1.0" /> | ||
<PackageReference Include="System.Device.Gpio" Version="3.1.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using skullOS.Core; | ||
using skullOS.HardwareServices; | ||
using skullOS.Modules.Interfaces; | ||
|
||
namespace skullOS.Modules | ||
{ | ||
public enum CameraMode | ||
{ | ||
Image, | ||
ShortVideo, | ||
ContinuousVideo | ||
} | ||
|
||
public class Camera : Module, ICameraModule | ||
{ | ||
public CameraService CameraService; | ||
public MicrophoneService MicrophoneService; | ||
public CameraMode CameraMode = CameraMode.Image; | ||
|
||
public Camera() | ||
{ | ||
FileManager.CreateSubDirectory("Captures"); | ||
CameraService = new CameraService(); | ||
MicrophoneService = new MicrophoneService(); | ||
} | ||
|
||
public void TakePicture() | ||
{ | ||
// Console.WriteLine($"({DateTime.Now}) Picture taken!"); //Maybe think about a better logging solution? | ||
CameraService.Camera.Capture($"{FileManager.GetSkullDirectory()}/Captures/{DateTime.Now:yyyyMMddHHmmss}.jpg"); | ||
} | ||
|
||
public void RecordShortVideo() | ||
{ | ||
string audioLocation = $"{FileManager.GetSkullDirectory()}/Captures/{DateTime.Now:yyyyMMddHHmmss}.mp3"; | ||
string videoLocation = $"{FileManager.GetSkullDirectory()}/Captures/{DateTime.Now:yyyyMMddHHmmss}"; | ||
CameraService.RecordVideoAsync(FileManager.GetSkullDirectory() + "/Captures", 30); | ||
MicrophoneService.Microphone.Record(30, audioLocation); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace skullOS.Modules | ||
{ | ||
internal class Downlink | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace skullOS.Modules.Interfaces | ||
{ | ||
internal interface ICameraModule | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace skullOS.Modules | ||
{ | ||
public abstract class Module | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace skullOS.Modules | ||
{ | ||
internal class Prop | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace skullOS.Modules | ||
{ | ||
internal class QrCodeReader | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace skullOS.Modules | ||
{ | ||
internal class Uplink | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\skullOS.HardwareServices\skullOS.HardwareServices.csproj" /> | ||
<ProjectReference Include="..\skullOS.Core\skullOS.Core.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |