Ejemplo n.º 1
0
        public async Task <LED> GetLEDMatrix()
        {
            var ledMatrixService = _nuimo.GetGattService(Constants.Services.LEDMatrix);
            var characteristic   = ledMatrixService.GetCharacteristics(Constants.Characteristics.LEDMatrix)[0];
            var readResult       = await characteristic.ReadValueAsync();

            return(LED.FromByteArrary(readResult.Value.ToArray()));
        }
Ejemplo n.º 2
0
        public async Task SetLEDMatrix(string characterMatrix, byte brightness = 0x7F, byte timeout = 0x64)
        {
            var ledMatrixService = _nuimo.GetGattService(Constants.Services.LEDMatrix);
            var characteristic   = ledMatrixService.GetCharacteristics(Constants.Characteristics.LEDMatrix)[0];

            LED led = new LED(characterMatrix, brightness, timeout);

            byte[] buffer = led.ToByteArrary();

            var writer = new DataWriter();

            writer.ByteOrder = ByteOrder.BigEndian;
            writer.WriteBytes(buffer);

            await characteristic.WriteValueAsync(writer.DetachBuffer());
        }
Ejemplo n.º 3
0
        public static LED FromByteArrary(byte[] buffer)
        {
            if (buffer.Length != 13)
            {
                throw new ArgumentException("The buffer is not a valid length");
            }

            var led = new LED();

            byte[] matrix = new byte[11];
            for (int i = 0; i < matrix.Length; i++)
            {
                matrix[i] = buffer[i];
            }

            led.Matrix     = matrix;
            led.Brightness = buffer[11];
            led.Timeout    = buffer[12];

            return(led);
        }