13.3.3 RPi-Spark CLI interface (RPi-Spark smiley face)

In the previous section, we introduced the command list file format for the RPi-Spark CLI interface. Next we use these commands to create a simple smiley face app.

Create a file named: smiley_face.json and type the content below:

{
    "board":"rpi_spark_v110",
    "cmd_list":
    [
        {"cmd":"device", "params":{"device":"dsp", "act":"ON"} },
        {"cmd":"device", "params":{"device":"dsp", "act":"clear"} },
        {"cmd":"device", "params":{"device":"dsp", "act":"refresh"} },

        {"cmd":"draw", "params":{"shape":"circle", "x":64, "y":32, "r":45, "fill":0, "outline":1} },
        {"cmd":"device", "params":{"device":"dsp", "act":"refresh"} },
        {"cmd":"draw", "params":{"shape":"circle", "x":64, "y":32, "r":40, "fill":1, "outline":1} },
        {"cmd":"device", "params":{"device":"dsp", "act":"refresh"} },
        {"cmd":"draw", "params":{"shape":"circle", "x":64, "y":32, "r":35, "fill":0, "outline":1} },
        {"cmd":"device", "params":{"device":"dsp", "act":"refresh"} },
        {"cmd":"draw", "params":{"shape":"circle", "x":64, "y":32, "r":30, "fill":1, "outline":1} },
        {"cmd":"device", "params":{"device":"dsp", "act":"refresh"} },
        {"cmd":"draw", "params":{"shape":"circle", "x":64, "y":32, "r":25, "fill":0, "outline":1} },
        {"cmd":"device", "params":{"device":"dsp", "act":"refresh"} },
        {"cmd":"draw", "params":{"shape":"circle", "x":64, "y":32, "r":20, "fill":1, "outline":1} },
        {"cmd":"device", "params":{"device":"dsp", "act":"refresh"} },
        {"cmd":"draw", "params":{"shape":"circle", "x":64, "y":32, "r":15, "fill":0, "outline":1} },
        {"cmd":"device", "params":{"device":"dsp", "act":"refresh"} },
        {"cmd":"draw", "params":{"shape":"circle", "x":64, "y":32, "r":10, "fill":1, "outline":1} },
        {"cmd":"device", "params":{"device":"dsp", "act":"refresh"} },
        {"cmd":"draw", "params":{"shape":"circle", "x":64, "y":32, "r":5, "fill":0, "outline":1} },

        {"cmd":"delay", "params":{"sec": 1} },

        {"cmd":"draw", "params":{"shape":"rect", "x1":-1, "y1":32, "x2":128, "y2":32, "fill":0, "outline":1} },
        {"cmd":"device", "params":{"device":"dsp", "act":"refresh"} },
        {"cmd":"delay", "params":{"sec": 0.02} },
        {"cmd":"draw", "params":{"shape":"rect", "x1":-1, "y1":28, "x2":128, "y2":36, "fill":0, "outline":1} },
        {"cmd":"device", "params":{"device":"dsp", "act":"refresh"} },
        {"cmd":"delay", "params":{"sec": 0.02} },           
        {"cmd":"draw", "params":{"shape":"rect", "x1":-1, "y1":24, "x2":128, "y2":40, "fill":0, "outline":1} },
        {"cmd":"draw", "params":{"shape":"text", "x":3, "y":22, "text":"RPi-Spark CLI", "fill":1, "font_name": "AHandMadeFont.ttf", "font_size": 22} },
        {"cmd":"device", "params":{"device":"dsp", "act":"refresh"} },
        {"cmd":"delay", "params":{"sec": 0.02} },
        {"cmd":"draw", "params":{"shape":"rect", "x1":-1, "y1":20, "x2":128, "y2":44, "fill":0, "outline":1} },
        {"cmd":"draw", "params":{"shape":"text", "x":3, "y":22, "text":"RPi-Spark CLI", "fill":1, "font_name": "AHandMadeFont.ttf", "font_size": 22} },
        {"cmd":"device", "params":{"device":"dsp", "act":"refresh"} },
        {"cmd":"delay", "params":{"sec": 0.02} },
        {"cmd":"draw", "params":{"shape":"rect", "x1":-1, "y1":16, "x2":128, "y2":48, "fill":0, "outline":1} },
        {"cmd":"draw", "params":{"shape":"text", "x":3, "y":22, "text":"RPi-Spark CLI", "fill":1, "font_name": "AHandMadeFont.ttf", "font_size": 22} },
        {"cmd":"device", "params":{"device":"dsp", "act":"refresh"} },
        {"cmd":"delay", "params":{"sec": 0.02} },
        {"cmd":"draw", "params":{"shape":"rect", "x1":-1, "y1":12, "x2":128, "y2":52, "fill":0, "outline":1} },
        {"cmd":"draw", "params":{"shape":"text", "x":3, "y":22, "text":"RPi-Spark CLI", "fill":1, "font_name": "AHandMadeFont.ttf", "font_size": 22} },
        {"cmd":"device", "params":{"device":"dsp", "act":"refresh"} },
        {"cmd":"delay", "params":{"sec": 0.02} },
        {"cmd":"draw", "params":{"shape":"rect", "x1":-1, "y1":8, "x2":128, "y2":56, "fill":0, "outline":1} },
        {"cmd":"draw", "params":{"shape":"text", "x":3, "y":22, "text":"RPi-Spark CLI", "fill":1, "font_name": "AHandMadeFont.ttf", "font_size": 22} },
        {"cmd":"device", "params":{"device":"dsp", "act":"refresh"} },
        {"cmd":"delay", "params":{"sec": 0.02} },
        {"cmd":"draw", "params":{"shape":"rect", "x1":-1, "y1":4, "x2":128, "y2":60, "fill":0, "outline":1} },
        {"cmd":"draw", "params":{"shape":"text", "x":3, "y":22, "text":"RPi-Spark CLI", "fill":1, "font_name": "AHandMadeFont.ttf", "font_size": 22} },
        {"cmd":"device", "params":{"device":"dsp", "act":"refresh"} },
        {"cmd":"delay", "params":{"sec": 0.02} },
        {"cmd":"draw", "params":{"shape":"rect", "x1":-1, "y1":0, "x2":128, "y2":64, "fill":0, "outline":0} },
        {"cmd":"draw", "params":{"shape":"text", "x":3, "y":22, "text":"RPi-Spark CLI", "fill":1, "font_name": "AHandMadeFont.ttf", "font_size": 22} },
        {"cmd":"device", "params":{"device":"dsp", "act":"refresh"} },
        {"cmd":"delay", "params":{"sec": 1} },

        {"cmd":"device", "params":{"device":"dsp", "act":"OFF"} },
        {"cmd":"delay", "params":{"sec": 0.2} },
        {"cmd":"device", "params":{"device":"dsp", "act":"ON"} },
        {"cmd":"delay", "params":{"sec": 0.2} },
        {"cmd":"device", "params":{"device":"dsp", "act":"OFF"} },
        {"cmd":"delay", "params":{"sec": 0.2} },
        {"cmd":"device", "params":{"device":"dsp", "act":"ON"} },
        {"cmd":"delay", "params":{"sec": 1} },

        {"cmd":"device", "params":{"device":"dsp", "act":"clear"} },
        {"cmd":"draw", "params":{"shape":"line", "x1":57, "y1":20, "x2":53, "y2":37, "fill":1, "width":2} },
        {"cmd":"device", "params":{"device":"dsp", "act":"refresh"} },
        {"cmd":"delay", "params":{"sec": 0.05} },
        {"cmd":"draw", "params":{"shape":"line", "x1":53, "y1":37, "x2":60, "y2":38, "fill":1, "width":3} },
        {"cmd":"device", "params":{"device":"dsp", "act":"refresh"} },
        {"cmd":"delay", "params":{"sec": 0.05} },

        {"cmd":"draw", "params":{"shape":"arc", "x1":46, "y1":45, "x2":72, "y2":53, "start":0, "end":180, "fill": 1} },
        {"cmd":"draw", "params":{"shape":"arc", "x1":48, "y1":45, "x2":70, "y2":58, "start":0, "end":180, "fill": 1} },
        {"cmd":"device", "params":{"device":"dsp", "act":"refresh"} },
        {"cmd":"delay", "params":{"sec": 0.05} },

        {"cmd":"draw", "params":{"shape":"ellipse", "x1":32, "y1":8, "x2":48, "y2":26, "fill":1, "outline":1} },
        {"cmd":"draw", "params":{"shape":"circle", "x":40, "y":19, "r":5, "fill":0, "outline":0} },
        {"cmd":"device", "params":{"device":"dsp", "act":"refresh"} },
        {"cmd":"delay", "params":{"sec": 0.05} },

        {"cmd":"draw", "params":{"shape":"ellipse", "x1":70, "y1":8, "x2":85, "y2":26, "fill":1, "outline":1} },
        {"cmd":"draw", "params":{"shape":"circle", "x":76, "y":19, "r":5, "fill":0, "outline":0} },
        {"cmd":"device", "params":{"device":"dsp", "act":"refresh"} },
        {"cmd":"delay", "params":{"sec": 0.05} },

        {"cmd":"draw", "params":{"shape":"ellipse", "x1":32, "y1":8, "x2":48, "y2":26, "fill":1, "outline":1} },
        {"cmd":"draw", "params":{"shape":"circle", "x":39, "y":19, "r":5, "fill":0, "outline":0} },
        {"cmd":"draw", "params":{"shape":"ellipse", "x1":70, "y1":8, "x2":85, "y2":26, "fill":1, "outline":1} },
        {"cmd":"draw", "params":{"shape":"circle", "x":75, "y":19, "r":5, "fill":0, "outline":0} },
        {"cmd":"device", "params":{"device":"dsp", "act":"refresh"} },
        {"cmd":"delay", "params":{"sec": 0.05} },

        {"cmd":"draw", "params":{"shape":"ellipse", "x1":32, "y1":8, "x2":48, "y2":26, "fill":1, "outline":1} },
        {"cmd":"draw", "params":{"shape":"circle", "x":39, "y":18, "r":5, "fill":0, "outline":0} },
        {"cmd":"draw", "params":{"shape":"ellipse", "x1":70, "y1":8, "x2":85, "y2":26, "fill":1, "outline":1} },
        {"cmd":"draw", "params":{"shape":"circle", "x":75, "y":18, "r":5, "fill":0, "outline":0} },
        {"cmd":"device", "params":{"device":"dsp", "act":"refresh"} },
        {"cmd":"delay", "params":{"sec": 0.08} },

        {"cmd":"draw", "params":{"shape":"ellipse", "x1":32, "y1":8, "x2":48, "y2":26, "fill":1, "outline":1} },
        {"cmd":"draw", "params":{"shape":"circle", "x":39, "y":16, "r":5, "fill":0, "outline":0} },
        {"cmd":"draw", "params":{"shape":"ellipse", "x1":70, "y1":8, "x2":85, "y2":26, "fill":1, "outline":1} },
        {"cmd":"draw", "params":{"shape":"circle", "x":75, "y":16, "r":5, "fill":0, "outline":0} },
        {"cmd":"device", "params":{"device":"dsp", "act":"refresh"} },
        {"cmd":"delay", "params":{"sec": 0.08} },

        {"cmd":"draw", "params":{"shape":"ellipse", "x1":32, "y1":8, "x2":48, "y2":26, "fill":1, "outline":1} },
        {"cmd":"draw", "params":{"shape":"circle", "x":39, "y":17, "r":5, "fill":0, "outline":0} },
        {"cmd":"draw", "params":{"shape":"ellipse", "x1":70, "y1":8, "x2":85, "y2":26, "fill":1, "outline":1} },
        {"cmd":"draw", "params":{"shape":"circle", "x":75, "y":17, "r":5, "fill":0, "outline":0} },
        {"cmd":"device", "params":{"device":"dsp", "act":"refresh"} },
        {"cmd":"delay", "params":{"sec": 0.08} },

        {"cmd":"draw", "params":{"shape":"ellipse", "x1":32, "y1":8, "x2":48, "y2":26, "fill":1, "outline":1} },
        {"cmd":"draw", "params":{"shape":"circle", "x":39, "y":19, "r":5, "fill":0, "outline":0} },
        {"cmd":"draw", "params":{"shape":"ellipse", "x1":70, "y1":8, "x2":85, "y2":26, "fill":1, "outline":1} },
        {"cmd":"draw", "params":{"shape":"circle", "x":75, "y":19, "r":5, "fill":0, "outline":0} },
        {"cmd":"device", "params":{"device":"dsp", "act":"refresh"} },
        {"cmd":"delay", "params":{"sec": 0.08} },

        {"cmd":"draw", "params":{"shape":"ellipse", "x1":32, "y1":8, "x2":48, "y2":26, "fill":1, "outline":1} },
        {"cmd":"draw", "params":{"shape":"circle", "x":39, "y":20, "r":5, "fill":0, "outline":0} },
        {"cmd":"draw", "params":{"shape":"ellipse", "x1":70, "y1":8, "x2":85, "y2":26, "fill":1, "outline":1} },
        {"cmd":"draw", "params":{"shape":"circle", "x":75, "y":20, "r":5, "fill":0, "outline":0} },
        {"cmd":"device", "params":{"device":"dsp", "act":"refresh"} },
        {"cmd":"delay", "params":{"sec": 0.08} },

        {"cmd":"draw", "params":{"shape":"ellipse", "x1":32, "y1":8, "x2":48, "y2":26, "fill":1, "outline":1} },
        {"cmd":"draw", "params":{"shape":"circle", "x":40, "y":20, "r":5, "fill":0, "outline":0} },
        {"cmd":"draw", "params":{"shape":"ellipse", "x1":70, "y1":8, "x2":85, "y2":26, "fill":1, "outline":1} },
        {"cmd":"draw", "params":{"shape":"circle", "x":76, "y":20, "r":5, "fill":0, "outline":0} },
        {"cmd":"device", "params":{"device":"dsp", "act":"refresh"} },
        {"cmd":"delay", "params":{"sec": 0.08} },

        {"cmd":"draw", "params":{"shape":"point", "x1":32, "y1":4, "fill":1} },
        {"cmd":"draw", "params":{"shape":"point", "x1":42, "y1":4, "fill":1} },
        {"cmd":"draw", "params":{"shape":"point", "x1":72, "y1":4, "fill":1} },
        {"cmd":"draw", "params":{"shape":"point", "x1":84, "y1":4, "fill":1} },

        {"cmd":"device", "params":{"device":"dsp", "act":"refresh"} },

        {"cmd":"data", "params":{"data":"accel"} },
        {"cmd":"data", "params":{"data":"gyro"} },
        {"cmd":"data", "params":{"data":"temp"} },
        {"cmd":"data", "params":{"data":"key", "keys":["act_a", "act_b", "joy_up"]} }
    ]
}

Save this file and execute the following command in the terminal:

$> cat smiley_face.json | rpi-spark

At this time you should see the following smiley face animation on your RPi-Spark.


 

Was this article helpful?

YES     |     NO

 

Enjoying the project? Spotted a mistake? Any opinions on the website? Let us know!