Example #1
0
        // Project takes some 3D coordinates and transform them
        // in 2D coordinates using the transformation matrix
        private ScreenPoint Project(ref DeviceComponent deviceComponent, Vector3 coord, Matrix4X4 transMat)
        {
            // transforming the coordinates
            var point = coord.TransformCoordinate(transMat);

            var z = point.Z;

            if (_farZ > z)
            {
                _farZ = z;
            }

            if (_nearZ < z)
            {
                _nearZ = z;
            }

            // The transformed coordinates will be based on coordinate system
            // starting on the center of the screen. But drawing on screen normally starts
            // from top left. We then need to transform them again to have x:0, y:0 on top left.
            var x = point.X * deviceComponent.BmpWidth + deviceComponent.BmpWidth / 2f;
            var y = -point.Y * deviceComponent.BmpHeight + deviceComponent.BmpHeight / 2f;

            return(new ScreenPoint(new Vector2Int((int)x, (int)y), z));
        }
    public void SetDevice(DeviceComponent itemComponent)
    {
        _isCable = false;

        deviceComponent = itemComponent;

        nameObject.text  = deviceComponent.deviceName;
        priceObject.text = deviceComponent.price.ToString() + " $";

        imageObject.sprite   = deviceComponent.image;
        firstEntrance.sprite = deviceComponent.firstEntrance;

        if (deviceComponent.secondEntrance != null)
        {
            secondEntrance.sprite = deviceComponent.secondEntrance;
        }
        else
        {
            secondEntrance.gameObject.SetActive(false);
        }

        if (deviceComponent.IsAvailabe)
        {
            buyButton.interactable = false;
        }
    }
Example #3
0
        //Simple draw line (use for align axis lines)
        private void DrawLine(ref DeviceComponent deviceComponent, ScreenPoint p0, ScreenPoint p1, Color color)
        {
            int deltaX = 0;
            int deltaY = 0;
            int len;

            if (p0.X == p1.X)
            {
                var diff = p1.Y - p0.Y;
                var sign = System.Math.Sign(diff);
                deltaY = sign;
                len    = diff * sign;
            }
            else if (p0.Y == p1.Y)
            {
                var diff = p1.X - p0.X;
                var sign = System.Math.Sign(diff);
                deltaX = sign;
                len    = diff * sign;
            }
            else
            {
                throw new ArgumentException($"Points {p0} and {p1} doesn't have common axis value");
            }

            var p0X = p0.X;
            var p0Y = p0.Y;

            for (var i = -1; i < len + 1; ++i)
            {
                var z = MathUtilities.Lerp(p0.Z, p1.Z, (float)i / len);
                DrawPoint(ref deviceComponent, new ScreenPoint(deltaX * i + p0X, deltaY * i + p0Y, z), color);
            }
        }
        public async Task InitializeAsync()
        {
            // Create various resources.
            Patient = await FhirClient.CreateAsync(Samples.GetJsonSample <Patient>("Patient-f001"));

            string patientReference = $"Patient/{Patient.Id}";

            Observation observationToCreate = Samples.GetJsonSample <Observation>("Observation-For-Patient-f001");

            observationToCreate.Subject.Reference = patientReference;

            Observation = await FhirClient.CreateAsync(observationToCreate);

            Encounter encounterToCreate = Samples.GetJsonSample <Encounter>("Encounter-For-Patient-f001");

            encounterToCreate.Subject.Reference = patientReference;

            Encounter = await FhirClient.CreateAsync(encounterToCreate);

            Condition conditionToCreate = Samples.GetJsonSample <Condition>("Condition-For-Patient-f001");

            conditionToCreate.Subject.Reference = patientReference;

            Condition = await FhirClient.CreateAsync(conditionToCreate);

            Device = await FhirClient.CreateAsync(Samples.GetJsonSample <Device>("Device-d1"));

            DeviceComponent deviceComponent = Samples.GetJsonSample <DeviceComponent>("DeviceComponent-For-Device-d1");

            deviceComponent.Source.Reference = $"Device/{Device.Id}";

            DeviceComponent = await FhirClient.CreateAsync(deviceComponent);
        }
