|
|
@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Mvc;
|
|
|
|
using Swashbuckle.AspNetCore.Annotations;
|
|
|
|
using Swashbuckle.AspNetCore.Annotations;
|
|
|
|
using System;
|
|
|
|
using System;
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
|
|
|
using System.Threading;
|
|
|
|
|
|
|
|
|
|
|
|
namespace IoTNode.Controllers
|
|
|
|
namespace IoTNode.Controllers
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -18,51 +19,19 @@ namespace IoTNode.Controllers
|
|
|
|
this._deviceService = deviceService;
|
|
|
|
this._deviceService = deviceService;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[HttpGet, Route("/[controller]/[action]"), SwaggerOperation("亮度")]
|
|
|
|
|
|
|
|
public ApiResponse SetBrightness([SwaggerParameter("设备编号"), Required] string number, [SwaggerParameter("亮度"), Range(0, 255), Required] int brightness)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (number is null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw new ArgumentNullException(nameof(number));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var values = number.Split('-');
|
|
|
|
|
|
|
|
this._deviceService.X83(values[0], values[1], (byte)brightness);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ex.PrintStack();
|
|
|
|
|
|
|
|
return ApiResponse.Error(ex.Message);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return ApiResponse.AsyncSuccess();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[HttpGet, Route("/[controller]/[action]"), SwaggerOperation("色度")]
|
|
|
|
|
|
|
|
public ApiResponse SetColor([SwaggerParameter("设备编号"), Required] string number, [SwaggerParameter("色调"), Range(0, 255), Required] int hue, [SwaggerParameter("饱和度"), Range(0, 255), Required] int saturation)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var values = number.Split('-');
|
|
|
|
|
|
|
|
this._deviceService.X84(values[0], values[1], (byte)hue, (byte)saturation);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ex.PrintStack();
|
|
|
|
|
|
|
|
return ApiResponse.Error(ex.Message);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return ApiResponse.AsyncSuccess();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[HttpGet, Route("/[controller]/[action]"), SwaggerOperation("设置")]
|
|
|
|
[HttpGet, Route("/[controller]/[action]"), SwaggerOperation("设置")]
|
|
|
|
public ApiResponse Change([SwaggerParameter("设备编号"), Required] string number, [SwaggerParameter("亮度"), Range(0, 255), Required] int brightness, [SwaggerParameter("色调"), Required][Range(0, 255)] int hue, [SwaggerParameter("饱和度"), Range(0, 255), Required] int saturation)
|
|
|
|
public ApiResponse Change([SwaggerParameter("设备编号"), Required] string number, [SwaggerParameter("亮度"), Range(0, 255), Required] int brightness, [SwaggerParameter("色调"), Required][Range(0, 255)] int hue, [SwaggerParameter("饱和度"), Range(0, 255), Required] int saturation)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var values = number.Split('-');
|
|
|
|
var values = number.Split('-');
|
|
|
|
this._deviceService.X84(values[0], values[1], (byte)hue, (byte)saturation);
|
|
|
|
var sn = values[0];
|
|
|
|
this._deviceService.X83(values[0], values[1], (byte)brightness);
|
|
|
|
var ieee = values[1];
|
|
|
|
|
|
|
|
this._deviceService.X84(sn, ieee, (byte)hue, (byte)saturation);
|
|
|
|
|
|
|
|
this._deviceService.X83(sn, ieee, (byte)brightness);
|
|
|
|
|
|
|
|
Thread.Sleep(100);
|
|
|
|
|
|
|
|
this._deviceService.X87(sn, ieee);
|
|
|
|
|
|
|
|
this._deviceService.X86(sn, ieee);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
{
|
|
|
|