Compare commits
3 commits
82d7ab5e6f
...
83bba359cb
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
83bba359cb | ||
|
|
76f8f4a777 | ||
|
|
1ea476ef21 |
|
|
@ -19,7 +19,13 @@ namespace Proculite.GpioRest.Controllers
|
||||||
if (!ModelState.IsValid)
|
if (!ModelState.IsValid)
|
||||||
return BadRequest();
|
return BadRequest();
|
||||||
|
|
||||||
return Ok(_gpioService.CurrentPinValue(pinNumber).ToString());
|
return Ok(_gpioService.PinValueModelOfPin(pinNumber));
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("pin-value")]
|
||||||
|
public IActionResult AllPinValues()
|
||||||
|
{
|
||||||
|
return Ok(_gpioService.StateOfAllPins());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
14
Proculite.GpioRest/Models/PinValueModel.cs
Normal file
14
Proculite.GpioRest/Models/PinValueModel.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using System.Device.Gpio;
|
using System.Device.Gpio;
|
||||||
|
using Proculite.GpioRest.Models;
|
||||||
|
|
||||||
namespace Proculite.GpioRest.Services
|
namespace Proculite.GpioRest.Services
|
||||||
{
|
{
|
||||||
|
|
@ -40,7 +41,6 @@ namespace Proculite.GpioRest.Services
|
||||||
}
|
}
|
||||||
|
|
||||||
_gpioController.OpenPin(pin, pinMode, PinValue.Low);
|
_gpioController.OpenPin(pin, pinMode, PinValue.Low);
|
||||||
Thread.Sleep(200);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -48,5 +48,15 @@ namespace Proculite.GpioRest.Services
|
||||||
{
|
{
|
||||||
return _gpioController.Read(pinNumber);
|
return _gpioController.Read(pinNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PinValueModel PinValueModelOfPin(int pinNumber)
|
||||||
|
{
|
||||||
|
return new PinValueModel(pinNumber, _gpioController.Read(pinNumber));
|
||||||
|
}
|
||||||
|
|
||||||
|
public PinValueModel[] StateOfAllPins()
|
||||||
|
{
|
||||||
|
return _pins.Select(PinValueModelOfPin).ToArray();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue