/// <summary> /// Remove fields with given values /// </summary> /// <param name="dipSwitch">DipSwitch to remove fields from</param> private void RemoveFields(DipSwitch dipSwitch) { #region Common if (DatItemFields.Contains(DatItemField.Tag)) { dipSwitch.Tag = null; } if (DatItemFields.Contains(DatItemField.Mask)) { dipSwitch.Mask = null; } if (dipSwitch.ConditionsSpecified) { foreach (Condition subCondition in dipSwitch.Conditions) { RemoveFields(subCondition, true); } } if (dipSwitch.LocationsSpecified) { foreach (Location subLocation in dipSwitch.Locations) { RemoveFields(subLocation); } } if (dipSwitch.ValuesSpecified) { foreach (Setting subValue in dipSwitch.Values) { RemoveFields(subValue); } } #endregion #region SoftwareList if (dipSwitch.PartSpecified) { RemoveFields(dipSwitch.Part); } #endregion }
public static void Main() { var dipSwitch = new DipSwitch(new H.Cpu.Pin[] { N.Pins.GPIO_PIN_D0, N.Pins.GPIO_PIN_D1, N.Pins.GPIO_PIN_D2, N.Pins.GPIO_PIN_D3, N.Pins.GPIO_PIN_D4, N.Pins.GPIO_PIN_D5, N.Pins.GPIO_PIN_D6, N.Pins.GPIO_PIN_D7 }, CircuitTerminationType.CommonGround); dipSwitch.Changed += (object s, ArrayEventArgs e) => { Debug.Print("Switch " + e.ItemIndex + " changed to " + (((ISwitch)e.Item).IsOn ? "on" : "off")); }; Thread.Sleep(Timeout.Infinite); }
/// <summary> /// Read DipSwitch DipValues information /// </summary> /// <param name="reader">XmlReader representing a diskarea block</param> /// <param name="dipSwitch">DipSwitch to populate</param> private void ReadDipSwitch(XmlReader reader, DipSwitch dipSwitch) { // If we have an empty dipswitch, skip it if (reader == null) { return; } // Get list ready dipSwitch.Values = new List <Setting>(); // Otherwise, add what is possible reader.MoveToContent(); while (!reader.EOF) { // We only want elements if (reader.NodeType != XmlNodeType.Element) { reader.Read(); continue; } // Get the information from the dipswitch switch (reader.Name) { case "dipvalue": var dipValue = new Setting { Name = reader.GetAttribute("name"), Value = reader.GetAttribute("value"), Default = reader.GetAttribute("default").AsYesNo(), }; dipSwitch.Values.Add(dipValue); reader.Read(); break; default: reader.Read(); break; } } }
public DipSwitchApp() { IDigitalInputPort[] ports = { Device.CreateDigitalInputPort(Device.Pins.D06, InterruptMode.LevelHigh, ResistorMode.PullDown), // Device.CreateDigitalInputPort(Device.Pins.D07, InterruptMode.EdgeFalling, ResistorMode.PullDown), // Device.CreateDigitalInputPort(Device.Pins.D08, InterruptMode.EdgeFalling, ResistorMode.PullDown), // Device.CreateDigitalInputPort(Device.Pins.D09, InterruptMode.EdgeFalling, ResistorMode.PullDown), // Device.CreateDigitalInputPort(Device.Pins.D10, InterruptMode.EdgeFalling, ResistorMode.PullDown), // Device.CreateDigitalInputPort(Device.Pins.D11, InterruptMode.EdgeFalling, ResistorMode.PullDown), // Device.CreateDigitalInputPort(Device.Pins.D12, InterruptMode.EdgeFalling, ResistorMode.PullDown), // Device.CreateDigitalInputPort(Device.Pins.D13, InterruptMode.EdgeFalling, ResistorMode.PullDown), }; dipSwitch = new DipSwitch(ports); dipSwitch.Changed += DipSwitchChanged; }
public MeadowApp() { Console.WriteLine("Initializing..."); IDigitalInputPort[] ports = { Device.CreateDigitalInputPort(Device.Pins.D06, InterruptMode.EdgeRising, ResistorMode.InternalPullDown), // Device.CreateDigitalInputPort(Device.Pins.D07, InterruptMode.EdgeFalling, ResistorMode.InternalPullDown), // Device.CreateDigitalInputPort(Device.Pins.D08, InterruptMode.EdgeFalling, ResistorMode.InternalPullDown), // Device.CreateDigitalInputPort(Device.Pins.D09, InterruptMode.EdgeFalling, ResistorMode.InternalPullDown), // Device.CreateDigitalInputPort(Device.Pins.D10, InterruptMode.EdgeFalling, ResistorMode.InternalPullDown), // Device.CreateDigitalInputPort(Device.Pins.D11, InterruptMode.EdgeFalling, ResistorMode.InternalPullDown), // Device.CreateDigitalInputPort(Device.Pins.D12, InterruptMode.EdgeFalling, ResistorMode.InternalPullDown), // Device.CreateDigitalInputPort(Device.Pins.D13, InterruptMode.EdgeFalling, ResistorMode.InternalPullDown), }; dipSwitch = new DipSwitch(ports); dipSwitch.Changed += (s, e) => { Console.WriteLine("Switch " + e.ItemIndex + " changed to " + (((ISwitch)e.Item).IsOn ? "on" : "off")); }; Console.WriteLine("DipSwitch..."); }
/// <summary> /// Read part information /// </summary> /// <param name="reader">XmlReader representing a part block</param> /// <param name="machine">Machine information to pass to contained items</param> /// <param name="part">Part information to pass to contained items</param> /// <param name="filename">Name of the file to be parsed</param> /// <param name="indexId">Index ID for the DAT</param> private bool ReadPart(XmlReader reader, Machine machine, Part part, string filename, int indexId) { // If we have an empty port, skip it if (reader == null) { return(false); } // Get lists ready part.Features = new List <PartFeature>(); List <DatItem> items = new List <DatItem>(); while (!reader.EOF) { // We only want elements if (reader.NodeType != XmlNodeType.Element) { reader.Read(); continue; } // Get the elements from the software switch (reader.Name) { case "feature": var feature = new PartFeature() { Name = reader.GetAttribute("name"), Value = reader.GetAttribute("value"), }; part.Features.Add(feature); reader.Read(); break; case "dataarea": var dataArea = new DataArea { Name = reader.GetAttribute("name"), Size = Sanitizer.CleanLong(reader.GetAttribute("size")), Width = Sanitizer.CleanLong(reader.GetAttribute("width")), Endianness = reader.GetAttribute("endianness").AsEndianness(), }; List <DatItem> roms = ReadDataArea(reader.ReadSubtree(), dataArea); // If we got valid roms, add them to the list if (roms != null) { items.AddRange(roms); } // Skip the dataarea now that we've processed it reader.Skip(); break; case "diskarea": var diskArea = new DiskArea { Name = reader.GetAttribute("name"), }; List <DatItem> disks = ReadDiskArea(reader.ReadSubtree(), diskArea); // If we got valid disks, add them to the list if (disks != null) { items.AddRange(disks); } // Skip the diskarea now that we've processed it reader.Skip(); break; case "dipswitch": var dipSwitch = new DipSwitch { Name = reader.GetAttribute("name"), Tag = reader.GetAttribute("tag"), Mask = reader.GetAttribute("mask"), }; // Now read the internal tags ReadDipSwitch(reader.ReadSubtree(), dipSwitch); items.Add(dipSwitch); // Skip the dipswitch now that we've processed it reader.Skip(); break; default: reader.Read(); break; } } // Loop over all of the items, if they exist string key = string.Empty; foreach (DatItem item in items) { // Add all missing information switch (item.ItemType) { case ItemType.DipSwitch: (item as DipSwitch).Part = part; break; case ItemType.Disk: (item as Disk).Part = part; break; case ItemType.Rom: (item as Rom).Part = part; // If the rom is continue or ignore, add the size to the previous rom // TODO: Can this be done on write? We technically lose information this way. // Order is not guaranteed, and since these don't tend to have any way // of determining what the "previous" item was after this, that info would // have to be stored *with* the item somehow if ((item as Rom).LoadFlag == LoadFlag.Continue || (item as Rom).LoadFlag == LoadFlag.Ignore) { int index = Items[key].Count - 1; DatItem lastrom = Items[key][index]; if (lastrom.ItemType == ItemType.Rom) { (lastrom as Rom).Size += (item as Rom).Size; Items[key].RemoveAt(index); Items[key].Add(lastrom); } continue; } break; } item.Source = new Source(indexId, filename); item.CopyMachineInformation(machine); // Finally add each item key = ParseAddHelper(item); } return(items.Any()); }