コード例 #1
0
        private void UpdateUI()
        {
            int    value  = MPUSB.ReadDigitalOutPortD();
            string binary = Convert.ToString(value, 2).PadLeft(8, '0');
            int    l      = binary.Length;

            for (int i = 0; i < l; i++)
            {
                CheckBox chk = this.stpChk.Children[i] as CheckBox;
                chk.Tag = i;
                var b = binary.Substring(7 - i, 1);

                chk.Checked   -= chkChanged;
                chk.Unchecked -= chkChanged;

                if (b == "1")
                {
                    chk.IsChecked = true;
                }
                else
                {
                    chk.IsChecked = false;
                }

                chk.Checked   += chkChanged;
                chk.Unchecked += chkChanged;
            }
        }
コード例 #2
0
        void bg_DoWork(object sender, DoWorkEventArgs e)
        {
            BoardStatus oldStatus = null;

            while (true)
            {
                byte        portD     = (byte)MPUSB.ReadDigitalOutPortD();
                byte        portB     = (byte)MPUSB.ReadDigitalInPortB();
                BoardStatus newStatus = new BoardStatus();

                // ingedrukt = nul
                newStatus.Button1 = (portB & 1) == 0;
                newStatus.Button2 = (portB & 2) == 0;

                if (oldStatus != newStatus)
                {
                    Dispatcher.Invoke(new Action(() => {
                        chkButton1.IsChecked = newStatus.Button1;
                        chkButton2.IsChecked = newStatus.Button2;
                        lblDigitalB.Content  = Convert.ToString(portB, 2);
                        lblDigitalD.Content  = Convert.ToString(portD, 2);
                    }));
                }

                System.Threading.Thread.Sleep(100);
            }
        }
コード例 #3
0
        private bool WriteLCD(byte data, bool instruction)
        {
            if (data > 0xFF)
            {
                return(false);
            }

            if (instruction)
            {
                EHoogInstructie();
            }
            else
            {
                EHoogData();
            }

            int x = MPUSB.ReadDigitalOutPortD();
            int y = x & 0xF00;//datalijnen op 0 -> 1111 0000 0000
            int z = y | data;

            MPUSB.WriteDigitalOutPortD((short)z);

            if (instruction)
            {
                ELaagInstructie();
            }
            else
            {
                ELaagData();
            }

            MPUSB.Wait(1);

            return(true);
        }
コード例 #4
0
        private void ELaagInstructie()
        {
            //E = 0, RS = 0, RW = 0
            int x = MPUSB.ReadDigitalOutPortD();
            int y = x & 0x0FF;//E, RW en RS op 0 -> & 0000 1111 1111

            MPUSB.WriteDigitalOutPortD((short)y);
        }
コード例 #5
0
        private void ELaagInstructie()
        {
            int value = MPUSB.ReadDigitalOutPortD();

            value = value & 0x0FF;
            MPUSB.WriteDigitalOutPortD((short)value);
            MPUSB.Wait(25);
        }
コード例 #6
0
        private void ELaagData()
        {
            //E = 0, RS = 1, RW = 0
            int x = MPUSB.ReadDigitalOutPortD();
            int y = x & 0x8FF; //E, RW en RS op 0 -> & 1000 1111 1111
            int z = y | 0x400; //E op 0, RS op 1 -> | 0100 0000 0000

            MPUSB.WriteDigitalOutPortD((short)z);
        }
コード例 #7
0
        private void EHoogData()
        {
            //E = 1, RS = 1, RW = 0
            int x = MPUSB.ReadDigitalOutPortD();
            int y = x & 0x0FF; //E, RW en RS op 0 -> & 0000 1111 1111
            int z = y | 0x500; //E op 1, RS op 1 -> | 0101 0000 0000

            MPUSB.WriteDigitalOutPortD((short)z);
        }
コード例 #8
0
        private void EHoogInstructie()
        {
            // E = 1 / RW = 0 / RS = 0
            int x = MPUSB.ReadDigitalOutPortD();
            int y = x & 0x8FF; //E, RW en RS op 0 -> & 1000 1111 1111
            int z = y | 0x100; //E op 1 -> | 0001 0000 0000

            MPUSB.WriteDigitalOutPortD((short)z);
        }
