Exemple #1
0
        protected void treeView1_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
        {
            //currentNode = null;
            this.objectListView1.ClearObjects();
            propertyList = new List <ShieldProperty>();
            currentNode  = e.Node;

            if (e.Node is ShieldTreeNode)
            {
                ShieldTreeNode node   = (ShieldTreeNode)e.Node;
                Shield         shield = shields.shieldFromNodeId((String)node.Tag);
                // name
                ShieldProperty sp = new ShieldProperty();
                sp.Name        = property_ShieldName;
                sp.Description = "Shield name";
                sp.Value       = shield.shieldName;
                propertyList.Add(sp);
                // started
                sp             = new ShieldProperty();
                sp.Name        = property_ShieldStarted;
                sp.Description = "Scheda avviata";
                if (shield.started)
                {
                    sp.Value = "Started";
                }
                else
                {
                    sp.Value = "Not Started";
                }
                propertyList.Add(sp);
                objectListView1.DisableObject(sp);
                // id
                sp             = new ShieldProperty();
                sp.Name        = property_ShieldId;
                sp.Description = "Shield id";
                sp.Value       = "" + shield.id;
                sp.Action      = "register";
                propertyList.Add(sp);
                // port
                sp             = new ShieldProperty();
                sp.Name        = property_Port;
                sp.Description = "local port";
                sp.Value       = "" + shield.localPort;
                propertyList.Add(sp);
                // mac addrress
                sp             = new ShieldProperty();
                sp.Name        = property_MACAddress;
                sp.Description = "MAC Address";
                sp.Value       = shield.MACAddress;
                propertyList.Add(sp);
                // temperaturesensorsenabled
                sp             = new ShieldProperty();
                sp.Name        = property_TemperatureSensorEnabled;
                sp.Description = "Temperature sensor enabled";
                if (shield.temperatureSensorsEnabled)
                {
                    sp.Value = "Enabled";
                }
                else
                {
                    sp.Value = "Disabled";
                }
                propertyList.Add(sp);
            }
            else if (e.Node is SensorTreeNode)
            {
                SensorTreeNode node   = (SensorTreeNode)e.Node;
                Shield         shield = shields.shieldFromNodeId(node.shieldNodeId);
                Sensor         sensor = shield.sensorFromNodeId((String)node.Tag);

                ShieldProperty sp = new ShieldProperty();
                sp.ShieldNodeId = node.shieldNodeId;
                sp.NodeId       = (String)node.Tag; sp.Name = property_SensorName;
                sp.Description  = "Sensor name";
                sp.Value        = sensor.sensorname;
                propertyList.Add(sp);

                sp = new ShieldProperty();
                sp.ShieldNodeId = node.shieldNodeId;
                sp.NodeId       = (String)node.Tag; sp.Name = property_Enabled;
                sp.Description  = "Enabled";
                if (sensor.enabled)
                {
                    sp.Value  = "true";
                    sp.Action = "Disable";
                }
                else
                {
                    sp.Value  = "false";
                    sp.Action = "Enable";
                }
                propertyList.Add(sp);

                if (sensor is DS18S20Sensor)
                {
                    sp = new ShieldProperty();
                    sp.ShieldNodeId = node.shieldNodeId;
                    sp.NodeId       = (String)node.Tag;
                    sp.Name         = property_TemperatureSensor_Temperature;
                    sp.Description  = "Temperature";
                    DS18S20Sensor dsSensor = (DS18S20Sensor)sensor;
                    sp.Value  = "" + dsSensor.temperature;
                    sp.Action = "Update";

                    propertyList.Add(sp);
                }
                else if (sensor is DoorSensor)
                {
                    sp = new ShieldProperty();
                    sp.ShieldNodeId = node.shieldNodeId;
                    sp.NodeId       = (String)node.Tag;
                    sp.Name         = property_DoorSensor_Open;
                    sp.Description  = "Status";
                    DoorSensor doorSensor = (DoorSensor)sensor;

                    if (doorSensor.getStatusOpen())
                    {
                        sp.Value  = "open";
                        sp.Action = "close";
                    }
                    else
                    {
                        sp.Value  = "closed";
                        sp.Action = "open";
                    }
                    propertyList.Add(sp);
                }
            }
            else if (e.Node is ActuatorTreeNode)
            {
                ActuatorTreeNode node     = (ActuatorTreeNode)e.Node;
                Shield           shield   = shields.shieldFromNodeId(node.shieldNodeId);
                Sensor           actuator = shield.actuatorFromNodeId((String)node.Tag);

                ShieldProperty sp = new ShieldProperty();
                sp.ShieldNodeId = node.shieldNodeId;
                sp.NodeId       = (String)node.Tag;
                sp.Name         = property_ActuatorName;
                sp.Description  = "Actuator name";
                sp.Value        = actuator.sensorname;
                propertyList.Add(sp);
            }
            else if (e.Node is SettingsTreeNode)
            {
                SettingsTreeNode node = (SettingsTreeNode)e.Node;

                ShieldProperty sp = new ShieldProperty();
                sp.Name        = property_ServerIp;
                sp.Value       = Settings.serverIpAddress;
                sp.Description = "Server Ip Address";
                propertyList.Add(sp);
                sp             = new ShieldProperty();
                sp.Name        = property_ServerPort;
                sp.Description = "Server Port";
                sp.Value       = "" + Settings.serverPort;
                propertyList.Add(sp);
            }

            this.objectListView1.SetObjects(propertyList);
            this.objectListView1.Refresh();
        }
