Browse Source

APA102: Initial implementation

Signed-off-by: Yannick Adam <yannick.adam@gmail.com>
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
Jeako 8 years ago
parent
commit
9fb4be1b44

BIN
docs/images/apa102.jpg View File


+ 1
- 0
examples/c++/CMakeLists.txt View File

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

+ 51
- 0
examples/c++/apa102.cxx View File

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

+ 44
- 0
examples/java/APA102Sample.java View File

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

+ 1
- 1
examples/java/CMakeLists.txt View File

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

+ 44
- 0
examples/javascript/apa102.js View File

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

+ 48
- 0
examples/python/apa102.py View File

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

+ 5
- 0
src/apa102/CMakeLists.txt View File

@@ -0,0 +1,5 @@
1
+set (libname "apa102")
2
+set (libdescription "upm apa102 led strip spi output module")
3
+set (module_src ${libname}.cxx)
4
+set (module_h ${libname}.h)
5
+upm_module_init()

+ 166
- 0
src/apa102/apa102.cxx View File

@@ -0,0 +1,166 @@
1
+/*
2
+ * Author: Yannick Adam <yannick.adam@gmail.com>
3
+ * Copyright (c) 2016 Yannick Adam
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining
6
+ * a copy of this software and associated documentation files (the
7
+ * "Software"), to deal in the Software without restriction, including
8
+ * without limitation the rights to use, copy, modify, merge, publish,
9
+ * distribute, sublicense, and/or sell copies of the Software, and to
10
+ * permit persons to whom the Software is furnished to do so, subject to
11
+ * the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be
14
+ * included in all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ */
24
+
25
+#include <cstring>
26
+#include <iostream>
27
+#include <stdexcept>
28
+#include <stdlib.h>
29
+#include <unistd.h>
30
+
31
+#include "apa102.h"
32
+
33
+using namespace upm;
34
+
35
+APA102::APA102(uint16_t ledCount, uint8_t spiBus, bool batchMode, int8_t csn)
36
+        : m_ledCount(ledCount), m_batchMode(batchMode)
37
+{
38
+    mraa::Result res = mraa::SUCCESS;
39
+    m_leds = NULL;
40
+
41
+    // Optional chip select pin
42
+    m_csnPinCtx = NULL;
43
+    if (csn > -1) {
44
+        m_csnPinCtx = new mraa::Gpio(csn);
45
+        res = m_csnPinCtx->dir(mraa::DIR_OUT);
46
+        if (res != mraa::SUCCESS) {
47
+            throw std::invalid_argument(std::string(__FUNCTION__) +
48
+                                        ": GPIO failed to set direction");
49
+        }
50
+    }
51
+
52
+    CSOff();
53
+    // Initialize SPI
54
+    m_spi = new mraa::Spi(spiBus);
55
+
56
+    // Initialize LED array
57
+    uint16_t endFrameLength = (m_ledCount + 15) / 16; // End frame should be (leds/2) bits
58
+    m_frameLength = endFrameLength + (m_ledCount + 1) * 4;
59
+    if ((m_leds = (uint8_t*) malloc(m_frameLength))) {
60
+        memset(m_leds, 0x00, m_frameLength - 4);                               // Clear state
61
+        memset(&m_leds[m_frameLength - endFrameLength], 0xFF, endFrameLength); // Frame End
62
+
63
+        // Need to set the brightness to "0" for each Led
64
+        for (int i = 1; i <= m_ledCount; i++) {
65
+            m_leds[i * 4] = 224;
66
+        }
67
+
68
+    } else {
69
+        throw std::runtime_error(std::string(__FUNCTION__) +
70
+                                 ": Failed to allocate memory for LED Strip");
71
+    }
72
+}
73
+
74
+APA102::~APA102()
75
+{
76
+    // Clear leds
77
+    if (m_leds) {
78
+        free(m_leds);
79
+    }
80
+
81
+    // Clear SPI
82
+    if (m_spi) {
83
+        delete m_spi;
84
+    }
85
+
86
+    // Clear GPIO
87
+    if (m_csnPinCtx) {
88
+        delete m_csnPinCtx;
89
+    }
90
+}
91
+
92
+
93
+void
94
+APA102::setLed(uint16_t ledIdx, uint8_t brightness, uint8_t r, uint8_t g, uint8_t b)
95
+{
96
+    setLeds(ledIdx, ledIdx, brightness, r, g, b);
97
+}
98
+
99
+void
100
+APA102::setAllLeds(uint8_t brightness, uint8_t r, uint8_t g, uint8_t b)
101
+{
102
+    setLeds(0, m_ledCount - 1, brightness, r, g, b);
103
+}
104
+
105
+void
106
+APA102::setLeds(uint16_t startIdx, uint16_t endIdx, uint8_t brightness, uint8_t r, uint8_t g, uint8_t b)
107
+{
108
+    uint16_t s_idx = (startIdx + 1) * 4;
109
+    uint16_t e_idx = (endIdx + 1) * 4;
110
+
111
+    for (uint16_t i = s_idx; i <= e_idx; i += 4) {
112
+        m_leds[i] = brightness | 224;
113
+        m_leds[i + 1] = b;
114
+        m_leds[i + 2] = g;
115
+        m_leds[i + 3] = r;
116
+    }
117
+
118
+    if (!m_batchMode) {
119
+        pushState();
120
+    }
121
+}
122
+
123
+void
124
+APA102::setLeds(uint16_t startIdx, uint16_t endIdx, uint8_t* colors)
125
+{
126
+    uint16_t s_idx = (startIdx + 1) * 4;
127
+    memcpy(&m_leds[s_idx], colors, (endIdx - startIdx + 1) * 4);
128
+
129
+    if (!m_batchMode) {
130
+        pushState();
131
+    }
132
+}
133
+
134
+void
135
+APA102::pushState(void)
136
+{
137
+    CSOn();
138
+    m_spi->write(m_leds, m_frameLength);
139
+    CSOff();
140
+}
141
+
142
+/*
143
+ * **************
144
+ *  private area
145
+ * **************
146
+ */
147
+
148
+mraa::Result
149
+APA102::CSOn()
150
+{
151
+    if (m_csnPinCtx) {
152
+        return m_csnPinCtx->write(HIGH);
153
+    }
154
+
155
+    return mraa::ERROR_FEATURE_NOT_SUPPORTED;
156
+}
157
+
158
+mraa::Result
159
+APA102::CSOff()
160
+{
161
+    if (m_csnPinCtx) {
162
+        return m_csnPinCtx->write(LOW);
163
+    }
164
+
165
+    return mraa::ERROR_FEATURE_NOT_SUPPORTED;
166
+}

