Beispiel #1
0
 public CeilingFan(IDeviceInput inp, IDeviceOutput outp, TimeFrame frame) :
     base(inp, outp, frame)
 {
     Enabled = false;
     State   = 0;
     Class   = "CeilingFan";
 }
 public Keyboard1Controller(IDeviceOutput output, int baseAddress, int irq)
 {
     _output             = output;
     _updateFormDelegate = new UpdateFormDelegate(UpdateForm);
     _baseAddress        = baseAddress * 0x10;
     _irq = (byte)irq;
 }
Beispiel #3
0
 public LightSwitch(IDeviceInput inp, IDeviceOutput outp, TimeFrame frame) :
     base(inp, outp, frame)
 {
     _enabled = false;
     _light   = new Light();
     Class    = "LightSwitch";
 }
Beispiel #4
0
        /**
         * Given a JSON string representing a device, instantiates the device as desired. Raw instantiation, which shouldn't
         * be used by end-clients typically
         * \param[in] info JSON string representing device. Must have a key named "class" which
         *            names the class deriving from Device to instantiate.
         * \param[in] inp IDeviceInput to create device with
         * \param[in] outp IDeviceOutput to create device with
         * \param[in] frame TimeFrame to initialize the frame
         */
        public static Device DeserializeDevice(string info, IDeviceInput inp, IDeviceOutput outp, TimeFrame frame)
        {
            if (String.IsNullOrEmpty(info))
            {
                return(null);
            }

            Device device = null;

            try
            {
                JObject device_obj = JObject.Parse(info);
                JToken  type_tok;
                if (!device_obj.TryGetValue("class", StringComparison.OrdinalIgnoreCase, out type_tok))
                {
                    return(null);
                }

                var device_type = GetDeviceType(type_tok.ToString());
                if (device_type != null)
                {
                    device = (Device)Activator.CreateInstance(device_type, null, null, frame);
                    update(device, info, update_id: true, force: true);
                    device.update();
                    device.resetIO(inp, outp);             //this way, population doesn't trigger house comms
                }
            }
            catch (JsonException ex)
            {
                //TODO: Figure out how to pass exceptions up, or record error
                Debug.WriteLine("Error deserializing the list of devices" + ex.Message);
                Debug.WriteLine("Error deserializing the list of devices" + ex.InnerException.Message);
            }
            return(device);
        }
        /**
         * Given a JSON string representing a device, instantiates the device as desired.
         * \param[in] info JSON string representing device. Must have a key named "class" which
         *            names the class deriving from Device to instantiate.
         */
        public static Device DeserializeDevice(string info, IDeviceInput inp, IDeviceOutput outp)
        {
            if (String.IsNullOrEmpty(info))
            {
                return(null);
            }

            JObject device_obj = JObject.Parse(info);
            JToken  type_tok;

            if (!device_obj.TryGetValue("class", out type_tok))
            {
                return(null);
            }

            var    device_type = GetDeviceType(type_tok.ToString());
            Device device      = null;

            if (device_type != null)
            {
                device = (Device)Activator.CreateInstance(device_type, inp, outp);
                JsonConvert.PopulateObject(info, device);
            }
            return(device);
        }
 public Timer5Controller(IDeviceOutput output)
 {
     _output             = output;
     _updateFormDelegate = new UpdateFormDelegate(UpdateForm);
     _timer = new MicroTimer(1000);
     _timer.MicroTimerElapsed += new MicroTimer.MicroTimerElapsedEventHandler(OnTimerEvent);
 }
 public Timer5Controller(IDeviceOutput output, int baseAddress, int irq)
 {
     _output             = output;
     _updateFormDelegate = new UpdateFormDelegate(UpdateForm);
     _timer = new MicroTimer(1000);
     _timer.MicroTimerElapsed += new MicroTimer.MicroTimerElapsedEventHandler(OnTimerEvent);
     _baseAddress              = baseAddress * 0x10;
     _irq = (byte)irq;
 }
Beispiel #8
0
 public Thermostat(IDeviceInput inp, IDeviceOutput outp) :
     base(inp, outp)
 {
     Enabled  = false;
     SetPoint = new Temperature()
     {
         Temp = 0
     };
     Value = new Temperature()
     {
         Temp = 0
     };
 }
