Skip to content

Commit

Permalink
#17 API Work
Browse files Browse the repository at this point in the history
Tried to add the camera and buzzer to the api, but it didn't like something
  • Loading branch information
David032 committed Nov 26, 2023
1 parent 3897ea9 commit 8c1dbed
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 8 deletions.
1 change: 1 addition & 0 deletions ServoSkull.sln
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "skullOS.API", "skullOS.API\skullOS.API.csproj", "{5E1EC385-4B61-4E8C-82C7-46695A33AC72}"
ProjectSection(ProjectDependencies) = postProject
{464B162B-62FC-49CC-A6AB-72DBE959DD8C} = {464B162B-62FC-49CC-A6AB-72DBE959DD8C}
{DE800E5A-E68B-4BCA-AC99-4BC9DB44FD56} = {DE800E5A-E68B-4BCA-AC99-4BC9DB44FD56}
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "skullOS.Modules", "skullOS.Modules\skullOS.Modules.csproj", "{DE800E5A-E68B-4BCA-AC99-4BC9DB44FD56}"
Expand Down
28 changes: 28 additions & 0 deletions skullOS.API/Controllers/BuzzerController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Microsoft.AspNetCore.Mvc;
using skullOS.Modules.Interfaces;
using static skullOS.Modules.BuzzerLibrary;

namespace skullOS.API.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class BuzzerController : ControllerBase
{
private readonly ILogger<BuzzerController> _logger;
private IBuzzerModule _module;

public BuzzerController(ILogger<BuzzerController> logger, IBuzzerModule buzzer)
{
_logger = logger;
_module = buzzer;
}

public string PlayTune(string tune)
{
Tunes tuneToPlay = (Tunes)Enum.Parse(typeof(Tunes), tune);
_module.PlayTune(tuneToPlay);
return "Playing " + tuneToPlay.ToString();
}

}
}
33 changes: 33 additions & 0 deletions skullOS.API/Controllers/CameraController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Microsoft.AspNetCore.Mvc;
using skullOS.Modules.Interfaces;

namespace skullOS.API.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class CameraController : ControllerBase
{
private readonly ILogger<CameraController> _logger;
private ICameraModule _module;

public CameraController(ILogger<CameraController> logger, ICameraModule camera)
{
_logger = logger;
_module = camera;
}

[HttpGet]
public string TakePicture()
{
_module.TakePicture();
return "Picture Taken!";
}

[HttpGet]
public string RecordVideo()
{
_module.RecordShortVideo();
return "Video Recorded!";
}
}
}
10 changes: 9 additions & 1 deletion skullOS.API/Runner.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace skullOS.API
using skullOS.Modules;
using skullOS.Modules.Interfaces;

namespace skullOS.API
{
public class Runner
{
Expand All @@ -14,6 +17,11 @@ public Task StartWebAPI(string[] args)
builder.Services.AddSwaggerGen();
builder.WebHost.UseUrls("http://*:5000;https://*:5001");

#region Skull Modules
builder.Services.AddScoped<ICameraModule, Camera>();
builder.Services.AddScoped<IBuzzerModule, Buzzer>();
#endregion


var app = builder.Build();

Expand Down
1 change: 1 addition & 0 deletions skullOS.API/skullOS.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

<ItemGroup>
<ProjectReference Include="..\skullOS.Core\skullOS.Core.csproj" />
<ProjectReference Include="..\skullOS.Modules\skullOS.Modules.csproj" />
</ItemGroup>

</Project>
6 changes: 3 additions & 3 deletions skullOS.Modules/Buzzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public static class BuzzerStructures
/// <summary>
/// Represents all twelve notes.
/// </summary>
internal enum Note
public enum Note
{
C = 1,
Db = 2,
Expand All @@ -280,7 +280,7 @@ internal enum Note
/// <summary>
/// Represents music octave.
/// </summary>
internal enum Octave
public enum Octave
{
First = 1,
Second = 2,
Expand All @@ -295,7 +295,7 @@ internal enum Octave
/// <summary>
/// Represents music note duration.
/// </summary>
internal enum Duration
public enum Duration
{
Whole = 1,
Half = 2,
Expand Down
3 changes: 2 additions & 1 deletion skullOS.Modules/Interfaces/IBuzzerModule.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace skullOS.Modules.Interfaces
{
internal interface IBuzzerModule
public interface IBuzzerModule
{
void PlayTune(BuzzerLibrary.Tunes tuneToPlay);
}
}
4 changes: 3 additions & 1 deletion skullOS.Modules/Interfaces/ICameraModule.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
namespace skullOS.Modules.Interfaces
{
internal interface ICameraModule
public interface ICameraModule
{
void RecordShortVideo();
void TakePicture();
}
}
2 changes: 1 addition & 1 deletion skullOS/Data/Modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ Downlink=True
Uplink=True
Prop=True
QrCodeReader=True

Buzzer=True
7 changes: 6 additions & 1 deletion skullOS/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,13 @@ static void Run(bool shouldCreateDirectory = true)
logger.LogMessage("Enabling API...");
if (bool.Parse(useAPI))
{
string[] arguments = new string[1];
#if DEBUG
arguments[0] = "environment=development";
logger.LogMessage("Set first argument to " + arguments[0]);
#endif
Runner apiRunner = new();
Task apiStatus = apiRunner.StartWebAPI(null);
Task apiStatus = apiRunner.StartWebAPI(arguments);
deviceManager.AttachApi(apiStatus);
logger.LogMessage("API enabled");
}
Expand Down

0 comments on commit 8c1dbed

Please sign in to comment.