public bool Start(TrainProject project) { if (IsRunning) { return(true); } // We first initialize the program if (!Init(project)) { return(false); } // Then we plug all event handlers foreach (Hub t in hubs) { t.ColorTriggered += ColorTriggeredHandler; t.DistanceTriggered += DistanceTriggeredHandler; t.RemoteTriggered += RemoteTriggeredHandler; } MainBoard.WriteLine($"All Sensor Events for {Name} are active.", Color.DarkMagenta); IsRunning = true; return(true); }
/// <summary> /// Click on the "Open All" /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public static TrainProject Load(string path) { try { IFormatter formatter = new BinaryFormatter(); using (Stream stream = new FileStream(path, FileMode.Open, FileAccess.Read)) { TrainProject project = (TrainProject)formatter.Deserialize(stream); project.Path = path; stream.Close(); // Make sure we clear any event serialized foreach (Hub train in project.RegisteredTrains) { train.CleanAllEvents(); } return(project); } } catch (Exception ex) { MainBoard.WriteLine("ERROR - Could not open file: " + ex.Message, System.Drawing.Color.Red); return(null); } }
//modified by Tom Cook for MU function to add TrainProject project to class where need to loop thru all hubs and ports //public EV3Hub(BluetoothLEDevice device, Types type, string comAddress) : base(device, type) public EV3Hub(BluetoothLEDevice device, Types type, TrainProject project, string comAddress) : base(device, type, project) { Name = "EV3"; DeviceId = comAddress; Type = type; IsConnected = false; InitPorts(); }
public SectionsEditor(TrainProject project) { Project = project; InitializeComponent(); RecreateTrainsUI(); RecreateSectionsUI(); // Hook up event if any part of the sections change Project.Sections.DataUpdated += RefreshTrainProperties; }
public TrainSectionControl(TrainProject project, SectionsEditor editor, Hub h, Port p) { Project = project; Train = h; PortId = p.Id; Editor = editor; Train.DataUpdated += Train_DataUpdated; SuspendLayout(); InitializeComponent(); RefreshUI(); }
public SectionControl(TrainProject project, Section section, SectionsEditor editor, bool showDelete) { Project = project; Section = section; Editor = editor; InitializeComponent(); RefreshUI(); if (showDelete) { pictureBoxDelete.Show(); } }
//modified by Tom Cook for MU function to add TrainProject project to class where need to loop thru all hubs and ports //public HubControl(Hub hub) public HubControl(Hub hub, TrainProject project) { Hub = hub; Hub.PortTypeUpdated += RefreshUI; Hub.DataUpdated += UpdateLabels; //modified by Tom Cook, see above //Editor = new HubEditor(Hub); Editor = new HubEditor(Hub, project); //added by Tom Cook, see above Project = project; InitializeComponent(); InitControl(); }
public bool Init(TrainProject project) { sections = project.Sections; hubs = project.RegisteredTrains; if (hubs == null || hubs.Count == 0) { return(false); } foreach (Hub t in hubs) { t.State = (t.State == null) ? new int[100] : t.State; } // Make sure GlobalStates exist Global = (Global == null) ? new int[100] : Global; // Make sure GlobalCode exist GlobalCode = (project.GlobalCode == null) ? new TrainProgramEvent(TrainProgramEvent.EventType.Global_Code) : project.GlobalCode; return(true); }
public FormCodeEditor(TrainProgramEvent codeEvent, TrainProject project, bool editGlobalCode) { // Init code to edit and global code CodeEvent = codeEvent; GlobalCode = (editGlobalCode) ? null : project.GlobalCode; // Attach Hubs without launching sensors. this.hubs = project.RegisteredTrains; this.sections = project.Sections; foreach (Hub h in hubs) { h.State = h.State ?? (new int[100]); } // Init Components InitializeComponent(); if (codeEvent.Name != null) { textBoxName.Text = codeEvent.Name; } fastColoredTextBox1.Text = codeEvent.CodeToRun; fastColoredTextBox1.TextChanged += fastColoredTextBox1_TextChanged; fastColoredTextBox1.SelectAll(); fastColoredTextBox1.Selection.SetStyle(GreenStyle, @"//.*$", RegexOptions.Multiline); fastColoredTextBox1.Selection.SetStyle(BrownStyle, @"""""|@""""|''|@"".*?""|(?<!@)(?<range>"".*?[^\\]"")|'.*?[^\\]'"); fastColoredTextBox1.Selection.SetStyle(MagentaStyle, @"\b\d+[\.]?\d*([eE]\-?\d+)?[lLdDfF]?\b|\b0x[a-fA-F\d]+\b"); fastColoredTextBox1.Selection = new Range(fastColoredTextBox1, 0); // if Globa Code is null, it means we are editing the global code itself buttonTestCode.Text = (GlobalCode == null) ? "Compile Code" : "Run Code"; InitLabel(); InitAutocomplete(); }
//modified by Tom Cook to add project of connected hubs for MU function //public HubEditor(Hub hub) public HubEditor(Hub hub, TrainProject project) { //added by Tom Cook, see above Project = project; CurrentHub = hub; InitializeComponent(); foreach (Hub.Types ev in (Hub.Types[])Enum.GetValues(typeof(Hub.Types))) { comboBoxType.Items.Add(Enum.GetName(typeof(Hub.Types), ev)); } foreach (Port.Colors ev in (Port.Colors[])Enum.GetValues(typeof(Port.Colors))) { comboBoxColors.Items.Add(Enum.GetName(typeof(Port.Colors), ev)); } if (hub.Type == Hub.Types.SBRICK) { comboBoxType.Enabled = false; } }
//modified by Tom Cook for MU function to add TrainProject project to class where need to loop thru all hubs and ports //public BuWizzHub(BluetoothLEDevice device, Types type) : base(device, type) public BuWizzHub(BluetoothLEDevice device, Types type, TrainProject project) : base(device, type, project) { }
public void Init(Section sectionToEdit, TrainProject project) { Project = project; CurrentSection = sectionToEdit; RefreshUI(); }