Exemple #1
0
        //load file
        private void actionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Motion != null)
            {
                if (!onPC)
                    RoBoIO.rcservo_Close();
                DialogResult dialogResult = MessageBox.Show("Do you want to save?", "", MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.Yes)
                {
                    saveFileToolStripMenuItem_Click(sender,e);
                }
            }
            NewMotion nMotion = new NewMotion();
            ME_Triggerlist = new ArrayList();
            ME_Motionlist = new ArrayList();
            string[] rbver = new string[] { "---unset---",
                                            "RB_100b1",
                                            "RB_100b2",
                                            "RB_100b3",
                                            "RB_100",
                                            "RB_100RD",
                                            "RB_110",
                                            "unknow"};
            string[] servo = new string[] { "---noServo---",
                                            "KONDO_KRS786",
                                            "KONDO_KRS788",
                                            "KONDO_KRS78X",
                                            "KONDO_KRS4014",
                                            "KONDO_KRS4024",
                                            "HITEC_HSR8498",
                                            "FUTABA_S3003",
                                            "SHAYYE_SYS214050",
                                            "TOWERPRO_MG995",
                                            "TOWERPRO_MG996",
                                            "DMP_RS0263",
                                            "DMP_RS1270",
                                            "GWS_S777",
                                            "GWS_S03T",
                                            "GWS_MICRO"};
            ME_Motion motiontag = null;

            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Filter = "rbm files (*.rbm)|*.rbm";
            dialog.InitialDirectory = Environment.CurrentDirectory + "\\";
            dialog.Title = "Open File";
            String filename = (dialog.ShowDialog() == DialogResult.OK) ? dialog.FileName : null;
            if (filename == null)
            {
                return;
            }
            using (StreamReader reader = new StreamReader(filename))
            {
                nfilename = Path.GetFileName(dialog.FileName);
                triggerlist.Items.Clear();
                MotionCombo.Items.Clear();
                MotionCombo.Text = "";
                Motionlist.Items.Clear();
                delaytext.Text = "0";
                typecombo.Text = "";
                string[] datas = reader.ReadToEnd().Split(delimiterChars);
                for (int i = 0; i < datas.Length; i++)
                {
                    if (String.Compare(datas[i], "RoBoardVer") == 0)
                    {
                        i++;
                        for (int j = 0; j < rbver.Length; j++)
                            if (String.Compare(datas[i], rbver[j]) == 0)
                            {
                                nMotion.comboBox1.SelectedIndex = j;
                            }
                    }
                    else if (String.Compare(datas[i], "Homeframe") == 0)
                    {
                        i++;
                        if (String.Compare(datas[i], "Yes") == 0)
                            nMotion.checkBox1.Checked = true;
                        else
                            nMotion.checkBox1.Checked = false;
                    }
                    else if (String.Compare(datas[i], "Range") == 0)
                    {
                        i++;
                        if (String.Compare(datas[i], "Yes") == 0)
                            nMotion.checkBox2.Checked = true;
                        else
                            nMotion.checkBox2.Checked = false;
                    }
                    else if (String.Compare(datas[i], "Servo") == 0)
                    {

                        for (int k = 0; k < 32; k++)
                        {
                            i++;
                            for (int j = 0; j < servo.Length; j++)
                                if (String.Compare(datas[i], servo[j]) == 0)
                                    nMotion.fbox[k].SelectedIndex = j;
                        }
                    }
                    else if (String.Compare(datas[i], "Trigger") == 0)
                    {
                        ME_Trigger m = new ME_Trigger();
                        i++;
                        m.key = datas[i];
                        i++;
                        if (String.Compare(datas[i], "null") != 0)
                        {
                            m.motion = new ME_Motion();
                            m.motion.name = datas[i];
                            ME_Motionlist.Add(m.motion);
                        }
                        else
                            m.motion = null;
                        ME_Triggerlist.Add(m);
                    }
                    else if (String.Compare(datas[i], "Motion") == 0)
                    {
                        i++;
                        for (int j = 0; j < ME_Motionlist.Count; j++)
                        {
                            motiontag = (ME_Motion)ME_Motionlist[j];
                            if (String.Compare(datas[i], motiontag.name) != 0)
                                motiontag = null;
                            else
                                break;
                        }
                        if (motiontag == null)
                        {
                            motiontag = new ME_Motion();
                            motiontag.name = datas[i];
                            ME_Motionlist.Add(motiontag);
                        }
                    }
                    else if (String.Compare(datas[i], "MotionEnd") == 0)
                    {
                        i++;
                        if (String.Compare(datas[i], motiontag.name) == 0)
                            motiontag = null;
                    }
                    else if (String.Compare(datas[i], "frame") == 0)
                    {

                        ME_Frame nframe = new ME_Frame();
                        i++;
                        nframe.delay = int.Parse(datas[i]);
                        int j = 0;
                        while (j < 32)
                        {
                            if (String.Compare(nMotion.fbox[j].SelectedItem.ToString(), "---noServo---") != 0)
                            {
                                i++;
                                nframe.frame[j] = int.Parse(datas[i]);
                            }
                            else
                            {
                                nframe.frame[j] = 0;
                            }
                            j++;
                        }
                        motiontag.Events.Add(nframe);
                    }
                    else if (String.Compare(datas[i], "delay") == 0)
                    {
                        ME_Delay ndelay = new ME_Delay();
                        i++;
                        ndelay.delay = int.Parse(datas[i]);
                        motiontag.Events.Add(ndelay);
                    }
                    else if (String.Compare(datas[i], "sound") == 0)
                    {
                        ME_Sound nsound = new ME_Sound();
                        i++;
                        nsound.filename = datas[i];
                        i++;
                        nsound.delay = int.Parse(datas[i]);
                        motiontag.Events.Add(nsound);
                    }
                    else if (String.Compare(datas[i], "flag") == 0)
                    {
                        ME_Flag nflag = new ME_Flag();
                        i++;
                        nflag.name = datas[i];
                        motiontag.Events.Add(nflag);
                    }
                    else if (String.Compare(datas[i], "goto") == 0)
                    {
                        ME_Goto ngoto = new ME_Goto();
                        i++;
                        ngoto.name = datas[i];
                        i++;
                        ngoto.key = datas[i];
                        motiontag.Events.Add(ngoto);
                    }
                }
            }

            if (File.Exists("offset.txt"))
                using (StreamReader reader = new StreamReader(Environment.CurrentDirectory + "\\offset.txt"))
                {
                    string[] datas = reader.ReadToEnd().Split(delimiterChars);
                    for (int i = 0; i < 32; i++)
                    {
                        offset[i] = uint.Parse(datas[i]);
                    }

                }
            else
                for (int i = 0; i < 32; i++)
                {
                    offset[i] = 0;
                }
            if (File.Exists("homeframe.txt"))
                using (StreamReader reader = new StreamReader(Environment.CurrentDirectory + "\\homeframe.txt"))
                {
                    string[] datas = reader.ReadToEnd().Split(delimiterChars);
                    for (int i = 0; i < 32; i++)
                    {
                        homeframe[i] = uint.Parse(datas[i]);
                    }

                }
            else
                for (int i = 0; i < 32; i++)
                {
                    homeframe[i] = 0;
                }
            if (File.Exists("Range.txt"))
                using (StreamReader reader = new StreamReader(Environment.CurrentDirectory + "\\Range.txt"))
                {
                    string[] datas = reader.ReadToEnd().Split(delimiterChars);
                    for (int i = 0; i < 32; i++)
                    {
                        min[i] = uint.Parse(datas[i]);
                        Max[i] = uint.Parse(datas[i + 32]);
                    }
                }
            else
                for (int i = 0; i < 32; i++)
                {
                    min[i] = 600;
                    Max[i] = 2300;
                }
            if (nMotion.picfilename != null)
                Framelist.BackgroundImage = Image.FromFile(Environment.CurrentDirectory + "\\" + nMotion.picfilename);
            groupBox2.Enabled = true;
            groupBox3.Enabled = true;
            optionToolStripMenuItem.Enabled = true;
            saveFileToolStripMenuItem.Enabled = true;
            NewMotion.Enabled = false;
            Motion = nMotion;
            for (int i = 0; i < ME_Motionlist.Count; i++)
            {
                ME_Motion m = (ME_Motion)ME_Motionlist[i];
                MotionCombo.Items.Add(m.name);
            }
            for (int i = 0; i < ME_Triggerlist.Count; i++)
            {
                ME_Trigger t = (ME_Trigger)ME_Triggerlist[i];
                if(t.motion != null)
                    triggerlist.Items.Add("Trigger: " + t.key + "\tMotion: " + t.motion.name);
                else
                    triggerlist.Items.Add("Trigger: " + t.key + "\tMotion: ");

            }
            if (!onPC)
            {
                set_RBver();
                set_RCservo();
            }
        }
Exemple #2
0
 private void NewMotion_Click(object sender, EventArgs e)
 {
     if (MotionCombo.Text.IndexOf(" ") == -1)
     {
         MotionCombo.Items.Add(MotionCombo.Text);
         ME_Motion m = new ME_Motion();
         m.name = MotionCombo.Text;
         ME_Motionlist.Add(m);
         MotionCombo.SelectedIndex = MotionCombo.Items.Count - 1;
         Motionlist.Controls.Clear();
     }
     else
         MessageBox.Show("Motion name should without space.");
 }
Exemple #3
0
 public ME_Trigger()
 {
     this.key = null;
     this.motion = null;
 }