コード例 #9
0
        private void ELaagData()
        {
            int value = MPUSB.ReadDigitalOutPortD();

            value = value & 0x0FF;
            value = value | 0x400;
            MPUSB.WriteDigitalOutPortD((short)value);
            MPUSB.Wait(25);
        }
コード例 #10
0
        private void DataVeranderen(int data)
        {
            int value = MPUSB.ReadDigitalOutPortD();

            value = value & 0xF00;
            value = value | data;
            MPUSB.WriteDigitalOutPortD((short)value);
            MPUSB.Wait(25);
        }
コード例 #11
0
        private void MoveLedsDown()
        {
            var value = (short)MPUSB.ReadDigitalOutPortD();
            var newv  = value >> 1;

            if (value % 2 == 1)
            {
                newv += 128;
            }

            MPUSB.WriteDigitalOutPortD((short)newv);
        }
コード例 #12
0
        private void chkChanged(object sender, RoutedEventArgs e)
        {
            CheckBox chk           = sender as CheckBox;
            int      current       = MPUSB.ReadDigitalOutPortD();
            string   currentString = Convert.ToString(current, 2).PadLeft(8, '0');

            int    change       = (int)Math.Pow(2, (int)chk.Tag);
            string changeString = Convert.ToString(change, 2).PadLeft(8, '0');

            int newValue = current ^ change;

            MPUSB.WriteDigitalOutPortD((short)newValue);
        }
コード例 #13
0
        private void MoveLedsUp()
        {
            var   value = (short)MPUSB.ReadDigitalOutPortD();
            short b128  = 128;
            var   ish   = value & b128;

            if (ish != 0)
            {
                value -= 128;
            }
            var newv = value << 1;

            if (ish != 0)
            {
                newv += 1;
            }
            MPUSB.WriteDigitalOutPortD((short)newv);
            Console.WriteLine(MPUSB.ReadDigitalOutPortD());
        }
コード例 #14
0
        private void ParseAndExecuteCommand(string command)
        {
            bool bekend = true; // of het command bekend is

            // commands
            if (command == "ledsaan")
            {
                MPUSB.WriteDigitalOutPortD(0xFF);
            }
            else if (command == "ledsuit")
            {
                MPUSB.WriteDigitalOutPortD(0x00);
            }
            else if (new Regex("^(?:ledsaan )[0-7]*$").Match(command).Success)     // ledsaan 0125 turns on leds 0, 1, 2 and 5
            {
                var    test      = new Regex("^(?:ledsaan )[0-7]*$").Match(command);
                string leds      = new Regex("^(?:ledsaan )[0-7]*$").Match(command).Value;
                string substring = leds.Substring(7);
                foreach (char c in substring)
                {
                    int   i       = (int)Char.GetNumericValue(c);
                    short status  = (short)MPUSB.ReadDigitalOutPortD();
                    short toWrite = (short)(status | (short)(Math.Pow(2, i)));
                    MPUSB.WriteDigitalOutPortD(toWrite);
                }
            }
            else
            {
                Console.WriteLine("Command niet herkend: " + command);
                bekend = false;
            }


            if (bekend)
            {
                this.Dispatcher.Invoke(new Action(() => lstCommands.Items.Add(command + " <gelukt>")));
            }
            else
            {
                this.Dispatcher.Invoke(new Action(() => lstCommands.Items.Add(command + " <niet gekend>")));
            }
        }
コード例 #15
0
 public byte GetLedStatus()
 {
     return((byte)MPUSB.ReadDigitalOutPortD());
 }
コード例 #16
0
 private void Button_ReadOutputs_Click(object sender, RoutedEventArgs e)
 {
     lblDigitalD.Content = Convert.ToString(MPUSB.ReadDigitalOutPortD(), 2);
     lblDigitalB.Content = Convert.ToString(MPUSB.ReadDigitalInPortB(), 2);
 }