diff --git a/projects/IoTNode/DeviceServices/FBee/Controllers/ColorLightController.cs b/projects/IoTNode/DeviceServices/FBee/Controllers/ColorLightController.cs index 4c0033f0..325da290 100644 --- a/projects/IoTNode/DeviceServices/FBee/Controllers/ColorLightController.cs +++ b/projects/IoTNode/DeviceServices/FBee/Controllers/ColorLightController.cs @@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Mvc; using Swashbuckle.AspNetCore.Annotations; using System; using System.ComponentModel.DataAnnotations; +using System.Threading; namespace IoTNode.Controllers { @@ -18,51 +19,19 @@ namespace IoTNode.Controllers 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("设置")] 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 { var values = number.Split('-'); - this._deviceService.X84(values[0], values[1], (byte)hue, (byte)saturation); - this._deviceService.X83(values[0], values[1], (byte)brightness); + var sn = values[0]; + 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) { diff --git a/projects/IoTNode/DeviceServices/FBee/FBeeService.cs b/projects/IoTNode/DeviceServices/FBee/FBeeService.cs index 0295c8a4..eb04102e 100644 --- a/projects/IoTNode/DeviceServices/FBee/FBeeService.cs +++ b/projects/IoTNode/DeviceServices/FBee/FBeeService.cs @@ -422,7 +422,7 @@ namespace IoTNode.DeviceServices.FBee //deviceRepo.SaveChanges(); //var deviceDto = device.To(); //this.SendToServer(Methods.EditDevice, deviceDto); - //this.UpdateStatus(device); + this.UpdateStatus(device); } else { diff --git a/projects/IoTNode/wwwroot/js/home/index.js b/projects/IoTNode/wwwroot/js/home/index.js index f58a38ba..57a264e5 100644 --- a/projects/IoTNode/wwwroot/js/home/index.js +++ b/projects/IoTNode/wwwroot/js/home/index.js @@ -1,4 +1,22 @@ -var app = new Vue({ +PubSub.subscribes = function (events, action) { + if (!events || !action) { + return; + } + for (var i = 0; i < events.length; i++) { + PubSub.subscribe(events[i], function (m, d) { action(m, d); }); + } +} + +PubSub.unsubscribes = function (events) { + if (!events) { + return; + } + for (var i = 0; i < events.length; i++) { + PubSub.unsubscribe(events[i]); + } +} +// +var app = new Vue({ el: '#app', data() { return { diff --git a/projects/Platform/Views/Home/Index.cshtml b/projects/Platform/Views/Home/Index.cshtml index e55544e6..cc2b2e6a 100644 --- a/projects/Platform/Views/Home/Index.cshtml +++ b/projects/Platform/Views/Home/Index.cshtml @@ -10,6 +10,7 @@ { @section scripts{ + } diff --git a/projects/Platform/wwwroot/components/devices/lamp.html b/projects/Platform/wwwroot/components/devices/lamp.html index e8fd4214..f7a17fb2 100644 --- a/projects/Platform/wwwroot/components/devices/lamp.html +++ b/projects/Platform/wwwroot/components/devices/lamp.html @@ -13,7 +13,7 @@
-
+
@@ -30,9 +30,20 @@
- - - + + + + + + + + + + + + + +
色调:
饱和度:
亮度:
@@ -47,7 +58,7 @@ }, methods: { changeHue: function (hue) { - execApi(this.device.number, '/ColorLight/Change', 'hue=' + hue + '&saturation=' + this.saturation + '&brightness=' + this.brightness); + execApi(this.device.number, '/ColorLight/Change', 'hue=' + hue + '&saturation=' + 254 + '&brightness=' + this.brightness); }, changeSaturation: function (saturation) { execApi(this.device.number, '/ColorLight/Change', 'hue=' + this.hue + '&saturation=' + saturation + '&brightness=' + this.brightness); @@ -76,12 +87,17 @@ return result; }, hsl: function () { - var h = Math.round(parseInt(this.hue || 128) * 360 / 255); + var h = Math.round(parseInt(this.hue || 128) * 360 / 254); var s = Math.round(parseInt(this.saturation || 128) * 100 / 254); var l = Math.round(parseInt(this.brightness || 128) * 100 / 254); - var result = 'hsl(' + h + ',' + s + '%,' + l + '%);'; - console.log('hsl:' + result); + var result = 'hsl(' + h + ',' + s + '%,' + l + '%)'; + console.warn('raw:'+this.hue+' '+this.saturation+' '+this.brightness); + console.warn('hsl:' + result); return result; + }, + color: function () { + var h = Math.round(parseInt(this.hue || 128) * 360 / 254); + return 'hsl(' + h + ',100%,0%)'; } } }; diff --git a/projects/Platform/wwwroot/js/app.js b/projects/Platform/wwwroot/js/app.js index 03956ea5..b09ba863 100644 --- a/projects/Platform/wwwroot/js/app.js +++ b/projects/Platform/wwwroot/js/app.js @@ -91,7 +91,7 @@ function getIoTDataDescription(device, name) { //调用API function execApi(number, method, query) { loading.show(); - axios.post(config.service('platform') + 'api/v1/api/execApi', { connectionId, number, method, query }) + axios.post(config.service('platform/api/v1/api/execApi'), { connectionId, number, method, query }) .then(function (response) { }) .catch(function (error) { @@ -104,7 +104,7 @@ function execApi(number, method, query) { //调用场景 function execScene(id) { loading.show(); - axios.post(config.service('platform') + 'api/v1/api/execScene', { id, connectionId }) + axios.post(config.service('platform/api/v1/api/execScene'), { id, connectionId }) .then(function (response) { console.log(response); }) diff --git a/projects/Platform/wwwroot/js/config.js b/projects/Platform/wwwroot/js/config.js index 4ce23045..0ca11151 100644 --- a/projects/Platform/wwwroot/js/config.js +++ b/projects/Platform/wwwroot/js/config.js @@ -10,6 +10,6 @@ const config = { }, gateway: 'http://example_gateway_host/', service: function (service) { - return (this.crossDomain ? this.gateway : '/') + service + '/'; + return (this.crossDomain ? this.gateway : '/') + service; } }; \ No newline at end of file