private void checkProgramThenDoSomething(ModeType mode) { InstructionList copy_inst_list = new InstructionList(); foreach (InstructionEditor inst_ed in this.instructions.Items) { copy_inst_list.contents.Add(inst_ed.inst); } copy_inst_list.name = this.namebox.Text; // create a programming command Command c = new Command(); c.program_bytes = new byte[Comms.program_size]; // translate the program to bytes int rc = copy_inst_list.encode(c.program_bytes); copy_inst_list.updateProperties(); string err = ""; if (rc == InstructionList.program_too_big) { err = "This program is too large: there are too many instructions."; } else if (rc <= 0) { err = "This program contains no instructions: add at least one."; } else if (copy_inst_list.end_time <= 0) { err = "This program has no running time. It must contain some delays."; } switch (mode) { case ModeType.RunMode: // Start running the program if (err != "") { MessageBox.Show(err, "Run Program"); } else { c.t = CommandType.CommandRunTemporaryProgram; this.comms.SendCommand(c); SetProgram(copy_inst_list, this.program_number); buttonsUpdate(); } break; case ModeType.CheckMode: // Just checking, no other action if (err != "") { this.properties.Text = err; } break; case ModeType.SaveMode: // Are you sure you want to save? if (err != "") { MessageBox.Show(err, "Save Program"); } else { DialogResult dialogResult = MessageBox.Show("Really store program " + this.program_number + " in memory?", "Save Program", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { c.t = CommandType.CommandSaveEEPROMProgram; c.program_number = this.program_number; this.comms.SendCommand(c); this.Hide(); SetProgram(copy_inst_list, this.program_number); buttonsUpdate(); } } break; case ModeType.ExportMode: if (err != "") { MessageBox.Show(err, "Export Program"); } else { SaveFileDialog theDialog = new SaveFileDialog(); theDialog.Title = "Export Light Program File"; theDialog.Filter = save_filter; theDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); theDialog.FileName = this.save_filename; if (theDialog.ShowDialog() == DialogResult.OK) { this.save_filename = theDialog.FileName; ProgramIO.writeProgram(this.save_filename, c.program_bytes); } } break; } }
public void SetProgram(InstructionList inst_list, int program_number) { this.transition.Hide(); // make a copy of the program byte[] tmp = new byte[Comms.program_size]; inst_list.encode(tmp); InstructionList copy_inst_list = new InstructionList(tmp); // update the GUI with the details this.instructions.Items.Clear(); foreach (Instruction inst in copy_inst_list.contents) { this.instructions.Items.Add(new InstructionEditor (inst)); } this.instructions.Refresh(); this.program_number = program_number; this.namebox.Text = copy_inst_list.name; this.properties.Text = copy_inst_list.getProperties(); this.Text = "Edit Program " + program_number; buttonsUpdate(); }