Compare commits

...

3 commits

3 changed files with 32 additions and 2 deletions

View file

@ -19,7 +19,13 @@ namespace Proculite.GpioRest.Controllers
if (!ModelState.IsValid)
return BadRequest();
return Ok(_gpioService.CurrentPinValue(pinNumber).ToString());
return Ok(_gpioService.PinValueModelOfPin(pinNumber));
}
[HttpGet("pin-value")]
public IActionResult AllPinValues()
{
return Ok(_gpioService.StateOfAllPins());
}
}
}

View file

@ -0,0 +1,14 @@
using System.Device.Gpio;
using System.Text.Json.Serialization;
namespace Proculite.GpioRest.Models
{
public class PinValueModel(int pinNumber, PinValue pinValue)
{
public int PinNumber { get; set; } = pinNumber;
[JsonIgnore]
public PinValue PinValue { get; set; } = pinValue;
public int Value => PinValue == PinValue.High ? 1 : 0;
}
}

View file

@ -1,4 +1,5 @@
using System.Device.Gpio;
using Proculite.GpioRest.Models;
namespace Proculite.GpioRest.Services
{
@ -40,7 +41,6 @@ namespace Proculite.GpioRest.Services
}
_gpioController.OpenPin(pin, pinMode, PinValue.Low);
Thread.Sleep(200);
}
}
@ -48,5 +48,15 @@ namespace Proculite.GpioRest.Services
{
return _gpioController.Read(pinNumber);
}
public PinValueModel PinValueModelOfPin(int pinNumber)
{
return new PinValueModel(pinNumber, _gpioController.Read(pinNumber));
}
public PinValueModel[] StateOfAllPins()
{
return _pins.Select(PinValueModelOfPin).ToArray();
}
}
}