-
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.
Merge pull request #53 from David032/51-megacon-birmingham-2024-integ…
…ration 51 MegaCon Birmingham 2024 Integration
- Loading branch information
Showing
29 changed files
with
313 additions
and
126 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|Env Sensor|Grey |x|x| | | | ||
|Env Sensor|Green |x|x|White |RGB Array | | ||
|Env Sensor|Blue |x|x|Grey |RGB Array | | ||
| | |x|x| | | | ||
|Env Sensor|Purple|x|x| | | | ||
| | |x|x| | | | ||
| | |x|x|Brown |Power LED | | ||
| | |x|x|Red |Power LED | | ||
| | |x|x| | | | ||
|RGB Array |Black |x|x|Yellow |Button | | ||
| | |x|x|Yellow |Button | | ||
| | |x|x| | | | ||
|Buzzer |Black |x|x| | | | ||
| | |x|x| | | | ||
| | |x|x|Orange |Notification LED| | ||
| | |x|x|Yellow |Notification LED| | ||
|Buzzer |White |x|x|Green |Warning LED | | ||
| | |x|x|Dark Blue|Warning LED | | ||
|White LED |Red |x|x| | | | ||
|White LED |Brown |x|x| | | |
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
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 |
---|---|---|
@@ -1,56 +1,91 @@ | ||
using Iot.Device.Camera.Settings; | ||
using Iot.Device.Camera.Settings; | ||
using Iot.Device.Common; | ||
using Iot.Device.Media; | ||
using skullOS.HardwareServices.Exceptions; | ||
using skullOS.HardwareServices.Interfaces; | ||
using System.Diagnostics; | ||
|
||
namespace skullOS.HardwareServices | ||
{ | ||
public class CameraService : ICameraService | ||
{ | ||
public VideoDevice Camera { get; private set; } | ||
private ProcessSettings _processSettings; | ||
int xResolution; | ||
int yResolution; | ||
|
||
private readonly ProcessSettings _processSettings; | ||
|
||
public CameraService(int x = 2592, int y = 1944) | ||
{ | ||
_processSettings = ProcessSettingsFactory.CreateForLibcamerastill(); | ||
xResolution = x; | ||
yResolution = y; | ||
} | ||
|
||
public CameraService(VideoConnectionSettings? cameraSettings = null) | ||
//Why are we back to hard-calling libcamera again?! :( | ||
//Remember that this needs rpicam-apps full to be installed(lite os doesn't come with it) | ||
//TODO: Still needs quality setting | ||
public async Task<string> RecordShortVideoAsync(string fileLocation, bool useMic) | ||
{ | ||
cameraSettings ??= new(busId: 0, captureSize: (2592, 1944), pixelFormat: VideoPixelFormat.JPEG); | ||
Camera = VideoDevice.Create(cameraSettings); | ||
Camera.Settings.HorizontalFlip = true; | ||
Camera.Settings.VerticalFlip = true; | ||
try | ||
{ | ||
using Process videoRecording = new(); | ||
string args = string.Empty; | ||
if (useMic) | ||
{ | ||
args = " --codec libav --hflip --vflip --libav-audio --width 1920 --height 1080 -t 30000 -o " + $"{fileLocation}" | ||
+ DateTime.Now.ToString("yyyyMMddHHmmss") + ".mp4"; | ||
} | ||
else | ||
{ | ||
args = " --codec libav --hflip --vflip --width 1920 --height 1080 -t 30000 -o " + $"{fileLocation}" | ||
+ DateTime.Now.ToString("yyyyMMddHHmmss") + ".mp4"; | ||
} | ||
videoRecording.StartInfo.UseShellExecute = false; | ||
videoRecording.StartInfo.FileName = "libcamera-vid"; | ||
videoRecording.StartInfo.Arguments = args; | ||
videoRecording.EnableRaisingEvents = true; | ||
#if DEBUG | ||
await Console.Out.WriteLineAsync("Running:"); | ||
await Console.Out.WriteLineAsync(videoRecording.StartInfo.FileName + videoRecording.StartInfo.Arguments); | ||
#endif | ||
videoRecording.Start(); | ||
await Task.WhenAny(Task.Delay(30000)); | ||
} | ||
catch (CameraErrorException e) | ||
{ | ||
await Console.Out.WriteLineAsync(e.Message); | ||
return "Camera errored when recording video!"; | ||
} | ||
|
||
_processSettings = ProcessSettingsFactory.CreateForLibcamerastill(); | ||
return $"({DateTime.Now}) Short video recorded!"; | ||
} | ||
|
||
public async Task<string> TakePictureAsync(string fileLocation, int x = 2592, int y = 1944) | ||
public async Task<string> TakePictureAsync(string fileLocation) | ||
{ | ||
var builder = new CommandOptionsBuilder() | ||
.WithTimeout(1) | ||
.WithVflip() | ||
.WithHflip() | ||
.WithPictureOptions(quality: 100) | ||
.WithResolution(x, y); | ||
.WithResolution(xResolution, yResolution); | ||
var args = builder.GetArguments(); | ||
|
||
_processSettings = ProcessSettingsFactory.CreateForLibcamerastill(); | ||
using var proc = new ProcessRunner(_processSettings); | ||
Console.WriteLine("Using the following command line:"); | ||
Console.WriteLine(proc.GetFullCommandLine(args)); | ||
Console.WriteLine(); | ||
|
||
var timestamp = DateTime.Now.ToString("yyyyMMddHHmmss"); | ||
string? filename = fileLocation + timestamp + ".jpg"; | ||
//string? filename = $"{DateTime.Now:yyyyMMddHHmmss}.jpg"; //Fakename | ||
|
||
try | ||
{ | ||
using var file = File.OpenWrite(filename); | ||
await proc.ExecuteAsync(args, file); | ||
} | ||
catch (Exception) | ||
{ | ||
await Console.Out.WriteLineAsync("Cam errored!"); | ||
await Console.Out.WriteLineAsync("Cam errored when taking picture!"); | ||
} | ||
|
||
return filename; | ||
return $"({DateTime.Now}) Picture taken!"; | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
skullOS.HardwareServices/Exceptions/CameraErrorException.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,14 @@ | ||
namespace skullOS.HardwareServices.Exceptions | ||
{ | ||
public enum CameraMode | ||
{ | ||
Picture, | ||
ShortVideo, | ||
LongVideo | ||
} | ||
|
||
public class CameraErrorException(string message, CameraMode modeWhenFailed) : Exception(message) | ||
Check warning on line 10 in skullOS.HardwareServices/Exceptions/CameraErrorException.cs GitHub Actions / build (ubuntu-latest)
|
||
{ | ||
public CameraMode Mode; | ||
} | ||
} |
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
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
Oops, something went wrong.