protected async Task InitializeLifxClient()
        {
            this.EventAggregator.GetEvent <MessageEvent>().Publish(new MessageEventArgs(MessageEventType.Information, "Ready."));

            try
            {
                // ***
                // *** Configure the LIFX client.
                // ***
                this.LifxClient = await LifxClient.CreateAsync();

                this.LifxClient.DeviceDiscovered += this.LifxClient_DeviceDiscovered;
                this.LifxClient.DeviceLost       += this.LifxClient_DeviceLost;
                this.LifxClient.StartDeviceDiscovery();
            }
            catch (SocketException)
            {
                string message = this.ResourceLoader.GetString(MagicString.Resource.LifxApplicationError);
                this.EventAggregator.GetEvent <MessageEvent>().Publish(new MessageEventArgs(MessageEventType.Error, message));
            }
            catch (Exception ex)
            {
                this.EventAggregator.GetEvent <MessageEvent>().Publish(new MessageEventArgs(MessageEventType.Error, ex.Message));
            }
        }
Beispiel #2
0
    async void StartLivX()
    {
        client = await LifxClient.CreateAsync();

        client.DeviceDiscovered += Client_DeviceDiscovered;
        // client.DeviceLost += Client_DeviceLost;
        client.StartDeviceDiscovery();
    }
Beispiel #3
0
        private static async Task <int> RunLightOff(string deviceSpec)
        {
            var parsedSpec = DeviceSpec.Parse(deviceSpec);
            var bulb       = LightBulb.Create(parsedSpec.IPEndPoint, parsedSpec.MacAddress, service: 1);

            var client = await LifxClient.CreateAsync(new TraceLogger());

            await client.TurnBulbOffAsync(bulb, TimeSpan.FromMilliseconds(0));

            return(0);
        }
Beispiel #4
0
        private static async Task <int> RunGetDeviceLabel(string deviceSpec)
        {
            var parsedSpec = DeviceSpec.Parse(deviceSpec);
            // TODO: don't assume it's a bulb
            var device = LightBulb.Create(parsedSpec.IPEndPoint, parsedSpec.MacAddress, service: 1);

            var client = await LifxClient.CreateAsync(new TraceLogger());

            var result = await client.GetDeviceLabelAsync(device);

            Console.WriteLine(result);
            return(0);
        }
        public async Task InitAsync(Dictionary <string, string> parameters)
        {
            _client = await LifxClient.CreateAsync();

            _client.DeviceDiscovered += _client_DeviceDiscovered;
            _client.DeviceLost       += _client_DeviceLost;
            _client.StartDeviceDiscovery();

            if (!parameters.TryGetValue("SELECTED_DEVICE", out _initLabel))
            {
                throw new Exception("SELECTED_DEVICE parameter is not defined.");
            }
        }
Beispiel #6
0
        public void InitialiseBulbs()
        {
            // Wait for bulb task to warm up
            var task = LifxClient.CreateAsync();

            task.Wait();
            client = task.Result;

            // Attach discovery event handlers
            client.DeviceDiscovered += Client_DeviceDiscoveredAsync;
            client.DeviceLost       += Client_DeviceLost;

            // Trigger discovery process
            client.StartDeviceDiscovery();
        }
Beispiel #7
0
        public static async Task Init(bool startHTTPListener = true)
        {
            if (startHTTPListener)
            {
                Log.Bulb("Starting BixListens");
                var bixListens = new BixListens();
                bixListens.OnHttpEventReceived += BixListens_OnHttpEventReceived;
            }

            Log.Bulb("Creating LifxClient");
            _client = await LifxClient.CreateAsync();

            _client.DeviceDiscovered += Client_DeviceDiscovered;
            _client.DeviceLost       += Client_DeviceLost;
            Log.Bulb("Start Device Discovery");
            _client.StartDeviceDiscovery();
        }
Beispiel #8
0
    // Use this for initialization
    void Start()
    {
        var task = LifxClient.CreateAsync();

        task.Wait();
        Client = task.Result;
        Client.DeviceDiscovered += Client_DeviceDiscovered;
        Client.DeviceLost       += Client_DeviceLost;
        Client.StartDeviceDiscovery();

        // Print the label of each device
        Client.Devices.ToList().ForEach(device => Debug.Log(Client.GetDeviceLabelAsync(device)));

        // MIDI IN 4
        OpenMidiDevice(
            Tuple.Create("MIDIIN4 (mio4)", 10)
            );
    }
