public override void OnInputChange(Input input)
        {

            double position = double.Parse(Inputs[0].Value);

            position = Clamp(position, 0, 100);

            int pointsCount = Inputs.Count - 1; 

            double stepSize = 100D / (pointsCount - 1);

            double stepIndex = (position / stepSize) + 1;


            double positionInStep = stepIndex - ((int)stepIndex);

            double startValue = ((int)stepIndex-1)* stepSize;
            if (Inputs[(int)stepIndex].Value != null)
                startValue = double.Parse(Inputs[(int)stepIndex].Value);

            if (position>=100)
            {
                Outputs[0].Value = startValue.ToString();
                return;
            }

            double endValue = startValue+ stepSize;
            if (Inputs[(int)stepIndex + 1].Value != null)
                endValue = double.Parse(Inputs[(int)stepIndex + 1].Value);//25

            double result = Remap(positionInStep, 0, 1, startValue, endValue);

            Outputs[0].Value = result.ToString();
        }
        public override void OnInputChange(Input input)
        {
            if (input == Inputs[0] && input.Value != null)
            {
                int maxValues=10;
                int.TryParse(Settings["maxvalues"].Value, out maxValues);

                Values.Add(double.Parse(input.Value));

                if (Values.Count > maxValues)
                {
                    int more = Values.Count - maxValues;
                    for (int i = 0; i < more; i++)
                        Values.RemoveAt(0);
                }

                Outputs[0].Value = (Values.Sum() / Values.Count).ToString("0.##");
            }

            if (input == Inputs[1] && input.Value == "1")
            {
                Values.Clear();
                Outputs[0].Value = null;
            }
        }
        public override void OnInputChange(Input input)
        {
            if (input == Inputs[0])
            {
                if (input.Value == null)
                {
                    if (Settings["StopWhenDisconnected"].Value == "true")
                        Stop();

                    if (Settings["ResetWhenDisconnected"].Value == "true")
                        Reset();
                }
                else
                {
                    startValue = currentValue;
                    endValue = double.Parse(input.Value);

                    Start();
                }
            }


            if (input == Inputs[1])
            {
                if (input.Value == null)
                    interval = DEFAULT_INTERVAL;
                else
                    double.TryParse(input.Value, out interval);

                if (interval < 1)
                    interval = 1;

                LogInfo($"Interval changed to {interval} ms");
            }
        }
        public override void OnInputChange(Input input)
        {
            var a = double.Parse(Inputs[0].Value);
            var b = Math.Sin(a);

            Outputs[0].Value = b.ToString();
        }
        public override void OnInputChange(Input input)
        {
            if (input == Inputs[1])
            {
                address = input.Value;
                LogInfo($"Address changed: [{address ?? "NULL"}]");
            }

            if (input == Inputs[3])
            {
                password = input.Value;
                string pass = null;

                if (password != null)
                    for (var i = 0; i < password.Length; i++)
                    {
                        pass += "*";
                    }

                LogInfo($"Password changed: {pass ?? "NULL"}");
            }

            if (input == Inputs[2])
            {
                channel = input.Value == null ? 0 : int.Parse(input.Value);
                LogInfo($"Channel changed: {channel}");
            }

            if (input == Inputs[0] && address != null)
            {
                SendValue(input.Value);
            }
        }
        public override void OnInputChange(Input input)
        {
            if (input == Inputs[0])
            {
                if (input.Value == null)
                {
                    if (Settings["StopWhenDisconnected"].Value == "true")
                        Stop();

                    if (Settings["ResetWhenDisconnected"].Value == "true")
                        Reset();
                }
                else
                {
                    endValue = double.Parse(input.Value);

                    Start();
                }
            }


            if (input == Inputs[1])
            {
                if (input.Value == null)
                    range = DEFAULT_RANGE;
                else
                    double.TryParse(input.Value, out range);

                if (range < 0.0001)
                    range = 0.0001;

                LogInfo($"Range changed to {range}/s");
            }
        }
        public override void OnInputChange(Input input)
        {
            try
            {
                double value = double.Parse(Inputs[0].Value);
                var outMinRGB = Inputs[1].Value;
                var outMaxRGB = Inputs[2].Value;
                
                if (outMinRGB[0] == '#')
                    outMinRGB = outMinRGB.Remove(0, 1);

                if (outMaxRGB[0] == '#')
                    outMaxRGB = outMaxRGB.Remove(0, 1);

                var resultRGB = "";

                for (var i = 0; i < 4; i++)
                {
                    var outMin = int.Parse(outMinRGB.Substring(i * 2, 2), NumberStyles.HexNumber);
                    var outMax = int.Parse(outMaxRGB.Substring(i * 2, 2), NumberStyles.HexNumber);

                    var result = (int)Remap(value, 0, 100, outMin, outMax);
                    result = Clamp(result, 0, 255);

                    resultRGB += result.ToString("X2");
                }

                Outputs[0].Value = resultRGB;
            }
            catch
            {
                LogError($"Incorrect value in input.");
                ResetOutputs();
            }
        }
        public override void OnInputChange(Input input)
        {

            if (input == Inputs[3] && input.Value == "1")
            {
                Counter = -1;
                Outputs[0].Value = "0";
                return;
            }

            if (input == Inputs[1] && input.Value == "1")
            {
                Counter++;

                double divideBy = double.Parse(Inputs[0].Value);

                double width = 50;
                if (Inputs[2].Value != null)
                    width = double.Parse(Inputs[2].Value);


                if (Counter >= divideBy)
                {
                    Counter = 0;
                }

                Outputs[0].Value = divideBy * (width / 100) > Counter ? "1" : "0";
            }
        }
        public override void OnInputChange(Input input)
        {
            var a = double.Parse(Inputs[0].Value);
            var b = double.Parse(Inputs[1].Value);
            var c = Math.Pow(a, b);

            Outputs[0].Value = c.ToString();
        }
        public override void OnInputChange(Input input)
        {
            if (input.Value == null)
                return;

            LastRecordCached = new NodeData(Id, input.Value);
            LastRecordUpdated = true;
        }
        public override void OnInputChange(Input input)
        {
            if (input == Inputs[2])
            {
                if (input.Value == null)
                    interval = DEFAULT_INTERVAL;
                else
                    double.TryParse(input.Value, out interval);

                if (interval < 1)
                    interval = 1;

                LogInfo($"Interval changed to {interval} ms");
            }

            if (Inputs[0].Value == null || Inputs[1].Value == null)
            {
                Stop();

                if (Outputs[0].Value != null)
                    Outputs[0].Value = null;

                return;
            }

            if (input == Inputs[3])
            {
                if (input.Value == "0")
                {
                    Stop();
                    return;
                }
                if (input.Value == "1")
                {
                    try
                    {
                        startValue = ConvertHexStringToIntArray(Inputs[0].Value);
                        endValue = ConvertHexStringToIntArray(Inputs[1].Value);

                        if (startValue.Length != 3 || endValue.Length != 3)
                            throw new Exception("Incorrect value in input.");

                        Start();
                    }
                    catch
                    {
                        LogError("Incorrect value in input.");
                        Stop();

                        if (Outputs[0].Value != null)
                            Outputs[0].Value = null;
                    }

                }
            }

        }
        public override void OnInputChange(Input input)
        {
            if (input == Inputs[1])
            {
                if (input.Value == null)
                    interval = DEFAULT_INTERVAL;
                else
                    double.TryParse(input.Value, out interval);

                if (interval < 1)
                    interval = 1;

                LogInfo($"Interval changed to {interval} ms");
            }


            if (input == Inputs[0])
            {
                if (input.Value == null)
                {
                    if (Settings["StopWhenDisconnected"].Value == "true")
                        Stop();

                    if (Settings["ResetWhenDisconnected"].Value == "true")
                        Reset();
                }
                else
                {
                    try
                    {
                        startValue = (int[])currentValue.Clone();
                        endValue = ConvertHexStringToIntArray(Inputs[0].Value);

                        if (endValue.Length != 3)
                            throw new Exception("Incorrect value in input.");

                        Start();
                    }
                    catch
                    {
                        LogError("Incorrect value in input.");

                        if (Settings["StopWhenDisconnected"].Value == "true")
                            Stop();

                        if (Settings["ResetWhenDisconnected"].Value == "true")
                            Reset();
                    }

                }
            }

        }
        public override void OnInputChange(Input input)
        {
            try
            {
                var a = double.Parse(Inputs[0].Value);
                var b = Math.Sqrt(a);

                Outputs[0].Value = b.ToString();
            }
            catch
            {
                Outputs[0].Value = null;
            }
        }
        public override void OnInputChange(Input input)
        {
            if (input == Inputs[0] && Inputs[0].Value == "1")
            {
                var rand = new Random(DateTime.Now.Millisecond);

                var min = Inputs[1].Value == null ? DEFAULT_MIN*100 : (int) (double.Parse(Inputs[1].Value)*100);
                var max = Inputs[2].Value == null ? DEFAULT_MAX*100 : (int) (double.Parse(Inputs[2].Value)*100);

                double rnd = rand.Next(min, max);
                rnd = rnd/100;

                Outputs[0].Value = rnd.ToString();
            }
        }
        public override void OnInputChange(Input input)
        {
            //delete
            if (input == Inputs[4] && input.Value == "1")
            {
                var fileName = Inputs[0].Value;
                try
                {
                    File.Delete(fileName);
                }
                catch (Exception)
                {
                    LogError($"Failed to delete file [{fileName}]");
                }
                Outputs[0].Value = null;
            }

            //write
            if (input == Inputs[3] && input.Value == "1")
            {
                var fileName = Inputs[0].Value;
                try
                {
                    var text = Inputs[1].Value;
                    File.AppendAllText(fileName, text);
                }
                catch (Exception)
                {
                    LogError($"Failed to write file [{fileName}]");
                }
            }

            //read
            if (input == Inputs[2] && input.Value == "1")
            {
                var fileName = Inputs[0].Value;
                try
                {
                    var text = File.ReadAllText(fileName);
                    Outputs[0].Value = text;
                }
                catch (Exception)
                {
                    LogError($"Failed to read file [{fileName}]");
                    Outputs[0].Value = null;
                }
            }
        }
        public override void OnInputChange(Input input)
        {
            List<ConnectionLocalReceiverNode> receivers;

            lock (engine.nodesLock)
                receivers = engine.GetNodes()
                    .OfType<ConnectionLocalReceiverNode>()
                    .Where(x => x.Settings["Channel"].Value == Settings["Channel"].Value)
                    .ToList();

            foreach (var receiver in receivers)
            {
                receiver.ReceiveValue(input.Value, PanelName);
                LogInfo($"Transmit to [{receiver.PanelName}: Receiver] : [{input.Value ?? "NULL"}]");
            }
        }
        public override void OnInputChange(Input input)
        {
            if (input.Value == null)
                return;

            MySensorsNodeInput mySensorsNodeInput = (MySensorsNodeInput)input;

            //LogInfo($"Hardware Node{nodeId} Sensor{mySensorsNodeInput.sensorId} input: {input.Value}");

            if (MySensorsNodesEngine.gateway != null)
                MySensorsNodesEngine.gateway.SendSensorState(mySensorsNodeInput.nodeId, mySensorsNodeInput.sensorId,
                    input.Value);
            else
            {
                // LogError($"Can`t send message to Node[{mySensorsNodeInput.nodeId}] Sensor[{mySensorsNodeInput.sensorId}]. Gateway is not connected.");
            }
        }
