Exemplo n.º 1
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);
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 3
0
 private void ZendNul()
 {
     MPUSB.WriteDigitalOutPortD(0);
     MPUSB.WriteDigitalOutPortD(2);
     MPUSB.Wait(1);
     MPUSB.WriteDigitalOutPortD(0);
 }
Exemplo n.º 4
0
        private void btnOpen(object sender, RoutedEventArgs e)
        {
            if (MPUSB.OpenMPUSBDevice() == 0)
            {
                txtVersie.Text = "Connected";
            }
            else if (MPUSB.OpenMPUSBDevice() == -1)
            {
                txtVersie.Text = "Connection failed";
                return;
            }
            DispatcherTimer UITimer = new DispatcherTimer();

            UITimer.Interval  = TimeSpan.FromMilliseconds(100);
            UITimer.Tick     += UITimer_Tick;
            UITimer.IsEnabled = true;

            DispatcherTimer ButtonTimer = new DispatcherTimer();

            ButtonTimer.Interval  = TimeSpan.FromMilliseconds(100);
            ButtonTimer.Tick     += ButtonTimer_Tick;
            ButtonTimer.IsEnabled = true;

            DispatcherTimer InputBTimer = new DispatcherTimer();

            InputBTimer.Interval  = TimeSpan.FromMilliseconds(1);
            InputBTimer.Tick     += InputBTimer_Tick;
            InputBTimer.IsEnabled = true;
        }
Exemplo n.º 5
0
        void InputBTimer_Tick(object sender, EventArgs e)
        {
            byte value = MPUSB.ReadDigitalInPortB();

            string pValue          = Convert.ToString(value, 2).Substring(4, 1);
            bool   isButtonPressed = false;

            if (pValue == "0")
            {
                isButtonPressed = true;
            }

            //txtInputB.Text = Convert.ToString(value, 2).PadLeft(8,'0');

            string turnValue = Convert.ToString(value, 2).PadLeft(8, '0').Substring(0, 2);

            if (turnValue != oldTurnValue)
            {
                if (oldTurnValue == "11")
                {
                    if (turnValue == "10")
                    {
                        txtInputB.Text = "links";
                        if (isButtonPressed)
                        {
                            MoveLedsDown();
                        }
                    }
                    else if (turnValue == "01")
                    {
                        txtInputB.Text = "rechts";
                        if (isButtonPressed)
                        {
                            MoveLedsUp();
                        }
                    }
                    else if (oldTurnValue == "00")
                    {
                        if (turnValue == "10")
                        {
                            txtInputB.Text = "rechts";
                            if (isButtonPressed)
                            {
                                MoveLedsDown();
                            }
                        }
                        else if (turnValue == "01")
                        {
                            txtInputB.Text = "links";
                            if (isButtonPressed)
                            {
                                MoveLedsUp();
                            }
                        }
                    }
                }

                oldTurnValue = turnValue;
            }
        }
Exemplo n.º 6
0
 private void ZendEen()
 {
     MPUSB.WriteDigitalOutPortD(0);
     MPUSB.WriteDigitalOutPortD(3);
     MPUSB.Wait(1);
     MPUSB.WriteDigitalOutPortD(0);
 }
Exemplo n.º 7
0
        public MainWindow()
        {
            InitializeComponent();

            CheckBox[] leds = new CheckBox[8];
            leds[0] = chk1;
            leds[1] = chk2;
            leds[2] = chk3;
            leds[3] = chk4;
            leds[4] = chk5;
            leds[5] = chk6;
            leds[6] = chk7;
            leds[7] = chk8;

            ledControl = new LedControlLayer(leds);

            MPUSB.OpenMPUSBDevice();

            timer.AutoReset = true;
            timer.Interval  = 200;
            timer.Elapsed  += timer_Elapsed;
            timer.Start();

            BackgroundWorker bg = new BackgroundWorker();

            bg.DoWork += bg_DoWork;
            bg.RunWorkerAsync();

            timer.AutoReset = true;
            timer.Interval  = 1;
            timer.Elapsed  += timerNew_Elapsed;
            timer.Start();
        }
Exemplo n.º 8
0
 private void btnTeller(object sender, RoutedEventArgs e)
 {
     for (short i = 0; i <= 255; i++)
     {
         MPUSB.WriteDigitalOutPortD(i);
     }
 }
Exemplo n.º 9
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;
            }
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
0
 public void TurnOffAllLeds()
 {
     MPUSB.WriteDigitalOutPortD(0x00);
     foreach (CheckBox c in checkboxes)
     {
         c.IsChecked = false;
     }
 }
Exemplo n.º 12
0
 public void TurnOnAllLeds()
 {
     MPUSB.WriteDigitalOutPortD(0xFF);
     foreach (CheckBox c in checkboxes)
     {
         c.IsChecked = true;
     }
 }
Exemplo n.º 13
0
        private void ELaagInstructie()
        {
            int value = MPUSB.ReadDigitalOutPortD();

            value = value & 0x0FF;
            MPUSB.WriteDigitalOutPortD((short)value);
            MPUSB.Wait(25);
        }
Exemplo n.º 14
0
        private void DataVeranderen(int data)
        {
            int value = MPUSB.ReadDigitalOutPortD();

            value = value & 0xF00;
            value = value | data;
            MPUSB.WriteDigitalOutPortD((short)value);
            MPUSB.Wait(25);
        }