Example #5
0
        private void DrawPoint(ref DeviceComponent deviceComponent, ScreenPoint p, Color?color = null, float order = 0)
        {
            var x = p.X;
            var y = p.Y;
            var z = p.Z;

            // Clipping what's visible on screen
            if (x < 0 || y < 0 || x >= deviceComponent.BmpWidth || y >= deviceComponent.BmpHeight)
            {
                return;
            }

            var rawIndex = (x + y * deviceComponent.Resolution.X);

            lock (_syncObject)
            {
                if (deviceComponent.DepthBuffer[rawIndex] > z + order)
                {
                    return; // Discard
                }

                deviceComponent.DepthBuffer[rawIndex] = z + order;

                if (color == null)
                {
                    color = ColorUtilities.Lerp(Colors.Green, Colors.Red, (z - _farZ) / (_nearZ - _farZ));
                }

                var index = rawIndex * 4;
                deviceComponent.BackBuffer[index]     = color.Value.B;
                deviceComponent.BackBuffer[index + 1] = color.Value.G;
                deviceComponent.BackBuffer[index + 2] = color.Value.R;
                deviceComponent.BackBuffer[index + 3] = color.Value.A;
            }
        }
Example #6
0
        //Draw Line by Bresenham algorithm
        private void DrawBLine(ref DeviceComponent deviceComponent, ScreenPoint p0, ScreenPoint p1, Color color)
        {
            var dx  = System.Math.Abs(p1.X - p0.X);
            var dy  = System.Math.Abs(p1.Y - p0.Y);
            var sx  = (p0.X < p1.X) ? 1 : -1;
            var sy  = (p0.Y < p1.Y) ? 1 : -1;
            var err = dx - dy;

            var x = p0.X;
            var y = p0.Y;

            var fullDistance = (p0.Point - p1.Point).GetMagnitude();

            while (true)
            {
                var z = MathUtilities.Lerp(p0.Z, p1.Z,
                                           new Vector2Int(p0.X - x, p0.Y - y).GetMagnitude() / fullDistance);
                DrawPoint(ref deviceComponent, new ScreenPoint(x, y, z), color);

                if (x == p1.X && y == p1.Y)
                {
                    break;
                }
                var e2 = 2 * err;
                if (e2 > -dy)
                {
                    err -= dy; x += sx;
                }
                if (e2 < dx)
                {
                    err += dx; y += sy;
                }
            }
        }
        public void Initialize(DeviceComponent model)
        {
            _model = model as AccelerometerDeviceComponent;

            if (_model == null)
                throw new ApplicationException();

            lblName.Text = _model.Name;
        }
        public void Initialize(DeviceComponent model)
        {
            _model = model as ButtonDeviceComponent;

            if (_model == null)
                throw new ApplicationException();

            chkButton.Text = _model.Name;
        }
Example #9
0
 private async Task SelectedComponentAsync(DeviceComponent component)
 {
     await _injectionControl.NavigateAsync <DeviceCapabilitiesViewModel>(vm => {
         vm.DeviceLabel          = DeviceLabel;
         vm.ComponentLabel       = component.Id;
         vm.PastDeviceComponents = DeviceComponents;
         vm.DeviceCapabilities   = component.Capabilities;
         vm.DeviceId             = DeviceId;
     });
 }
Example #10
0
 // Once everything is ready, we can flush the back buffer
 // into the front buffer.
 private void Present(ref DeviceComponent deviceComponent)
 {
     unsafe
     {
         byte *backBuffer = (byte *)deviceComponent.Bmp.BackBuffer;
         for (int i = 0, len = deviceComponent.BackBuffer.Length; i < len; ++i)
         {
             // ReSharper disable once PossibleNullReferenceException
             backBuffer[i] = deviceComponent.BackBuffer[i];
         }
     }
 }
Example #11
0
        public async Task InitializeAsync()
        {
            // Create various resources.
            _patient = await CreateResourceAsync(Samples.GetJsonSample <Patient>("Patient-f001"));

            _observation = await CreateResourceAsync(Samples.GetJsonSample <Observation>("Observation-For-Patient-f001"));

            _encounter = await CreateResourceAsync(Samples.GetJsonSample <Encounter>("Encounter-For-Patient-f001"));

            _device = await CreateResourceAsync(Samples.GetJsonSample <Device>("Device-d1"));

            _deviceComponent = await CreateResourceAsync(Samples.GetJsonSample <DeviceComponent>("DeviceComponent-For-Device-d1"));

            _condition = await CreateResourceAsync(Samples.GetJsonSample <Condition>("Condition-For-Patient-f001"));
        }
    public static Dictionary <string, DeviceComponent> GetAllDevices()
    {
        SetDevicePrefabList();

        foreach (GameObject g in _devicePrefabs)
        {
            DeviceComponent componentComponent = g.GetComponentInChildren <DeviceComponent>(true);
            if (!_deviceList.ContainsKey(DeviceComponentHelper.DeviceName(componentComponent.deviceType)))
            {
                _deviceList.Add(DeviceComponentHelper.DeviceName(componentComponent.deviceType), componentComponent);
            }
        }

        return(_deviceList);
    }
