public LightServer(string IP, int port, LogObj log) { Log = log; ZoneCodes = new Dictionary <string, byte[]> [4]; ZoneCodes[0] = new Dictionary <string, byte[]>(); ZoneCodes[1] = new Dictionary <string, byte[]>(); ZoneCodes[2] = new Dictionary <string, byte[]>(); ZoneCodes[3] = new Dictionary <string, byte[]>(); ZoneCodes[0].Add("On", new byte[] { 0x45 }); ZoneCodes[0].Add("Off", new byte[] { 0x46 }); ZoneCodes[0].Add("White", new byte[] { 0x45, 0xC5 }); ZoneCodes[0].Add("Night", new byte[] { 0x46, 0xC6 }); ZoneCodes[1].Add("On", new byte[] { 0x47 }); ZoneCodes[1].Add("Off", new byte[] { 0x48 }); ZoneCodes[1].Add("White", new byte[] { 0x47, 0xC7 }); ZoneCodes[1].Add("Night", new byte[] { 0x48, 0xC8 }); ZoneCodes[2].Add("On", new byte[] { 0x49 }); ZoneCodes[2].Add("Off", new byte[] { 0x4A }); ZoneCodes[2].Add("White", new byte[] { 0x49, 0xC9 }); ZoneCodes[2].Add("Night", new byte[] { 0x4A, 0xCA }); ZoneCodes[3].Add("On", new byte[] { 0x4B }); ZoneCodes[3].Add("Off", new byte[] { 0x4C }); ZoneCodes[3].Add("White", new byte[] { 0x4B, 0xCB }); ZoneCodes[3].Add("Night", new byte[] { 0x4C, 0xCC }); sock = new Messenger(IP, port, Log); for (int i = 0; i < 4; i++) { this.Zones[i] = new LightZone(ZoneCodes[i], sock.Send, Log); } }
public Messenger(string IP, int port, LogObj log) { Log = log; newMessageAlert[0] = new ManualResetEvent(false); MessageThread = new System.Threading.Thread(SendMessageList); this.IP = IP; this.port = port; MessageThread.Start(); }
public Controller() { Log = new LogObj(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "//Log.txt", 40); PsuedoRandomLightTimings NormalRoomActivity = new PsuedoRandomLightTimings(time(8), time(22), span(.5), span(1.5), 14); PsuedoRandomLightTimings BathroomActivity = new PsuedoRandomLightTimings(time(0), time(23), span(.1), span(.25), span(.5), span(2), 14); PsuedoRandomLightTimings OutdoorLightsP1 = new PsuedoRandomLightTimings(time(16), time(22, 30), true, 17); OutdoorLightsP1.FollowUpEvent(true);//There is a followup event PsuedoRandomLightTimings OutdoorLightsP2 = new PsuedoRandomLightTimings(time(22, 30), time(4, 30), true, 1); OutdoorLightsP2.FollowUpEvent(true);//There is a followup event PsuedoRandomLightTimings OutdoorLightsP3 = new PsuedoRandomLightTimings(time(4, 30), time(8), true, 17); LightServer MainServer = new LightServer("192.168.1.68", 8899, Log); MusicDriver MainSound = new MusicDriver(); Song testingSong = new Song(@"C:/Users/Sam/Music/D&D/Background Music/Hero Down.mp3", MainSound.wplayer); for (int i = 0; i < 10; i++) { MainSound.Load(testingSong); } MainSound.Play(); MainServer.Zones[2].name = "Bathroom"; MainServer.Zones[1].name = "Normal Rooms"; MainServer.Zones[0].name = "Outside"; MainServer.Zones[0].SetBrightness(10); MainServer.Zones[1].SetBrightness(10); MainServer.Zones[2].SetBrightness(10); MainServer.Zones[3].SetBrightness(10); AutoController BathroomManager = new AutoController(MainServer.Zones[2], new List <Event> { BathroomActivity }); AutoController NormalRoomManager = new AutoController(MainServer.Zones[1], new List <Event> { NormalRoomActivity }); AutoController OutdoorManager = new AutoController(MainServer.Zones[0], new List <Event> { OutdoorLightsP1, OutdoorLightsP2, OutdoorLightsP3 }); Thread BathroomThread = new Thread(BathroomManager.ThreadedTask); BathroomThread.Name = "Bathroom"; Thread NormalRoomThread = new Thread(NormalRoomManager.ThreadedTask); NormalRoomThread.Name = "Hall"; Thread OutdoorThread = new Thread(OutdoorManager.ThreadedTask); OutdoorThread.Name = "Outdoor"; int consequtiveErrors = 0; BathroomThread.Start(); NormalRoomThread.Start(); OutdoorThread.Start(); consequtiveErrors = 0; }
public LightZone(Dictionary <string, byte[]> givenCodes, Action <byte[]> sender, LogObj log) { Log = log; Send = sender; //Sender is something that will handles sending messages. It will almost certainly be connected to a messenger.Send command. codes = givenCodes; }