Skip to content

All files related to the All Spark Cube built by Adaptive Computing and friends

License

Notifications You must be signed in to change notification settings

chadharrington/all_spark_cube

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

General Cube Info

The All Spark Cube was built in 2012-2013 by Adaptive Computing and friends. More info is available here:

Cube Client Libraries

To interact with the All Spark Cube, you'll need a client library for your preferred programming language. There are currently cube client libraries available for Python and Java. Skip to the relevant section for your language.

Python Client

Usage

Here is the Python Hello World demo:

#!/usr/bin/env python

from all_spark_cube_client import CubeClient, Color, Colors

#HOST = 'localhost'
HOST = 'cube.ac'
PORT = 12345

client = CubeClient(HOST, PORT)

# Built-in colors are: red, green, blue, yellow, cyan, magenta, 
# white, black, gray, orange, pink, light_yellow, and dark_green
# You can also create any arbitrary color by creating an instance 
# of the Color class with the R, G, and B values specified.

# Set all LEDs to blue. 
client.set_all_leds(Colors.blue)

# Set the first LED (#0) to red
client.set_led(0, Colors.red)

# Set the second LED (#1) to a custom color (teal-ish)
client.set_led(1, Color(100, 255, 95))

# Starting at LED #48, set 16 LEDs to yellow
client.set_led_range(48, 16, Colors.yellow)

# Set the last LED (#4095) to green
client.set_led(4095, Colors.green)

# Actually send the data to the cube
client.send();  

print 'Success...'

Installation

Install the Python client library using pip. If you don't have pip installed, get it here.

$ pip install all_spark_cube_client

You can safely ignore the 10 or so warnings generated by pip, these are a part of the underlying Thrift library, and don't affect the cube client library.

Download the code and run the Hello World demo on the cube:

$ wget -O helloworld.py http://git.io/hellopycube
$ python helloworld.py

You should see the cube change colors as specified in the program (first LED red, second LED teal, a row of yellow LEDs, etc.) You should see "Success..." on your command line. If you get errors instead, open the helloworld.py file and make sure the HOST parameter is set to the correct network address for the cube. You should also make sure the cube is turned on and reachable over the network.

Java Client

Usage

The Java Hello World demo is below. Note that the API uses the java.awt.Color class to specify colors for the LEDs.

import java.awt.Color;

import com.allsparkcube.CubeClient;
import org.apache.thrift.TException;


public class HelloWorld {
    public static void main(String[] args) {
        try {

            // final String HOST = "localhost";
            final String HOST = "cube.ac";
            final int PORT = 12345;
        
            CubeClient client = new CubeClient(HOST, PORT);

            // Set all LEDs to blue
            client.setAllLeds(Color.white); 

            // Set the first LED (#0) to red
            client.setLed(0, Color.red);

            // Set the second LED (#1) to a custom color (teal-ish)
            Color teal = new Color(100, 255, 95);
            client.setLed(1, teal);
        
            // Starting at LED #48, set 16 LEDs to yellow
            client.setLedRange(48, 16, Color.yellow); 

            // Set the last LED (#4095) to green
            client.setLed(4095, Color.green);
        
            // Actually send the data to the cube
            client.send();  
        
            System.out.println("Success...");
        } catch (TException e) {
            e.printStackTrace();
        }
    }
}

Installation

You can install and use the Java client with or without Maven.

Using Maven

Clone the git repository, then build and run the Hello World example using Maven:

$ git clone https://github.com/chadharrington/all_spark_cube.git
$ cd all_spark_cube/software/clients/java_client/examples/
$ mvn package
$ cd target/com/mycompany
$ java -cp hello-world-0.1-standalone.jar HelloWorld

You should see the cube change colors as specified in the program (first LED red, second LED teal, a row of yellow LEDs, etc.) You should see "Success..." on your command line. If you get errors instead, open the HelloWorld.java file and make sure the HOST parameter is set to the correct network address for the cube. You should also make sure the cube is turned on and reachable over the network.

Direct Download

If you don't use Maven, you can download the client jar and Hello World example directly from GitHub:

$ wget http://git.io/cubejar -O cube_client-0.6-standalone.jar
$ wget http://git.io/hellojavacube -O HelloWorld.java 
$ javac -cp .:cube_client-0.6-standalone.jar HelloWorld.java
$ java -cp .:cube_client-0.6-standalone.jar HelloWorld

You should see the cube change colors as specified in the program (first LED red, second LED teal, a row of yellow LEDs, etc.) You should see "Success..." on your command line. If you get errors instead, open the HelloWorld.java file and make sure the HOST parameter is set to the correct network address for the cube. You should also make sure the cube is turned on and reachable over the network.

Cube Server Install

These instructions are only relevant for installing the server onto the computer inside the All Spark Cube. Cube users need not install the server code.

The server code and these instructions assume a CentOS / RHEL server.

1 - Install supervisor from http://supervisord.org 2 - Run these commands:

$ git clone https://github.com/chadharrington/all_spark_cube.git
$ cd all_spark_cube/software/server
$ sudo make install
$ sudo reboot now

The server will automatically start on reboot / powerup. If everything installed correctly, the cube should display all white LEDs after booting.

Support

Having trouble? Open an issue.

License

All code in this repository is licensed under an MIT license.

About

All files related to the All Spark Cube built by Adaptive Computing and friends

Resources

License

Stars

Watchers

Forks

Packages

No packages published