Beispiel #9
0
        private static async Task <int> RunGetDeviceVersion(string deviceSpec)
        {
            var parsedSpec = DeviceSpec.Parse(deviceSpec);
            // TODO: don't assume it's a bulb
            var device = LightBulb.Create(parsedSpec.IPEndPoint, parsedSpec.MacAddress, service: 1);

            var client = await LifxClient.CreateAsync(new TraceLogger());

            var versionTask         = client.GetDeviceVersionAsync(device);
            var firmwareVersionTask = client.GetDeviceHostFirmwareAsync(device);

            var version         = await versionTask;
            var firmwareVersion = await firmwareVersionTask;

            // TODO: look up values to something meaningful
            Console.WriteLine($"Vendor ID: {version.Vendor} Product ID: {version.Product} Version: {version.Version}");
            Console.WriteLine($"Firmware version {firmwareVersion.Version} (built at {firmwareVersion.Build})");

            return(0);
        }
Beispiel #10
0
        private static async Task <int> RunDiscover()
        {
            var client = await LifxClient.CreateAsync(new TraceLogger());

            client.DeviceDiscovered += (o, e) =>
            {
                Console.WriteLine($"{e.Device.MacAddressName}@{e.Device.Endpoint.Address}:{e.Device.Endpoint.Port}");
                //Console.WriteLine($"Device {e.Device.MacAddressName} found @ {e.Device.Endpoint}");
                //var version = await client.GetDeviceVersionAsync(e.Device);
                //var label = await client.GetDeviceLabelAsync(e.Device);
                //var state = await client.GetLightStateAsync(e.Device as LightBulb);
                //Console.WriteLine($"{state.Label}\n\tIs on: {state.IsOn}\n\tHue: {state.Hue}\n\tSaturation: {state.Saturation}\n\tBrightness: {state.Brightness}\n\tTemperature: {state.Kelvin}");
            };

            client.StartDeviceDiscovery();

            // give some time for discovery to complete
            await Task.Delay(1000);

            return(0);
        }
Beispiel #11
0
 public dynamic?CreateAgent(ControlService cs)
 {
     _lc = LifxClient.CreateAsync().Result;
     return(_lc);
 }
Beispiel #12
0
        // This initializes all of the data in our class and starts function loops
        private void Initialize()
        {
            LogUtil.Write("Initializing dream client...");
            // Create cancellation token sources
            _sendTokenSource    = new CancellationTokenSource();
            _captureTokenSource = new CancellationTokenSource();
            _camTokenSource     = new CancellationTokenSource();

            // Init lifx client
            _lifxClient = LifxClient.CreateAsync().Result;

            // Init nano HttpClient
            _nanoClient = new HttpClient();

            // Init nano socket
            _nanoSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            _nanoSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
            _nanoSocket.EnableBroadcast = false;

            // Cache data store
            // Check default settings
            DataUtil.CheckDefaults(_lifxClient);
            var dd = DataUtil.GetDb();

            // Get audio input if exists
            _aStream = GetStream();
            // Get our device data
            _dev = DataUtil.GetDeviceData();
            // Create scene builder
            _dreamScene = new DreamScene();
            // Get a list of devices
            _devices = new List <BaseDevice>();
            // Read other variables
            _devMode      = _dev.Mode;
            _ambientMode  = _dev.AmbientModeType;
            _ambientShow  = _dev.AmbientShowType;
            _ambientColor = ColorFromString(_dev.AmbientColor);
            _brightness   = _dev.Brightness;
            _autoDisabled = false;
            try {
                _autoDisabled = DataUtil.GetItem("AutoDisabled");
            } catch {
            }

            CaptureMode = DataUtil.GetItem("CaptureMode");

            // Set default values
            _prevMode           = -1;
            _prevAmbientMode    = -1;
            _prevAmbientShow    = -1;
            _streamStarted      = false;
            _showBuilderStarted = false;
            _group          = (byte)_dev.GroupNumber;
            _targetEndpoint = new IPEndPoint(IPAddress.Parse(DataUtil.GetItem("DsIp")), 8888);
            _sDevices       = new List <IStreamingDevice>();
            _wlStrips       = new List <WLedStrip>();
            // Start our timer to refresh devices
            StartRefreshTimer();
            // Start our service to capture (if capture mode is set)
            StartCaptureServices(_captureTokenSource.Token);
            StartVideoCaptureTask();
            // Now, start listening for UDP commands
            StartListening();
            // Finally start our normal device behavior
            if (!_autoDisabled)
            {
                UpdateMode(_dev.Mode);
            }
        }