Ejemplo n.º 1
0
 public Board(SerialPortInterface serialInterface, int id)
 {
     mInterface = serialInterface;
     mInterface.MessageReceived += messageReceived;
     mBoardID = id;
     Buttons  = new Button[4] {
         new Button(), new Button(), new Button(), new Button()
     };
     Encoders = new Encoder[4] {
         new Encoder(), new Encoder(), new Encoder(), new Encoder()
     };
     Leds = new Led[4] {
         new Led(mInterface, 0, id), new Led(mInterface, 1, id), new Led(mInterface, 2, id), new Led(mInterface, 3, id)
     };
 }
Ejemplo n.º 2
0
        void mSerialPortInterface_MessageReceived(object sender, SerialMessageReceivedEventArgs e)
        {
            mInterface = (SerialPortInterface)sender;
            mPortValid = true;

            UInt16 u16dat = BitConverter.ToUInt16(e.Message.Data, 0);
            Int16  i16dat = BitConverter.ToInt16(e.Message.Data, 0);

            if (e.Message.Command == Command.SET_ID)
            {
                IsConnected = true;
                if (Connected != null)
                {
                    Connected(this, null);
                }
            }
        }
Ejemplo n.º 3
0
 public BoardManager()
 {
     IsConnected = false;
     portNames.AddRange(System.IO.Ports.SerialPort.GetPortNames());
     mInterface = new SerialPortInterface(-1);
     mInterface.MessageReceived += mSerialPortInterface_MessageReceived;
     if (portNames.Count > 0)
     {
         mInterface.PortName = portNames[0];
         mInterface.Connect();
         mInterface.WriteMessage(new SerialMessage(Command.SET_ID, 0, 0));
         mThread = new Thread(portSelectionThread);
         mThread.IsBackground = true;
         mThread.Priority     = ThreadPriority.BelowNormal;
         mThread.Start();
     }
     else
     {
         MessageBox.Show("No COM ports found! Buttons and knobs will not work!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
     Boards = new Board[] { new Board(mInterface, 1), new Board(mInterface, 2), new Board(mInterface, 4), new Board(mInterface, 8) };
 }
Ejemplo n.º 4
0
 public Led(SerialPortInterface serialInterface, int number, int boardID)
 {
     mInterface = serialInterface;
     mLedNumber = number;
     mBoardId   = boardID;
 }
Ejemplo n.º 5
0
        void messageReceived(object sender, SerialMessageReceivedEventArgs e)
        {
            mInterface = (SerialPortInterface)sender;
            if (e.Message.ID != (byte)mBoardID)
            {
                return;
            }

            //byte[] swapped = new byte[]{e.Message.Data[1] ,e.Message.Data[0]};
            UInt16 u16dat = BitConverter.ToUInt16(e.Message.Data, 0);
            Int16  i16dat = BitConverter.ToInt16(e.Message.Data, 0);

            switch (e.Message.Command)
            {
            case Command.BTN:
                Buttons[0].Set(!isBitSet(u16dat, 0));
                Buttons[1].Set(!isBitSet(u16dat, 1));
                Buttons[2].Set(!isBitSet(u16dat, 2));
                Buttons[3].Set(!isBitSet(u16dat, 3));
                break;

            case Command.RT_BTN:
                Encoders[0].Button.Set(!isBitSet(u16dat, 0));
                Encoders[1].Button.Set(!isBitSet(u16dat, 1));
                Encoders[2].Button.Set(!isBitSet(u16dat, 2));
                Encoders[3].Button.Set(!isBitSet(u16dat, 3));
                break;

            case Command.RT_DELTA1:
                Encoders[0].Delta = i16dat;
                break;

            case Command.RT_DELTA2:
                Encoders[1].Delta = i16dat;
                break;

            case Command.RT_DELTA3:
                Encoders[2].Delta = i16dat;
                break;

            case Command.RT_DELTA4:
                Encoders[3].Delta = i16dat;
                break;

            case Command.TEMP:
                Temperature = ((double)i16dat) / 10.0;
                if (TemperatureChanged != null)
                {
                    TemperatureChanged(this, Temperature);
                }
                break;

            case Command.ANA:
                Analog = u16dat;
                if (AnalogChanged != null)
                {
                    AnalogChanged(this, Analog);
                }
                break;

            default:
                // Do nothing
                break;
            }
        }