Exemplo n.º 15
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);
        }
Exemplo n.º 16
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);
        }
Exemplo n.º 17
0
 public void DecreaseTeller()
 {
     this.teller--;
     if (teller < 0)
     {
         teller = 0;
     }
     MPUSB.WriteDigitalOutPortD(teller);
 }
Exemplo n.º 18
0
 public void IncreaseTeller()
 {
     this.teller++;
     if (teller > Math.Pow(2, 8))
     {
         teller = (Int16)Math.Pow(2, 8);
     }
     MPUSB.WriteDigitalOutPortD(teller);
 }
Exemplo n.º 19
0
        private void ELaagData()
        {
            int value = MPUSB.ReadDigitalOutPortD();

            value = value & 0x0FF;
            value = value | 0x400;
            MPUSB.WriteDigitalOutPortD((short)value);
            MPUSB.Wait(25);
        }
Exemplo n.º 20
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);
        }
Exemplo n.º 21
0
        private void MoveLedsDown()
        {
            var value = (short)MPUSB.ReadDigitalOutPortD();
            var newv  = value >> 1;

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

            MPUSB.WriteDigitalOutPortD((short)newv);
        }
Exemplo n.º 22
0
        void timerNew_Elapsed(object sender, ElapsedEventArgs e)
        {
            byte zotteKnopAb = MPUSB.ReadDigitalInPortB();

            zotteKnopAb = (byte)(zotteKnopAb >> 6);

            if (zotteKnopAb == zotteKnopAbOud)
            {
                return;
            }

            bool?draaiNaarLinks = null;

            if (zotteKnopAbOud == 0x3)  // 11b
            {
                if (zotteKnopAb == 0x2) // 10b
                {
                    draaiNaarLinks = true;
                }
                else
                {
                    draaiNaarLinks = false;
                }
            }
            else if (zotteKnopAbOud == 0x0) // 00
            {
                if (zotteKnopAb == 0x2)     // 10
                {
                    draaiNaarLinks = false;
                }
                else
                {
                    draaiNaarLinks = true;
                }
            }

            zotteKnopAbOud = zotteKnopAb;

            Dispatcher.Invoke(new Action(() => {
                if (draaiNaarLinks.HasValue)
                {
                    if (draaiNaarLinks.Value)
                    {
                        lblDraai.Content = "links";
                    }
                    else
                    {
                        lblDraai.Content = "rechts";
                    }
                }
            }));
        }
Exemplo n.º 23
0
        void ButtonTimer_Tick(object sender, EventArgs e)
        {
            var b = MPUSB.ReadDigitalInPortB();


            string binary = Convert.ToString(b, 2);

            txtVersie.Text = binary.ToString();
            string button1 = binary.Substring(binary.Length - 1, 1);
            string button2 = binary.Substring(binary.Length - 2, 1);
            int    val1    = Convert.ToInt32(button1);
            int    val2    = Convert.ToInt32(button2);
        }
Exemplo n.º 24
0
        private void Bw_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            AnalogOutput AnalogData = (AnalogOutput)e.UserState;

            pgbIngang1.Value = AnalogData.Potent1;
            pgbIngang2.Value = AnalogData.Potent2;
            pgbLight.Value   = AnalogData.LightSensor;


            double test = (double)AnalogData.LightSensor / 1024 * 256;

            MPUSB.WriteDigitalOutPortD((short)test);
        }
Exemplo n.º 25
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);
        }
Exemplo n.º 26
0
 private void btnInit_Click(object sender, RoutedEventArgs e)
 {
     MPUSB.OpenMPUSBDevice();
     if (rad8bit.IsChecked == true)
     {
         WriteLCD(0x38, true);                          //Function set, 8b, 2L, 5x7 -> 0011 1000
     }
     else
     {
         WriteLCD(0x28, true); //Function set, 4b, 2L, 5x7 -> 0010 1000
     }
     WriteLCD(0x02, true);     //Cursor home
     WriteLCD(0x0F, true);     //Display on, blink
 }
Exemplo n.º 27
0
        public MainWindow()
        {
            InitializeComponent();
            MPUSB.OpenMPUSBDevice();

            bw.WorkerSupportsCancellation = true;
            bw.WorkerReportsProgress      = true;

            bw.DoWork          += Bw_DoWork;
            bw.ProgressChanged += Bw_ProgressChanged;

            bw.RunWorkerAsync();

            pgbIngang1.Value = Convert.ToInt16(MPUSB.ReadAnalogIn(1));
            pgbIngang2.Value = Convert.ToInt16(MPUSB.ReadAnalogIn(0));
        }
Exemplo n.º 28
0
        private void Bw_DoWork(object sender, DoWorkEventArgs e)
        {
            AnalogOutput data = new AnalogOutput();

            do
            {
                System.Threading.Thread.Sleep(500);

                data.Potent1     = MPUSB.ReadAnalogIn(1);
                data.Potent2     = MPUSB.ReadAnalogIn(0);
                data.LightSensor = MPUSB.ReadAnalogIn(3);

                bw.ReportProgress(100, data);
            }while (!bw.CancellationPending);

            e.Cancel = true;
        }
Exemplo n.º 29
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());
        }
Exemplo n.º 30
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>")));
            }
        }