Beispiel #9
0
 public Thermostat(IDeviceInput inp, IDeviceOutput outp, TimeFrame frame) :
     base(inp, outp, frame)
 {
     Enabled  = false;
     SetPoint = new Temperature()
     {
         Temp = 0
     };
     Value = new Temperature()
     {
         Temp = 0
     };
     Class = "Thermostat";
 }
Beispiel #10
0
 /**
  * Rests internal IO objects for this Device. With no arguments, the
  * device will no longer communicate with any remote authority, making this object
  * useful for storing old results/dumb usage.
  * \param[in] inp IDeviceInput instance, defaults to a NullDeviceInput.
  * \param[out] outp IDeviceOutput instance, defaults to a NullDeviceOutput.
  */
 public void resetIO(IDeviceInput inp = default(IDeviceInput), IDeviceOutput outp = default(IDeviceOutput))
 {
     //Force sane defaults, so we can assume these are always valid
     if (inp == null)
     {
         inp = new NullDeviceInput();
     }
     if (outp == null)
     {
         outp = new NullDeviceOutput();
     }
     _in  = inp;
     _out = outp;
 }
Beispiel #11
0
 public Device(IDeviceInput inp, IDeviceOutput outp,
               TimeFrame frame)
 {
     resetIO(inp, outp);
     if (frame == null)
     {
         frame = new TimeFrame();
     }
     _frame     = frame;
     _last_time = DateTime.MinValue;     //Set to minimum possible time
     _id        = new FullID();
     _name      = "";
     _update_ok = false;
 }
			public bool SetResolution(int width, int height, float ppi, ScreenOrientation orientation, IDeviceOutput deviceOutput) {

				var result = false;

				this.orientation = orientation;
				this.deviceOutput = deviceOutput;

				this.ppi = ppi;
				this.currentWidth = width;
				this.currentHeight = height;
				
				this.tempScreenshot = new Texture2D(width, height, TextureFormat.RGB24, false);

				this.tempRenderTexture = new RenderTexture(width, height, 24, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default);
				/*
				if (this.previewCamera == null) {

					var go = new GameObject("__TempCamera");
					this.previewCamera = go.AddComponent<DevicePreviewCamera>();

				}

				this.previewCamera.Initialize(this.tempRenderTexture, () => {

					this.root.Repaint();
					GameObject.DestroyImmediate(this.previewCamera.gameObject);

				});*/

				var size = new Vector2(this.width, this.height);
				var imageSize = new Vector2(this.currentWidth, this.currentHeight);
				var factor = this.GetFactor(imageSize, size);
				var k = Screen.dpi / this.ppi;

				if (factor / k < 1f) {

					result = true;

				}

				this.isActive = true;

				this.Update();

				return result;

			}
            public bool SetResolution(int width, int height, float ppi, ScreenOrientation orientation, IDeviceOutput deviceOutput)
            {
                var result = false;

                this.orientation  = orientation;
                this.deviceOutput = deviceOutput;

                this.ppi           = ppi;
                this.currentWidth  = width;
                this.currentHeight = height;

                this.tempScreenshot = new Texture2D(width, height, TextureFormat.RGB24, false);

                this.tempRenderTexture = new RenderTexture(width, height, 24, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default);

                /*
                 * if (this.previewCamera == null) {
                 *
                 *      var go = new GameObject("__TempCamera");
                 *      this.previewCamera = go.AddComponent<DevicePreviewCamera>();
                 *
                 * }
                 *
                 * this.previewCamera.Initialize(this.tempRenderTexture, () => {
                 *
                 *      this.root.Repaint();
                 *      GameObject.DestroyImmediate(this.previewCamera.gameObject);
                 *
                 * });*/

                var size      = new Vector2(this.width, this.height);
                var imageSize = new Vector2(this.currentWidth, this.currentHeight);
                var factor    = this.GetFactor(imageSize, size);
                var k         = Screen.dpi / this.ppi;

                if (factor / k < 1f)
                {
                    result = true;
                }

                this.isActive = true;

                this.Update();

                return(result);
            }
