Example #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);
        }
        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);
            }
        }
Example #3
0
 private void ZendNul()
 {
     MPUSB.WriteDigitalOutPortD(0);
     MPUSB.WriteDigitalOutPortD(2);
     MPUSB.Wait(1);
     MPUSB.WriteDigitalOutPortD(0);
 }
Example #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;
        }
Example #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;
            }
        }
Example #6
0
 private void ZendEen()
 {
     MPUSB.WriteDigitalOutPortD(0);
     MPUSB.WriteDigitalOutPortD(3);
     MPUSB.Wait(1);
     MPUSB.WriteDigitalOutPortD(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();
        }
Example #8
0
 private void btnTeller(object sender, RoutedEventArgs e)
 {
     for (short i = 0; i <= 255; i++)
     {
         MPUSB.WriteDigitalOutPortD(i);
     }
 }
Example #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;
            }
        }
Example #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);
        }
Example #11
0
 public void TurnOffAllLeds()
 {
     MPUSB.WriteDigitalOutPortD(0x00);
     foreach (CheckBox c in checkboxes)
     {
         c.IsChecked = false;
     }
 }
Example #12
0
 public void TurnOnAllLeds()
 {
     MPUSB.WriteDigitalOutPortD(0xFF);
     foreach (CheckBox c in checkboxes)
     {
         c.IsChecked = true;
     }
 }
        private void ELaagInstructie()
        {
            int value = MPUSB.ReadDigitalOutPortD();

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

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

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

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

            MPUSB.WriteDigitalOutPortD((short)newv);
        }
        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";
                    }
                }
            }));
        }
Example #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);
        }
        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);
        }
Example #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);
        }
Example #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
 }
        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));
        }
        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;
        }
Example #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());
        }
        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>")));
            }
        }