Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2 Buzzer API #8

Merged
merged 2 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -366,3 +366,5 @@ API/Build/
GrowHAT/GrowHatSample/GrowHatSample/

API/API-Dev/

API/Builds/
31 changes: 31 additions & 0 deletions API/Controllers/BuzzerController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Iot.Device.GrowHat;
using Microsoft.AspNetCore.Mvc;

namespace API.Controllers
{
[Route("api/Buzzer")]
[ApiController]
public class BuzzerController(ILogger<BuzzerController> logger, IGrowHat Board) : ControllerBase
{
ILogger<BuzzerController> logger = logger;
IGrowHat Board = Board;

[HttpPost("PlayBuzzerTone")]
public void PlayBuzzerTone(double frequency, int seconds)
{
Board.GetBuzzer().PlayTone(frequency, (seconds * 1000));
}

[HttpPost("TurnBuzzerOn")]
public void TurnBuzzerOn(double frequency)
{
Board.GetBuzzer().StartPlaying(frequency);
}

[HttpPost("TurnBuzzerOff")]
public void TurnBuzzerOff()
{
Board.GetBuzzer().StopPlaying();
}
}
}
5 changes: 5 additions & 0 deletions GrowHAT/GrowHAT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@

public GrowHatSoilSensor GetSoilSensor(SoilSensorPin Sensor)
{
return Sensor switch

Check warning on line 170 in GrowHAT/GrowHAT.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.

Check warning on line 170 in GrowHAT/GrowHAT.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.
{
SoilSensorPin.S1 => SoilSensor1,
SoilSensorPin.S2 => SoilSensor2,
Expand All @@ -175,5 +175,10 @@
_ => null,
};
}

public Buzzer.Buzzer GetBuzzer()
{
return HatBuzzer;

Check warning on line 181 in GrowHAT/GrowHAT.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.

Check warning on line 181 in GrowHAT/GrowHAT.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.
}
}
}
1 change: 1 addition & 0 deletions GrowHAT/IGrowHat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public interface IGrowHat
{
public List<GrowHatSoilSensor> GetSoilSensors();
public GrowHatSoilSensor GetSoilSensor(SoilSensorPin Sensor);
public Buzzer.Buzzer GetBuzzer();

}
}
Loading