コード例 #1
0
        public IRReceiver(String id, String name, int receivePin, IRDB db = null) : base(id, name, db)
        {
            Category = DeviceCategory.IR_RECEIVER;

            _receivePin = receivePin;
            _receiving  = false;

            ConfigurePin(_receivePin, PinMode.DigitalInput);

            ArduinoCommand cmd = new ArduinoCommand();

            cmd.CommandAlias = "Start";
            cmd.Type         = ArduinoCommand.CommandType.START;
            AddCommand(cmd);

            cmd = new ArduinoCommand();
            cmd.CommandAlias = "Stop";
            cmd.Type         = ArduinoCommand.CommandType.STOP;
            AddCommand(cmd);

            cmd = new ArduinoCommand();
            cmd.CommandAlias = "Save";
            cmd.Type         = ArduinoCommand.CommandType.SAVE;
            AddCommand(cmd);
        }
コード例 #2
0
 public (int AcX, int AcY, int AcZ, int Temp, int GyX, int GyY, int GyZ) GetAccelerations()
 {
     try
     {
         ArduinoCommand cmd = new ArduinoCommand()
         {
             Command = Command.GetAccelerations
         };
         byte[] toWrite = cmd.GetCommandBytes();
         stream.Write(toWrite, 0, toWrite.Length);
         char          c;
         StringBuilder sb = new StringBuilder();
         while ((c = (char)stream.ReadByte()) != '}')
         {
             if (c != '{')
             {
                 sb.Append(c);
             }
         }
         string   str  = sb.ToString();
         string[] vals = str.Split(';');
         int      X    = int.Parse(vals[0].Substring(2));
         int      Y    = int.Parse(vals[1].Substring(2));
         int      Z    = int.Parse(vals[2].Substring(2));
         int      temp = int.Parse(vals[3].Substring(2));
         int      GyX  = int.Parse(vals[4].Substring(2));
         int      GyY  = int.Parse(vals[5].Substring(2));
         int      GyZ  = int.Parse(vals[6].Substring(2));
         return(X, Y, Z, temp, GyX, GyY, GyZ);
     }
     catch (Exception) { return(0, 0, 0, 0, 0, 0, 0); }
 }
コード例 #3
0
        override protected void ExecuteCommand(ArduinoCommand command, ExecutionArguments xargs)
        {
            switch (command.Type)
            {
            case ArduinoCommand.CommandType.START:
                _irCodes.Clear();
                _unknownCodes.Clear();
                _receiving = true;
                if (xargs != null && xargs.Arguments.Count > 0)
                {
                    _commandName = (String)xargs.Arguments[0];
                }
                break;

            case ArduinoCommand.CommandType.STOP:
                _receiving = false;
                break;

            case ArduinoCommand.CommandType.SAVE:
                _receiving = false;
                WriteIRCodes();
                return;
            }
            base.ExecuteCommand(command, xargs);
        }
コード例 #4
0
        protected ArduinoCommand AddRawCommand(String commandAlias, RawCommand rcmd)
        {
            ArduinoCommand command = AddCommand(commandAlias, ArduinoCommand.CommandType.SEND);

            command.AddArgument((int)rcmd);               //which raw command do we want to send
            command.AddArgument(0);                       //this is normally the 'bits' field so it isn't used
            command.AddArgument((int)IRProtocol.UNKNOWN); //this is how the board-side identifies it as
            return(command);
        }
コード例 #5
0
        internal StaticUpdateHandler(ApplicationState state)
        {
            _state = state;
            _commander = new ArduinoCommand();
            _commander.UpdateColorValue(ArduinoCommand.Colors.Red, _state.Red);
            _commander.UpdateColorValue(ArduinoCommand.Colors.Green, _state.Green);
            _commander.UpdateColorValue(ArduinoCommand.Colors.Blue, _state.Blue);

            _state.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(state_PropertyChanged);
        }
コード例 #6
0
        public override void ReadDevice()
        {
            base.ReadDevice();
            if (DB != null)
            {
                ClearCommands();
                AddCommands(DB.GetCommands(DeviceName));

                _repeatCommand = GetCommand(REPEAT_COMMAND);
            }
        }