Beispiel #14
0
        /**
         * Given an instance of the device, attempts to update all public properties with info
         * from the new device instance. Note that devices currently must have the same ID, but
         * the actual classes do not need to be the same.
         * \param[in] old_dev Device which will be updated.
         * \param[in] new_dev Device which contains values to be updated with
         * \param[in] silence_io Temporarily disable the Device IO for simple value updating
         * \param[out] Flag indicating if a field was updated with a new value
         */
        public static bool UpdateDevice(Device old_dev, Device new_dev, bool silence_io = false)
        {
            if (old_dev == null || new_dev == null)
            {
                return(false);
            }

            var  props        = old_dev.GetType().GetRuntimeProperties();
            bool update_field = false;

            IDeviceInput  inp  = null;
            IDeviceOutput outp = null;

            if (silence_io)
            {
                inp  = old_dev.Input;
                outp = old_dev.Output;
                old_dev.resetIO();
            }
            foreach (var info in props)
            {
                //Can't update this method
                if (info.SetMethod == null || !info.SetMethod.IsPublic || info.GetMethod == null)
                {
                    continue;
                }

                if (info.Name != "LastUpdate")
                {
                    var updated = !(info.GetValue(old_dev).Equals(info.GetValue(new_dev)));
                    update_field |= updated;
                }
                info.SetValue(old_dev, info.GetValue(new_dev));
            }

            if (silence_io)
            {
                old_dev.resetIO(inp, outp);
            }
            return(update_field);
        }
Beispiel #15
0
 public GarageDoor(IDeviceInput inp, IDeviceOutput outp, TimeFrame frame) :
     base(inp, outp, frame)
 {
     Enabled = true;
     Class   = "GarageDoor";
 }
Beispiel #16
0
 public DisplayController(IDeviceOutput output, int baseAddress)
 {
     _output             = output;
     _updateFormDelegate = new SetCharacterDelegate((textBoxIndex, character) => _form.SetCharacter(textBoxIndex, character));
     _baseAddress        = baseAddress * 0x10;
 }
Beispiel #17
0
 public AlarmSystem(IDeviceInput inp, IDeviceOutput outp, TimeFrame frame) :
     base(inp, outp, frame)
 {
     Enabled = false;
     Class   = "AlarmSystem";
 }
 public OscillographController(IDeviceOutput output)
 {
     _output             = output;
     _updateFormDelegate = new UpdateFormDelegate(UpdateForm);
     ConnectedDevices.AddRange(_output.Devices.Where(x => x.GetType() == typeof(Timer5Controller)));
 }
 public CeilingFan(IDeviceInput inp, IDeviceOutput outp) :
     base(inp, outp)
 {
     Enabled = false;
     State   = 0;
 }
 public LightSwitch(IDeviceInput inp, IDeviceOutput outp) :
     base(inp, outp)
 {
     _enabled = false;
     _light   = new Light();
 }
 public DisplayController(IDeviceOutput output)
 {
     _output             = output;
     _updateFormDelegate = new SetCharacterDelegate((textBoxIndex, character) => _form.SetCharacter(textBoxIndex, character));
 }
 public Keyboard1Controller(IDeviceOutput output)
 {
     _output             = output;
     _updateFormDelegate = new UpdateFormDelegate(UpdateForm);
 }
Beispiel #23
0
 public KeypadAndIndicationController(IDeviceOutput output, int baseAddress, int irq)
 {
     _output      = output;
     _baseAddress = baseAddress * 0x10;
     _irq         = (byte)irq;
 }
 public GarageDoor(IDeviceInput inp, IDeviceOutput outp) :
     base(inp, outp)
 {
     Enabled = true;
 }
Beispiel #25
0
 public GraphicDisplayController(IDeviceOutput output, int baseAddress)
 {
     _output             = output;
     _updateFormDelegate = new UpdateFormDelegate(UpdateForm);
     _baseAddress        = baseAddress * 0x10;
 }
 public AlarmSystem(IDeviceInput inp, IDeviceOutput outp) :
     base(inp, outp)
 {
     Enabled = false;
 }
Beispiel #27
0
 public DevicesFactory(IDeviceOutput output)
 {
     _output = output;
 }
