Created an endpoint which reads current value of a pin.

This commit is contained in:
Filip Strajnar 2024-09-24 23:58:37 +02:00
parent 96c7e17da0
commit 95ae6220bb
2 changed files with 30 additions and 0 deletions

View file

@ -0,0 +1,25 @@
using Microsoft.AspNetCore.Mvc;
using Proculite.GpioRest.Services;
namespace Proculite.GpioRest.Controllers
{
[Route("/gpio")]
public class GpioController : Controller
{
private readonly GpioService _gpioService;
public GpioController(GpioService gpioService)
{
_gpioService = gpioService;
}
[HttpGet("pin-value/{pinNumber}")]
public IActionResult PinValue(int pinNumber)
{
if(!ModelState.IsValid)
return BadRequest();
return Ok(_gpioService.CurrentPinValue(pinNumber));
}
}
}

View file

@ -42,5 +42,10 @@ namespace Proculite.GpioRest.Services
_gpioController.OpenPin(pin, pinMode, PinValue.Low);
}
}
public PinValue CurrentPinValue(int pinNumber)
{
return _gpioController.Read(pinNumber);
}
}
}