コード例 #7
0
        override public void ReadDevice()
        {
            base.ReadDevice();

            ArduinoCommand cmd = DB.GetCommand(DeviceName, REPEAT_COMMAND);

            if (cmd != null)
            {
                long code = System.Convert.ToInt64(cmd.Arguments[0]);
                _ignoreCodes.Add(code);
            }
        }
コード例 #8
0
        override protected void SendCommand(ArduinoCommand command, ExecutionArguments xargs)
        {
            var timeDiff = (DateTime.Now.Ticks - LastCommandSentOn) / TimeSpan.TicksPerMillisecond;

            if (UseRepeatCommand && _repeatCommand != null && LastCommandSent != null && LastCommandSent.Equals(command) && timeDiff < RepeatInterval)
            {
                base.SendCommand(_repeatCommand, xargs);
                LastCommandSent = command;
            }
            else
            {
                base.SendCommand(command, xargs);
            }
        }
コード例 #9
0
        internal KeyboardUpdateHandler(ApplicationState state)
        {
            // Listen for name change changes across all processes/threads on current desktop...
            IntPtr hhook = SetWinEventHook(EVENT_OBJECT_NAMECHANGE, EVENT_OBJECT_NAMECHANGE, IntPtr.Zero,
                    procDelegate, 0, 0, WINEVENT_OUTOFCONTEXT);

            _state = state;
            _instance = this;
            _commander = new ArduinoCommand();
            _dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
            _dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
            _dispatcherTimer.Interval = new TimeSpan(0, 0, 0,0,50);
            _dispatcherTimer.Start();
        }
コード例 #10
0
        internal RandomUpdateHandler(ApplicationState state)
        {
            _state = state;
            _commander = new ArduinoCommand();
            _commander.UpdateColorValue(ArduinoCommand.Colors.Red, _state.Red);
            _commander.UpdateColorValue(ArduinoCommand.Colors.Green, _state.Green);
            _commander.UpdateColorValue(ArduinoCommand.Colors.Blue, _state.Blue);

            _dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
            _dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
            _dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 50);
            _dispatcherTimer.Start();

            _targetRed = _rand.Next(0, 256);
            _targetBlue = _rand.Next(0, 256);
            _targetGreen = _rand.Next(0, 256);
        }
コード例 #11
0
 //pin will not correspond to pin number for analog input pins being used
 //for digitalWrite
 public bool DigitalWrite(int pin, bool on)
 {
     try
     {
         ArduinoCommand cmd = new ArduinoCommand()
         {
             Command = Command.DigitalWrite,
             NumberOfReturnedBytes = 0
         };
         cmd.AddParameter(pin);
         cmd.AddParameter(on ? 1: 0);
         byte[] toWrite = cmd.GetCommandBytes();
         stream.Write(toWrite, 0, toWrite.Length);
         return(true);
     }
     catch (Exception) { return(false); }
 }
コード例 #12
0
        protected override void ExecuteCommand(ArduinoCommand command, ExecutionArguments xargs)
        {
            switch (command.CommandAlias.ToLower())
            {
            case "silence":
                int duration = xargs.GetInt(0, 10);
                Silence(duration);
                break;

            case "unsilence":
                Unsilence();
                break;

            default:
                base.ExecuteCommand(command, xargs);
                break;
            }
        }
コード例 #13
0
 //Sends the authorize command to arduino. Should be the first command sent, besides GetName.
 public bool Authorize()
 {
     try
     {
         ArduinoCommand command = new ArduinoCommand()
         {
             Command = Command.Authorize,
             NumberOfReturnedBytes = 1
         };
         command.Parameters.Add(ArduinoCommand.GetBytes(connection.Password));
         byte[] toWrite = command.GetCommandBytes();
         stream.Write(toWrite, 0, toWrite.Length);
         byte[] toRead = new byte[1];
         stream.Read(toRead, 0, toRead.Length);
         return(toRead[0] == 0x01);
     }
     catch (Exception) { return(false); }
 }