+ 142
- 0
src/apa102/apa102.h View File

@@ -0,0 +1,142 @@
1
+/*
2
+ * Author: Yannick Adam <yannick.adam@gmail.com>
3
+ * Copyright (c) 2016 Yannick Adam
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining
6
+ * a copy of this software and associated documentation files (the
7
+ * "Software"), to deal in the Software without restriction, including
8
+ * without limitation the rights to use, copy, modify, merge, publish,
9
+ * distribute, sublicense, and/or sell copies of the Software, and to
10
+ * permit persons to whom the Software is furnished to do so, subject to
11
+ * the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be
14
+ * included in all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ */
24
+#pragma once
25
+
26
+#include <mraa/gpio.hpp>
27
+#include <mraa/spi.hpp>
28
+#include <string>
29
+
30
+#define HIGH 1
31
+#define LOW 0
32
+
33
+namespace upm
34
+{
35
+/**
36
+ * @brief APA102 RGB LED Strip driver library
37
+ * @defgroup apa102 libupm-apa102
38
+ * @ingroup spi led
39
+ */
40
+
41
+/**
42
+ * @library apa102
43
+ * @sensor apa102
44
+ * @comname APA102/DotStar LED Strip
45
+ * @type led
46
+ * @man adafruit
47
+ * @con spi
48
+ *
49
+ * @brief API for controlling APA102/DotStar RGB LED Strips
50
+ *
51
+ * APA102 LED Strips provide individually controllable LEDs through a SPI interface.
52
+ * For each LED, brightness (0-31) and RGB (0-255) values can be set.
53
+ *
54
+ * @image html apa102.jpg
55
+ */
56
+class APA102
57
+{
58
+  public:
59
+    /**
60
+     * Instantiates a new APA102 LED Strip
61
+     *
62
+     * @param ledCount 	Number of APA102 leds in the strip
63
+     * @param spiBus 	SPI Bus number
64
+     * @param batchMode (optional) Immediatly write to SPI (false, default) or wait for a pushState
65
+     * call (true)
66
+     * @param csn 		(optional) Chip Select Pin
67
+     */
68
+    APA102(uint16_t ledCount, uint8_t spiBus, bool batchMode = false, int8_t csn = -1);
69
+
70
+    /**
71
+     * APA102 destructor
72
+     */
73
+    ~APA102();
74
+
75
+    /**
76
+     * Change the color for a single led
77
+     *
78
+     * @param ledIdx		Index of the LED in the strip (0 based)
79
+     * @param brightness	Brightness value (0-31)
80
+     * @param r				Red component (0-255)
81
+     * @param g				Green component (0-255)
82
+     * @param b				Blue component (0-255)
83
+     */
84
+    void setLed(uint16_t ledIdx, uint8_t brightness, uint8_t r, uint8_t g, uint8_t b);
85
+
86
+    /**
87
+     * Change the color for all leds
88
+     *
89
+     * @param brightness	Brightness value (0-31)
90
+     * @param r				Red component (0-255)
91
+     * @param g				Green component (0-255)
92
+     * @param b				Blue component (0-255)
93
+     */
94
+    void setAllLeds(uint8_t brightness, uint8_t r, uint8_t g, uint8_t b);
95
+
96
+    /**
97
+     * Change the color for a range of leds
98
+     *
99
+     * @param startIdx		Start index of the range of LEDs in the strip (0 based)
100
+     * @param endIdx		End index of the range of LEDs in the strip (0 based)
101
+     * @param brightness	Brightness value (0-31)
102
+     * @param r				Red component (0-255)
103
+     * @param g				Green component (0-255)
104
+     * @param b				Blue component (0-255)
105
+     */
106
+    void
107
+    setLeds(uint16_t startIdx, uint16_t endIdx, uint8_t brightness, uint8_t r, uint8_t g, uint8_t b);
108
+
109
+    /**
110
+     * (Advanced) Manually control the colors of a range of LEDS
111
+     * Best used to maximize performance
112
+     *
113
+     * @param startIdx		Start index of the range of LEDs to update (0 based)
114
+     * @param endIdx		End index of the range of LEDs to update (0 based)
115
+     * @param colors		Pointer to an array of bytes. Each color is described as the following:
116
+     *						B1: Brightness (224-255) B2: Blue (0-255) B3: Green (0-255) B4: Red
117
+     *(0-255)
118
+     *						No check done on the boundaries
119
+     */
120
+    void setLeds(uint16_t startIdx, uint16_t endIdx, uint8_t* colors);
121
+
122
+    /**
123
+     * Outputs the current LED data to the SPI bus
124
+     * Note: Only required if batch mode is set to TRUE
125
+     *
126
+     */
127
+    void pushState();
128
+
129
+  private:
130
+    mraa::Spi* m_spi;
131
+    mraa::Gpio* m_csnPinCtx;
132
+
133
+    uint16_t m_ledCount;
134
+    uint8_t* m_leds;
135
+    uint16_t m_frameLength;
136
+
137
+    bool m_batchMode;
138
+
139
+    mraa::Result CSOn();
140
+    mraa::Result CSOff();
141
+};
142
+}