Exemple #2
0
        private void objectListView1_CellEditFinished(object sender, BrightIdeasSoftware.CellEditEventArgs e)
        {
            if (currentNode != null && e.Column.Text.Equals("Value"))
            {
                if (currentNode is ShieldTreeNode)
                {
                    ShieldTreeNode node   = (ShieldTreeNode)currentNode;
                    Shield         shield = shields.shieldFromNodeId((String)node.Tag);

                    ShieldProperty property = (ShieldProperty)e.RowObject;
                    if (property.Name.Equals(property_ShieldName))
                    {
                        shield.shieldName = (string)e.NewValue;
                    }
                    else if (property.Name.Equals(property_MACAddress))
                    {
                        shield.MACAddress = (string)e.NewValue;
                    }
                    else if (property.Name.Equals(property_Port))
                    {
                        shield.localPort = (string)e.NewValue;
                    }
                    else if (property.Name.Equals(property_TemperatureSensorEnabled))
                    {
                        if (e.NewValue.Equals("Enabled"))
                        {
                            shield.temperatureSensorsEnabled = true;
                        }
                        else
                        {
                            shield.temperatureSensorsEnabled = false;
                        }
                    }
                }
                else if (currentNode is SensorTreeNode)
                {
                    SensorTreeNode node   = (SensorTreeNode)currentNode;
                    Shield         shield = shields.shieldFromNodeId(node.shieldNodeId);
                    Sensor         sensor = shield.sensorFromNodeId((String)node.Tag);

                    ShieldProperty property = (ShieldProperty)e.RowObject;
                    if (property.Name.Equals(property_SensorName))
                    {
                        sensor.sensorname = (string)e.NewValue;
                    }
                    else if (sensor is DS18S20Sensor)
                    {
                        DS18S20Sensor tempSensor = (DS18S20Sensor)sensor;
                        if (property.Name.Equals(property_TemperatureSensor_Temperature))
                        {
                            tempSensor.temperature = float.Parse((string)e.NewValue);
                        }
                    }
                }
                else if (currentNode is ActuatorTreeNode)
                {
                    ActuatorTreeNode node     = (ActuatorTreeNode)currentNode;
                    Shield           shield   = shields.shieldFromNodeId(node.shieldNodeId);
                    Sensor           actuator = shield.sensorFromNodeId((String)node.Tag);

                    ShieldProperty property = (ShieldProperty)e.RowObject;
                    if (property.Name.Equals(property_ActuatorName))
                    {
                        actuator.sensorname = (string)e.NewValue;
                    }
                }
                else if (currentNode is SettingsTreeNode)
                {
                    SettingsTreeNode node     = (SettingsTreeNode)currentNode;
                    ShieldProperty   property = (ShieldProperty)e.RowObject;
                    if (property.Name.Equals(property_ServerIp))
                    {
                        Settings.serverIpAddress = (string)e.NewValue;
                        Settings.serverIpAddress = (string)e.NewValue;
                    }
                    else if (property.Name.Equals(property_ServerPort))
                    {
                        Settings.serverPort = Int32.Parse((string)e.NewValue);
                    }
                }
            }
        }
Exemple #3
0
        public void cellButtonClick(object sender, CellClickEventArgs e)
        {
            Debug.WriteLine(String.Format("Button clicked: ({0}, {1}, {2})", e.RowIndex, e.SubItem, e.Model));

            // Take some action on e.Model based on which button (e.ColumnIndex) was clicked

            ShieldProperty property = (ShieldProperty)e.Model;

            if (property.Name.Equals(property_TemperatureSensor_Temperature))
            {
                Shield shield = shields.shieldFromNodeId(property.NodeId);
                shield.sendSensorsStatus();
            }
            else if (property.Name.Equals(property_ShieldId))
            {
                Shield shield = shields.shieldFromNodeId(property.NodeId);
                shield.registerShield();
            }
            else if (property.Name.Equals(property_Enabled))
            {
                Shield shield = shields.shieldFromNodeId(property.ShieldNodeId);
                if (shield != null)
                {
                    Sensor sensor = (Sensor)shield.sensorFromNodeId(property.NodeId);
                    if (sensor != null)
                    {
                        sensor.enabled = !sensor.enabled;
                        if (sensor.enabled)
                        {
                            property.Value  = "true";
                            property.Action = "Disable";
                        }
                        else
                        {
                            property.Value  = "false";
                            property.Action = "Enable";
                        }
                        shield.sendSensorsStatus();
                    }
                }
            }
            else if (property.Name.Equals(property_DoorSensor_Open))
            {
                Shield     shield     = shields.shieldFromNodeId(property.ShieldNodeId);
                DoorSensor doorSensor = (DoorSensor)shield.sensorFromNodeId(property.NodeId);
                doorSensor.setStatusOpen(!doorSensor.getStatusOpen());
                if (doorSensor.getStatusOpen())
                {
                    property.Value  = "open";
                    property.Action = "close";
                }
                else
                {
                    property.Value  = "closed";
                    property.Action = "open";
                }
                shield.sendSensorsStatus();
            }
            // If something about the object changed, you probably want to refresh the model
            this.objectListView1.RefreshObject(e.Model);
            //this.objectListView1.Update();
            //this.objectListView1.SetObjects(propertyList);
            //this.objectListView1.Refresh();
        }