コード例 #1
0
 private void StopPlayButton_Click(object sender, EventArgs e)
 {
     if (SerPort.IsOpen)
     {
         bot_busy = true;
         byte[] b = new byte[1];
         b[0] = 3;
         SerPort.Write(b, 0, 5);
     }
 }
コード例 #2
0
ファイル: Form1.cs プロジェクト: HaKDMoDz/circle-of-current
 private void SendCmd(int cmd)
 {
     if (SerPort.IsOpen)
     {
         byte[] b = new byte[1] {
             Convert.ToByte(cmd)
         };
         SerPort.Write(b, 0, 1);
     }
 }
コード例 #3
0
ファイル: Form1.cs プロジェクト: HaKDMoDz/circle-of-current
 private void AbortButton_Click(object sender, EventArgs e)
 {
     is_playing = false;
     byte[] b = new byte[5];
     b[0] = 0;
     b[1] = 3;
     b[2] = 0;
     b[3] = 0;
     b[4] = 0xFF;
     SerPort.Write(b, 0, 5);
 }
コード例 #4
0
        private void SendNextInstruct()
        {
            if (SerPort.BytesToWrite < 8)
            {
                byte[] b = new byte[5];
                b[0] = 0;
                b[1] = (byte)dev_event[event_cnt].sp_code;

                int delay = dev_event[event_cnt].delay;

                delay += dev_event[event_cnt].delay_manualadj;

                if (is_cali == false)
                {
                    delay += dev_event[event_cnt].delay_autoadj;
                }

                delay = Convert.ToInt32(Math.Round((double)delay * percent_adj));

                b[3] = Convert.ToByte(delay % 256);
                b[2] = Convert.ToByte((delay - Convert.ToInt32(b[3])) / 256);

                b[4] = (byte)dev_event[event_cnt].bitmask;

                SerPort.Write(b, 0, 5);

                event_cnt++;

                if (b[1] == 3)
                {
                    is_playing = false;
                    if (is_cali)
                    {
                        CalcAutoAdj();
                        ApplyToList();
                    }
                }
            }
        }
