public Command(string room, string item, string action, TheWorld world) { mSubCommands = new List<Command>(); //is item a device class? bool itemIsDeviceClass = false; EDeviceClass itemClass = EDeviceClass.Kinect; Array vals = Enum.GetValues(typeof(EDeviceClass)); foreach (EDeviceClass c in vals) { if (SoundsLike.Get(c, false) == item) { itemIsDeviceClass = true; itemClass = c; break; } } //convert the action to a devicecapabilitiesenum EDeviceCapabilities actionResolved = EDeviceCapabilities.None; vals = Enum.GetValues(typeof(EDeviceCapabilities)); foreach (EDeviceCapabilities c in vals) { if (SoundsLike.Get(c, true) == action) { actionResolved = c; break; } } //find the devices foreach (Room rm in world.ListRooms()) { if (room == "" || rm.Name == room) { foreach (Device d in rm.ListDevices()) { bool hit = false; if (itemIsDeviceClass) { if (itemClass == d.Class) hit = true; } else { if (item == d.FriendlyName) hit = true; } if (hit) { Command c = new Command(rm, d, actionResolved); mSubCommands.Add(c); } } } } }
public static TheWorld CreateTestWorld() { Room livingroom = new Room("living room"); Room study = new Room("study"); Room bedroom = new Room("bedroom"); Room corridor = new Room("corridor"); corridor.AddDoorway(livingroom); corridor.AddDoorway(study); corridor.AddDoorway(bedroom); Device study_light = new Device("R1D1", "study light", EDeviceClass.Light, EDeviceProtocol.LWRF, new DeviceCapabilities("Dimmer"), null); Device bedroom_light = new Device("R2D1", "bedroom light", EDeviceClass.Light, EDeviceProtocol.LWRF, new DeviceCapabilities("Dimmer"), null); Device study_kinect = new Device("192.168.1.32", "study kinect", EDeviceClass.Kinect, EDeviceProtocol.AudioProto, new DeviceCapabilities("AudioIn"), null); Device bedroom_kinect = new Device("192.168.1.191", "bedroom kinect", EDeviceClass.Kinect, EDeviceProtocol.AudioProto, new DeviceCapabilities("AudioIn"), null); Device living_kinect = new Device("192.168.1.190", "living room kinect", EDeviceClass.Kinect, EDeviceProtocol.AudioProto, new DeviceCapabilities("AudioIn"), null); Dictionary<string,string> study_xbmc_args = new Dictionary<string,string>(); study_xbmc_args.Add("port", "8080"); study_xbmc_args.Add("user", "xbmc"); study_xbmc_args.Add("pass", "test"); Device study_xbmc = new Device("192.168.1.130", "study xbmc", EDeviceClass.XBMC, EDeviceProtocol.XBMC, new DeviceCapabilities("XBMC"), study_xbmc_args); Dictionary<string, string> bedroom_xbmc_args = new Dictionary<string, string>(); bedroom_xbmc_args.Add("port", "8080"); bedroom_xbmc_args.Add("user", "xbmc"); bedroom_xbmc_args.Add("pass", "xbmc"); Device bedroom_xbmc = new Device("192.168.1.191", "bedroom xbmc", EDeviceClass.XBMC, EDeviceProtocol.XBMC, new DeviceCapabilities("XBMC"), bedroom_xbmc_args); Dictionary<string, string> living_xbmc_args = new Dictionary<string, string>(); living_xbmc_args.Add("port", "8080"); living_xbmc_args.Add("user", "xbmc"); living_xbmc_args.Add("pass", "xbmc"); Device living_xbmc = new Device("192.168.1.190", "living room xbmc", EDeviceClass.XBMC, EDeviceProtocol.XBMC, new DeviceCapabilities("XBMC"), living_xbmc_args); study.AddDevice(study_xbmc); study.AddDevice(study_kinect); study.AddDevice(study_light); bedroom.AddDevice(bedroom_xbmc); bedroom.AddDevice(bedroom_kinect); bedroom.AddDevice(bedroom_light); livingroom.AddDevice(living_xbmc); livingroom.AddDevice(living_kinect); TheWorld ret = new TheWorld(); ret.AddRoom(livingroom); ret.AddRoom(study); ret.AddRoom(bedroom); ret.AddRoom(corridor); ret.CurrentLocation = study; return ret; }
public Form1() { InitializeComponent(); Form1.server = this; //recogSAPI = new AudioRecog_SAPI(); //recogSAPI.RecognitionSuccessful += new AudioRecog.RecognitionSuccessfulDelegate(r_RecognitionSuccessful); //recogSphinx = new AudioRecog_CMUSphinx(); //recogSphinx.RecognitionSuccessful += new AudioRecog.RecognitionSuccessfulDelegate(r_RecognitionSuccessful); Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB"); Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-GB"); Talker = new SpeechOut(); Talker.AddEndpoint("beast", null); lwrf = new LWRF(); clkActions = new Dictionary<string, Tuple<bool, bool,string>>(); Recog = new AudioRecogHolder(); Recog.RegisterRecogEngine(new AudioRecog_SAPI()); Recog.RegisterRecogEngine(new AudioRecog_CMUSphinx()); Recog.RecognitionSuccessful += new AudioRecogHolder.RecognitionSuccessfulDelegate(Recog_RecognitionSuccessful); mControllables = new List<IControllable>(); //Controllables theWorld = TheWorld.CreateTestWorld(); mControllables.Add(theWorld); clk = new AlarmClock(); clk.ControllableEvent += new IControllableEventDelegate(clk_ControllableEvent); mControllables.Add(clk); List<Device> devs = theWorld.ListDevicesByCaps(null, EDeviceCapabilities.Special_XBMC); if (devs != null) { foreach (Device d in devs) { XBMC xbmc = new XBMC(d.ID, d.Args["port"], d.Args["user"], d.Args["pass"]); if (!xbmc.VerifyConnection()) { Form1.updateLog("Couldn't connect to XBMC at " + d.ID + ":" + d.Args["port"], ELogLevel.Warning, ELogType.XBMC); d.Disable(); continue; } xbmc.ControllableEvent += new IControllableEventDelegate(xbmc_ControllableEvent); mControllables.Add(xbmc); d.Instance = xbmc; } } protos = new DeviceProtocolMappings(); protos.SetWorld(theWorld); List<string> done = new List<string>(); foreach (IControllable ic in mControllables) { Recog.AddControllable(ic); } p = new AudioProto(); p.Listen(s_port); p.NewAudioStream += new AudioProto.NewAudioStreamDelegate(p_NewAudioStream); prog1.Minimum = 0; prog1.Maximum = 250; prog2.Minimum = 0; prog2.Maximum = 250; prog3.Minimum = 0; prog3.Maximum = 250; progCmd1.Minimum = 0; progCmd1.Maximum = 250; progCmd2.Minimum = 0; progCmd2.Maximum = 250; progCmd3.Minimum = 0; progCmd3.Maximum = 250; UpdateControlD += new UpdateControlDelegate(UpdateControl); tick = new System.Timers.Timer(); tick.Elapsed += new ElapsedEventHandler(tick_Elapsed); tick.Interval = 1000; tick.Start(); }
public void SetWorld(TheWorld world) { mWorld = world; }