Skip to content

Looking-Glass/LKG-Toolkit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

74 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Looking Glass Toolkit

Looking Glass Toolkit is an open source set of tools for interacting with Looking Glass Bridge. Bridge facilitates communication between your computer and any connected Looking Glass devices.

Toolkit currently consists of three core tools:

  • API - C# Bridge SDK for accessing the Bridge API.
  • CLI - CLI wrapper around the Bridge API for Windows, MacOS, and Linux.
    • Checks display state
    • Monitors display state changes
    • Plays sets of quilts and quilt videos
    • Synchronizes sets of quilts and quilt videos
  • GUI - GUI version of the CLI for Windows and MacOS.

Warning

This is ALPHA software and as such should not be used in any critical applications. If you find any bugs or issues, please open an issue on this github repo.

This project is still a WIP some features may not be included currently. LKG-Toolkit may be behind Toolkit CLI, which may not implement all of the Bridge API.

How to build

Prerequisites:

  1. Looking Glass Bridge
  2. .NET 7.0 SDK

Windows and MacOS

  1. Install Visual Studio 2022 for (Windows or MacOS).
  2. Make sure to include the .NET Multi-platform App UI development workload.
  3. Clone this repo and open in Visual Studio.

If you would rather use VS code or some other editor, follow the Linux instructions below.

Linux:

# Download LKG-Toolkit repo
git clone https://github.com/Looking-Glass/LKG-Toolkit
cd LKG-Toolkit
# Setup, install project, and build
dotnet workload restore # Installs necessary .NET tools
dotnet restore          # Installs Nuget dependencies
dotnet build            # Builds all the projects
# Run the CLI
cd Toolkit-CLI
dotnet run

CLI Examples

Help

> Toolkit-CLI.exe --help

Toolkit-CLI 1.0.0
Copyright (C) 2023 Toolkit-CLI
USAGE:

Listen for Bridge events:
  Toolkit_CLI

  -t, --task             (Default: listen) Task to perform

  -o, --orchestration    (Default: default) Sets the orchestration to connect to

  -a, --address          (Default: localhost) Sets the address to connect to bridge through

  --help                 Display this help screen.

  --version              Display version information.

Listening for events

> Toolkit-CLI.exe -t listen

Connecting to: ws://localhost:9724/event_source
Connected to bridge
Listening for events, press any key to stop.

List connected devices

> Toolkit-CLI.exe -t list

Connecting to: ws://localhost:9724/event_source
Connected to bridge
Display Type: portrait
Display Serial: LKG-P03273
Display Loc: [3840, 0]
Calibration Version: 3.0

Playback quilt

> Toolkit-CLI.exe -t play -i https://s3.amazonaws.com/lkg-blocks/legacy/715/source.png -c 7 -r 11 -v 77 --loop --aspect 0.75

Connecting to: ws://localhost:9724/event_source
Connected to bridge
Listening for events, press any key to stop.

API Examples

Listening for events

This is the exact code executed by: Toolkit-CLI.exe -t listen

// Create BridgeConnectionHTTP instance with the default IP address and ports
// Make sure to use the using pattern or properly dispose of the BridgeConnectionHTTP object
using BridgeConnectionHTTP b = new BridgeConnectionHTTP();

// Connect to bridge
bool connectionStatus = b.Connect();
if (connectionStatus)
{
    Console.WriteLine("Connected to bridge");
    b.AddListener("", (e) => { Console.WriteLine(e); });

    // Enter the default Orchestration
    // This is similar to a session but multiple
    // clients can connect to the same one
    if (!b.TryEnterOrchestration())
    {
        Console.WriteLine("Failed to enter orchestration");
        return;
    }

    if (!b.TrySubscribeToEvents())
    {
        Console.WriteLine("Failed to subscribe to events");
        return;
    }

    if (!b.TryUpdateDevices())
    {
        Console.WriteLine("Failed to update devices");
        return;
    }
}
else
{
    Console.WriteLine("Failed to connect to bridge, ensure bridge is running");
    return;
}

Console.WriteLine("Listening for events, press any key to stop.");
Console.ReadKey();

List Devices

This is the exact code executed by: Toolkit-CLI.exe -t list

// Create BridgeConnectionHTTP instance.
// Make sure to use the using pattern or properly dispose of the BridgeConnectionHTTP object
using BridgeConnectionHTTP b = new BridgeConnectionHTTP(args.address);

// Connect to bridge
bool connectionStatus = b.Connect();
if (connectionStatus)
{
    Console.WriteLine("Connected to bridge");

    // Enter the named Orchestration
    // This is similar to a session but multiple
    // clients can connect to the same instance, receive
    // the same events and control the same state
    if (!b.TryEnterOrchestration(args.orchestrationName))
    {
        Console.WriteLine("Failed to enter orchestration");
        return;
    }

    if (!b.TrySubscribeToEvents())
    {
        Console.WriteLine("Failed to subscribe to events");
        return;
    }

    if (b.TryUpdateDevices())
    {
        List<Display> displays = b.GetLKGDisplays();
        foreach (Display display in displays)
        {
            Console.WriteLine(display.getInfoString());
        }
    }
    else
    {
        Console.WriteLine("Failed to update devices");
        return;
    }
}
else
{
    Console.WriteLine("Failed to connect to bridge, ensure bridge is running");
    return;
}

Playback Quilt

This is the exact code executed by: Toolkit-CLI.exe -t play -i https://s3.amazonaws.com/lkg-blocks/legacy/715/source.png -c 7 -r 11 -v 77 --loop --aspect 0.75

// Create BridgeConnectionHTTP instance.
// Make sure to use the using pattern or properly dispose of the BridgeConnectionHTTP object
using BridgeConnectionHTTP b = new BridgeConnectionHTTP(args.address);

// Connect to bridge
bool connectionStatus = b.Connect();
if (connectionStatus)
{
    Console.WriteLine("Connected to bridge");

    // Enter the named Orchestration
    // This is similar to a session but multiple
    // clients can connect to the same instance, receive
    // the same events and control the same state
    if (!b.TryEnterOrchestration(args.orchestrationName))
    {
        Console.WriteLine("Failed to enter orchestration");
        return;
    }

    if (!b.TrySubscribeToEvents())
    {
        Console.WriteLine("Failed to subscribe to events");
        return;
    }

    if (!b.TryUpdateDevices())
    {
        Console.WriteLine("Failed to update devices");
        return;
    }

    Playlist p = new Playlist("default", args.loopPlaylist);
    p.AddItem(args.inputFile, args.rows, args.cols, args.aspect, args.viewCount);

    if (!b.TryPlayPlaylist(p, args.head))
    {
        Console.WriteLine("Failed to play playlist");
        return;
    }
}
else
{
    Console.WriteLine("Failed to connect to bridge, ensure bridge is running");
    return;
}

Console.WriteLine("Listening for events, press any key to stop.");
Console.ReadKey();
}