Example #18
0
        public override void OnInputChange(Input input)
        {
            int max = (int)double.Parse(Settings["MaxRecords"].Value);
            if (max < 0)
                max = 0;

            LastRecord = new NodeData(Id, input.Value);
            log.Add(LastRecord);

            while (log.Count > max)
                log.Remove(log.First());

            UpdateMeOnDashboard();

            if (Settings["WriteInDatabase"].Value == "true")
                AddNodeData(input.Value, max);
        }
Example #19
0
        public void AddInputNode(PanelInputNode node)
        {
            if (Inputs.Any(x => x.Id == node.Id))
                return;

            var input = new Input
            {
                Id = node.Id,
                Name = GenerateNewInputName()
            };

            node.Settings["Name"].Value = input.Name;
            AddInput(input);

            UpdateMeInEditor();
            UpdateMeInDb();
        }
        public override void OnInputChange(Input input)
        {
            if (input == Inputs[0])
            {
                if (input.Value == null)
                    return;

                var delay = (DateTime.Now - lasTime).TotalMilliseconds;
                lasTime = DateTime.Now;

                Outputs[0].Value = delay.ToString();
            }
            if (input == Inputs[1] && input.Value == "1")
            {
                lasTime = DateTime.Now;
                ResetOutputs();
            }
        }
        public override void OnInputChange(Input input)
        {
            if (input == Inputs[0] && input.Value != null)
            {
                double val = double.Parse(input.Value);

                if (min == null || val < min)
                {
                    min = val;
                    Outputs[0].Value = min.ToString();
                }
            }

            if (input == Inputs[1] && input.Value == "1")
            {
                min = null;
                Outputs[0].Value = null;
            }
        }
        public override void OnInputChange(Input input)
        {
            if (input == Inputs[2])
            {
                if (input.Value == null)
                    interval = DEFAULT_INTERVAL;
                else
                    double.TryParse(input.Value, out interval);

                if (interval < 1)
                    interval = 1;

                LogInfo($"Interval changed to {interval} ms");
            }

            if (Inputs[0].Value == null || Inputs[1].Value == null)
            {
                Stop();
                return;
            }

            if (input == Inputs[3])
            {
                if (input.Value == "0")
                {
                    Stop();

                    if (Outputs[0].Value != null)
                        Outputs[0].Value = null;

                    return;
                }
                if (input.Value == "1")
                {
                    startValue = double.Parse(Inputs[0].Value);
                    endValue = double.Parse(Inputs[1].Value);

                    Start();
                }
            }

        }
        public override void OnInputChange(Input input)
        {
            try
            {
                int index = (int)double.Parse(Inputs[0].Value) + 1;


                if (index < 1 || index > Outputs.Count)
                {
                    LogError("Output Number is out of range");
                    return;
                }

                Outputs[index - 1].Value = Inputs[1].Value;
            }
            catch
            {
                LogIncorrectInputValueError(Inputs[0]);
            }
        }
        public override void OnInputChange(Input input)
        {
            if (input == Inputs[0])
            {
                if (input.Value == null)
                    interval = DEFAULT_INTERVAL;
                else
                    double.TryParse(input.Value, out interval);

                LogInfo($"Interval changed to {interval} ms");
            }


            if (input == Inputs[1])
            {
                enabled = input.Value == "1" || input.Value == null;
                state = enabled;
                LogInfo(enabled ? "Start" : "Stop");
                Outputs[0].Value = state ? "1" : "0";
            }
        }
        public override void OnInputChange(Input input)
        {
            if (input == Inputs[0])
            {
                delayedValues.Add(new DelayedValue(input.Value));
            }


            if (input == Inputs[1])
            {
                if (input.Value == null)
                    interval = DEFAULT_INTERVAL;
                else
                    double.TryParse(input.Value, out interval);

                if (interval < 1)
                    interval = 1;

                LogInfo($"Interval changed to {interval} ms");
            }
        }
        public override void OnInputChange(Input input)
        {
            if (input == Inputs[0] && Inputs[0].Value == "1")
            {
                try
                {
                    var inMinRGB = Inputs[1].Value == null ? DEFAULT_MIN : Inputs[1].Value;
                    var inMaxRGB = Inputs[2].Value == null ? DEFAULT_MAX : Inputs[2].Value;

                    if (inMinRGB[0] == '#')
                        inMinRGB = inMinRGB.Remove(0, 1);

                    if (inMaxRGB[0] == '#')
                        inMaxRGB = inMaxRGB.Remove(0, 1);


                    var resultRGB = "";

                    var rand = new Random(DateTime.Now.Millisecond);

                    for (var i = 0; i < 3; i++)
                    {
                        int min = int.Parse(inMinRGB.Substring(i * 2, 2), NumberStyles.HexNumber);
                        int max = int.Parse(inMaxRGB.Substring(i * 2, 2), NumberStyles.HexNumber);

                        int rnd = rand.Next(min, max + 1);
                        rnd = Clamp(rnd, 0, 255);

                        resultRGB += rnd.ToString("X2");
                    }

                    Outputs[0].Value = resultRGB;
                }
                catch
                {
                    LogError($"Incorrect value in input.");
                    ResetOutputs();
                }
            }
        }
        public override void OnInputChange(Input input)
        {
            if (input == Inputs[1])
            {
                if (input.Value == null)
                    frequency = DEFAULT_FREQUENCY;
                else
                {
                    double f;
                    double.TryParse(input.Value, out f);
                    frequency = (int)(f < 37 ? 37 : f > 32767 ? 32767 : f);
                }
            }

            if (input == Inputs[2])
            {
                if (input.Value == null)
                    duration = DEFAULT_DURATION;
                else
                {
                    double d;
                    double.TryParse(input.Value, out d);
                    duration = (int)(d < 1 ? 1 : d > 10000 ? 10000 : d);
                }
            }

            if (input == Inputs[0] && input.Value == "1")
            {
                try
                {
                    Beep(frequency, duration);
                    LogInfo($"Beep");
                }
                catch
                {
                    LogError($"Incorrect value in input");
                }
            }
        }
        public override void OnInputChange(Input input)
        {
            if (input == Inputs[1] && input.Value != null)
            {
                interval = double.Parse(input.Value);
                return;
            }

            if (input == Inputs[0])
            {
                if (!IsBlocked())
                {
                    lastTime = DateTime.Now;
                    Outputs[0].Value = input.Value;
                }
                else if (Settings["sendlast"].Value == "true")
                {
                    lastValue = input.Value;
                    waitingToSend = true;
                }
            }
        }
        public override void OnInputChange(Input input)
        {
            if (input == Inputs[1])
            {
                if (input.Value == null)
                    interval = DEFAULT_INTERVAL;
                else
                    double.TryParse(input.Value, out interval);

                if (interval < 1)
                    interval = 1;

                timer.Stop();
                timer.Interval = interval / 2;
                timer.Start();

                LogInfo($"Interval changed to {interval} ms");
            }

            if (input == Inputs[0])
            {
                if (input.Value == null)
                    Stop();
                else
                {
                    count = (int)double.Parse(input.Value);
                    LogInfo($"Count changed to [{count}]");
                }
            }


            if (input == Inputs[2] && input.Value == "1")
                Start();

            if (input == Inputs[3] && input.Value == "1")
                Stop();
        }
        public override void OnInputChange(Input input)
        {
            if (input == Inputs[1] && Inputs[1].Value == "1")
            {
                try
                {
                    var path = Inputs[0].Value;

                    var proc1 = new ProcessStartInfo();
                    proc1.UseShellExecute = true;
                    proc1.WorkingDirectory = @"C:\Windows\System32";
                    proc1.FileName = @"C:\Windows\System32\cmd.exe";
                    proc1.Arguments = "/c " + path;
                    proc1.WindowStyle = ProcessWindowStyle.Hidden;
                    Process.Start(proc1);

                    LogInfo("Executed");
                }
                catch (Exception)
                {
                    LogInfo("Incorrect command");
                }
            }
        }