From 90fff1a56d32b2eebe7106dc659e0c2c0bf79f60 Mon Sep 17 00:00:00 2001 From: David Kelly Date: Sun, 17 Nov 2024 18:13:23 +0000 Subject: [PATCH] Gen 3 SkullOS (#70) * Gen 3 Skull Action Button = GPIO 4, Change mode button = GPIO 14 Heartbeat light = GPIO 26 Activity Light = GPIO 13 Buzzer = GPIO 12 Now uses the new camera system for videos, but it doesn't appear to be very good --- .../skullOS.HardwareServices/CameraService.cs | 45 ++++++++----------- .../skullOS.Modules/Data/CameraSettings.txt | 2 +- Source/skullOS.Modules/Data/PropSettings.txt | 2 +- Source/skullOS/InputManager.cs | 4 +- 4 files changed, 22 insertions(+), 31 deletions(-) diff --git a/Source/skullOS.HardwareServices/CameraService.cs b/Source/skullOS.HardwareServices/CameraService.cs index 7f6e70f..ce032e1 100644 --- a/Source/skullOS.HardwareServices/CameraService.cs +++ b/Source/skullOS.HardwareServices/CameraService.cs @@ -1,8 +1,6 @@ using Iot.Device.Camera.Settings; using Iot.Device.Common; -using skullOS.HardwareServices.Exceptions; using skullOS.HardwareServices.Interfaces; -using System.Diagnostics; namespace skullOS.HardwareServices { @@ -24,35 +22,28 @@ public CameraService(int x = 2592, int y = 1944) //TODO: Still needs quality setting public async Task RecordShortVideoAsync(string fileLocation, bool useMic) { + var processSettings = ProcessSettingsFactory.CreateForLibcameravid(); + var builder = new CommandOptionsBuilder() + .WithContinuousStreaming() + .WithVflip() + .WithHflip() + .WithResolution(1920, 1080); + var args = builder.GetArguments(); + using var proc = new ProcessRunner(processSettings); + + var timestamp = DateTime.Now.ToString("yyyyMMddHHmmss"); + string? filename = fileLocation + timestamp + ".h264"; + using var file = File.OpenWrite(filename); + + var task = await proc.ContinuousRunAsync(args, file); + await Task.Delay(30000); + proc.Dispose(); 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)); + await task; } - catch (CameraErrorException e) + catch (Exception) { - await Console.Out.WriteLineAsync(e.Message); - return "Camera errored when recording video!"; } return $"({DateTime.Now}) Short video recorded!"; diff --git a/Source/skullOS.Modules/Data/CameraSettings.txt b/Source/skullOS.Modules/Data/CameraSettings.txt index 1c90400..fc89f0c 100644 --- a/Source/skullOS.Modules/Data/CameraSettings.txt +++ b/Source/skullOS.Modules/Data/CameraSettings.txt @@ -1,3 +1,3 @@ UseMic=False -UseBuzzer=False +UseBuzzer=True CameraLight=6 \ No newline at end of file diff --git a/Source/skullOS.Modules/Data/PropSettings.txt b/Source/skullOS.Modules/Data/PropSettings.txt index 10600e6..518c531 100644 --- a/Source/skullOS.Modules/Data/PropSettings.txt +++ b/Source/skullOS.Modules/Data/PropSettings.txt @@ -1,3 +1,3 @@ Sounds=False -Lights=False +Lights=True Servos=False \ No newline at end of file diff --git a/Source/skullOS/InputManager.cs b/Source/skullOS/InputManager.cs index bc9704a..3200cee 100644 --- a/Source/skullOS/InputManager.cs +++ b/Source/skullOS/InputManager.cs @@ -9,8 +9,8 @@ internal class InputManager { GpioButton ActionButton; GpioButton ToggleButton; - int actionButtonPin = 24; //25 - int toggleButtonPin = 23; //26 + int actionButtonPin = 4; //25 + int toggleButtonPin = 14; //26 private Module? activeModule; List<(int, Module, string)> inputModules = []; int index = 0;