+ 30
- 0
src/apa102/javaupm_apa102.i View File

@@ -0,0 +1,30 @@
1
+%module javaupm_apa102
2
+
3
+%include "../upm.i"
4
+%include "typemaps.i"
5
+
6
+%typemap(jtype) (uint8_t *colors) "byte[]"
7
+%typemap(jstype) (uint8_t *colors) "byte[]"
8
+%typemap(jni) (uint8_t *colors) "jbyteArray"
9
+%typemap(javain) (uint8_t *colors) "$javainput"
10
+
11
+%typemap(in) (uint8_t *colors) {
12
+  $1 = (uint8_t*)JCALL2(GetByteArrayElements, jenv, $input, NULL);
13
+}
14
+
15
+%{
16
+    #include "apa102.h"
17
+%}
18
+
19
+%include "apa102.h"
20
+
21
+%pragma(java) jniclasscode=%{
22
+    static {
23
+        try {
24
+            System.loadLibrary("javaupm_apa102");
25
+        } catch (UnsatisfiedLinkError e) {
26
+            System.err.println("Native code library failed to load. \n" + e);
27
+            System.exit(1);
28
+        }
29
+    }
30
+%}

+ 19
- 0
src/apa102/jsupm_apa102.i View File

@@ -0,0 +1,19 @@
1
+%module jsupm_apa102
2
+ 
3
+%include "../upm.i"
4
+%inline %{
5
+    #include <node_buffer.h>
6
+%}
7
+
8
+%typemap(in) (uint8_t *colors) {
9
+  if (!node::Buffer::HasInstance($input)) {
10
+      SWIG_exception_fail(SWIG_ERROR, "Expected a node Buffer");
11
+  }
12
+  $1 = (uint8_t*) node::Buffer::Data($input);
13
+}
14
+
15
+%include "apa102.h" 
16
+
17
+%{
18
+    #include "apa102.h"
19
+%}

+ 25
- 0
src/apa102/pyupm_apa102.i View File

@@ -0,0 +1,25 @@
1
+// Include doxygen-generated documentation
2
+%include "pyupm_doxy2swig.i"
3
+ 
4
+%module pyupm_apa102
5
+ 
6
+%include "../upm.i"
7
+ 
8
+%feature("autodoc", "3");
9
+ 
10
+// setLeds 
11
+%typemap(in) (uint8_t *colors) {
12
+  if (PyByteArray_Check($input)) {
13
+    $1 = (uint8_t*) PyByteArray_AsString($input);
14
+  } else {
15
+    PyErr_SetString(PyExc_ValueError, "bytearray expected");
16
+    return NULL;
17
+  }
18
+}
19
+ 
20
+%include "apa102.h"
21
+ 
22
+%{
23
+ 
24
+    #include "apa102.h"
25
+%}