コード例 #14
0
        override protected void ExecuteCommand(ArduinoCommand command, ExecutionArguments xargs)
        {
            if (!_enabled)
            {
                List <ArduinoDevice> devices = Mgr.GetDevicesByPin(_transmitPin);

                foreach (var device in devices)
                {
                    if (device is IRTransmitter && device != this)
                    {
                        ((IRTransmitter)device).Disable();
                    }
                }

                Enable();
            }

            base.ExecuteCommand(command, xargs);
        }
コード例 #15
0
        override protected void ExecuteCommand(ArduinoCommand command, ExecutionArguments xargs)
        {
            switch (command.CommandAlias.ToLower())
            {
            case "blinktest":
                Blink(10, 100);
                break;

            case "blink":
                int repeat = xargs.GetInt(0, 1);
                int delay  = xargs.GetInt(1, 1000);
                Blink(repeat, delay);
                break;

            default:
                base.SendCommand(command, xargs);
                break;
            }
        }
コード例 #16
0
 public bool SetThruster(Thrusters thruster, int value)
 {
     try
     {
         ArduinoCommand command = new ArduinoCommand()
         {
             Command = Command.SetThruster,
             NumberOfReturnedBytes = 0
         };
         command.AddParameter((int)thruster);
         command.AddParameter(value);
         {
             byte[] toWrite = command.GetCommandBytes();
             stream.Write(toWrite, 0, toWrite.Length);
             return(true);
         }
     }
     catch (Exception) { return(false); }
 }
コード例 #17
0
 public bool VerticalStabilize(int verticalLeftPwr, int verticalRightPwr)
 {
     try
     {
         ArduinoCommand command = new ArduinoCommand()
         {
             Command = Command.VerticalStabilize,
             NumberOfReturnedBytes = 0
         };
         int verticalSpeed = ((verticalLeftPwr + verticalRightPwr) / 2) - 1500;
         int rollPos       = (verticalLeftPwr - verticalRightPwr) / 2;
         command.AddParameter(verticalSpeed);
         command.AddParameter(rollPos);
         byte[] toWrite = command.GetCommandBytes();
         stream.Write(toWrite, 0, toWrite.Length);
         return(true);
     }
     catch (Exception) { return(false); }
 }
コード例 #18
0
ファイル: IRDB.cs プロジェクト: billchetch/Arduino-Library-VS
        protected override ArduinoCommand CreateCommand(string deviceName, DBRow row)
        {
            var command = new ArduinoCommand((String)row["command_alias"]);

            command.Type = ArduinoCommand.CommandType.SEND;
            switch (Encoding)
            {
            case IREncoding.HEX:
                command.AddArgument(Convert.ToInt64((String)row["command"], 16));
                break;

            case IREncoding.LONG:
                command.AddArgument(Convert.ToInt64((String)row["command"]));
                break;
            }
            command.AddArgument(Convert.ToUInt16(row["bits"]));
            command.AddArgument(Convert.ToInt16(row["protocol"]));
            return(command);
        }
コード例 #19
0
        public bool SetServoSpeed(Servos servo, int speed)
        {
            ArduinoCommand cmd = new ArduinoCommand()
            {
                Command = Command.SetServoSpeed,
                NumberOfReturnedBytes = 0
            };

            cmd.AddParameter((int)servo);
            cmd.AddParameter(speed);
            try
            {
                byte[] toWrite = cmd.GetCommandBytes();
                stream.Write(toWrite, 0, toWrite.Length);
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
コード例 #20
0
 public string GetName()
 {
     if (isConnected())
     {
         try
         {
             ArduinoCommand command = new ArduinoCommand()
             {
                 Command = Command.GetName,
                 NumberOfReturnedBytes = 16
             };
             byte[] toWrite = command.GetCommandBytes();
             stream.Write(toWrite, 0, toWrite.Length);
             byte[] toRead = new byte[command.NumberOfReturnedBytes];
             stream.Read(toRead, 0, toRead.Length);
             return(ArduinoCommand.GetString(toRead));
         }
         catch (Exception)
         {
             return("Failed To Get Name");
         }
     }
     return("Failed to Get Name");
 }