diff --git a/Proculite.GpioRest/Controllers/GpioController.cs b/Proculite.GpioRest/Controllers/GpioController.cs new file mode 100644 index 0000000..07ab667 --- /dev/null +++ b/Proculite.GpioRest/Controllers/GpioController.cs @@ -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)); + } + } +} \ No newline at end of file diff --git a/Proculite.GpioRest/Services/GpioService.cs b/Proculite.GpioRest/Services/GpioService.cs index b2e89bb..a680d71 100644 --- a/Proculite.GpioRest/Services/GpioService.cs +++ b/Proculite.GpioRest/Services/GpioService.cs @@ -42,5 +42,10 @@ namespace Proculite.GpioRest.Services _gpioController.OpenPin(pin, pinMode, PinValue.Low); } } + + public PinValue CurrentPinValue(int pinNumber) + { + return _gpioController.Read(pinNumber); + } } }