Beispiel #28
0
        /**
         * Internal device updating function.
         * \param[in] dev Device to be updated
         * \param[in] json JSON blob of fields to update
         * \param[in] silence_io Temporarily disable the Device IO for simple value updating
         * \param[in] update_id Flag indicating if the DeviceID should be updated at all
         * \param[in] force Flag indicating if public/private flags should be respected for the update
         * \param[out] Flag indicating if at least one field was updated
         */
        protected static bool update(Device dev, string json, bool silence_io = false,
                                     bool update_id = false, bool force = false)
        {
            if (dev == null)
            {
                return(false);
            }

            IDeviceInput  inp  = null;
            IDeviceOutput outp = null;

            if (silence_io)
            {
                inp  = dev.Input;
                outp = dev.Output;
                dev.resetIO();
            }
            bool updated_value = true;

            try
            {
                var props    = dev.GetType().GetRuntimeProperties();
                var json_obj = JObject.Parse(json);

                foreach (var info in props)
                {
                    if (info.SetMethod == null || !(force || info.SetMethod.IsPublic) || info.Name == "Frame")
                    {
                        continue;
                    }
                    JToken field;
                    if (!json_obj.TryGetValue(info.Name, StringComparison.OrdinalIgnoreCase, out field))
                    {
                        continue;
                    }

                    if (update_id && info.Name == "ID")
                    {
                        if (field.Type == JTokenType.Integer)
                        {
                            dev.ID.DeviceID = field.ToObject <UInt64>();
                        }
                        else
                        {
                            dev.ID = field.ToObject <FullID>();
                        }
                    }
                    else if (info.Name != "ID")
                    {
                        var value = field.ToObject(info.PropertyType);
                        info.SetValue(dev, value);
                    }
                    updated_value = true;
                }
            }
            catch (JsonException ex)
            {
                //TODO: Report error somehow?
                Debug.WriteLine("Error updating the device" + ex.Message);
                Debug.WriteLine("Error updating the device" + ex.InnerException.Message);
            }

            if (silence_io)
            {
                dev.resetIO(inp, outp);
            }
            return(updated_value);
        }
        private void DrawDevicesList()
        {
            var scrollWidth = 20f;
            var offset      = 10;

            var elementStyle = new GUIStyle("flow node hex 0");

            elementStyle.contentOffset = Vector2.zero;
            elementStyle.fixedWidth    = PANEL_WIDTH - scrollWidth - offset;
            elementStyle.margin        = new RectOffset(offset, 0, 0, 0);
            elementStyle.padding       = new RectOffset(20, 20, 10, 20);
            elementStyle.alignment     = TextAnchor.MiddleLeft;

            var elementStyleSelected = new GUIStyle("flow node hex 1 on");

            elementStyleSelected.contentOffset = Vector2.zero;
            elementStyleSelected.fixedWidth    = PANEL_WIDTH - scrollWidth - offset;
            elementStyleSelected.margin        = new RectOffset(offset, 0, 0, 0);
            elementStyleSelected.padding       = new RectOffset(20, 20, 10, 20);
            elementStyleSelected.alignment     = TextAnchor.MiddleLeft;

            var elementStylePortrait = new GUIStyle("flow node hex 2");

            elementStylePortrait.contentOffset = Vector2.zero;
            elementStylePortrait.fixedWidth    = PANEL_WIDTH - scrollWidth - offset;
            elementStylePortrait.margin        = new RectOffset(offset, 0, 0, 0);
            elementStylePortrait.padding       = new RectOffset(20, 20, 10, 20);
            elementStylePortrait.alignment     = TextAnchor.MiddleLeft;

            var elementStyleSelectedPortrait = new GUIStyle("flow node hex 2 on");

            elementStyleSelectedPortrait.contentOffset = Vector2.zero;
            elementStyleSelectedPortrait.fixedWidth    = PANEL_WIDTH - scrollWidth - offset;
            elementStyleSelectedPortrait.margin        = new RectOffset(offset, 0, 0, 0);
            elementStyleSelectedPortrait.padding       = new RectOffset(20, 20, 10, 20);
            elementStyleSelectedPortrait.alignment     = TextAnchor.MiddleLeft;


            var headerLabel = new GUIStyle(EditorStyles.whiteLargeLabel);

            headerLabel.padding = new RectOffset(0, 0, 0, 0);
            headerLabel.margin  = new RectOffset(0, 0, 0, 0);

            var miniLabel = new GUIStyle(EditorStyles.miniLabel);

            miniLabel.padding = new RectOffset(0, 0, 0, 0);
            miniLabel.margin  = new RectOffset(0, 0, 0, 0);


            var foldOutStyle = new GUIStyle("flow node hex 4");

            foldOutStyle.contentOffset = Vector2.zero;
            foldOutStyle.fixedWidth    = PANEL_WIDTH - scrollWidth;
            foldOutStyle.font          = headerLabel.font;
            foldOutStyle.fontSize      = headerLabel.fontSize;
            foldOutStyle.padding       = new RectOffset(20, 20, 15, 15);
            foldOutStyle.alignment     = TextAnchor.MiddleLeft;

            var foldOutStyleSelected = new GUIStyle("flow node hex 4 on");

            foldOutStyleSelected.contentOffset = Vector2.zero;
            foldOutStyleSelected.fixedWidth    = PANEL_WIDTH - scrollWidth;
            foldOutStyleSelected.font          = headerLabel.font;
            foldOutStyleSelected.fontSize      = headerLabel.fontSize;
            foldOutStyleSelected.padding       = new RectOffset(20, 20, 15, 15);
            foldOutStyleSelected.alignment     = TextAnchor.MiddleLeft;

            this.scrollPosition = EditorGUILayout.BeginScrollView(this.scrollPosition, false, false);

            var i           = 0;
            var directories = Parser.manufacturerToDevices;

            if (this.directoriesFoldOut.Count != directories.Count)
            {
                this.directoriesFoldOut = new List <bool>();

                for (i = 0; i < directories.Count; ++i)
                {
                    this.directoriesFoldOut.Add(false);
                }
            }

            i = 0;
            var f = 0;

            foreach (var directory in directories)
            {
                if (GUILayout.Button(directory.Key, this.directoriesFoldOut[f] ? foldOutStyleSelected : foldOutStyle) == true)
                {
                    this.directoriesFoldOut[f] = !this.directoriesFoldOut[f];
                }

                if (this.directoriesFoldOut[f] == true)
                {
                    GUILayout.BeginVertical();

                    var list = directory.Value;
                    if (list != null && list.Count > 0)
                    {
                        foreach (var item in list)
                        {
                            var style = this.selectedId == i ? (item.orientation == ScreenOrientation.Landscape ? elementStyleSelected : elementStyleSelectedPortrait) : (item.orientation == ScreenOrientation.Landscape ? elementStyle : elementStylePortrait);

                            if (item.current == true)
                            {
                                item.width       = Mathf.RoundToInt(this.gameView.width);
                                item.height      = Mathf.RoundToInt(this.gameView.height);
                                item.orientation = item.orientation;
                            }

                            if (GUILayout.Button(item.model, style) == true)
                            {
                                // Apply Device Info
                                if (EditorApplication.timeSinceStartup - this.lastClickTime < 0.3d && this.selectedId == i)
                                {
                                    item.orientation = (item.orientation == ScreenOrientation.Landscape) ? ScreenOrientation.Portrait : ScreenOrientation.Landscape;
                                }

                                this.selectedId = i;

                                this.lastClickTime = EditorApplication.timeSinceStartup;

                                IDeviceOutput specialInstance = null;
                                if (string.IsNullOrEmpty(item.deviceOutput) == false)
                                {
                                    var outputNamespace = "UnityEditor.UI.Windows.Plugins.DevicePreview.Output";
                                    var type            = outputNamespace + "." + item.deviceOutput;

                                    var specialOutput = System.Type.GetType(type);
                                    if (specialOutput != null)
                                    {
                                        specialInstance = Activator.CreateInstance(specialOutput) as IDeviceOutput;
                                    }
                                    else
                                    {
                                        Debug.LogWarning("Class not found: " + type);
                                    }
                                }

                                if (this.gameView.SetResolution(item.width, item.height, item.ppi, item.orientation, specialInstance) == true)
                                {
                                    this.ShowNotification(new GUIContent("Drawing screen (" + item.width.ToString() + "x" + item.height.ToString() + ") doesn't fit into your window size (" + this.gameView.width.ToString() + "x" + this.gameView.height.ToString() + ")."));
                                }
                                else
                                {
                                    this.RemoveNotification();
                                }

                                this.Repaint();
                            }

                            var rect = GUILayoutUtility.GetLastRect();
                            rect.x += style.padding.left;
                            rect.y += rect.height - style.padding.bottom;
                            GUI.Label(rect, "Resolution: " + item.width.ToString() + "x" + item.height.ToString() + " (" + item.ppi.ToString() + ")", miniLabel);

                            ++i;
                        }
                    }

                    GUILayout.EndVertical();
                }
                else
                {
                    i += directory.Value.Count;
                }

                ++f;
            }

            EditorGUILayout.EndScrollView();
        }
Beispiel #30
0
 public Device(IDeviceInput inp, IDeviceOutput outp)
 {
     _in        = inp;
     _out       = outp;
     LastUpdate = DateTime.Now.ToUniversalTime();
 }