private static void SendPinOn(string pin, Device device) { if (String.IsNullOrEmpty(pin)) return; if (device == null) { Console.WriteLine("Please provide device or alias (-d\t--device [device alias] or [device id])"); return; } ushort upin = 0; if(!ushort.TryParse(pin, out upin)) { Console.WriteLine("Invalid pin"); return; } if(device.TurnOn(upin)) { Console.WriteLine("pin " + upin.ToString() + " is on for " + device.Alias); } else { Console.WriteLine("pin " + upin.ToString() + " couldn't be turned on for " + device.Alias); } //turn on master after secondary pins if(device.Pins.ContainsKey(device.MasterPin)) { if (device.Pins[device.MasterPin]) return; else { if (device.TurnOn(device.MasterPin)) { Console.WriteLine("master pin " + device.MasterPin + " is on for " + device.Alias); } else { Console.WriteLine("master pin " + device.MasterPin + " couldn't be turned on for " + device.Alias); } } } else { if(Device.IsVerbose) Console.WriteLine("warning no master pin set for " + device.GUID); } }
private static void AddDevice(string device) { if (!String.IsNullOrEmpty(device)) { Console.WriteLine("Added device " + device); Device dev = new Device() { GUID = device.Trim() }; Device.Add(dev); } }
private static void SetAlias(string alias, Device device) { if (String.IsNullOrEmpty(alias)) return; if(device == null) { Console.WriteLine("Please provide device or alias (-d\t--device [device alias] or [device id])"); return; } device.SetAlias(alias.Trim()); Console.WriteLine("Added alias \"" + device.Alias + "\" to device " + device.GUID); }
private static void SetMaster(string master, Device device) { if (String.IsNullOrEmpty(master)) return; if (device == null) { Console.WriteLine("Please provide device or alias (-d\t--device [device alias] or [device id])"); return; } ushort pin = 0; if(!ushort.TryParse(master, out pin)) { Console.Write("Invalid pin, enter valid positive integer (1-255)"); return; } device.SetMasterPin(pin); }
public static void Add(Device device) { foreach(var d in Devices) { if (d.GUID == device.GUID) { if (IsVerbose) Console.WriteLine(d.GUID + " already exists in device list"); return; } } Devices.Add(device); if(IsVerbose) { Console.WriteLine(device.GUID + " has been added to device list"); } Device.Save(); }