Example #13
0
        private void DrawTriangle(ref DeviceComponent deviceComponent, ScreenPoint p1, ScreenPoint p2, ScreenPoint p3, Color color)
        {
            // at first sort the three vertices by y-coordinate ascending so p1 is the topmost vertex
            if (p1.Point.Y > p2.Point.Y)
            {
                var temp = p2;
                p2 = p1;
                p1 = temp;
            }

            if (p2.Point.Y > p3.Point.Y)
            {
                var temp = p2;
                p2 = p3;
                p3 = temp;
            }

            if (p1.Point.Y > p2.Point.Y)
            {
                var temp = p2;
                p2 = p1;
                p1 = temp;
            }

            // here we know that p1.y <= p2.y <= p3.y
            // check for trivial case of bottom-flat triangle
            if (p2.Point.Y == p3.Point.Y)
            {
                FillBottomFlatTriangle(ref deviceComponent, p1, p2, p3, color);
            }
            // check for trivial case of top-flat triangle
            else if (p1.Point.Y == p2.Point.Y)
            {
                FillTopFlatTriangle(ref deviceComponent, p1, p2, p3, color);
            }
            else
            {
                // general case - split the triangle in a topflat and bottom-flat one
                var splitPoint = new Vector2Int(
                    (int)(p1.Point.X + ((float)(p2.Point.Y - p1.Point.Y) / (p3.Y - p1.Y)) * (p3.X - p1.X)), p2.Y);
                var v4 = new ScreenPoint(splitPoint, MathUtilities.Lerp(p3.Z, p1.Z,
                                                                        (splitPoint - p3.Point).GetMagnitude() /
                                                                        (p1.Point - p3.Point).GetMagnitude()));

                FillBottomFlatTriangle(ref deviceComponent, p1, p2, v4, color);
                FillTopFlatTriangle(ref deviceComponent, p2, v4, p3, color);
            }
        }
    public static void AddDeviceSelection(DeviceComponent component)
    {
        if (_selectedDevices == null || _selectedDevices.Count == 0)
        {
            _selectedDevices = new List <GameObject>();
        }

        foreach (GameObject g in _devicePrefabs)
        {
            if ((DeviceComponentHelper.DeviceName(g.GetComponentInChildren <DeviceComponent>(true).deviceType) ==
                 DeviceComponentHelper.DeviceName(component.deviceType)) && !_selectedDevices.Contains(g))
            {
                _selectedDevices.Add(g);
                break;
            }
        }
    }
Example #15
0
        private void FillTopFlatTriangle(ref DeviceComponent deviceComponent, ScreenPoint v1, ScreenPoint v2, ScreenPoint v3, Color color)
        {
            var invSlope1 = (float)(v3.X - v1.X) / (v3.Y - v1.Y);
            var invSlope2 = (float)(v3.X - v2.X) / (v3.Y - v2.Y);

            float curX1 = v3.X;
            float curX2 = v3.X;

            for (var scanLineY = v3.Y; scanLineY > v1.Y; --scanLineY)
            {
                var z1 = MathUtilities.Lerp(v1.Z, v3.Z, (v1.Y - (float)scanLineY) / (v1.Y - v3.Y));
                var z2 = MathUtilities.Lerp(v2.Z, v3.Z, (v2.Y - (float)scanLineY) / (v2.Y - v3.Y));

                DrawLine(ref deviceComponent, new ScreenPoint((int)curX1, scanLineY, z1), new ScreenPoint((int)curX2, scanLineY, z2), color);
                curX1 -= invSlope1;
                curX2 -= invSlope2;
            }
        }
Example #16
0
 private void Clear(ref DeviceComponent deviceComponent)
 {
     Array.Copy(deviceComponent.ClearBackBuffer, deviceComponent.BackBuffer, deviceComponent.BackBuffer.Length);
     Array.Copy(deviceComponent.ClearDepthBuffer, deviceComponent.DepthBuffer, deviceComponent.DepthBuffer.Length);
 }
