APA102: Initial implementation

Signed-off-by: Yannick Adam <yannick.adam@gmail.com>
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
This commit is contained in:
Jeako
2016-03-01 20:10:17 +01:00
committed by Abhishek Malik
parent 42ff8b3a6e
commit 9fb4be1b44
13 changed files with 576 additions and 1 deletions

View File

@ -250,6 +250,7 @@ add_example (si7005)
add_example (t6713)
add_example (cwlsxxa)
add_example (teams)
add_example (apa102)
# These are special cases where you specify example binary, source file and module(s)
include_directories (${PROJECT_SOURCE_DIR}/src)

51
examples/c++/apa102.cxx Normal file
View File

@ -0,0 +1,51 @@
/*
* Author: Yannick Adam <yannick.adam@gmail.com>
* Copyright (c) 2016 Yannick Adam
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "apa102.h"
#include <iostream>
#include <signal.h>
#include <unistd.h>
using namespace std;
int
main(int argc, char** argv)
{
//! [Interesting]
// Instantiate a strip of 30 LEDs on SPI bus 0
upm::APA102* ledStrip = new upm::APA102(800, 0);
// Set all LEDs to Red
ledStrip->setAllLeds(31, 255, 0, 0);
// Set a section (10 to 20) to blue
ledStrip->setLeds(10, 20, 31, 0, 0, 255);
// Set a single LED to green
ledStrip->setLed(15, 31, 0, 255, 0);
delete ledStrip;
//! [Interesting]
return 0;
}

View File

@ -0,0 +1,44 @@
/*
* Author: Yannick Adam <yannick.adam@gmail.com>
* Copyright (c) 2016 Yannick Adam
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
public class APA102Sample {
public static void main(String[] args) throws InterruptedException {
// ! [Interesting]
// Instantiate a strip of 30 LEDs on SPI bus 0
upm_apa102.APA102 ledStrip =
new upm_apa102.APA102(30, (short)0, false, (byte)-1);
System.out.println("Set all LEDs to blue");
ledStrip.setAllLeds((short)31, (short)0, (short)0, (short)255);
System.out.println("Set LEDs between 10 and 20 to green");
ledStrip.setLeds(10, 20, (short)31, (short)0, (short)255, (short)0);
System.out.println("Set a single LED to red at index 15");
ledStrip.setLed(15, (short)31, (short)255, (short)0, (short)0);
// ! [Interesting]
}
}

View File

@ -107,7 +107,7 @@ add_example(Th02Example th02)
add_example(FlexSensorExample flex)
add_example(CWLSXXA_Example cwlsxxa)
add_example(TEAMS_Example teams)
add_example(APA102Sample apa102)
add_example_with_path(Jhd1313m1_lcdSample lcd/upm_i2clcd.jar)
add_example_with_path(Jhd1313m1Sample lcd/upm_i2clcd.jar)

View File

@ -0,0 +1,44 @@
/*jslint node:true, vars:true, bitwise:true, unparam:true */
/*jshint unused:true */
/*
* Author: Yannick Adam <yannick.adam@gmail.com>
* Copyright (c) 2016 Yannick Adam
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
var lib = require('jsupm_apa102');
// Instantiate a strip of 30 LEDs on SPI Bus 0
var ledStrip = new lib.APA102(30, 0);
// Set all LEDs to blue
ledStrip.setAllLeds(31, 0, 0, 255);
// Set a mid-section to red
ledStrip.setLeds(10,20, 31, 255, 0, 0);
// Set a single led to green
ledStrip.setLed(15, 31, 0, 255, 0);
// Exit
ledStrip = null;
process.exit(0);

48
examples/python/apa102.py Normal file
View File

@ -0,0 +1,48 @@
#!/usr/bin/python
# Author: Yannick Adam <yannick.adam@gmail.com>
# Copyright (c) 2016 Yannick Adam
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import time, sys, signal, atexit
import pyupm_apa102 as mylib
# Instantiate a strip of 30 LEDs on SPI bus 0
ledStrip = mylib.APA102(30, 0, False)
## Exit handlers ##
# This stops python from printing a stacktrace when you hit control-C
def SIGINTHandler(signum, frame):
raise SystemExit
# Register exit handlers
signal.signal(signal.SIGINT, SIGINTHandler)
print "Setting all LEDs to Green"
ledStrip.setAllLeds(31, 0, 255, 0)
print "Setting LEDs between 10 and 20 to Red"
ledStrip.setLeds(10, 20, 31, 255, 0, 0)
print "Setting LED 15 to Blue"
ledStrip.setLed(15, 31, 0, 0, 255)