コード例 #5
0
        private void ProcessSend()
        {
            if (SerPort.IsOpen == false || bootload_enabled == false)
            {
                Thread.Sleep(250);
                return;
            }
            while (SerPort.BytesToRead >= 2)
            {
                while (SerPort.BytesToRead != 2)
                {
                    SerPort.ReadByte();
                }
                int c0   = SerPort.ReadByte();
                int c1   = SerPort.ReadByte();
                int addr = c0 + (c1 << 8);

                if (addr == 0xFFFF)
                {
                    stopwatch.Start();
                    byte[] b = new byte[2] {
                        (byte)(page_num % 256), (byte)(page_num >> 8),
                    };
                    SerPort.Write(b, 0, 2);
                    Log("MCU Sent Ready Signal");
                    Log("Replied Number of Pages: " + Convert.ToString(page_num, 10));
                }
                else if (addr == page_num)
                {
                    stopwatch.Stop();
                    long time_ms = stopwatch.ElapsedMilliseconds;
                    stopwatch.Reset();
                    double time_s = (double)time_ms / 1000.0;

                    Log("Bootloader Finished in " + Convert.ToString(time_s) + " Seconds");

                    bootload_enabled = false;
                    ButtonsSet(true, true, false);
                }
                else
                {
                    if (previous_addr == addr)
                    {
                        Log("Page Re-requested: " + Convert.ToString(addr, 10));
                        retry_cnt++;
                    }
                    else
                    {
                        retry_cnt = 0;
                    }
                    if ((previous_addr == addr || previous_addr + 1 == addr) && retry_cnt < 3)
                    {
                        previous_addr = (short)addr;
                        checksum      = 0;
                        byte[] b = new byte[256];
                        while ((SerPort.WriteBufferSize - 256) < SerPort.BytesToWrite)
                        {
                            ;
                        }
                        if (page_num < 6)
                        {
                            for (int i = addr * 256, j = 0; j < 256; i++, j++)
                            {
                                b[0]      = (byte)flash_data[i];
                                checksum += flash_data[i];
                                SerPort.Write(b, 0, 1);
                                ProgressSet(Convert.ToInt32(Math.Min(i, LoadProgress.Maximum)));
                            }
                        }
                        else
                        {
                            for (int i = addr * 256, j = 0; j < 256; i++, j++)
                            {
                                b[j]      = (byte)flash_data[i];
                                checksum += flash_data[i];
                            }
                            SerPort.Write(b, 0, 256);
                            ProgressSet(Convert.ToInt32(Math.Min((addr * 256) + 256, LoadProgress.Maximum)));
                        }
                        b[0] = (byte)(checksum % 256);
                        b[1] = (byte)(checksum >> 8);
                        SerPort.Write(b, 0, 2);
                    }
                    else
                    {
                        Log("Fatal Error, Received: 0x" + Convert.ToString(addr, 16).ToUpper() + ", Checksum was: 0x" + Convert.ToString(checksum, 16).ToUpper() + ", Retried: " + Convert.ToString(retry_cnt));

                        bootload_enabled = false;
                        ButtonsSet(true, true, false);
                    }
                }
            }
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: HaKDMoDz/circle-of-current
        void BotCtrl()
        {
            if (bot_status == 0)
            {
            }
            else if (bot_status == 1)
            {
                bot_busy           = false;
                bot_do_not_disturb = false;

                SongStatusLabel.Text = "Robot Wants File Name";

                if (FileListBox.Items[FileListBox.SelectedIndex].Length != 0)
                {
                    string str = "";
                    int    i;
                    for (i = 0; i < 8 && i < FileListBox.Items[FileListBox.SelectedIndex].Length; i++)
                    {
                        str += FileListBox.Items[FileListBox.SelectedIndex].SubString(i, 1);
                    }
                    for (int j = i; j < 8; j++)
                    {
                        str += "_";
                    }
                    SerPort.Write(str);

                    bot_status = 0;

                    SongStatusLabel.Text = "Robot is Waiting for Command";
                }
            }
            else if (bot_status == 2)
            {
                bot_do_not_disturb = true;
                bot_busy           = true;
                byte[] b = new byte[2];
                b[0] = event_length % 256;
                b[1] = Convert.ToByte((event_length - (int)b[0]) / 256);
                SerPort.Write(b, 0, 2);

                f_ptr = 0;

                bot_status = 0;
            }
            else if (bot_status == 3)
            {
                SongStatusLabel.Text = "Robot is Loading New Chart";

                bot_busy           = true;
                bot_do_not_disturb = true;

                if (SerPort.BytesToWrite < 8)
                {
                    byte[] b = new byte[5];
                    b[0] = 0;
                    b[1] = (byte)dev_event[f_ptr].sp_code;

                    int delay = dev_event[f_ptr].delay;

                    delay += dev_event[f_ptr].delay_manualadj;

                    delay = Convert.ToInt32(Math.Round((double)delay * percent_adj));

                    b[3] = Convert.ToByte(delay % 256);
                    b[2] = Convert.ToByte((delay - Convert.ToInt32(b[3])) / 256);

                    b[4] = (byte)dev_event[f_ptr].bitmask;

                    SerPort.Write(b, 0, 5);

                    f_ptr++;

                    ProgBar.Value = f_ptr;

                    bot_status = 0;
                }
            }
            else if (bot_status == 4)
            {
                bot_busy           = false;
                bot_do_not_disturb = false;

                SongStatusLabel.Text = "Robot is Finished Loading";

                bot_status = 0;
            }
            else if (bot_status == 5)
            {
                bot_busy = true;

                SongStatusLabel.Text = "Robot is Playing";

                bot_status = 0;
            }
            else if (bot_status == 6)
            {
                bot_busy = true;

                SongStatusLabel.Text = "Robot is Finished Playing";

                bot_status = 0;
            }
            else if (bot_status == 7)
            {
                stop_watch.Reset();
                stop_watch.Start();
                bot_status = 0;
            }
            else if (bot_status == 8)
            {
                stop_watch.Stop();
                time_taken          = (double)stop_watch.ElapsedMilliseconds / (double)1000;
                TimeTakenLabel.Text = Convert.ToString(time_taken);
                bot_status          = 0;
            }
            else if (bot_status == 128)
            {
                SongStatusLabel.Text = "File Missing on Disk";
                bot_status           = 0;
            }
            else if (bot_status == 255)
            {
                SongStatusLabel.Text = "Disk Error on Robot";
            }

            if (bot_busy)
            {
                PlayButton.Enabled     = false;
                LoadFileButton.Enabled = false;
                FileListBox.Enabled    = false;
            }
            else
            {
                PlayButton.Enabled     = true;
                LoadFileButton.Enabled = true;
                FileListBox.Enabled    = true;
            }

            if (bot_do_not_disturb)
            {
                StopPlayButton.Enabled = false;
            }
            else
            {
                StopPlayButton.Enabled = true;
            }
        }