Example #17
0
        public static async Task <string> UpdateSecure(
            [OrchestrationTrigger] DurableOrchestrationContext context)
        {
            _targetDeviceId = context.GetInput <string[]>();

            if (Client == null)
            {
                Client = await GetSecureDocumentClient();
            }

            var deviceId        = _targetDeviceId[0];
            var updateVersionId = _targetDeviceId[1];
            var specType        = _targetDeviceId[2];



            // Get the DeviceComponent Document
            var doc = await context.CallActivityAsync <dynamic>("GetDoc", deviceId);


            _documentId = doc.Id;


            var binder = new Binder();

            binder.BindingData.Add("documentId", _documentId);
            binder.BindingData.Add("attachmentId", updateVersionId);

            // Get the Attachment
            string attachment = await context.CallActivityAsync <dynamic>(nameof(GetAttachment), binder);


            var result = await context.CallActivityAsync <CloudToDeviceMethodResult>(nameof(StartFirmwareUpdate), attachment);

            if (result.Status != 0)
            {
                return(result.Status.ToString());
            }


            var status = await context.CallActivityAsync <string>(nameof(QueryTwinFwUpdateReportedSecure), DateTime.Now);

            var instant = new DateTimeOffset(DateTime.Parse(status));

            var spec = new DeviceComponent.ProductionSpecificationComponent
            {
                ComponentId    = { Value = Guid.NewGuid().ToString() },
                ProductionSpec = updateVersionId
            };
            var coding = new Coding(null, specType, specType.ToUpper());

            spec.SpecType.Coding.Add(coding);

            var ps = new DeviceComponent().ProductionSpecification;

            ps.Add(spec);

            // Update the LastSystemChange value
            var deviceComponentUpdate = new DeviceComponent
            {
                Id                          = _documentId,
                Type                        = doc.Type,
                Text                        = doc.Text,
                Source                      = doc.Source,
                Parent                      = doc.Parent,
                FhirComments                = doc.FhirComments,
                ImplicitRules               = doc.ImplicitRules,
                Identifier                  = doc.Identifier,
                OperationalStatus           = doc.OperationalStatus,
                Contained                   = doc.Contained,
                LastSystemChange            = instant,
                MeasurementPrinciple        = doc.MeasurementPrinciple,
                ParameterGroup              = doc.ParameterGroup,
                MeasurementPrincipleElement = doc.MeasurementPrincipleElement,
                LanguageCode                = doc.LanguageCode,
                ProductionSpecification     = ps,
                Language                    = doc.Language
            };

            var json = JsonConvert.SerializeObject(deviceComponentUpdate);


            // Update the Device Docuument
            var upDate = await context.CallActivityAsync <HttpResponseMessage>(nameof(UpdateDoc), json);

            if (!upDate.IsSuccessStatusCode)
            {
                return(upDate.StatusCode.ToString());
            }

            var cal = new DeviceMetric.CalibrationComponent
            {
                Type =
                    null,                     //values: unspecified, ofset, gin, two-point see https://www.hl7.org/fhir/valueset-metric-calibration-type.html
                State =
                    null,                     // values: not-calibrated,  calibration-required, calibrated, unspecified see https://www.hl7.org/fhir/valueset-metric-calibration-state.html
                Time = instant                // value: DateTimeOffset
            };
            var calibration = new DeviceMetric().Calibration;

            calibration.Add(cal);


            var deviceMetric = new DeviceMetric
            {
                OperationalStatus = doc.Result.OperationalStatus,
                Category          = doc.Result.Category,
                Color             = doc.Result.Color,
                Contained         = doc.Result.Contained,
                Type              = doc.Result.Type,
                Unit              = doc.Result.Unit,
                Source            = doc.Result.Source,
                Parent            = doc.Result.Parent,
                MeasurementPeriod = null,
                Calibration       = calibration
            };

            json = JsonConvert.SerializeObject(deviceMetric);

            upDate = await context.CallActivityAsync <HttpResponseMessage>(nameof(UpdateDoc), json);


            return(upDate.StatusCode.ToString());
        }
 public void Initialize(DeviceComponent model)
 {
     _model = model as DeltaDeviceComponent;
     chkDelta.Text = model.Name;
 }