Exemplo n.º 1
0
        private void SetPinMode(NamedPin pin, PinMode mode)
        {
            Logger.Log("Sending SetPinMode( Pin={0}, PinMode={1} )", pin, mode);
            var c = new SendCommand((int)Command.SetPinMode);

            c.AddArgument(pin.Pin);
            c.AddArgument((int)mode);
            _messenger.SendCommand(c);
        }
Exemplo n.º 2
0
        private void Messenger_PinSetCommand(ReceivedCommand args)
        {
            int  pin   = args.ReadInt16Arg();
            bool state = args.ReadBoolArg();

            NamedPin p = NamedPin.GetNamedPin(pin);

            OnPinSet(p, state);
        }
Exemplo n.º 3
0
        public void SetPin(NamedPin pin, bool state)
        {
            Logger.Log("Sending SetPin( Pin={0}, State={1} )", pin, state);
            var c = new SendCommand((int)Command.SetPin);

            c.AddArgument(pin.Pin);
            c.AddArgument(state);
            _messenger.SendCommand(c);
        }
Exemplo n.º 4
0
 private void Server_MessageReceived(Object sender, MessageReceivedEventArgs e)
 {
     String[] s = e.Message.Split(',');
     if (s.Length == 2)
     {
         try
         {
             NamedPin p = NamedPin.GetNamedPin(s[0].Trim());
             bool     state;
             if (Boolean.TryParse(s[1], out state))
             {
                 _board.SetPin(p, state);
             }
         }
         catch (ArgumentException) { }
     }
 }
 public static NamedPin CreateNamedPin(int pin, String name)
 {
     if (_namedPinsByPin.ContainsKey(pin))
     {
         NamedPin p = _namedPinsByPin[pin];
         if (p.Name != name)
         {
             throw new ArgumentException(String.Format("Named pin already exists: {0} - {1}", pin, _namedPinsByPin[pin]));
         }
         return(p);
     }
     else
     {
         NamedPin p = new NamedPin(pin, name);
         _namedPinsByPin.Add(pin, p);
         _namedPinsByName.Add(name, p);
         return(p);
     }
 }
Exemplo n.º 6
0
 public PinSetEventArgs(NamedPin pin, bool state)
 {
     Pin   = pin;
     State = state;
 }
Exemplo n.º 7
0
 private void OnPinSet(NamedPin pin, bool state)
 {
     Logger.Log("OnPinSet( Pin={0}, State={1} )", pin, state);
     PinSet?.Invoke(this, new PinSetEventArgs(pin, state));
 }
Exemplo n.º 8
0
 private void CreateButton(NamedPin pin)
 {
     Logger.Log("Sending CreateButton( Pin={0} )", pin);
     _messenger.SendCommand(new SendCommand((int)Command.CreateButton, pin.Pin));
 }
Exemplo n.º 9
0
 public void TogglePin(NamedPin pin)
 {
     Logger.Log("Sending TogglePin( Pin={0} )", pin);
     _messenger.SendCommand(new SendCommand((int)Command.TogglePin, pin.Pin));
 }
Exemplo n.º 10
0
        private bool CreateActionFromUi(out BoardAction action)
        {
            if (NoAction.Checked)
            {
                action = null;
                return(true);
            }
            else if (SetLedAction.Checked)
            {
                bool setToState = SetLedActionStateOption.Checked;
                action = new SetLedBoardAction(setToState);
                return(true);
            }
            else if (SetPinAction.Checked)
            {
                if (SetPinActionPinOption.SelectedItem != null)
                {
                    NamedPin pin        = (NamedPin)SetPinActionPinOption.SelectedItem;
                    bool     setToState = SetPinActionStateOption.Checked;
                    action = new SetPinBoardAction(pin, setToState);
                    return(true);
                }
                else
                {
                    ShowError("Must select pin.");
                }
            }
            else if (TogglePinAction.Checked)
            {
                if (TogglePinActionPinOption.SelectedItem != null)
                {
                    NamedPin pin = (NamedPin)TogglePinActionPinOption.SelectedItem;
                    action = new TogglePinBoardAction(pin);
                    return(true);
                }
                else
                {
                    ShowError("Must select pin.");
                }
            }
            else if (RunScriptAction.Checked)
            {
                String fileName  = RunScriptActionFileNameOption.Text;
                String arguments = RunScriptActionArgumentsOption.Text;
                if (String.IsNullOrWhiteSpace(fileName))
                {
                    ShowError("File name cannot be blank.");
                }
                else
                {
                    action = new RunScriptBoardAction(fileName, arguments);
                    return(true);
                }
            }
            else if (SendTextAction.Checked)
            {
                String text = SendTextActionTextOption.Text;
                if (String.IsNullOrEmpty(text))
                {
                    ShowError("Text cannot be empty.");
                }
                else
                {
                    action = new SendTextBoardAction(text);
                    return(true);
                }
            }

            action = null;
            return(false);
        }
 public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
 {
     return(NamedPin.GetNamedPin(JToken.Load(reader).Value <String>()));
 }