Created an endpoint which reads current value of a pin.
This commit is contained in:
parent
96c7e17da0
commit
95ae6220bb
25
Proculite.GpioRest/Controllers/GpioController.cs
Normal file
25
Proculite.GpioRest/Controllers/GpioController.cs
Normal 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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -42,5 +42,10 @@ namespace Proculite.GpioRest.Services
|
||||||
_gpioController.OpenPin(pin, pinMode, PinValue.Low);
|
_gpioController.OpenPin(pin, pinMode, PinValue.Low);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PinValue CurrentPinValue(int pinNumber)
|
||||||
|
{
|
||||||
|
return _gpioController.Read(pinNumber);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue